10 void testChangePrognameInMysyslog(void);
11 void testOpenLogfileTest(void);
12 void testWriteInCustomLogfile(void);
21 //in var/log/syslog (may differ depending on your OS), logged name of the program will be "TEST_PROGNAME".
24 testChangePrognameInMysyslog(void)
26 sntp_init_logging("TEST_PROGNAME");
27 msyslog(LOG_ERR, "TESTING sntp_init_logging()");
32 //writes log files in your own file instead of syslog! (MAY BE USEFUL TO SUPPRESS ERROR MESSAGES!)
35 testOpenLogfileTest(void)
37 sntp_init_logging("TEST_PROGNAME2"); //this name is consistent through the entire program unless changed
38 open_logfile("testLogfile.log");
39 //open_logfile("/var/log/syslog"); //this gives me "Permission Denied" when i do %m
41 msyslog(LOG_ERR, "Cannot open log file %s","abcXX");
42 //cleanup_log(); //unnecessary after log.c fix!
48 //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.
51 testWriteInCustomLogfile(void)
53 char testString[256] = "12345 ABC";
54 char testName[256] = "TEST_PROGNAME3";
56 (void)remove("testLogfile2.log");
58 sntp_init_logging(testName);
59 open_logfile("testLogfile2.log"); // ./ causing issues
60 //sntp_init_logging(testName);
63 msyslog(LOG_ERR, "%s", testString);
64 FILE * f = fopen("testLogfile2.log","r");
67 TEST_ASSERT_TRUE( f != NULL);
69 //should be only 1 line
70 while (fgets(line, sizeof(line), f)) {
75 char* x = strstr(line,testName);
77 TEST_ASSERT_TRUE( x != NULL);
79 x = strstr(line,testString);
80 TEST_ASSERT_TRUE( x != NULL);
82 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);
83 //After the 1st fclose, syslog_file = NULL, and is never reset -> hopefully fixed by editing log.c
84 //TEST_ASSERT_EQUAL_STRING(testString,line); //doesn't work, line is dynamic because the process name is random.