1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainSearch.h>
9 #include "testsecevent.h"
11 void tests(int dont_skip
)
13 SecKeychainRef keychain
= NULL
, default_keychain
= NULL
;
14 is_status(SecKeychainCopyDefault(&default_keychain
),
15 errSecNoDefaultKeychain
, "no default keychain");
17 ok_status(test_sec_event_register(kSecEveryEventMask
),
18 "register for all events");
19 ok_status(SecKeychainCreate("test", 4, "test", FALSE
, NULL
, &keychain
),
21 is_sec_event(kSecKeychainListChangedEvent
, NULL
, NULL
, NULL
,
22 "list changed event");
23 SecKeychainRef notKc
= NULL
;
25 is_sec_event(kSecDefaultChangedEvent
, ¬Kc
, NULL
, NULL
,
26 "default changed event");
28 is((intptr_t)keychain
, (intptr_t)notKc
,
29 "keychain in notification is keychain");
31 no_sec_event("no event");
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");
39 CFRelease(default_keychain
);
40 default_keychain
= NULL
;
43 SecKeychainRef keychain2
;
44 ok_status(SecKeychainCreate("test2", 4, "test", FALSE
, NULL
, &keychain2
),
46 is_sec_event(kSecKeychainListChangedEvent
, NULL
, NULL
, NULL
,
47 "list changed event");
48 no_sec_event("no event");
50 ok_status(SecKeychainCopyDefault(&default_keychain
),
51 "get default keychain");
53 is((intptr_t)default_keychain
, (intptr_t)keychain
,
54 "default kc is first created kc");
58 CFRelease(default_keychain
);
59 default_keychain
= NULL
;
62 ok_status(SecKeychainDelete(keychain
), "delete default keychain");
63 is_sec_event(kSecKeychainListChangedEvent
, NULL
, NULL
, NULL
,
64 "list changed event");
66 is_sec_event(kSecDefaultChangedEvent
, NULL
, NULL
, NULL
,
67 "default changed event");
69 no_sec_event("no event");
72 ok_status(SecKeychainDelete(keychain2
), "delete keychain2");
74 is_sec_event(kSecKeychainListChangedEvent
, NULL
, NULL
, NULL
,
75 "list changed event");
76 no_sec_event("no event");
78 ok_status(test_sec_event_deregister(), "deregister events.");
81 ok(tests_end(1), "cleanup");
84 int main(int argc
, char *const *argv
)
87 int dont_skip
= argc
> 1 && !strcmp(argv
[1], "-s");
90 if (!tests_begin(argc
, argv
))
91 BAIL_OUT("tests_begin failed");