9 void testChangePrognameInMysyslog(void);
10 void testOpenLogfileTest(void);
13 //in var/log/syslog (may differ depending on your OS), logged name of the program will be "TEST_PROGNAME".
15 void testChangePrognameInMysyslog(void){
16 sntp_init_logging("TEST_PROGNAME");
17 msyslog(LOG_ERR, "TESTING sntp_init_logging()"); //%m will print the last errno?
20 //writes log files in your own file instead of syslog! (MAY BE USEFUL TO SUPPRESS ERROR MESSAGES!)
22 void testOpenLogfileTest(void){
23 sntp_init_logging("TEST_PROGNAME2"); //this name is consistent through the entire program unless changed
24 open_logfile("testLogfile.log");
25 //open_logfile("/var/log/syslog"); //this gives me "Permission Denied" when i do %m
27 msyslog(LOG_ERR, "Cannot open log file %s","abcXX");
28 //cleanup_log(); //unnecessary after log.c fix!
33 //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.
35 void testWriteInCustomLogfile(void){
36 char testString[256] = "12345 ABC";
37 char testName[256] = "TEST_PROGNAME3";
39 remove("testLogfile2.log");
41 sntp_init_logging(testName);
42 open_logfile("testLogfile2.log"); // ./ causing issues
43 //sntp_init_logging(testName);
46 msyslog(LOG_ERR, testString);
47 FILE * f = fopen("testLogfile2.log","r");
50 //should be only 1 line
51 while (fgets(line, sizeof(line), f)) {
56 char* x = strstr(line,testName);
58 TEST_ASSERT_TRUE( x != NULL);
60 x = strstr(line,testString);
61 TEST_ASSERT_TRUE( x != NULL);
63 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);
64 //After the 1st fclose, syslog_file = NULL, and is never reset -> hopefully fixed by editing log.c
65 //TEST_ASSERT_EQUAL_STRING(testString,line); //doesn't work, line is dynamic because the process name is random.