|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -#import<XCTest/XCTest.h> |
18 | 17 | #import"FDevice.h"
|
| 18 | +#import<XCTest/XCTest.h> |
19 | 19 |
|
20 | 20 | #import<FirebaseDatabase/FIRDatabaseReference.h>
|
21 | 21 |
|
22 |
| -#import"FRepoManager.h" |
23 |
| -#import"FIRDatabaseReference_Private.h" |
24 | 22 | #import"FIRDatabaseConfig_Private.h"
|
25 |
| -#import"SenTest+FWaiter.h" |
| 23 | +#import"FIRDatabaseReference_Private.h" |
| 24 | +#import"FRepoManager.h" |
26 | 25 | #import"FTestHelpers.h"
|
| 26 | +#import"SenTest+FWaiter.h" |
27 | 27 |
|
28 |
| -@interfaceFDevice() { |
29 |
| -FIRDatabaseConfig *config; |
30 |
| -NSString *url; |
31 |
| -BOOL isOnline; |
32 |
| -BOOL disposed; |
| 28 | +@interfaceFDevice() { |
| 29 | + FIRDatabaseConfig *config; |
| 30 | +NSString *url; |
| 31 | +BOOL isOnline; |
| 32 | +BOOL disposed; |
33 | 33 | }
|
34 | 34 | @end
|
35 | 35 |
|
36 | 36 | @implementationFDevice
|
37 | 37 |
|
38 | 38 | - (id)initOnline {
|
39 |
| -FIRDatabaseReference *ref = [FTestHelpers getRandomNode]; |
40 |
| -return [selfinitOnlineWithUrl:[ref description]]; |
| 39 | + FIRDatabaseReference *ref = [FTestHelpers getRandomNode]; |
| 40 | +return [selfinitOnlineWithUrl:[ref description]]; |
41 | 41 | }
|
42 | 42 |
|
43 | 43 | - (id)initOffline {
|
44 |
| -FIRDatabaseReference *ref = [FTestHelpers getRandomNode]; |
45 |
| -return [selfinitOfflineWithUrl:[ref description]]; |
| 44 | + FIRDatabaseReference *ref = [FTestHelpers getRandomNode]; |
| 45 | +return [selfinitOfflineWithUrl:[ref description]]; |
46 | 46 | }
|
47 | 47 |
|
48 | 48 | - (id)initOnlineWithUrl:(NSString *)firebaseUrl {
|
49 |
| -return [selfinitWithUrl:firebaseUrl andOnline:YES]; |
| 49 | +return [selfinitWithUrl:firebaseUrl andOnline:YES]; |
50 | 50 | }
|
51 | 51 |
|
52 | 52 | - (id)initOfflineWithUrl:(NSString *)firebaseUrl {
|
53 |
| -return [selfinitWithUrl:firebaseUrl andOnline:NO]; |
| 53 | +return [selfinitWithUrl:firebaseUrl andOnline:NO]; |
54 | 54 | }
|
55 | 55 |
|
56 | 56 | staticNSUInteger deviceId = 0;
|
57 | 57 |
|
58 | 58 | - (id)initWithUrl:(NSString *)firebaseUrlandOnline:(BOOL)online {
|
59 |
| - self = [superinit]; |
60 |
| -if (self) { |
61 |
| - config = [FIRDatabaseConfig configForName:[NSStringstringWithFormat:@"device-%lu", deviceId++]]; |
62 |
| - config.persistenceEnabled = YES; |
63 |
| - url = firebaseUrl; |
64 |
| - isOnline = online; |
65 |
| - } |
66 |
| -return self; |
| 59 | + self = [superinit]; |
| 60 | +if (self) { |
| 61 | + config = |
| 62 | + [FIRDatabaseConfig configForName:[NSStringstringWithFormat:@"device-%lu", deviceId++]]; |
| 63 | + config.persistenceEnabled = YES; |
| 64 | + url = firebaseUrl; |
| 65 | + isOnline = online; |
| 66 | + } |
| 67 | +return self; |
67 | 68 | }
|
68 | 69 |
|
69 |
| -- (void) dealloc |
70 |
| -{ |
71 |
| -if (!self->disposed) { |
72 |
| - [NSExceptionraise:NSInternalInconsistencyExceptionformat:@"Forgot to dispose device"]; |
73 |
| - } |
| 70 | +- (void)dealloc { |
| 71 | +if (!self->disposed) { |
| 72 | + [NSExceptionraise:NSInternalInconsistencyExceptionformat:@"Forgot to dispose device"]; |
| 73 | + } |
74 | 74 | }
|
75 | 75 |
|
76 |
| -- (void)dispose { |
77 |
| -// TODO: clear persistence |
78 |
| -[FRepoManager disposeRepos:self->config]; |
79 |
| -self->disposed = YES; |
| 76 | +- (void)dispose { |
| 77 | +// TODO: clear persistence |
| 78 | + [FRepoManager disposeRepos:self->config]; |
| 79 | + self->disposed = YES; |
80 | 80 | }
|
81 | 81 |
|
82 | 82 | - (void)goOffline {
|
83 |
| -isOnline = NO; |
84 |
| -[FRepoManager interrupt:config]; |
| 83 | + isOnline = NO; |
| 84 | + [FRepoManager interrupt:config]; |
85 | 85 | }
|
86 | 86 |
|
87 | 87 | - (void)goOnline {
|
88 |
| -isOnline = YES; |
89 |
| -[FRepoManager resume:config]; |
| 88 | + isOnline = YES; |
| 89 | + [FRepoManager resume:config]; |
90 | 90 | }
|
91 | 91 |
|
92 | 92 | - (void)restartOnline {
|
93 |
| -@autoreleasepool { |
94 |
| -[FRepoManager disposeRepos:config]; |
95 |
| -isOnline = YES; |
96 |
| -} |
| 93 | + @autoreleasepool { |
| 94 | + [FRepoManager disposeRepos:config]; |
| 95 | + isOnline = YES; |
| 96 | + } |
97 | 97 | }
|
98 | 98 |
|
99 | 99 | - (void)restartOffline {
|
100 |
| -@autoreleasepool { |
101 |
| -[FRepoManager disposeRepos:config]; |
102 |
| -isOnline = NO; |
103 |
| -} |
| 100 | + @autoreleasepool { |
| 101 | + [FRepoManager disposeRepos:config]; |
| 102 | + isOnline = NO; |
| 103 | + } |
104 | 104 | }
|
105 | 105 |
|
106 |
| -// Waits for us to connect and then does an extra round-trip to make sure all initial state restoration is completely done. |
107 |
| -- (void)waitForIdleUsingWaiter:(XCTest*)waiter { |
108 |
| - [selfdo:^(FIRDatabaseReference *ref) { |
109 |
| - __block BOOL connected = NO; |
110 |
| - FIRDatabaseHandle handle = [[ref.root child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) { |
111 |
| - connected = [snapshot.value boolValue]; |
112 |
| - }]; |
113 |
| - [waiter waitUntil:^BOOL { return connected; }]; |
114 |
| - [ref.root removeObserverWithHandle:handle]; |
115 |
| - |
116 |
| -// HACK: Do a deep setPriority (which we expect to fail because there's no data there) to do a no-op roundtrip. |
117 |
| - __block BOOL done = NO; |
118 |
| - [[ref.root child:@"ENTOHTNUHOE/ONTEHNUHTOE"] setPriority:@"blah"withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) { |
119 |
| - done = YES; |
| 106 | +// Waits for us to connect and then does an extra round-trip to make sure all initial state |
| 107 | +// restoration is completely done. |
| 108 | +- (void)waitForIdleUsingWaiter:(XCTest *)waiter { |
| 109 | + [selfdo:^(FIRDatabaseReference *ref) { |
| 110 | + __block BOOL connected = NO; |
| 111 | + FIRDatabaseHandle handle = |
| 112 | + [[ref.root child:@".info/connected"] observeEventType:FIRDataEventTypeValue |
| 113 | +withBlock:^(FIRDataSnapshot *snapshot) { |
| 114 | + connected = [snapshot.value boolValue]; |
| 115 | + }]; |
| 116 | + [waiter waitUntil:^BOOL { |
| 117 | +return connected; |
| 118 | + }]; |
| 119 | + [ref.root removeObserverWithHandle:handle]; |
| 120 | + |
| 121 | +// HACK: Do a deep setPriority (which we expect to fail because there's no data there) to do a |
| 122 | +// no-op roundtrip. |
| 123 | + __block BOOL done = NO; |
| 124 | + [[ref.root child:@"ENTOHTNUHOE/ONTEHNUHTOE"] |
| 125 | +setPriority:@"blah" |
| 126 | +withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) { |
| 127 | + done = YES; |
120 | 128 | }];
|
121 |
| - [waiter waitUntil:^BOOL { return done; }]; |
| 129 | + [waiter waitUntil:^BOOL { |
| 130 | +return done; |
122 | 131 | }];
|
| 132 | + }]; |
123 | 133 | }
|
124 | 134 |
|
125 |
| -- (void)do:(void (^)(FIRDatabaseReference *))action { |
126 |
| - @autoreleasepool { |
127 |
| - FIRDatabaseReference *ref = [[[[FIRDatabaseReference alloc] initWithConfig:self->config] database] referenceFromURL:self->url]; |
128 |
| -if (!isOnline) { |
129 |
| - [FRepoManager interrupt:config]; |
130 |
| - } |
131 |
| -action(ref); |
| 135 | +- (void) do:(void (^)(FIRDatabaseReference *))action { |
| 136 | + @autoreleasepool { |
| 137 | + FIRDatabaseReference *ref = [[[[FIRDatabaseReference alloc] initWithConfig:self->config] |
| 138 | +database] referenceFromURL:self->url]; |
| 139 | +if (!isOnline) { |
| 140 | + [FRepoManager interrupt:config]; |
132 | 141 | }
|
| 142 | +action(ref); |
| 143 | + } |
133 | 144 | }
|
134 | 145 |
|
135 | 146 | @end
|
0 commit comments