diff options
Diffstat (limited to 'contrib/ntp/sntp/tests')
-rw-r--r-- | contrib/ntp/sntp/tests/keyFile.c | 31 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/kodDatabase.c | 2 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/kodFile.c | 1 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/run-kodDatabase.c | 11 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/run-t-log.c | 6 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/t-log.c | 55 | ||||
-rw-r--r-- | contrib/ntp/sntp/tests/utilities.c | 4 |
7 files changed, 73 insertions, 37 deletions
diff --git a/contrib/ntp/sntp/tests/keyFile.c b/contrib/ntp/sntp/tests/keyFile.c index 77dfee7..883658a 100644 --- a/contrib/ntp/sntp/tests/keyFile.c +++ b/contrib/ntp/sntp/tests/keyFile.c @@ -62,20 +62,27 @@ CompareKeysAlternative(int key_id, void test_ReadEmptyKeyFile(void) { struct key* keys = NULL; + const char *path = CreatePath("key-test-empty", INPUT_DIR); - TEST_ASSERT_EQUAL(0, auth_init(CreatePath("key-test-empty", INPUT_DIR), &keys)); + TEST_ASSERT_NOT_NULL(path); + TEST_ASSERT_EQUAL(0, auth_init(path, &keys)); TEST_ASSERT_NULL(keys); + + free((void *)path); } void test_ReadASCIIKeys(void) { struct key* keys = NULL; + const char *path = CreatePath("key-test-ascii", INPUT_DIR); - TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-ascii", INPUT_DIR), &keys)); - + TEST_ASSERT_NOT_NULL(path); + TEST_ASSERT_EQUAL(2, auth_init(path, &keys)); TEST_ASSERT_NOT_NULL(keys); + free((void *)path); + struct key* result = NULL; get_key(40, &result); TEST_ASSERT_NOT_NULL(result); @@ -91,10 +98,12 @@ test_ReadASCIIKeys(void) { void test_ReadHexKeys(void) { struct key* keys = NULL; + const char *path = CreatePath("key-test-hex", INPUT_DIR); - TEST_ASSERT_EQUAL(3, auth_init(CreatePath("key-test-hex", INPUT_DIR), &keys)); - + TEST_ASSERT_NOT_NULL(path); + TEST_ASSERT_EQUAL(3, auth_init(path, &keys)); TEST_ASSERT_NOT_NULL(keys); + free((void *)path); struct key* result = NULL; get_key(10, &result); @@ -119,10 +128,12 @@ test_ReadHexKeys(void) { void test_ReadKeyFileWithComments(void) { struct key* keys = NULL; + const char *path = CreatePath("key-test-comments", INPUT_DIR); - TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-comments", INPUT_DIR), &keys)); - + TEST_ASSERT_NOT_NULL(path); + TEST_ASSERT_EQUAL(2, auth_init(path, &keys)); TEST_ASSERT_NOT_NULL(keys); + free((void *)path); struct key* result = NULL; get_key(10, &result); @@ -140,10 +151,12 @@ test_ReadKeyFileWithComments(void) { void test_ReadKeyFileWithInvalidHex(void) { struct key* keys = NULL; + const char *path = CreatePath("key-test-invalid-hex", INPUT_DIR); - TEST_ASSERT_EQUAL(1, auth_init(CreatePath("key-test-invalid-hex", INPUT_DIR), &keys)); - + TEST_ASSERT_NOT_NULL(path); + TEST_ASSERT_EQUAL(1, auth_init(path, &keys)); TEST_ASSERT_NOT_NULL(keys); + free((void *)path); struct key* result = NULL; get_key(10, &result); diff --git a/contrib/ntp/sntp/tests/kodDatabase.c b/contrib/ntp/sntp/tests/kodDatabase.c index 0c3615d..3c05694 100644 --- a/contrib/ntp/sntp/tests/kodDatabase.c +++ b/contrib/ntp/sntp/tests/kodDatabase.c @@ -1,5 +1,6 @@ #include "config.h" +#include "ntp_workimpl.h" #include "ntp_types.h" #include "sntptest.h" #include "ntp_stdlib.h" @@ -20,6 +21,7 @@ void test_DeleteEntry(void); void setUp(void) { kod_init_kod_db("/dev/null", TRUE); + init_lib(); } diff --git a/contrib/ntp/sntp/tests/kodFile.c b/contrib/ntp/sntp/tests/kodFile.c index 6eb0971..f99d8cf 100644 --- a/contrib/ntp/sntp/tests/kodFile.c +++ b/contrib/ntp/sntp/tests/kodFile.c @@ -28,6 +28,7 @@ void setUp(void) { kod_db_cnt = 0; kod_db = NULL; + init_lib(); } diff --git a/contrib/ntp/sntp/tests/run-kodDatabase.c b/contrib/ntp/sntp/tests/run-kodDatabase.c index e5bf3d7..f655a6a 100644 --- a/contrib/ntp/sntp/tests/run-kodDatabase.c +++ b/contrib/ntp/sntp/tests/run-kodDatabase.c @@ -23,6 +23,7 @@ #include <setjmp.h> #include <stdio.h> #include "config.h" +#include "ntp_workimpl.h" #include "ntp_types.h" #include "sntptest.h" #include "ntp_stdlib.h" @@ -56,11 +57,11 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("kodDatabase.c"); - RUN_TEST(test_SingleEntryHandling, 13); - RUN_TEST(test_MultipleEntryHandling, 14); - RUN_TEST(test_NoMatchInSearch, 15); - RUN_TEST(test_AddDuplicate, 16); - RUN_TEST(test_DeleteEntry, 17); + RUN_TEST(test_SingleEntryHandling, 14); + RUN_TEST(test_MultipleEntryHandling, 15); + RUN_TEST(test_NoMatchInSearch, 16); + RUN_TEST(test_AddDuplicate, 17); + RUN_TEST(test_DeleteEntry, 18); return (UnityEnd()); } diff --git a/contrib/ntp/sntp/tests/run-t-log.c b/contrib/ntp/sntp/tests/run-t-log.c index dc9fa04..8d12345 100644 --- a/contrib/ntp/sntp/tests/run-t-log.c +++ b/contrib/ntp/sntp/tests/run-t-log.c @@ -49,9 +49,9 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("t-log.c"); - RUN_TEST(testChangePrognameInMysyslog, 9); - RUN_TEST(testOpenLogfileTest, 10); - RUN_TEST(testWriteInCustomLogfile, 35); + RUN_TEST(testChangePrognameInMysyslog, 10); + RUN_TEST(testOpenLogfileTest, 11); + RUN_TEST(testWriteInCustomLogfile, 12); return (UnityEnd()); } diff --git a/contrib/ntp/sntp/tests/t-log.c b/contrib/ntp/sntp/tests/t-log.c index 1546584..08d4b6c 100644 --- a/contrib/ntp/sntp/tests/t-log.c +++ b/contrib/ntp/sntp/tests/t-log.c @@ -6,63 +6,82 @@ //#include "log.h" #include "log.c" +void setUp(void); void testChangePrognameInMysyslog(void); void testOpenLogfileTest(void); +void testWriteInCustomLogfile(void); + + +void +setUp(void) { + init_lib(); +} //in var/log/syslog (may differ depending on your OS), logged name of the program will be "TEST_PROGNAME". -void testChangePrognameInMysyslog(void){ +void +testChangePrognameInMysyslog(void) +{ sntp_init_logging("TEST_PROGNAME"); - msyslog(LOG_ERR, "TESTING sntp_init_logging()"); //%m will print the last errno? + msyslog(LOG_ERR, "TESTING sntp_init_logging()"); + + return; } //writes log files in your own file instead of syslog! (MAY BE USEFUL TO SUPPRESS ERROR MESSAGES!) -void testOpenLogfileTest(void){ +void +testOpenLogfileTest(void) +{ sntp_init_logging("TEST_PROGNAME2"); //this name is consistent through the entire program unless changed - open_logfile("testLogfile.log"); + open_logfile("testLogfile.log"); //open_logfile("/var/log/syslog"); //this gives me "Permission Denied" when i do %m - + msyslog(LOG_ERR, "Cannot open log file %s","abcXX"); //cleanup_log(); //unnecessary after log.c fix! - + + return; } //multiple cleanup_log() causes segfault. Probably the reason it's static. Opening multiple open_logfile(name) will cause segfault x.x I'm guessing it's not intended to be changed. Cleanup after unity test doesn't fix it, looks like. Calling in tearDown() also causes issues. -void testWriteInCustomLogfile(void){ +void +testWriteInCustomLogfile(void) +{ char testString[256] = "12345 ABC"; char testName[256] = "TEST_PROGNAME3"; - remove("testLogfile2.log"); + (void)remove("testLogfile2.log"); sntp_init_logging(testName); open_logfile("testLogfile2.log"); // ./ causing issues //sntp_init_logging(testName); - - msyslog(LOG_ERR, testString); + + msyslog(LOG_ERR, "%s", testString); FILE * f = fopen("testLogfile2.log","r"); char line[256]; + TEST_ASSERT_TRUE( f != NULL); + //should be only 1 line - while (fgets(line, sizeof(line), f)) { - printf("%s", line); - } - + while (fgets(line, sizeof(line), f)) { + printf("%s", line); + } + char* x = strstr(line,testName); - + TEST_ASSERT_TRUE( x != NULL); x = strstr(line,testString); TEST_ASSERT_TRUE( x != NULL); //cleanup_log(); - fclose(f); //using this will also cause segfault, because at the end, log.c will call (using atexit(func) function) cleanup_log(void)-> fclose(syslog_file); + fclose(f); //using this will also cause segfault, because at the end, log.c will call (using atexit(func) function) cleanup_log(void)-> fclose(syslog_file); //After the 1st fclose, syslog_file = NULL, and is never reset -> hopefully fixed by editing log.c //TEST_ASSERT_EQUAL_STRING(testString,line); //doesn't work, line is dynamic because the process name is random. -} - + return; +} diff --git a/contrib/ntp/sntp/tests/utilities.c b/contrib/ntp/sntp/tests/utilities.c index 39d22d6..a68aaac 100644 --- a/contrib/ntp/sntp/tests/utilities.c +++ b/contrib/ntp/sntp/tests/utilities.c @@ -96,12 +96,12 @@ test_IPv4Address(void) { void test_IPv6Address(void) { - const struct in6_addr address = { + const struct in6_addr address = { { { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x08, 0xd3, 0x13, 0x19, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 - }; + } } }; const char * expected = "2001:db8:85a3:8d3:1319:8a2e:370:7334"; sockaddr_u input; struct addrinfo inputA; |