]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-23-notify.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-23-notify.c
1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainSearch.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include "testenv.h"
7 #include "testleaks.h"
8 #include "testmore.h"
9 #include "testsecevent.h"
10
11 void tests(int dont_skip)
12 {
13 SecKeychainRef keychain = NULL, default_keychain = NULL;
14 is_status(SecKeychainCopyDefault(&default_keychain),
15 errSecNoDefaultKeychain, "no default keychain");
16
17 ok_status(test_sec_event_register(kSecEveryEventMask),
18 "register for all events");
19 ok_status(SecKeychainCreate("test", 4, "test", FALSE, NULL, &keychain),
20 "create keychain");
21 is_sec_event(kSecKeychainListChangedEvent, NULL, NULL, NULL,
22 "list changed event");
23 SecKeychainRef notKc = NULL;
24
25 is_sec_event(kSecDefaultChangedEvent, &notKc, NULL, NULL,
26 "default changed event");
27
28 is((intptr_t)keychain, (intptr_t)notKc,
29 "keychain in notification is keychain");
30
31 no_sec_event("no event");
32
33 ok_status(SecKeychainCopyDefault(&default_keychain),
34 "get default keychain");
35 is((intptr_t)default_keychain, (intptr_t)keychain,
36 "default kc is just created kc");
37 if (default_keychain)
38 {
39 CFRelease(default_keychain);
40 default_keychain = NULL;
41 }
42
43 SecKeychainRef keychain2;
44 ok_status(SecKeychainCreate("test2", 4, "test", FALSE, NULL, &keychain2),
45 "create keychain2");
46 is_sec_event(kSecKeychainListChangedEvent, NULL, NULL, NULL,
47 "list changed event");
48 no_sec_event("no event");
49
50 ok_status(SecKeychainCopyDefault(&default_keychain),
51 "get default keychain");
52
53 is((intptr_t)default_keychain, (intptr_t)keychain,
54 "default kc is first created kc");
55
56 if (default_keychain)
57 {
58 CFRelease(default_keychain);
59 default_keychain = NULL;
60 }
61
62 ok_status(SecKeychainDelete(keychain), "delete default keychain");
63 is_sec_event(kSecKeychainListChangedEvent, NULL, NULL, NULL,
64 "list changed event");
65
66 is_sec_event(kSecDefaultChangedEvent, NULL, NULL, NULL,
67 "default changed event");
68
69 no_sec_event("no event");
70 CFRelease(keychain);
71
72 ok_status(SecKeychainDelete(keychain2), "delete keychain2");
73 CFRelease(keychain2);
74 is_sec_event(kSecKeychainListChangedEvent, NULL, NULL, NULL,
75 "list changed event");
76 no_sec_event("no event");
77
78 ok_status(test_sec_event_deregister(), "deregister events.");
79
80
81 ok(tests_end(1), "cleanup");
82 }
83
84 int main(int argc, char *const *argv)
85 {
86 #ifdef DEBUG
87 int dont_skip = argc > 1 && !strcmp(argv[1], "-s");
88 plan_tests(24);
89
90 if (!tests_begin(argc, argv))
91 BAIL_OUT("tests_begin failed");
92
93 tests(dont_skip);
94 #endif
95 plan_tests(1);
96 ok_leaks("no leaks");
97
98 return 0;
99 }