Browse code
test function invoker macro
Greg Wiley authored on 06/04/2017 16:20:42
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -74,16 +74,21 @@ int fails_with_invalid_token() { |
74 | 74 |
return result == PAM_AUTH_ERR; |
75 | 75 |
} |
76 | 76 |
|
77 |
+int runtests() { |
|
78 |
+ test(pam_sm_setcred_returns_success); |
|
79 |
+ test(pam_sm_authenticate_success_invokes_log_success); |
|
80 |
+ test(succeeds_with_valid_token); |
|
81 |
+ test(fails_with_invalid_token); |
|
82 |
+ succeed(); |
|
83 |
+} |
|
84 |
+ |
|
77 | 85 |
int main(int argc, char* argv[]) { |
78 |
- check(pam_sm_setcred_returns_success(), "set cred failed\n"); |
|
79 |
- check(pam_sm_authenticate_success_invokes_log_success(), "authenticate invokes log_success failed\n"); |
|
80 |
- check(succeeds_with_valid_token(), "succeeds with valid token failed\n"); |
|
81 |
- check(fails_with_invalid_token(), "fails with invalid token failed\n") |
|
82 |
- |
|
83 |
- if(at_least_one_failed_test) { |
|
84 |
- return 1; |
|
85 |
- } else { |
|
86 |
- fprintf(stderr, "dual_control_test: success!\n"); |
|
87 |
- return 0; |
|
88 |
- } |
|
86 |
+// check(pam_sm_setcred_returns_success(), "set cred failed\n"); |
|
87 |
+// check(pam_sm_authenticate_success_invokes_log_success(), "authenticate invokes log_success failed\n"); |
|
88 |
+// check(succeeds_with_valid_token(), "succeeds with valid token failed\n"); |
|
89 |
+// check(fails_with_invalid_token(), "fails with invalid token failed\n") |
|
90 |
+ |
|
91 |
+ return !runtests(); |
|
92 |
+ |
|
89 | 93 |
} |
94 |
+ |
... | ... |
@@ -13,6 +13,16 @@ |
13 | 13 |
#define checkstr(expected, actual, name) \ |
14 | 14 |
check(!strcmp(actual, expected), name " should be '" expected "'") |
15 | 15 |
|
16 |
+#define test(NAME) \ |
|
17 |
+ { \ |
|
18 |
+ fprintf(stderr, "here %s\n", #NAME); \ |
|
19 |
+ int result = NAME (); \ |
|
20 |
+ if (!result) { \ |
|
21 |
+ fprintf(stderr, "test failed: %s\n", #NAME); \ |
|
22 |
+ return 0; \ |
|
23 |
+ } \ |
|
24 |
+ } |
|
25 |
+ |
|
16 | 26 |
#define succeed() return 1 |
17 | 27 |
|
18 | 28 |
#endif |