Skip to content

Commit c0d0421

Browse files
committed
Squash of my previous local commits for Database Interop
Register Database with Interop: + Add AuthInterop dependency + Have Database register with Interop component container + Add weak dependency on Auth ~ Cleaned up imports Use Interop for Auth token fetching: + Use macro to get auth component ~ Change `getTokenForcingRefresh:withCallback:` call to use Interop component version of Auth ~ Clean up imports Implement necessary protocols: + Added FIRComponentRegistrant and FIRDatabaseNilProtocol to FIRDatabase Clean up Database tests: - Removed all unnecessary header files ~ Ran style.sh across all the tests Cleaned Up project file: Some header removals were missed in the last commit. Sorted some test files Fix Database Fake App Tests: + Added container property + Added an Auth fake in the container + Added the Shared utils files to the necessary targets + Added a missing XCTest reference in a test that didn't compile for me
1 parent f098fb2 commit c0d0421

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+15348
-13427
lines changed

Example/Database/Tests/Helpers/FDevice.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
@class FIRDatabaseReference;
2020
@class SenTest;
21+
@class XCTest;
2122

2223
@interfaceFDevice : NSObject
2324
- (id)initOnline;
@@ -28,8 +29,8 @@
2829
- (void)goOnline;
2930
- (void)restartOnline;
3031
- (void)restartOffline;
31-
- (void)waitForIdleUsingWaiter:(XCTest*)waiter;
32-
- (void)do:(void (^)(FIRDatabaseReference *))action;
32+
- (void)waitForIdleUsingWaiter:(XCTest*)waiter;
33+
- (void)do:(void (^)(FIRDatabaseReference *))action;
3334

3435
- (void)dispose;
3536

Example/Database/Tests/Helpers/FDevice.m

+77-66
Original file line numberDiff line numberDiff line change
@@ -14,122 +14,133 @@
1414
* limitations under the License.
1515
*/
1616

17-
#import<XCTest/XCTest.h>
1817
#import"FDevice.h"
18+
#import<XCTest/XCTest.h>
1919

2020
#import<FirebaseDatabase/FIRDatabaseReference.h>
2121

22-
#import"FRepoManager.h"
23-
#import"FIRDatabaseReference_Private.h"
2422
#import"FIRDatabaseConfig_Private.h"
25-
#import"SenTest+FWaiter.h"
23+
#import"FIRDatabaseReference_Private.h"
24+
#import"FRepoManager.h"
2625
#import"FTestHelpers.h"
26+
#import"SenTest+FWaiter.h"
2727

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;
3333
}
3434
@end
3535

3636
@implementationFDevice
3737

3838
- (id)initOnline {
39-
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
40-
return [selfinitOnlineWithUrl:[ref description]];
39+
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
40+
return [selfinitOnlineWithUrl:[ref description]];
4141
}
4242

4343
- (id)initOffline {
44-
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
45-
return [selfinitOfflineWithUrl:[ref description]];
44+
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
45+
return [selfinitOfflineWithUrl:[ref description]];
4646
}
4747

4848
- (id)initOnlineWithUrl:(NSString *)firebaseUrl {
49-
return [selfinitWithUrl:firebaseUrl andOnline:YES];
49+
return [selfinitWithUrl:firebaseUrl andOnline:YES];
5050
}
5151

5252
- (id)initOfflineWithUrl:(NSString *)firebaseUrl {
53-
return [selfinitWithUrl:firebaseUrl andOnline:NO];
53+
return [selfinitWithUrl:firebaseUrl andOnline:NO];
5454
}
5555

5656
staticNSUInteger deviceId = 0;
5757

5858
- (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;
6768
}
6869

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+
}
7474
}
7575

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;
8080
}
8181

8282
- (void)goOffline {
83-
isOnline = NO;
84-
[FRepoManager interrupt:config];
83+
isOnline = NO;
84+
[FRepoManager interrupt:config];
8585
}
8686

8787
- (void)goOnline {
88-
isOnline = YES;
89-
[FRepoManager resume:config];
88+
isOnline = YES;
89+
[FRepoManager resume:config];
9090
}
9191

9292
- (void)restartOnline {
93-
@autoreleasepool {
94-
[FRepoManager disposeRepos:config];
95-
isOnline = YES;
96-
}
93+
@autoreleasepool {
94+
[FRepoManager disposeRepos:config];
95+
isOnline = YES;
96+
}
9797
}
9898

9999
- (void)restartOffline {
100-
@autoreleasepool {
101-
[FRepoManager disposeRepos:config];
102-
isOnline = NO;
103-
}
100+
@autoreleasepool {
101+
[FRepoManager disposeRepos:config];
102+
isOnline = NO;
103+
}
104104
}
105105

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;
120128
}];
121-
[waiter waitUntil:^BOOL { return done; }];
129+
[waiter waitUntil:^BOOL {
130+
return done;
122131
}];
132+
}];
123133
}
124134

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];
132141
}
142+
action(ref);
143+
}
133144
}
134145

135146
@end

Example/Database/Tests/Helpers/FEventTester.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
@interfaceFEventTester : XCTestCase
2121

22-
- (id)initFrom:(XCTestCase*)elsewhere;
23-
- (void)addLookingFor:(NSArray*)l;
24-
- (void)wait;
25-
- (void)waitForInitialization;
26-
- (void)unregister;
22+
- (id)initFrom:(XCTestCase*)elsewhere;
23+
- (void)addLookingFor:(NSArray*)l;
24+
- (void)wait;
25+
- (void)waitForInitialization;
26+
- (void)unregister;
2727

28-
@property(nonatomic, strong) NSMutableArray* lookingFor;
29-
@property(readwrite) int callbacksCalled;
30-
@property(nonatomic, strong) NSMutableDictionary* seenFirebaseLocations;
28+
@property(nonatomic, strong) NSMutableArray* lookingFor;
29+
@property(readwrite) int callbacksCalled;
30+
@property(nonatomic, strong) NSMutableDictionary* seenFirebaseLocations;
3131
//@property (nonatomic, strong) NSMutableDictionary* initializationEvents;
32-
@property(nonatomic, strong) XCTestCase* from;
33-
@property(nonatomic, strong) NSMutableArray* errors;
34-
@property(nonatomic, strong) NSMutableArray* actualPathsAndEvents;
35-
@property(nonatomic) int initializationEvents;
32+
@property(nonatomic, strong) XCTestCase* from;
33+
@property(nonatomic, strong) NSMutableArray* errors;
34+
@property(nonatomic, strong) NSMutableArray* actualPathsAndEvents;
35+
@property(nonatomic) int initializationEvents;
3636

3737
@end

0 commit comments

Comments
 (0)
close