git.fiddlerwoaroof.com
Browse code

more syslog test coverage

Greg Wiley authored on 05/04/2017 22:52:07
Showing 2 changed files
1 1
Binary files a/logging_test and b/logging_test differ
... ...
@@ -4,10 +4,10 @@
4 4
 #include "dc_syslog.h"
5 5
 #include "logging.h"
6 6
 
7
-int test_priority = -1000;
7
+int logged_priority = -1000;
8 8
 const char *logged_message = "";
9 9
 void dc_syslog(int priority, const char *message, ...) {
10
-    test_priority = priority;
10
+    logged_priority = priority;
11 11
     logged_message = message;
12 12
 }
13 13
 
... ...
@@ -26,10 +26,16 @@ void dc_openlog(const char *ident, int logopt, int facility) {
26 26
 
27 27
 #define check(assertion, msg) \
28 28
     if (!(assertion)) { \
29
-      fprintf(stderr, "assertion failed %s\n", msg); \
29
+      fprintf(stderr, "assertion failed: %s\n", msg); \
30 30
       return 0; \
31 31
     }
32 32
 
33
+#define checkint(expected, actual, name) \
34
+    check(expected == actual, name " should be " #expected)
35
+
36
+#define checkstr(expected, actual, name) \
37
+    check(!strcmp(actual, expected), name " should be '" expected "'")
38
+
33 39
 #define succeed() return 1
34 40
 
35 41
 int test_log_success() {
... ...
@@ -37,18 +43,18 @@ int test_log_success() {
37 43
     opened_facility = -1000;
38 44
     opened_program_name = "";
39 45
     opened_logopt = -1000;
40
-    test_priority = -1000;
46
+    logged_priority = -1000;
41 47
     logged_message = "";
42 48
 
43 49
     // when
44 50
     log_success();
45 51
 
46 52
     // then
47
-    check(opened_facility == LOG_AUTHPRIV, "facility should be authpriv");
48
-    check(!strcmp(opened_program_name, "pam_dual_control"), "incorrect program name");
49
-    check(opened_logopt == 0, "incorrect log option");
50
-    check(test_priority == LOG_NOTICE, "incorrect priority");
51
-    check(!strcmp(logged_message, "dual control succeeded"), "incorrect logged message");
53
+    checkint(LOG_AUTHPRIV, opened_facility, "facility");
54
+    checkint(LOG_NOTICE, logged_priority, "priority");
55
+    checkint(0, opened_logopt, "logopt");
56
+    checkstr("pam_dual_control", opened_program_name, "program name");
57
+    checkstr("dual control succeeded", logged_message, "logged message");
52 58
 
53 59
     succeed();
54 60
 }