Update tests for cmake
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ configure_file (
|
|||||||
file(GLOB SOURCE_FILES *.c)
|
file(GLOB SOURCE_FILES *.c)
|
||||||
|
|
||||||
add_library(
|
add_library(
|
||||||
ucore SHARED
|
ucore SHARED
|
||||||
${SOURCE_FILES}
|
${SOURCE_FILES}
|
||||||
"${PROJECT_BINARY_DIR}/src/version.c"
|
"${PROJECT_BINARY_DIR}/src/version.c"
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -10,6 +10,6 @@ endif()
|
|||||||
add_executable(test_runner ${TEST_SOURCE_FILES})
|
add_executable(test_runner ${TEST_SOURCE_FILES})
|
||||||
target_link_libraries(test_runner check ucore)
|
target_link_libraries(test_runner check ucore)
|
||||||
|
|
||||||
add_custom_target(runtest COMMAND test_runner
|
add_custom_target(test COMMAND test_runner
|
||||||
DEPENDS test_runner
|
DEPENDS test_runner
|
||||||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
|
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
|
||||||
|
|||||||
+5
-6
@@ -61,7 +61,7 @@ START_TEST (test_gbuf_printf1)
|
|||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d", 1);
|
rc = uc_gbuf_printf(buf, "test %d", 1);
|
||||||
fail_if(rc != 6, "rc was %d", rc);
|
fail_if(rc != 6, "rc was %d", rc);
|
||||||
fail_if(buf->used != 6, "buf->used was %d", buf->used);
|
fail_if(buf->used != 6, "buf->used was %zu", buf->used);
|
||||||
fail_if(strcmp("test 1", buf->buf) != 0);
|
fail_if(strcmp("test 1", buf->buf) != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ START_TEST (test_gbuf_printf2)
|
|||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
||||||
fail_if(rc != 20, "rc was %d", rc);
|
fail_if(rc != 20, "rc was %d", rc);
|
||||||
fail_if(buf->used != 20, "buf->used was %d", buf->used);
|
fail_if(buf->used != 20, "buf->used was %zu", buf->used);
|
||||||
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|
||||||
@@ -93,13 +93,13 @@ START_TEST (test_gbuf_printf3)
|
|||||||
|
|
||||||
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
rc = uc_gbuf_printf(buf, "test %d test %d test %d", 1, 2, 3);
|
||||||
fail_if(rc != 20, "rc was %d", rc);
|
fail_if(rc != 20, "rc was %d", rc);
|
||||||
fail_if(buf->used != 20, "buf->used was %d", buf->used);
|
fail_if(buf->used != 20, "buf->used was %zu", buf->used);
|
||||||
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
fail_if(strcmp("test 1 test 2 test 3", buf->buf) != 0);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, " test %d test %d", 4, 5);
|
rc = uc_gbuf_printf(buf, " test %d test %d", 4, 5);
|
||||||
|
|
||||||
fail_if(rc != 14, "rc was %d", rc);
|
fail_if(rc != 14, "rc was %d", rc);
|
||||||
fail_if(buf->used != 34, "buf->used was %d", buf->used);
|
fail_if(buf->used != 34, "buf->used was %zu", buf->used);
|
||||||
fail_if(strcmp("test 1 test 2 test 3 test 4 test 5", buf->buf) != 0);
|
fail_if(strcmp("test 1 test 2 test 3 test 4 test 5", buf->buf) != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|
||||||
@@ -110,11 +110,10 @@ START_TEST (test_gbuf_printf_empty_string)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
GBuf *buf = uc_new_gbuf(1);
|
GBuf *buf = uc_new_gbuf(1);
|
||||||
const char *fmt = ""; //tricks gcc to not warn about empty format string
|
|
||||||
|
|
||||||
fail_if(buf == NULL);
|
fail_if(buf == NULL);
|
||||||
|
|
||||||
rc = uc_gbuf_printf(buf, fmt);
|
rc = uc_gbuf_printf(buf, "");
|
||||||
fail_if(rc != 0);
|
fail_if(rc != 0);
|
||||||
fail_if(buf->used != 0);
|
fail_if(buf->used != 0);
|
||||||
uc_gbuf_unref(buf);
|
uc_gbuf_unref(buf);
|
||||||
|
|||||||
+16
-17
@@ -10,7 +10,7 @@
|
|||||||
#define FILE_NAME "logfile_test.log"
|
#define FILE_NAME "logfile_test.log"
|
||||||
#define SUBDIR "log_subdir"
|
#define SUBDIR "log_subdir"
|
||||||
#define SUBDIR_FILE_NAME SUBDIR "/" FILE_NAME
|
#define SUBDIR_FILE_NAME SUBDIR "/" FILE_NAME
|
||||||
//Note that these tests are comewhat fragile as they depend on the
|
//Note that these tests are comewhat fragile as they depend on the
|
||||||
//file sizes that are created, which depends on the (relative)paths of this file.
|
//file sizes that are created, which depends on the (relative)paths of this file.
|
||||||
//for cleaning the created log files..
|
//for cleaning the created log files..
|
||||||
static void logging_rm_files(void)
|
static void logging_rm_files(void)
|
||||||
@@ -62,7 +62,6 @@ START_TEST (test_logfile_location)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
|
|
||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
uc_log_add_destination(dest); //adding this twice should do nothing
|
uc_log_add_destination(dest); //adding this twice should do nothing
|
||||||
@@ -98,7 +97,7 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 260, "was %ld", (long)st.st_size);
|
||||||
|
|
||||||
uc_log_delete_destination(dest);
|
uc_log_delete_destination(dest);
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ START_TEST (test_logfile_delete_destination)
|
|||||||
//since we deleted destinatiion, no more logging should appear in the file
|
//since we deleted destinatiion, no more logging should appear in the file
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 380, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 260, "was %ld", (long)st.st_size);
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -169,7 +168,7 @@ START_TEST (test_logfile_loglevel_surpressed_dest)
|
|||||||
|
|
||||||
|
|
||||||
//file destination have UC_LL_WARNING, so nothing should be logged
|
//file destination have UC_LL_WARNING, so nothing should be logged
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_WARNING, 10);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_WARNING, 10);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
|
|
||||||
@@ -203,7 +202,7 @@ START_TEST (test_logfile_loglevel_surpressed_module)
|
|||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
|
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
|
|
||||||
@@ -235,7 +234,7 @@ START_TEST (test_logfile_reopen_files)
|
|||||||
|
|
||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest == NULL);
|
fail_if(dest == NULL);
|
||||||
uc_log_add_destination(dest);
|
uc_log_add_destination(dest);
|
||||||
|
|
||||||
@@ -244,11 +243,11 @@ START_TEST (test_logfile_reopen_files)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 104, "was %ld", (long)st.st_size);
|
||||||
|
|
||||||
rc = remove(FILE_NAME);
|
rc = remove(FILE_NAME);
|
||||||
fail_if(rc != 0, "Remove failed %s", strerror(errno));
|
fail_if(rc != 0, "Remove failed %s", strerror(errno));
|
||||||
|
|
||||||
rc = uc_log_reopen_files();
|
rc = uc_log_reopen_files();
|
||||||
fail_if(rc != 0, "uc_log_reopen_files failed: %d", rc);
|
fail_if(rc != 0, "uc_log_reopen_files failed: %d", rc);
|
||||||
|
|
||||||
@@ -256,7 +255,7 @@ START_TEST (test_logfile_reopen_files)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 77, "was %ld", (long)st.st_size);//should only one line there now
|
fail_if(st.st_size != 52, "was %ld", (long)st.st_size);//should only one line there now
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
@@ -281,10 +280,10 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
uc_log_init(&mods);
|
uc_log_init(&mods);
|
||||||
|
|
||||||
|
|
||||||
dest1 = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 1);
|
dest1 = uc_log_new_file(FILE_NAME, UC_LL_DEBUG, 0);
|
||||||
fail_if(dest1 == NULL);
|
fail_if(dest1 == NULL);
|
||||||
|
|
||||||
dest2 = uc_log_new_stderr(UC_LL_WARNING, 1);
|
dest2 = uc_log_new_stderr(UC_LL_WARNING, 0);
|
||||||
fail_if(dest2 == NULL);
|
fail_if(dest2 == NULL);
|
||||||
|
|
||||||
uc_log_add_destination(dest1);
|
uc_log_add_destination(dest1);
|
||||||
@@ -295,7 +294,7 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);
|
fail_if(st.st_size != 104, "was %ld", (long)st.st_size);
|
||||||
|
|
||||||
uc_log_remove_destination(dest1);
|
uc_log_remove_destination(dest1);
|
||||||
|
|
||||||
@@ -303,16 +302,16 @@ START_TEST (test_logfile_remove_dest)
|
|||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
|
fail_if(st.st_size != 104, "was %ld", (long)st.st_size);//should be same size
|
||||||
|
|
||||||
//removing the last destination should be fine too
|
//removing the last destination should be fine too
|
||||||
uc_log_remove_destination(dest2);
|
uc_log_remove_destination(dest2);
|
||||||
|
|
||||||
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d", 1);
|
||||||
|
|
||||||
rc = stat(FILE_NAME, &st);
|
rc = stat(FILE_NAME, &st);
|
||||||
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
fail_if(rc != 0, "2. stat failed: %s", strerror(errno));
|
||||||
fail_if(st.st_size != 77*2, "was %ld", (long)st.st_size);//should be same size
|
fail_if(st.st_size != 104, "was %ld", (long)st.st_size);//should be same size
|
||||||
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|||||||
Reference in New Issue
Block a user