|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | #import"FTestHelpers.h"
|
18 |
| -#import"FConstants.h" |
19 |
| -#import<FirebaseCore/FIRApp.h> |
| 18 | + |
| 19 | +#import<FirebaseAuthInterop/FIRAuthInterop.h> |
| 20 | +#import<FirebaseCore/FIRAppInternal.h> |
| 21 | +#import<FirebaseCore/FIRComponent.h> |
| 22 | +#import<FirebaseCore/FIRComponentContainer.h> |
20 | 23 | #import<FirebaseCore/FIROptions.h>
|
| 24 | + |
| 25 | +#import"FConstants.h" |
| 26 | +#import"FIRAuthInteropFake.h" |
21 | 27 | #import"FIRDatabaseConfig_Private.h"
|
22 | 28 | #import"FTestAuthTokenGenerator.h"
|
23 | 29 |
|
24 | 30 | @implementationFTestHelpers
|
25 | 31 |
|
26 |
| -+ (NSTimeInterval)waitUntil:(BOOL (^)())predicatetimeout:(NSTimeInterval)seconds { |
27 |
| -NSTimeInterval start = [NSDatetimeIntervalSinceReferenceDate]; |
28 |
| -NSDate *timeoutDate = [NSDatedateWithTimeIntervalSinceNow:seconds]; |
29 |
| -NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate]; |
30 |
| -NSTimeInterval currentTime; |
| 32 | ++ (NSTimeInterval)waitUntil:(BOOL (^)())predicatetimeout:(NSTimeInterval)seconds { |
| 33 | +NSTimeInterval start = [NSDatetimeIntervalSinceReferenceDate]; |
| 34 | +NSDate *timeoutDate = [NSDatedateWithTimeIntervalSinceNow:seconds]; |
| 35 | +NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate]; |
| 36 | +NSTimeInterval currentTime; |
31 | 37 |
|
32 |
| -for (currentTime = [NSDatetimeIntervalSinceReferenceDate]; |
33 |
| - !predicate() && currentTime < timeoutTime; |
34 |
| - currentTime = [NSDatetimeIntervalSinceReferenceDate]) { |
35 |
| - [[NSRunLoopcurrentRunLoop] runMode:NSDefaultRunLoopModebeforeDate:[NSDatedateWithTimeIntervalSinceNow:0.25]]; |
36 |
| - } |
| 38 | +for (currentTime = [NSDatetimeIntervalSinceReferenceDate]; |
| 39 | + !predicate() && currentTime < timeoutTime; |
| 40 | + currentTime = [NSDatetimeIntervalSinceReferenceDate]) { |
| 41 | + [[NSRunLoopcurrentRunLoop] runMode:NSDefaultRunLoopMode |
| 42 | +beforeDate:[NSDatedateWithTimeIntervalSinceNow:0.25]]; |
| 43 | + } |
37 | 44 |
|
38 |
| -NSTimeInterval finish = [NSDatetimeIntervalSinceReferenceDate]; |
| 45 | +NSTimeInterval finish = [NSDatetimeIntervalSinceReferenceDate]; |
39 | 46 |
|
40 |
| -NSAssert(currentTime <= timeoutTime, @"Timed out"); |
| 47 | +NSAssert(currentTime <= timeoutTime, @"Timed out"); |
41 | 48 |
|
42 |
| -return (finish - start); |
| 49 | +return (finish - start); |
43 | 50 | }
|
44 | 51 |
|
45 |
| -+ (NSArray*) getRandomNodes:(int)numpersistence:(BOOL)persistence { |
46 |
| -staticdispatch_once_t pred = 0; |
47 |
| -staticNSMutableArray *persistenceRefs = nil; |
48 |
| -staticNSMutableArray *noPersistenceRefs = nil; |
49 |
| -dispatch_once(&pred, ^{ |
50 |
| - persistenceRefs = [[NSMutableArrayalloc] init]; |
51 |
| - noPersistenceRefs = [[NSMutableArrayalloc] init]; |
52 |
| -// Uncomment the following line to run tests against a background thread |
53 |
| -//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; |
54 |
| - }); |
55 |
| - |
56 |
| -NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs; |
57 |
| - |
58 |
| -id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderForApp:[FIRApp defaultApp]]; |
59 |
| - |
60 |
| -while (num > refs.count) { |
61 |
| -NSString *sessionIdentifier = [NSStringstringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-", refs.count]; |
62 |
| - FIRDatabaseConfig *config = [[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier authTokenProvider:authTokenProvider]; |
63 |
| - config.persistenceEnabled = persistence; |
64 |
| - FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:config]; |
65 |
| - [refs addObject:ref]; |
66 |
| - } |
| 52 | ++ (FIRDatabaseConfig *)defaultConfig { |
| 53 | +return [selfconfigForName:@"default"]; |
| 54 | +} |
67 | 55 |
|
68 |
| -NSMutableArray* results = [[NSMutableArrayalloc] init]; |
69 |
| -NSString* name = nil; |
70 |
| -for (int i = 0; i < num; ++i) { |
71 |
| - FIRDatabaseReference * ref = [refs objectAtIndex:i]; |
72 |
| -if (!name) { |
73 |
| - name = [ref childByAutoId].key; |
74 |
| - } |
75 |
| - [results addObject:[ref child:name]]; |
| 56 | ++ (FIRDatabaseConfig *)configForName:(NSString *)name { |
| 57 | +id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:niluserID:nilerror:nil]; |
| 58 | +id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth]; |
| 59 | +return [[FIRDatabaseConfig alloc] initWithSessionIdentifier:name |
| 60 | +authTokenProvider:authTokenProvider]; |
| 61 | +} |
| 62 | + |
| 63 | ++ (NSArray *)getRandomNodes:(int)numpersistence:(BOOL)persistence { |
| 64 | +staticdispatch_once_t pred = 0; |
| 65 | +staticNSMutableArray *persistenceRefs = nil; |
| 66 | +staticNSMutableArray *noPersistenceRefs = nil; |
| 67 | +dispatch_once(&pred, ^{ |
| 68 | + persistenceRefs = [[NSMutableArrayalloc] init]; |
| 69 | + noPersistenceRefs = [[NSMutableArrayalloc] init]; |
| 70 | +// Uncomment the following line to run tests against a background thread |
| 71 | +//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; |
| 72 | + }); |
| 73 | + |
| 74 | +NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs; |
| 75 | + |
| 76 | +id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:niluserID:nilerror:nil]; |
| 77 | +id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth]; |
| 78 | + |
| 79 | +while (num > refs.count) { |
| 80 | +NSString *sessionIdentifier = |
| 81 | + [NSStringstringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-", |
| 82 | + refs.count]; |
| 83 | + FIRDatabaseConfig *config = |
| 84 | + [[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier |
| 85 | +authTokenProvider:authTokenProvider]; |
| 86 | + config.persistenceEnabled = persistence; |
| 87 | + FIRDatabaseReference *ref = [[FIRDatabaseReference alloc] initWithConfig:config]; |
| 88 | + [refs addObject:ref]; |
| 89 | + } |
| 90 | + |
| 91 | +NSMutableArray *results = [[NSMutableArrayalloc] init]; |
| 92 | +NSString *name = nil; |
| 93 | +for (int i = 0; i < num; ++i) { |
| 94 | + FIRDatabaseReference *ref = [refs objectAtIndex:i]; |
| 95 | +if (!name) { |
| 96 | + name = [ref childByAutoId].key; |
76 | 97 | }
|
77 |
| -return results; |
| 98 | + [results addObject:[ref child:name]]; |
| 99 | + } |
| 100 | +return results; |
78 | 101 | }
|
79 | 102 |
|
80 | 103 | // Helpers
|
81 |
| -+ (FIRDatabaseReference *)getRandomNode { |
82 |
| -NSArray* refs = [selfgetRandomNodes:1persistence:YES]; |
83 |
| -return [refs objectAtIndex:0]; |
| 104 | ++ (FIRDatabaseReference *)getRandomNode { |
| 105 | +NSArray *refs = [selfgetRandomNodes:1persistence:YES]; |
| 106 | +return [refs objectAtIndex:0]; |
84 | 107 | }
|
85 | 108 |
|
86 |
| -+ (FIRDatabaseReference *)getRandomNodeWithoutPersistence { |
87 |
| -NSArray* refs = [selfgetRandomNodes:1persistence:NO]; |
88 |
| -return refs[0]; |
| 109 | ++ (FIRDatabaseReference *)getRandomNodeWithoutPersistence { |
| 110 | +NSArray *refs = [selfgetRandomNodes:1persistence:NO]; |
| 111 | +return refs[0]; |
89 | 112 | }
|
90 | 113 |
|
91 |
| -+ (FTupleFirebase *)getRandomNodePair { |
92 |
| -NSArray* refs = [selfgetRandomNodes:2persistence:YES]; |
| 114 | ++ (FTupleFirebase *)getRandomNodePair { |
| 115 | +NSArray *refs = [selfgetRandomNodes:2persistence:YES]; |
93 | 116 |
|
94 |
| -FTupleFirebase* tuple = [[FTupleFirebase alloc] init]; |
95 |
| -tuple.one = [refs objectAtIndex:0]; |
96 |
| -tuple.two = [refs objectAtIndex:1]; |
| 117 | + FTupleFirebase *tuple = [[FTupleFirebase alloc] init]; |
| 118 | + tuple.one = [refs objectAtIndex:0]; |
| 119 | + tuple.two = [refs objectAtIndex:1]; |
97 | 120 |
|
98 |
| -return tuple; |
| 121 | +return tuple; |
99 | 122 | }
|
100 | 123 |
|
101 |
| -+ (FTupleFirebase *)getRandomNodePairWithoutPersistence { |
102 |
| -NSArray* refs = [selfgetRandomNodes:2persistence:NO]; |
| 124 | ++ (FTupleFirebase *)getRandomNodePairWithoutPersistence { |
| 125 | +NSArray *refs = [selfgetRandomNodes:2persistence:NO]; |
103 | 126 |
|
104 |
| -FTupleFirebase* tuple = [[FTupleFirebase alloc] init]; |
105 |
| -tuple.one = refs[0]; |
106 |
| -tuple.two = refs[1]; |
| 127 | + FTupleFirebase *tuple = [[FTupleFirebase alloc] init]; |
| 128 | + tuple.one = refs[0]; |
| 129 | + tuple.two = refs[1]; |
107 | 130 |
|
108 |
| -return tuple; |
| 131 | +return tuple; |
109 | 132 | }
|
110 | 133 |
|
111 |
| -+ (FTupleFirebase *)getRandomNodeTriple { |
112 |
| -NSArray* refs = [selfgetRandomNodes:3persistence:YES]; |
113 |
| -FTupleFirebase* triple = [[FTupleFirebase alloc] init]; |
114 |
| -triple.one = [refs objectAtIndex:0]; |
115 |
| -triple.two = [refs objectAtIndex:1]; |
116 |
| -triple.three = [refs objectAtIndex:2]; |
| 134 | ++ (FTupleFirebase *)getRandomNodeTriple { |
| 135 | +NSArray *refs = [selfgetRandomNodes:3persistence:YES]; |
| 136 | + FTupleFirebase *triple = [[FTupleFirebase alloc] init]; |
| 137 | + triple.one = [refs objectAtIndex:0]; |
| 138 | + triple.two = [refs objectAtIndex:1]; |
| 139 | + triple.three = [refs objectAtIndex:2]; |
117 | 140 |
|
118 |
| -return triple; |
| 141 | +return triple; |
119 | 142 | }
|
120 | 143 |
|
121 | 144 | + (id<FNode>)leafNodeOfSize:(NSUInteger)size {
|
122 |
| -NSMutableString *string = [NSMutableStringstring]; |
123 |
| -NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
124 |
| -for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) { |
125 |
| -[string appendString:pattern]; |
126 |
| -} |
127 |
| -NSUInteger remainingLength = size - string.length; |
128 |
| -[string appendString:[pattern substringToIndex:remainingLength]]; |
129 |
| -return [FSnapshotUtilities nodeFrom:string]; |
| 145 | +NSMutableString *string = [NSMutableStringstring]; |
| 146 | +NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 147 | +for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) { |
| 148 | + [string appendString:pattern]; |
| 149 | + } |
| 150 | +NSUInteger remainingLength = size - string.length; |
| 151 | + [string appendString:[pattern substringToIndex:remainingLength]]; |
| 152 | +return [FSnapshotUtilities nodeFrom:string]; |
130 | 153 | }
|
131 | 154 |
|
132 | 155 | @end
|
0 commit comments