]> git.saurik.com Git - apple/security.git/blob - keychain/analytics/Tests/CKKSLaunchSequenceTests.m
Security-59306.11.20.tar.gz
[apple/security.git] / keychain / analytics / Tests / CKKSLaunchSequenceTests.m
1 //
2 // CKKSLaunchSequenceTests.m
3 //
4
5 #import <XCTest/XCTest.h>
6 #import <OCMock/OCMock.h>
7 #import "keychain/analytics/CKKSLaunchSequence.h"
8 #import <utilities/SecCoreAnalytics.h>
9
10
11 @interface CKKSLaunchSequenceTests : XCTestCase
12 @property (strong) XCTestExpectation *launchExpection;
13 @end
14
15 @implementation CKKSLaunchSequenceTests
16
17 - (void)mockSendEvent:(NSDictionary *)name event:(NSDictionary *)event {
18 NSLog(@"CAEvent: %@", event);
19 [self.launchExpection fulfill];
20 }
21
22 - (void)testLaunch {
23
24 id credentialStoreMock = OCMClassMock([SecCoreAnalytics class]);
25 OCMStub([credentialStoreMock sendEvent:[OCMArg any] event:[OCMArg any]]).andCall(self, @selector(mockSendEvent:event:));
26
27 CKKSLaunchSequence *launch = [[CKKSLaunchSequence alloc] initWithRocketName:@"rocket"];
28 [launch addEvent:@"keyword1"];
29 usleep(1000);
30 [launch addEvent:@"keyword2"];
31 [launch addAttribute:@"attribute" value:@"value"];
32
33 self.launchExpection = [self expectationWithDescription:@"launch"];
34
35 [launch launch];
36
37 [self waitForExpectations:@[self.launchExpection] timeout:0.2];
38
39 self.launchExpection = [self expectationWithDescription:@"launch"];
40 self.launchExpection.inverted = true;
41
42 [launch launch];
43
44 [self waitForExpectations:@[self.launchExpection] timeout:0.2];
45 self.launchExpection = nil;
46
47 NSArray *res = [launch eventsByTime];
48 XCTAssert(res.count > 0, "should have event");
49 bool found = false;
50 for (NSString *event in res) {
51 found |= [event hasPrefix:@"attr:"];
52 }
53 XCTAssert(found, "should have an attribute");
54
55
56
57 }
58
59 @end