Skip to content

Commit aad9e42

Browse files
committed
Merge branch 'bs-databaseinterop' into bs-auth-cleanup
* bs-databaseinterop: Fix Database Fake App Tests Sorted some test files Cleaned Up project file Revert "Squash of my previous local commits for Database Interop" Implement necessary protocols Use Interop for Auth token fetching Register Database with Interop
2 parents 779d900 + 19a9ec4 commit aad9e42

Some content is hidden

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

65 files changed

+13374
-15257
lines changed

Example/Database/Tests/Helpers/FDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
- (void)goOnline;
3030
- (void)restartOnline;
3131
- (void)restartOffline;
32-
- (void)waitForIdleUsingWaiter:(XCTest *)waiter;
33-
- (void) do:(void (^)(FIRDatabaseReference *))action;
32+
- (void)waitForIdleUsingWaiter:(XCTest*)waiter;
33+
- (void)do:(void (^)(FIRDatabaseReference *))action;
3434

3535
- (void)dispose;
3636

Example/Database/Tests/Helpers/FDevice.m

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

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

2020
#import <FirebaseDatabase/FIRDatabaseReference.h>
2121

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

28-
@interface FDevice () {
29-
FIRDatabaseConfig *config;
30-
NSString *url;
31-
BOOL isOnline;
32-
BOOL disposed;
28+
@interface FDevice() {
29+
FIRDatabaseConfig * config;
30+
NSString *url;
31+
BOOL isOnline;
32+
BOOL disposed;
3333
}
3434
@end
3535

3636
@implementation FDevice
3737

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

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

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

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

5656
static NSUInteger deviceId = 0;
5757

5858
- (id)initWithUrl:(NSString *)firebaseUrl andOnline:(BOOL)online {
59-
self = [super init];
60-
if (self) {
61-
config =
62-
[FIRDatabaseConfig configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
63-
config.persistenceEnabled = YES;
64-
url = firebaseUrl;
65-
isOnline = online;
66-
}
67-
return self;
59+
self = [super init];
60+
if (self) {
61+
config = [FIRDatabaseConfig configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
62+
config.persistenceEnabled = YES;
63+
url = firebaseUrl;
64+
isOnline = online;
65+
}
66+
return self;
6867
}
6968

70-
- (void)dealloc {
71-
if (!self->disposed) {
72-
[NSException raise:NSInternalInconsistencyException format:@"Forgot to dispose device"];
73-
}
69+
- (void) dealloc
70+
{
71+
if (!self->disposed) {
72+
[NSException raise:NSInternalInconsistencyException format:@"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
107-
// restoration is completely done.
108-
- (void)waitForIdleUsingWaiter:(XCTest *)waiter {
109-
[self do:^(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;
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+
[self do:^(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;
128120
}];
129-
[waiter waitUntil:^BOOL {
130-
return done;
121+
[waiter waitUntil:^BOOL { return done; }];
131122
}];
132-
}];
133123
}
134124

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];
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);
141132
}
142-
action(ref);
143-
}
144133
}
145134

146135
@end

Example/Database/Tests/Helpers/FEventTester.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
@interface FEventTester : 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)