git.fiddlerwoaroof.com
Browse code

openlog test coverage

Greg Wiley authored on 05/04/2017 22:04:58
Showing 3 changed files
... ...
@@ -26,10 +26,13 @@ distclean: clean
26 26
 
27 27
 dual_control_test: dual_control_test.c dual_control.o
28 28
 	$(CC) $(CFLAGS) $(CPPFLAGS) -lpam -o $@ $^
29
+logging_test: logging_test.c logging.o
30
+	$(CC) $(CFLAGS) $(CPPFLAGS) -lpam -o $@ $^
29 31
 
30 32
 .PHONY: test
31
-test: dual_control_test
33
+test: dual_control_test logging_test
32 34
 	@./dual_control_test > /dev/null
35
+	@./logging_test > /dev/null
33 36
 
34 37
 .PHONY: install
35 38
 install: $(MODULEOBJS)
36 39
new file mode 100755
37 40
Binary files /dev/null and b/logging_test differ
38 41
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+#include <stdio.h>
2
+
3
+#include "dc_syslog.h"
4
+#include "logging.h"
5
+
6
+void dc_syslog(int priority, const char *message, ...) {
7
+}
8
+
9
+void dc_closelog(void) {
10
+}
11
+
12
+int opened_facility = -1000;
13
+void dc_openlog(const char * ident, int logopt, int facility) {
14
+    opened_facility = facility;
15
+}
16
+
17
+
18
+int test_log_success_facility_authpriv() {
19
+    // given
20
+    opened_facility = -1000;
21
+
22
+    // when
23
+    log_success();
24
+
25
+    // then
26
+    return opened_facility == LOG_AUTHPRIV;
27
+}
28
+
29
+
30
+int main(int numargs, char **args) {
31
+    if(test_log_success_facility_authpriv()) {
32
+        fprintf(stderr, "Success!\n");
33
+        return 0;
34
+    } else {
35
+        return 1;
36
+    }
37
+}
38
+