|
|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <assert.h> |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_utils.h" |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
@ -69,6 +70,42 @@ static void cleanup_temp_config(void) {
|
|
|
|
|
if (temp_dir[0]) test_rmdir(temp_dir); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Все категории, включая последние в списке, сохраняются при чтении файла и текста.
|
|
|
|
|
static void test_all_debug_categories(void) { |
|
|
|
|
char text[4096]; |
|
|
|
|
int length = snprintf(text, sizeof(text), "%s\n[debug]\n", config_content); |
|
|
|
|
int count = 0; |
|
|
|
|
for (int category = 1; category < DEBUG_CATEGORY_COUNT; category++) { |
|
|
|
|
const char* name = debug_get_category_name(category); |
|
|
|
|
if (strcmp(name, "UNKNOWN") == 0) continue; |
|
|
|
|
int written = snprintf(text + length, sizeof(text) - length, "%s=%s\n", name, category == DEBUG_CATEGORY_SYS ? "disabled" : "debug"); |
|
|
|
|
assert(written > 0 && written < (int)sizeof(text) - length); |
|
|
|
|
length += written; count++; |
|
|
|
|
} |
|
|
|
|
assert(count > 16); |
|
|
|
|
FILE* file = fopen(config_path, "w"); |
|
|
|
|
assert(file); |
|
|
|
|
assert(fwrite(text, 1, length, file) == (size_t)length); |
|
|
|
|
assert(fclose(file) == 0); |
|
|
|
|
struct utun_config* configs[2] = {parse_config(config_path), parse_config_from_buf(text, length, "debug-categories")}; |
|
|
|
|
for (int parser = 0; parser < 2; parser++) { |
|
|
|
|
struct utun_config* config = configs[parser]; |
|
|
|
|
assert(config && config->global.debug_levels.count == count); |
|
|
|
|
assert(strcmp(config->global.debug_level, "debug") == 0); |
|
|
|
|
int index = 0; |
|
|
|
|
for (int category = 1; category < DEBUG_CATEGORY_COUNT; category++) { |
|
|
|
|
const char* name = debug_get_category_name(category); |
|
|
|
|
if (strcmp(name, "UNKNOWN") == 0) continue; |
|
|
|
|
assert(strcmp(config->global.debug_levels.category[index], name) == 0); |
|
|
|
|
debug_config_init(); |
|
|
|
|
assert(debug_apply_category_config(name, config->global.debug_levels.level[index++]) == 0); |
|
|
|
|
assert(debug_should_output(DEBUG_LEVEL_DEBUG, category) == (category != DEBUG_CATEGORY_SYS)); |
|
|
|
|
} |
|
|
|
|
free_config(config); |
|
|
|
|
} |
|
|
|
|
printf("All %d debug categories preserved by file and buffer parsers\n", count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
// Initialize socket platform (required for getaddrinfo on Windows)
|
|
|
|
|
if (socket_platform_init() != 0) { |
|
|
|
|
@ -126,6 +163,7 @@ int main() {
|
|
|
|
|
|
|
|
|
|
// Освобождение ресурсов
|
|
|
|
|
free_config(config); |
|
|
|
|
test_all_debug_categories(); |
|
|
|
|
|
|
|
|
|
// Cleanup temp config file
|
|
|
|
|
cleanup_temp_config(); |
|
|
|
|
@ -135,4 +173,4 @@ int main() {
|
|
|
|
|
|
|
|
|
|
socket_platform_cleanup(); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|