aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Database
diff options
context:
space:
mode:
authorGravatar Paul Beusterien <paulbeusterien@google.com>2017-06-30 10:47:37 -0700
committerGravatar VinayGuthal <vinayg@qhode.com>2017-06-30 13:47:37 -0400
commitddbfd4cc666f5227ab0e1f5a98c8a499ccbb32d1 (patch)
tree9c2ec4e15b6741f413d66f428c45f0278219d728 /Example/Database
parent925f4c8b7558373172dd9410b7844637afaa2424 (diff)
Add travis trailing whitespace check (#116)
* Add travis trailing whitespace check * Remove trailing white space
Diffstat (limited to 'Example/Database')
-rw-r--r--Example/Database/Tests/Helpers/FEventTester.m4
-rw-r--r--Example/Database/Tests/Helpers/FTestBase.m10
-rw-r--r--Example/Database/Tests/Helpers/FTestHelpers.m20
-rw-r--r--Example/Database/Tests/Helpers/SenTest+FWaiter.m4
-rw-r--r--Example/Database/Tests/Integration/FConnectionTest.m8
-rw-r--r--Example/Database/Tests/Integration/FData.m210
-rw-r--r--Example/Database/Tests/Integration/FDotInfo.m6
-rw-r--r--Example/Database/Tests/Integration/FEventTests.m158
-rw-r--r--Example/Database/Tests/Integration/FIRDatabaseQueryTests.m678
-rw-r--r--Example/Database/Tests/Integration/FIRDatabaseTests.m2
-rw-r--r--Example/Database/Tests/Integration/FOrder.m110
-rw-r--r--Example/Database/Tests/Integration/FOrderByTests.m12
-rw-r--r--Example/Database/Tests/Integration/FPersist.m12
-rw-r--r--Example/Database/Tests/Integration/FRealtime.m2
-rw-r--r--Example/Database/Tests/Integration/FTransactionTest.m24
-rw-r--r--Example/Database/Tests/Unit/FIRDataSnapshotTests.m78
-rw-r--r--Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m4
-rw-r--r--Example/Database/Tests/Unit/FPathTests.m4
-rw-r--r--Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m108
-rw-r--r--Example/Database/Tests/third_party/Base64.m40
20 files changed, 747 insertions, 747 deletions
diff --git a/Example/Database/Tests/Helpers/FEventTester.m b/Example/Database/Tests/Helpers/FEventTester.m
index fa7c081..8c7bd19 100644
--- a/Example/Database/Tests/Helpers/FEventTester.m
+++ b/Example/Database/Tests/Helpers/FEventTester.m
@@ -90,7 +90,7 @@
FIRDatabaseHandle movedHandle = [path observeEventType:FIRDataEventTypeChildMoved withBlock:[self makeEventCallback:FIRDataEventTypeChildMoved]];
FIRDatabaseHandle changedHandle = [path observeEventType:FIRDataEventTypeChildChanged withBlock:[self makeEventCallback:FIRDataEventTypeChildChanged]];
FIRDatabaseHandle valueHandle = [path observeEventType:FIRDataEventTypeValue withBlock:[self makeEventCallback:FIRDataEventTypeValue]];
-
+
fbt_void_void cb = ^() {
[path removeObserverWithHandle:removedHandle];
[path removeObserverWithHandle:addedHandle];
@@ -137,7 +137,7 @@
}
- (fbt_void_datasnapshot) makeEventCallback:(FIRDataEventType)type {
-
+
fbt_void_datasnapshot cb = ^(FIRDataSnapshot * snap) {
FIRDatabaseReference * ref = snap.ref;
diff --git a/Example/Database/Tests/Helpers/FTestBase.m b/Example/Database/Tests/Helpers/FTestBase.m
index f55c73b..1cfe7ad 100644
--- a/Example/Database/Tests/Helpers/FTestBase.m
+++ b/Example/Database/Tests/Helpers/FTestBase.m
@@ -30,11 +30,11 @@
[FIRApp configure];
});
}
-
+
- (void)setUp
{
[super setUp];
-
+
[FIRDatabase setLoggingEnabled:YES];
_databaseURL = [[FIRApp defaultApp] options].databaseURL;
@@ -49,13 +49,13 @@
fn(snap);
done = YES;
}];
-
+
NSTimeInterval timeTaken = [self waitUntil:^BOOL{
return done;
} timeout:kFirebaseTestWaitUntilTimeout];
-
+
NSLog(@"snapWaiter:withBlock: timeTaken:%f", timeTaken);
-
+
XCTAssertTrue(done, @"Properly finished.");
}
diff --git a/Example/Database/Tests/Helpers/FTestHelpers.m b/Example/Database/Tests/Helpers/FTestHelpers.m
index 8ffdc7d..bfbb9e1 100644
--- a/Example/Database/Tests/Helpers/FTestHelpers.m
+++ b/Example/Database/Tests/Helpers/FTestHelpers.m
@@ -28,17 +28,17 @@
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
NSTimeInterval currentTime;
-
+
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
!predicate() && currentTime < timeoutTime;
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
-
+
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];
-
+
NSAssert(currentTime <= timeoutTime, @"Timed out");
-
+
return (finish - start);
}
@@ -54,9 +54,9 @@
});
NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs;
-
+
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderForApp:[FIRApp defaultApp]];
-
+
while (num > refs.count) {
NSString *sessionIdentifier = [NSString stringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-", refs.count];
FIRDatabaseConfig *config = [[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier authTokenProvider:authTokenProvider];
@@ -64,7 +64,7 @@
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:config];
[refs addObject:ref];
}
-
+
NSMutableArray* results = [[NSMutableArray alloc] init];
NSString* name = nil;
for (int i = 0; i < num; ++i) {
@@ -90,11 +90,11 @@
+ (FTupleFirebase *) getRandomNodePair {
NSArray* refs = [self getRandomNodes:2 persistence:YES];
-
+
FTupleFirebase* tuple = [[FTupleFirebase alloc] init];
tuple.one = [refs objectAtIndex:0];
tuple.two = [refs objectAtIndex:1];
-
+
return tuple;
}
@@ -114,7 +114,7 @@
triple.one = [refs objectAtIndex:0];
triple.two = [refs objectAtIndex:1];
triple.three = [refs objectAtIndex:2];
-
+
return triple;
}
diff --git a/Example/Database/Tests/Helpers/SenTest+FWaiter.m b/Example/Database/Tests/Helpers/SenTest+FWaiter.m
index 4c5c854..a573fb9 100644
--- a/Example/Database/Tests/Helpers/SenTest+FWaiter.m
+++ b/Example/Database/Tests/Helpers/SenTest+FWaiter.m
@@ -36,13 +36,13 @@
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
NSTimeInterval currentTime;
-
+
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
!predicate() && currentTime < timeoutTime;
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
-
+
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];
if (currentTime > timeoutTime) {
if (desc != nil) {
diff --git a/Example/Database/Tests/Integration/FConnectionTest.m b/Example/Database/Tests/Integration/FConnectionTest.m
index e72f6e4..c658e8e 100644
--- a/Example/Database/Tests/Integration/FConnectionTest.m
+++ b/Example/Database/Tests/Integration/FConnectionTest.m
@@ -53,9 +53,9 @@
FRepoInfo *info = [[FRepoInfo alloc] initWithHost:host isSecure:YES withNamespace:@"default"];
FConnection *conn = [[FConnection alloc] initWith:info andDispatchQueue:[FIRDatabaseQuery sharedQueue] lastSessionID:nil];
FTestConnectionDelegate *delegate = [[FTestConnectionDelegate alloc] init];
-
+
__block BOOL done = NO;
-
+
delegate.onDisconnect = ^(FDisconnectReason reason) {
if (reason == DISCONNECT_REASON_SERVER_RESET) {
// It is very likely that the first connection attempt sends us a redirect to the project's designated server.
@@ -68,10 +68,10 @@
NSAssert([sessionID length] != 0, @"sessionID must have length > 0");
done = YES;
};
-
+
conn.delegate = delegate;
[conn open];
-
+
WAIT_FOR(done);
}
@end
diff --git a/Example/Database/Tests/Integration/FData.m b/Example/Database/Tests/Integration/FData.m
index 390522c..08b0586 100644
--- a/Example/Database/Tests/Integration/FData.m
+++ b/Example/Database/Tests/Integration/FData.m
@@ -49,7 +49,7 @@
- (void) testWriteAndReadData {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
[node setValue:@42];
-
+
[self snapWaiter:node withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertEqualObjects(@42, [snapshot value], @"Properly saw correct value");
}];
@@ -75,9 +75,9 @@
- (void) testValReturnsCompoundObjectWithChildren {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[node setValue:@{@"foo": @{@"bar": @5}}];
-
+
[self snapWaiter:node withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertEqualObjects([[[snapshot value] objectForKey:@"foo"] objectForKey:@"bar"], @5, @"Properly saw compound object");
}];
@@ -98,16 +98,16 @@
FIRDatabaseReference * writeNode = tuple.one;
FIRDatabaseReference * readNode = tuple.two;
-
+
__block BOOL done = NO;
-
+
[[[[writeNode child:@"a"] child:@"b"] child:@"c"] setValue:@1];
[[[[writeNode child:@"a"] child:@"d"] child:@"e"] setValue:@2];
[[[[writeNode child:@"a"] child:@"d"] child:@"f"] setValue:@3];
[[writeNode child:@"g"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) { done = YES; }];
-
+
[self waitUntil:^BOOL{ return done; }];
-
+
[super snapWaiter:readNode withBlock:^(FIRDataSnapshot *s) {
XCTAssertEqualObjects([[[[s childSnapshotForPath:@"a"] childSnapshotForPath:@"b"] childSnapshotForPath:@"c"] value], @1, @"Proper child value");
XCTAssertEqualObjects([[[[s childSnapshotForPath:@"a"] childSnapshotForPath:@"d"] childSnapshotForPath:@"e"] value], @2, @"Proper child value");
@@ -234,7 +234,7 @@
[[node repo] interrupt]; // Going offline ensures that local events get queued up before server events
FEventTester* et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:lookingFor];
-
+
[[node child:@"a/aa"] setValue:@1];
[[node child:@"a"] setValue:@{@"aa": @2}];
[[node child:@"a"] setValue:@{@"aa": @3}];
@@ -498,7 +498,7 @@
- (void) testWriteCompoundObjectAndGetItBack {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
NSDictionary* data = @{
@"a": @{@"aa": @5,
@"ab": @3},
@@ -511,19 +511,19 @@
@NO,
@"dude"]
};
-
+
__block FIRDataSnapshot *snap = nil;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
-
+
__block BOOL done = NO;
[node setValue:data withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) { done = YES; }];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
[self snapWaiter:node withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertTrue([[[[snapshot value] objectForKey:@"c"] objectAtIndex:3] boolValue], @"Got proper boolean");
}];
@@ -531,7 +531,7 @@
- (void) testCanPassValueToPush {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
FIRDatabaseReference * pushA = [node childByAutoId];
[pushA setValue:@5];
@@ -541,7 +541,7 @@
FIRDatabaseReference * pushB = [node childByAutoId];
[pushB setValue:@{@"a": @5, @"b": @6}];
-
+
[self snapWaiter:pushB withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertEqualObjects(@5, [[snapshot value] objectForKey:@"a"], @"Got proper value");
XCTAssertEqualObjects(@6, [[snapshot value] objectForKey:@"b"], @"Got proper value");
@@ -556,7 +556,7 @@
__block BOOL setDone = NO;
__block BOOL removeDone = NO;
__block BOOL readDone = NO;
-
+
[node setValue:@42 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
setDone = YES;
}];
@@ -579,22 +579,22 @@
[self waitUntil:^BOOL{
return readDone && removeDone;
- }];
+ }];
}
- (void) testRemoveCallbackIsHitForNodesThatAreAlreadyRemoved {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block int removes = 0;
-
+
[node removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
removes = removes + 1;
}];
-
+
[node removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
removes = removes + 1;
}];
-
+
[self waitUntil:^BOOL{
return removes == 2;
}];
@@ -622,35 +622,35 @@
FIRDatabaseReference * writeNode = tuple.one;
FIRDatabaseReference * readNode = tuple.two;
FIRDatabaseReference * readNodeB = tuple.three;
-
+
__block BOOL initialReadDone = NO;
[readNode observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertTrue([[snapshot value] isEqual:[NSNull null]], @"First callback is null");
initialReadDone = YES;
}];
-
+
[self waitUntil:^BOOL{
return initialReadDone;
}];
-
+
__block BOOL writeDone = NO;
-
+
[writeNode setValue:@42 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
writeDone = YES;
}];
-
+
[self waitUntil:^BOOL{
return writeDone;
}];
-
+
__block BOOL readDone = NO;
[readNodeB observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertEqualObjects(@42, [snapshot value], @"Proper second read");
readDone = YES;
}];
-
+
[self waitUntil:^BOOL{
return readDone;
}];
@@ -660,13 +660,13 @@
- (void) testSetAndThenListenForValueEventsAreCorrect {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block BOOL setDone = NO;
-
+
[node setValue:@"moo" withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
setDone = YES;
}];
-
+
__block int calls = 0;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -674,7 +674,7 @@
XCTAssertTrue(calls == 1, @"Only called once");
XCTAssertEqualObjects([snapshot value], @"moo", @"Proper snapshot value");
}];
-
+
[self waitUntil:^BOOL{
return setDone && calls == 1;
}];
@@ -682,9 +682,9 @@
- (void) testHasChildrenWorksCorrectly {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[node setValue:@{@"one" : @42, @"two": @{@"a": @5}, @"three": @{@"a": @5, @"b": @6}}];
-
+
__block BOOL removedTwo = NO;
__block BOOL done = NO;
@@ -703,7 +703,7 @@
done = YES;
}
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -711,9 +711,9 @@
- (void) testNumChildrenWorksCorrectly {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[node setValue:@{@"one" : @42, @"two": @{@"a": @5}, @"three": @{@"a": @5, @"b": @6}}];
-
+
__block BOOL removedTwo = NO;
__block BOOL done = NO;
@@ -734,7 +734,7 @@
done = YES;
}
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -745,51 +745,51 @@
FTupleFirebase* tuple = [FTestHelpers getRandomNodePairWithoutPersistence];
FIRDatabaseReference * writeNode = tuple.one;
FIRDatabaseReference * readNode = tuple.two;
-
+
__block BOOL done = NO;
-
+
NSDictionary* compound = @{@"a": @5, @"b": @6};
NSNumber* number = @76;
-
+
[writeNode setValue:compound];
-
+
[self snapWaiter:writeNode withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertTrue([snapshot hasChildren], @"Has children");
XCTAssertEqualObjects(@5, [[snapshot childSnapshotForPath:@"a"] value], @"First child");
XCTAssertEqualObjects(@6, [[snapshot childSnapshotForPath:@"b"] value], @"First child");
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
[self snapWaiter:readNode withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertTrue([snapshot hasChildren], @"has children");
XCTAssertEqualObjects(@5, [[snapshot childSnapshotForPath:@"a"] value], @"First child");
XCTAssertEqualObjects(@6, [[snapshot childSnapshotForPath:@"b"] value], @"First child");
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
[writeNode setValue:number withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
[self snapWaiter:readNode withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertFalse([snapshot hasChildren], @"No more children");
XCTAssertEqualObjects(number, [snapshot value], @"Proper non compound value");
@@ -799,30 +799,30 @@
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
[writeNode setValue:compound withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
[self snapWaiter:readNode withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertTrue([snapshot hasChildren], @"Has children");
XCTAssertEqualObjects(@5, [[snapshot childSnapshotForPath:@"a"] value], @"First child");
XCTAssertEqualObjects(@6, [[snapshot childSnapshotForPath:@"b"] value], @"First child");
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
XCTAssertTrue(done, @"Properly finished");
}
@@ -1421,7 +1421,7 @@
- (void) testSettingInvalidObjectsThrow {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
XCTAssertThrows([ref setValue:[NSDate date]], @"Should throw");
NSDictionary *data = @{@"invalid":@"data", @".sv":@"timestamp"};
@@ -1451,7 +1451,7 @@
- (void) testSettingNull {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
XCTAssertNoThrow([ref setValue:nil], @"Should not throw");
XCTAssertNoThrow([ref setValue:[NSNull null]], @"Should not throw");
}
@@ -1470,7 +1470,7 @@
- (void) testRemoveFromOnMobileGraffitiBugAtAngelHack {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block BOOL done = NO;
[node observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1478,53 +1478,53 @@
done = YES;
}];
}];
-
+
[[node childByAutoId] setValue:@"moo"];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
XCTAssertTrue(done, @"Properly finished");
}
- (void) testSetANodeWithAQuotedKey {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block BOOL done = NO;
__block FIRDataSnapshot * snap;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
-
+
[node setValue:@{@"\"herp\"": @1234} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
done = YES;
XCTAssertEqualObjects(@1234, [[snap childSnapshotForPath:@"\"herp\""] value], @"Got it back");
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
XCTAssertTrue(done, @"Properly finished");
}
- (void) testSetANodeWithASingleQuoteKey {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block BOOL done = NO;
__block FIRDataSnapshot * snap;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
-
+
[node setValue:@{@"\"": @1234} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
done = YES;
XCTAssertEqualObjects(@1234, [[snap childSnapshotForPath:@"\""] value], @"Got it back");
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -1534,18 +1534,18 @@
- (void) testEmptyChildGetValueEventBeforeParent {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
NSArray* lookingFor = @[
[[FTupleEventTypeString alloc] initWithFirebase:[node child:@"a/aa/aaa"] withEvent:FIRDataEventTypeValue withString:nil],
[[FTupleEventTypeString alloc] initWithFirebase:[node child:@"a/aa"] withEvent:FIRDataEventTypeValue withString:nil],
[[FTupleEventTypeString alloc] initWithFirebase:[node child:@"a"] withEvent:FIRDataEventTypeValue withString:nil],
];
-
+
FEventTester* et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:lookingFor];
-
+
[node setValue:@{@"b": @5}];
-
+
[et wait];
}
@@ -1909,14 +1909,14 @@
FTupleFirebase* refs = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * reader = refs.one;
FIRDatabaseReference * writer = refs.two;
-
+
__block FIRDataSnapshot * localSnap = nil;
__block BOOL ready = NO;
[writer observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
localSnap = snapshot;
}];
-
+
[writer setValue:@{@"a": @{@"aa": @1, @"ab": @2}}];
[writer updateChildValues:@{@"a/aa": @10,
@".priority": @3.0,
@@ -1925,7 +1925,7 @@
withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1937,7 +1937,7 @@
XCTAssertTrue([result isEqualToDictionary:expected], @"Should get new value");
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
NSDictionary* result = [localSnap value];
NSDictionary* expected = @{@"a": @{@"aa": @10, @"ab": @20}};
@@ -2165,7 +2165,7 @@
snap = nil;
[ref setValue:toSet];
-
+
[self waitUntil:^BOOL{
return snap != nil;
}];
@@ -2306,14 +2306,14 @@
@".priority": [FIRServerValue timestamp]
}
};
-
+
__block BOOL done = NO;
[writer setValue:data andPriority:[FIRServerValue timestamp] withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) { done = YES; }];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
[self snapWaiter:reader withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary* value = [snapshot value];
NSNumber* now = [NSNumber numberWithDouble:round([[NSDate date] timeIntervalSince1970]*1000)];
@@ -2359,7 +2359,7 @@
FTupleFirebase* refs = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * writer = refs.one;
FIRDatabaseReference * reader = refs.two;
-
+
__block FIRDataSnapshot *snap = nil;
__block BOOL done = NO;
[reader observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -2368,14 +2368,14 @@
done = YES;
}
}];
-
+
[[writer child:@"a/b/c"] setValue:@1];
[[writer child:@"a"] updateChildValues:@{ @"b": @{ @"c": [FIRServerValue timestamp], @"d":@1 } }];
[self waitUntil:^BOOL{
return done;
}];
-
+
NSNumber* now = [NSNumber numberWithDouble:round([[NSDate date] timeIntervalSince1970]*1000)];
NSNumber* timestamp = [[snap childSnapshotForPath:@"a/b/c"] value];
XCTAssertTrue([[[snap childSnapshotForPath:@"a/b/c"] value] isKindOfClass:[NSNumber class]], @"Should get back number");
@@ -2392,19 +2392,19 @@
@".priority": [FIRServerValue timestamp]
}
};
-
+
__block FIRDataSnapshot *snap = nil;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
-
+
__block BOOL done = NO;
[node setValue:data andPriority:[FIRServerValue timestamp] withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) { done = YES; }];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
[self snapWaiter:node withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary* value = [snapshot value];
NSNumber* now = [NSNumber numberWithDouble:round([[NSDate date] timeIntervalSince1970]*1000)];
@@ -2419,20 +2419,20 @@
- (void) testServerValuesSetPriorityLocalEvents {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot *snap = nil;
[node observeEventType:FIRDataEventTypeChildMoved withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
__block BOOL done = NO;
-
+
[[node child:@"a"] setValue:@1 andPriority:nil];
[[node child:@"b"] setValue:@1 andPriority:@1];
[[node child:@"a"] setPriority:[FIRServerValue timestamp] withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -2445,7 +2445,7 @@
- (void) testServerValuesUpdateLocalEvents {
FIRDatabaseReference * node1 = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot *snap1 = nil;
[node1 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap1 = snapshot;
@@ -2460,11 +2460,11 @@
[currentData setValue:[FIRServerValue timestamp]];
return [FIRTransactionResult successWithValue:currentData];
}];
-
+
[self waitUntil:^BOOL{
return snap1 != nil && snap2 != nil && [snap1 value] != nil && [snap2 value] != nil;
}];
-
+
NSNumber* now = [NSNumber numberWithDouble:round([[NSDate date] timeIntervalSince1970]*1000)];
NSNumber* timestamp1 = [snap1 value];
@@ -2478,19 +2478,19 @@
- (void) testServerValuesTransactionLocalEvents {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot *snap = nil;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
}];
-
+
[[node child:@"a/b/c"] setValue:@1];
[[node child:@"a"] updateChildValues:@{ @"b": @{ @"c": [FIRServerValue timestamp], @"d":@1 } }];
-
+
[self waitUntil:^BOOL{
return snap != nil && [[snap childSnapshotForPath:@"a/b/d"] value] != nil;
}];
-
+
NSNumber* now = [NSNumber numberWithDouble:round([[NSDate date] timeIntervalSince1970]*1000)];
NSNumber* timestamp = [[snap childSnapshotForPath:@"a/b/c"] value];
XCTAssertTrue([[[snap childSnapshotForPath:@"a/b/c"] value] isKindOfClass:[NSNumber class]], @"Should get back number");
@@ -2499,7 +2499,7 @@
- (void) testUpdateAfterChildSet {
FIRDatabaseReference *node = [FTestHelpers getRandomNode];
-
+
__block BOOL done = NO;
__weak FIRDatabaseReference *weakRef = node;
[node setValue:@{@"a": @"a"} withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
@@ -2508,12 +2508,12 @@
done = YES;
}
}];
-
+
[[weakRef child:@"b"] setValue:@"b"];
-
+
[weakRef updateChildValues:@{@"c" : @"c"}];
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -2555,7 +2555,7 @@
];
[self waitUntil:^BOOL{ return done; }];
-
+
// cleanup
[FRepoManager interrupt:cfg];
[FRepoManager disposeRepos:cfg];
diff --git a/Example/Database/Tests/Integration/FDotInfo.m b/Example/Database/Tests/Integration/FDotInfo.m
index 0245dc5..60869ce 100644
--- a/Example/Database/Tests/Integration/FDotInfo.m
+++ b/Example/Database/Tests/Integration/FDotInfo.m
@@ -105,10 +105,10 @@
- (void) testManualConnectionManagement {
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
FIRDatabaseConfig *altCfg = [FIRDatabaseConfig configForName:@"alt-config"];
-
+
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];
FIRDatabaseReference * refAlt = [[FIRDatabaseReference alloc] initWithConfig:altCfg];
-
+
// Wait until we're connected to both Firebases
__block BOOL ready = NO;
[[ref child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -116,7 +116,7 @@
}];
[self waitUntil:^{ return ready; }];
[[ref child:@".info/connected"] removeAllObservers];
-
+
ready = NO;
[[refAlt child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = [[snapshot value] boolValue];
diff --git a/Example/Database/Tests/Integration/FEventTests.m b/Example/Database/Tests/Integration/FEventTests.m
index cbd7f31..3dd28de 100644
--- a/Example/Database/Tests/Integration/FEventTests.m
+++ b/Example/Database/Tests/Integration/FEventTests.m
@@ -29,15 +29,15 @@
}
- (void) testWriteLeafExpectValueChanged {
-
+
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * writeNode = tuple.one;
FIRDatabaseReference * readNode = tuple.two;
-
+
__block BOOL done = NO;
[writeNode setValue:@1234 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
-
+
[super snapWaiter:readNode withBlock:^(FIRDataSnapshot *s) {
XCTAssertEqualObjects([s value], @1234, @"Proper value in snapshot");
}];
@@ -50,83 +50,83 @@
[super snapWaiter:writeNode withBlock:^(FIRDataSnapshot *s) {
XCTAssertEqualObjects([s value], @42, @"Proper value in snapshot");
}];
-
+
}
- (void) testWriteLeafNodeThenExpectChildAddedEventThenValueEvent {
-
+
FIRDatabaseReference * writeNode = [FTestHelpers getRandomNode];
-
+
[[writeNode child:@"foo"] setValue:@878787];
-
+
NSArray* lookingFor = @[
[[FTupleEventTypeString alloc] initWithFirebase:writeNode withEvent:FIRDataEventTypeChildAdded withString:@"foo"],
[[FTupleEventTypeString alloc] initWithFirebase:writeNode withEvent:FIRDataEventTypeValue withString:nil],
];
-
+
FEventTester* et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:lookingFor];
[et wait];
-
+
[super snapWaiter:writeNode withBlock:^(FIRDataSnapshot *s) {
XCTAssertEqualObjects([[s childSnapshotForPath:@"foo"] value], @878787, @"Got proper value");
}];
-
+
}
- (void) testSetMultipleEventListenersOnSameNode {
-
+
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * writeNode = tuple.one;
FIRDatabaseReference * readNode = tuple.two;
[writeNode setValue:@42];
-
+
// two write nodes
FEventTester* et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:@[[[FTupleEventTypeString alloc] initWithFirebase:writeNode withEvent:FIRDataEventTypeValue withString:nil] ]];
[et wait];
-
+
et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:@[[[FTupleEventTypeString alloc] initWithFirebase:writeNode withEvent:FIRDataEventTypeValue withString:nil] ]];
[et wait];
-
+
// two read nodes
et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:@[[[FTupleEventTypeString alloc] initWithFirebase:readNode withEvent:FIRDataEventTypeValue withString:nil] ]];
[et wait];
-
+
et = [[FEventTester alloc] initFrom:self];
[et addLookingFor:@[[[FTupleEventTypeString alloc] initWithFirebase:readNode withEvent:FIRDataEventTypeValue withString:nil] ]];
[et wait];
-
+
}
- (void) testUnsubscribeEventsAndConfirmThatEventsNoLongerFire {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
__block int numValueCB = 0;
-
+
FIRDatabaseHandle handle = [node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *s) {
numValueCB = numValueCB + 1;
}];
-
+
// Set
for(int i = 0; i < 3; i++) {
[node setValue:[NSNumber numberWithInt:i]];
}
-
+
// bye
[node removeObserverWithHandle:handle];
-
+
// set again
for(int i = 10; i < 15; i++) {
[node setValue:[NSNumber numberWithInt:i]];
}
-
+
for(int i = 20; i < 25; i++) {
[node setValue:[NSNumber numberWithInt:i]];
}
-
+
// Should just be 3
[self waitUntil:^BOOL{
return numValueCB == 3;
@@ -142,27 +142,27 @@
[writeNode setValue:@{@"a": @10, @"b": @20} withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
done = YES;
}];
-
+
[self waitUntil:^BOOL{ return done; }];
NSArray* lookingForW = @[
[[FTupleEventTypeString alloc] initWithFirebase:[writeNode child:@"a"] withEvent:FIRDataEventTypeValue withString:nil],
[[FTupleEventTypeString alloc] initWithFirebase:[writeNode child:@"b"] withEvent:FIRDataEventTypeValue withString:nil],
];
-
+
NSArray* lookingForR = @[
[[FTupleEventTypeString alloc] initWithFirebase:[readNode child:@"a"] withEvent:FIRDataEventTypeValue withString:nil],
[[FTupleEventTypeString alloc] initWithFirebase:[readNode child:@"b"] withEvent:FIRDataEventTypeValue withString:nil],
];
-
+
FEventTester* etW = [[FEventTester alloc] initFrom:self];
[etW addLookingFor:lookingForW];
[etW wait];
-
+
FEventTester* etR = [[FEventTester alloc] initFrom:self];
[etR addLookingFor:lookingForR];
[etR wait];
-
+
// Modify compound but just change one of them
lookingForW = @[[[FTupleEventTypeString alloc] initWithFirebase:[writeNode child:@"b"] withEvent:FIRDataEventTypeValue withString:nil] ];
@@ -170,29 +170,29 @@
[etW addLookingFor:lookingForW];
[etR addLookingFor:lookingForR];
-
- [writeNode setValue:@{@"a": @10, @"b": @30}];
-
+
+ [writeNode setValue:@{@"a": @10, @"b": @30}];
+
[etW wait];
[etR wait];
}
-
+
- (void) testValueEventIsFiredForEmptyNode {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block BOOL valueFired = NO;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *s) {
XCTAssertTrue([[s value] isEqual:[NSNull null]], @"Value is properly nil");
valueFired = YES;
}];
-
+
[self waitUntil:^BOOL{
return valueFired;
}];
}
-
+
- (void) testCorrectEventsRaisedWhenLeafTurnsIntoInternalNode {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
NSMutableString* eventString = [[NSMutableString alloc] init];
@@ -209,69 +209,69 @@
[node observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *s) {
[eventString appendFormat:@", child_added %@", [s key]];
}];
-
+
[node setValue:@42];
[node setValue:@{@"a": @2}];
[node setValue:@84];
__block BOOL done = NO;
[node setValue:nil withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
-
+
XCTAssertEqualObjects(@", value 42, child_added a, got children, value 84, value <null>", eventString, @"Proper order seen");
}
- (void) testRegisteringCallbackMultipleTimesAndUnregistering {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
__block int changes = 0;
-
+
fbt_void_datasnapshot cb = ^(FIRDataSnapshot *snapshot) { changes = changes + 1; };
-
+
FIRDatabaseHandle handle1 = [node observeEventType:FIRDataEventTypeValue withBlock:cb];
FIRDatabaseHandle handle2 = [node observeEventType:FIRDataEventTypeValue withBlock:cb];
FIRDatabaseHandle handle3 = [node observeEventType:FIRDataEventTypeValue withBlock:cb];
-
+
__block BOOL done = NO;
[node setValue:@42 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
done = NO;
-
+
XCTAssertTrue(changes == 3, @"Saw 3 callback events %d", changes);
[node removeObserverWithHandle:handle1];
[node setValue:@84 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
done = NO;
-
+
XCTAssertTrue(changes == 5, @"Saw 5 callback events %d", changes);
[node removeObserverWithHandle:handle2];
[node setValue:@168 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
done = NO;
-
+
XCTAssertTrue(changes == 6, @"Saw 6 callback events %d", changes);
-
+
[node removeObserverWithHandle:handle3];
[node setValue:@376 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
done = NO;
-
+
XCTAssertTrue(changes == 6, @"Saw 6 callback events %d", changes);
-
+
NSLog(@"callbacks: %d", changes);
-
+
}
- (void) testUnregisteringTheSameCallbackTooManyTimesDoesNothing {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
fbt_void_datasnapshot cb = ^(FIRDataSnapshot *snapshot) { };
-
+
FIRDatabaseHandle handle1 = [node observeEventType:FIRDataEventTypeValue withBlock:cb];
[node removeObserverWithHandle:handle1];
[node removeObserverWithHandle:handle1];
-
+
XCTAssertTrue(YES, @"Properly reached end of test without throwing errors.");
}
@@ -284,24 +284,24 @@
firstCall = NO;
XCTAssertEqualObjects(@42, [snapshot value], @"Properly saw node value");
}];
-
+
[path setValue:@42];
[path setValue:@84];
-
+
__block BOOL done = NO;
-
+
[path setValue:nil withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
}
- (void) testOnceChildAddedFiresExaclyOnce {
__block int badCount = 0;
-
+
// for(int i = 0; i < 100; i++) {
FIRDatabaseReference * path = [FTestHelpers getRandomNode];
__block BOOL firstCall = YES;
-
+
__block BOOL done = NO;
@@ -319,18 +319,18 @@
}];
-
+
[[path child:@"foo"] setValue:@42];
[[path child:@"bar"] setValue:@84]; // XXX FIXME sometimes this event fires first
[[path child:@"foo"] setValue:@168];
-
-
+
+
// [path setValue:nil withCompletionBlock:^(BOOL status) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
-
-
+
+
// }
-
+
NSLog(@"BADCOUNT: %d", badCount);
}
@@ -351,10 +351,10 @@
XCTFail(@"Callback got called more than once.");
}
}];
-
+
[path setValue:@42];
[path setValue:@84];
-
+
[self waitUntil:^BOOL{ return done; }];
}
@@ -368,11 +368,11 @@
XCTAssertEqualObjects(@84, [snapshot value], @"Properly saw node value");
XCTAssertEqualObjects(@"bar", [snapshot key], @"Properly saw the first node");
}];
-
+
[path setValue:@{@"foo": @42, @"bar": @84}];
-
+
__block BOOL done = NO;
-
+
[path setValue:nil withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) { done = YES; }];
[self waitUntil:^BOOL{ return done; }];
}
@@ -387,7 +387,7 @@
XCTAssertTrue([[snapshot value] isEqual:[NSNull null]], @"Properly saw nil child node");
done = YES;
}];
-
+
[self waitUntil:^BOOL{ return done; }];
}
@@ -400,7 +400,7 @@
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
parentDone = YES;
}];
-
+
[self waitUntil:^BOOL{
return parentDone;
}];
@@ -409,19 +409,19 @@
XCTAssertTrue([[snapshot value] isEqual:[NSNull null]], @"Child is properly nil");
done = YES;
}];
-
+
// This test really isn't in the same spirit as the JS test; we can't currently make sure that the test fires right away since the ON and callback are async
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
XCTAssertTrue(done, @"Done fired.");
}
- (void) testEventsAreRaisedChildRemovedChildAddedChildMoved {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
NSMutableArray* events = [[NSMutableArray alloc] init];
[node observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snap) {
@@ -435,9 +435,9 @@
[node observeEventType:FIRDataEventTypeChildMoved withBlock:^(FIRDataSnapshot *snap) {
[events addObject:[NSString stringWithFormat:@"moved %@", [snap key]]];
}];
-
+
__block BOOL done = NO;
-
+
[node setValue:@{
@"a": @{@".value": @1, @".priority": @0 },
@"b": @{@".value": @1, @".priority": @1 },
@@ -448,15 +448,15 @@
} withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
[events removeAllObjects];
-
+
done = NO;
-
+
[node setValue:@{
@"a": @{@".value": @1, @".priority": @5 },
@"aa": @{@".value": @1, @".priority": @0 },
@@ -469,11 +469,11 @@
done = YES;
}
];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
XCTAssertEqualObjects(@"removed c, removed f, added aa, added bb, moved a, moved e", [events componentsJoinedByString:@", "], @"Got expected results");
}
diff --git a/Example/Database/Tests/Integration/FIRDatabaseQueryTests.m b/Example/Database/Tests/Integration/FIRDatabaseQueryTests.m
index a5bff5a..ff4b5dc 100644
--- a/Example/Database/Tests/Integration/FIRDatabaseQueryTests.m
+++ b/Example/Database/Tests/Integration/FIRDatabaseQueryTests.m
@@ -23,7 +23,7 @@
- (void) testCanCreateBasicQueries {
// Just make sure none of these throw anything
-
+
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
[ref queryLimitedToFirst:10];
@@ -143,7 +143,7 @@
- (void) testInvalidKeys {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
NSArray* badKeys = @[ @".test", @"test.", @"fo$o", @"[what", @"ever]", @"ha#sh", @"/thing", @"th/ing", @"thing/"];
-
+
for (NSString* badKey in badKeys) {
XCTAssertThrows([[ref queryOrderedByPriority] queryStartingAtValue:nil childKey:badKey], @"Setting bad key");
XCTAssertThrows([[ref queryOrderedByPriority] queryEndingAtValue:nil childKey:badKey], @"Setting bad key");
@@ -152,7 +152,7 @@
- (void) testOffCanBeCalledOnDefault {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL called = NO;
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -162,32 +162,32 @@
called = YES;
}
}];
-
+
[ref setValue:@{@"a": @5, @"b": @6}];
-
+
[self waitUntil:^BOOL{
return called;
}];
-
+
called = NO;
-
+
[ref removeAllObservers];
-
+
__block BOOL complete = NO;
[ref setValue:@{@"a": @6, @"b": @7} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
complete = YES;
}];
-
+
[self waitUntil:^BOOL{
return complete;
}];
-
+
XCTAssertFalse(called, @"Should not have been called again");
}
- (void) testOffCanBeCalledOnHandle {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL called = NO;
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
FIRDatabaseHandle handle = [query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -197,32 +197,32 @@
called = YES;
}
}];
-
+
[ref setValue:@{@"a": @5, @"b": @6}];
-
+
[self waitUntil:^BOOL{
return called;
}];
-
+
called = NO;
-
+
[ref removeObserverWithHandle:handle];
-
+
__block BOOL complete = NO;
[ref setValue:@{@"a": @6, @"b": @7} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
complete = YES;
}];
-
+
[self waitUntil:^BOOL{
return complete;
}];
-
+
XCTAssertFalse(called, @"Should not have been called again");
}
- (void) testOffCanBeCalledOnSpecificQuery {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL called = NO;
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
FIRDatabaseHandle handle = [query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -232,26 +232,26 @@
called = YES;
}
}];
-
+
[ref setValue:@{@"a": @5, @"b": @6}];
-
+
[self waitUntil:^BOOL{
return called;
}];
-
+
called = NO;
-
+
[query removeObserverWithHandle:handle];
-
+
__block BOOL complete = NO;
[ref setValue:@{@"a": @6, @"b": @7} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
complete = YES;
}];
-
+
[self waitUntil:^BOOL{
return complete;
}];
-
+
XCTAssertFalse(called, @"Should not have been called again");
}
@@ -267,7 +267,7 @@
- (void) testOffCanBeCalledWithoutHandle {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL called1 = NO;
__block BOOL called2 = NO;
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
@@ -277,51 +277,51 @@
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
called2 = YES;
}];
-
+
[ref setValue:@{@"a": @5, @"b": @6}];
-
+
[self waitUntil:^BOOL{
return called1 && called2;
}];
-
+
called1 = NO;
called2 = NO;
-
+
[ref removeAllObservers];
-
+
__block BOOL complete = NO;
[ref setValue:@{@"a": @6, @"b": @7} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
complete = YES;
}];
-
+
[self waitUntil:^BOOL{
return complete;
}];
-
+
XCTAssertFalse(called1 || called2, @"Should not have called either callback");
}
- (void) testEnsureOnly5ItemsAreKept {
__block FIRDataSnapshot * snap = nil;
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
__block int count = 0;
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = snapshot;
count++;
}];
-
+
[ref setValue:nil];
for (int i = 0; i < 10; ++i) {
[[ref childByAutoId] setValue:[NSNumber numberWithInt:i]];
}
-
+
[self waitUntil:^BOOL{
// The initial set triggers the callback, so we need to wait for 11 events
return count == 11;
}];
-
+
count = 5;
for (FIRDataSnapshot * snapshot in snap.children) {
NSNumber* num = [snapshot value];
@@ -329,26 +329,26 @@
XCTAssertTrue([num isEqualToNumber:current], @"Expect children in order");
count++;
}
-
+
XCTAssertTrue(count == 10, @"Expected 5 children");
}
- (void) testOnlyLast5SentFromServer {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
__block int count = 0;
-
+
[ref setValue:nil];
-
+
for (int i = 0; i < 10; ++i) {
[[ref childByAutoId] setValue:[NSNumber numberWithInt:i] withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
count++;
}];
}
-
+
[self waitUntil:^BOOL{
return count == 10;
}];
-
+
FIRDatabaseQuery * query = [ref queryLimitedToLast:5];
count = 5;
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -359,7 +359,7 @@
count++;
}
}];
-
+
[self waitUntil:^BOOL{
return count == 10;
}];
@@ -374,17 +374,17 @@
[expectations addQuery:[[[ref queryOrderedByPriority] queryEndingAtValue:nil] queryLimitedToLast:2] withExpectation:@{@"b": @2, @"c": @3}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryEndingAtValue:nil] queryLimitedToLast:3] withExpectation:@{@"a": @1, @"b": @2, @"c": @3}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryEndingAtValue:nil] queryLimitedToLast:4] withExpectation:@{@"a": @1, @"b": @2, @"c": @3}];
-
-
+
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[expectations validate];
}
@@ -397,51 +397,51 @@
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:nil childKey:@"b"] queryLimitedToFirst:1] withExpectation:@{@"b": @2}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:nil childKey:@"b"] queryLimitedToFirst:2] withExpectation:@{@"b": @2, @"c": @3}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:nil childKey:@"b"] queryLimitedToFirst:3] withExpectation:@{@"b": @2, @"c": @3}];
-
-
+
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[expectations validate];
}
- (void) testLimitsAndStartAtWithServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
FTestExpectations* expectations = [[FTestExpectations alloc] initFrom:self];
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:nil] queryLimitedToFirst:1] withExpectation:@{@"a": @1}];
-
+
/*params = [[FQueryParams alloc] init];
params = [params setStartPriority:nil andName:@"c"];
params = [params limitTo:1];
[expectations addQuery:[ref queryWithParams:params] withExpectation:@{@"c": @3}];
-
+
params = [[FQueryParams alloc] init];
params = [params setStartPriority:nil andName:@"b"];
params = [params limitTo:1];
[expectations addQuery:[ref queryWithParams:params] withExpectation:@{@"b": @2}];
-
+
params = [[FQueryParams alloc] init];
params = [params setStartPriority:nil andName:@"b"];
params = [params limitTo:2];
[expectations addQuery:[ref queryWithParams:params] withExpectation:@{@"b": @2, @"c": @3}];
-
+
params = [[FQueryParams alloc] init];
params = [params setStartPriority:nil andName:@"b"];
params = [params limitTo:3];
@@ -456,7 +456,7 @@
- (void) testChildEventsAreFiredWhenLimitIsHit {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
NSMutableArray* removed = [[NSMutableArray alloc] init];
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -467,30 +467,30 @@
[removed addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"d"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[@"b"];
XCTAssertTrue([removed isEqualToArray:expected], @"Expected to remove b");
expected = @[@"d"];
@@ -500,16 +500,16 @@
- (void) testChildEventsAreFiredWhenLimitIsHitWithServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
NSMutableArray* removed = [[NSMutableArray alloc] init];
FIRDatabaseQuery * query = [ref queryLimitedToLast:2];
@@ -521,25 +521,25 @@
[removed addObject:[snapshot key]];
}];
-
+
[self waitUntil:^BOOL{
return [added count] == 2;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"d"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[@"b"];
XCTAssertTrue([removed isEqualToArray:expected], @"Expected to remove b");
expected = @[@"d"];
@@ -562,30 +562,30 @@
[removed addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"a", @"b"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"aa"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[@"b"];
XCTAssertTrue([removed isEqualToArray:expected], @"Expected to remove b");
expected = @[@"aa"];
@@ -595,12 +595,12 @@
- (void) testChildEventsAreFiredWhenLimitIsHitWithStartAndServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -616,25 +616,25 @@
[removed addObject:[snapshot key]];
}];
-
+
[self waitUntil:^BOOL{
return [added count] == 2;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"a", @"b"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"aa"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[@"b"];
XCTAssertTrue([removed isEqualToArray:expected], @"Expected to remove b");
expected = @[@"aa"];
@@ -655,30 +655,30 @@
[removed addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready && [added count] >= 1;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have one item");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Expected to remove nothing");
expected = @[@"b"];
XCTAssertTrue([added isEqualToArray:expected], @"Expected to add b");
@@ -687,12 +687,12 @@
- (void) testStartAndLimitWithIncompleteWindowAndServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -709,25 +709,25 @@
[removed addObject:[snapshot key]];
}];
-
+
[self waitUntil:^BOOL{
return [added count] == 1;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have one item");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Expected to remove nothing");
expected = @[@"b"];
XCTAssertTrue([added isEqualToArray:expected], @"Expected to add b");
@@ -738,7 +738,7 @@
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
FIRDatabaseQuery * query = [ref queryLimitedToLast:2];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
NSMutableArray* removed = [[NSMutableArray alloc] init];
[query observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -748,26 +748,26 @@
[removed addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready && [added count] >= 1;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have one item");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -781,18 +781,18 @@
-(void) testChildEventsAreFiredWhenItemDeletedAtServer {
FIRDatabaseReference * ref = [FTestHelpers getRandomNodeWithoutPersistence];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
FIRDatabaseQuery * query = [ref queryLimitedToLast:2];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
NSMutableArray* removed = [[NSMutableArray alloc] init];
[query observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -803,21 +803,21 @@
[removed addObject:[snapshot key]];
}];
-
+
[self waitUntil:^BOOL{
return [added count] == 2;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -840,26 +840,26 @@
[removed addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready && [added count] >= 1;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have one item");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -872,18 +872,18 @@
-(void) testRemoveFiredWhenItemDeletedAtServer {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"b": @2, @"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
FIRDatabaseQuery * query = [ref queryLimitedToLast:2];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
NSMutableArray* removed = [[NSMutableArray alloc] init];
[query observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -894,21 +894,21 @@
[removed addObject:[snapshot key]];
}];
-
+
[self waitUntil:^BOOL{
return [added count] == 2;
}];
-
+
XCTAssertTrue([removed count] == 0, @"Nothing should be removed from our window");
NSArray* expected = @[@"b", @"c"];
XCTAssertTrue([added isEqualToArray:expected], @"Should have two items");
-
+
[added removeAllObjects];
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -922,15 +922,15 @@
- (void) testStartAtPriorityAndEndAtPriorityWork {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
FTestExpectations* expectations = [[FTestExpectations alloc] initFrom:self];
-
+
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:@"w"] queryEndingAtValue:@"y"] withExpectation:@{@"b": @2, @"c": @3, @"d": @4}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:@"w"] queryEndingAtValue:@"w"] withExpectation:@{@"d": @4}];
-
+
__block id nullSnap = @"dummy";
[[[[ref queryOrderedByPriority] queryStartingAtValue:@"a"] queryEndingAtValue:@"c"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
nullSnap = [snapshot value];
}];
-
+
[ref setValue:@{
@"a": @{@".value": @1, @".priority": @"z"},
@"b": @{@".value": @2, @".priority": @"y"},
@@ -939,13 +939,13 @@
}];
WAIT_FOR(expectations.isReady && [nullSnap isEqual:[NSNull null]]);
-
+
[expectations validate];
}
- (void) testStartAtPriorityAndEndAtPriorityWorkWithServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[ref setValue:@{
@"a": @{@".value": @1, @".priority": @"z"},
@@ -957,19 +957,19 @@
}];
WAIT_FOR(ready);
-
+
FTestExpectations* expectations = [[FTestExpectations alloc] initFrom:self];
-
+
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:@"w"] queryEndingAtValue:@"y"] withExpectation:@{@"b": @2, @"c": @3, @"d": @4}];
[expectations addQuery:[[[ref queryOrderedByPriority] queryStartingAtValue:@"w"] queryEndingAtValue:@"w"] withExpectation:@{@"d": @4}];
-
+
__block id nullSnap = @"dummy";
[[[[ref queryOrderedByPriority] queryStartingAtValue:@"a"] queryEndingAtValue:@"c"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
nullSnap = [snapshot value];
}];
-
+
WAIT_FOR(expectations.isReady && [nullSnap isEqual:[NSNull null]]);
-
+
[expectations validate];
}
@@ -985,16 +985,16 @@
query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"c"] queryEndingAtValue:@2];
[expectations addQuery:query withExpectation:@{@"c": @3, @"d": @4}];
-
+
[ref setValue:@{
@"a": @{@".value": @1, @".priority": @1},
@"b": @{@".value": @2, @".priority": @1},
@"c": @{@".value": @3, @".priority": @2},
@"d": @{@".value": @4, @".priority": @2}
}];
-
+
WAIT_FOR(expectations.isReady);
-
+
[expectations validate];
}
@@ -1009,9 +1009,9 @@
} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
WAIT_FOR(ready);
-
+
FTestExpectations* expectations = [[FTestExpectations alloc] initFrom:self];
FIRDatabaseQuery * query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"a"] queryEndingAtValue:@2 childKey:@"d"];
@@ -1022,9 +1022,9 @@
query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"c"] queryEndingAtValue:@2];
[expectations addQuery:query withExpectation:@{@"c": @3, @"d": @4}];
-
+
WAIT_FOR(expectations.isReady);
-
+
[expectations validate];
}
@@ -1040,16 +1040,16 @@
query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"e"] queryEndingAtValue:@2];
[expectations addQuery:query withExpectation:@{@"a": @1, @"b": @2}];
-
+
[ref setValue:@{
@"c": @{@".value": @3, @".priority": @1},
@"d": @{@".value": @4, @".priority": @1},
@"a": @{@".value": @1, @".priority": @2},
@"b": @{@".value": @2, @".priority": @2}
}];
-
+
WAIT_FOR(expectations.isReady);
-
+
[expectations validate];
}
@@ -1064,9 +1064,9 @@
} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
WAIT_FOR(ready);
-
+
FTestExpectations* expectations = [[FTestExpectations alloc] initFrom:self];
FIRDatabaseQuery * query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"c"] queryEndingAtValue:@2 childKey:@"b"];
@@ -1077,9 +1077,9 @@
query = [[[ref queryOrderedByPriority] queryStartingAtValue:@1 childKey:@"e"] queryEndingAtValue:@2];
[expectations addQuery:query withExpectation:@{@"a": @1, @"b": @2}];
-
+
WAIT_FOR(expectations.isReady);
-
+
[expectations validate];
}
@@ -1190,7 +1190,7 @@
- (void) testPrevNameWorks {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* added = [[NSMutableArray alloc] init];
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeChildAdded andPreviousSiblingKeyWithBlock:^(FIRDataSnapshot *snapshot, NSString *prevName) {
@@ -1202,31 +1202,31 @@
}
}];
-
+
[[ref child:@"a"] setValue:@1];
[self waitUntil:^BOOL{
NSArray* expected = @[@"a", @"null"];
return [added isEqualToArray:expected];
}];
-
+
[added removeAllObjects];
-
+
[[ref child:@"c"] setValue:@3];
[self waitUntil:^BOOL{
NSArray* expected = @[@"c", @"a"];
return [added isEqualToArray:expected];
}];
-
+
[added removeAllObjects];
-
+
[[ref child:@"b"] setValue:@2];
[self waitUntil:^BOOL{
NSArray* expected = @[@"b", @"null"];
return [added isEqualToArray:expected];
}];
-
+
[added removeAllObjects];
-
+
[[ref child:@"d"] setValue:@3];
[self waitUntil:^BOOL{
NSArray* expected = @[@"d", @"c"];
@@ -1238,7 +1238,7 @@
- (void) testPrevNameWorksWithMoves {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* moved = [[NSMutableArray alloc] init];
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeChildMoved andPreviousSiblingKeyWithBlock:^(FIRDataSnapshot *snapshot, NSString *prevName) {
@@ -1249,56 +1249,56 @@
[moved addObject:@"null"];
}
}];
-
+
[ref setValue:@{
@"a": @{@".value": @"a", @".priority": @10},
@"b": @{@".value": @"b", @".priority": @20},
@"c": @{@".value": @"c", @".priority": @30},
@"d": @{@".value": @"d", @".priority": @40}
}];
-
+
__block BOOL ready = NO;
[[ref child:@"c"] setPriority:@50 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSArray* expected = @[@"c", @"d"];
XCTAssertTrue([moved isEqualToArray:expected], @"Expected changed node and prevChild");
-
+
[moved removeAllObjects];
ready = NO;
[[ref child:@"c"] setPriority:@35 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[@"c", @"null"];
XCTAssertTrue([moved isEqualToArray:expected], @"Expected changed node and prevChild");
-
+
[moved removeAllObjects];
ready = NO;
[[ref child:@"b"] setPriority:@33 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
expected = @[];
XCTAssertTrue([moved isEqualToArray:expected], @"Expected changed node and prevChild to be empty");
}
- (void) testLocalEvents {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* events = [[NSMutableArray alloc] init];
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
NSString *eventString = [NSString stringWithFormat:@"%@ added", [snapshot value]];
@@ -1309,7 +1309,7 @@
NSString *eventString = [NSString stringWithFormat:@"%@ removed", [snapshot value]];
[events addObject:eventString];
}];
-
+
__block BOOL ready = NO;
for (int i = 0; i < 5; ++i) {
[[ref childByAutoId] setValue:[NSNumber numberWithInt:i] withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
@@ -1318,11 +1318,11 @@
}
}];
}
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSArray* expected = @[@"0 added", @"1 added", @"0 removed", @"2 added", @"1 removed", @"3 added", @"2 removed", @"4 added"];
XCTAssertTrue([events isEqualToArray:expected], @"Expecting window to stay at two nodes");
}
@@ -1331,7 +1331,7 @@
FTupleFirebase* pair = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * writer = pair.one;
FIRDatabaseReference * reader = pair.two;
-
+
NSMutableArray* events = [[NSMutableArray alloc] init];
[[reader queryLimitedToLast:2] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1343,11 +1343,11 @@
NSString *oldEventString = [NSString stringWithFormat:@"%@ added", [snapshot value]];
[events removeObject:oldEventString];
}];
-
+
for (int i = 0; i < 5; ++i) {
[[writer childByAutoId] setValue:[NSNumber numberWithInt:i]];
}
-
+
NSArray* expected = @[@"3 added", @"4 added"];
[self waitUntil:^BOOL{
return [events isEqualToArray:expected];
@@ -1356,12 +1356,12 @@
- (void) testLimitOnEmptyNodeFiresValue {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
[[ref queryLimitedToLast:1] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1369,7 +1369,7 @@
- (void) testFilteringToNullPriorities {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
// Note: cannot set nil in a dictionary, just leave out priority
[ref setValue:@{
@"a": @0,
@@ -1378,7 +1378,7 @@
@"d": @{@".priority": @3, @".value": @3},
@"e": @{@".priority": @"hi", @".value": @4}
}];
-
+
__block BOOL ready = NO;
[[[[ref queryOrderedByPriority] queryStartingAtValue:nil] queryEndingAtValue:nil] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary *expected = @{@"a" : @0, @"b" : @1};
@@ -1386,7 +1386,7 @@
XCTAssertTrue([val isEqualToDictionary:expected], @"Expected only null priority keys");
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1394,7 +1394,7 @@
- (void) testNullPrioritiesIncludedInEndAt {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
// Note: cannot set nil in a dictionary, just leave out priority
[ref setValue:@{
@"a": @0,
@@ -1403,7 +1403,7 @@
@"d": @{@".priority": @3, @".value": @3},
@"e": @{@".priority": @"hi", @".value": @4}
}];
-
+
__block BOOL ready = NO;
[[[ref queryOrderedByPriority] queryEndingAtValue:@2] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
NSDictionary *expected = @{@"a" : @0, @"b" : @1, @"c" : @2};
@@ -1411,7 +1411,7 @@
XCTAssertTrue([val isEqualToDictionary:expected], @"Expected up to priority 2");
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1462,7 +1462,7 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected child listener");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1476,7 +1476,7 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected parent listener");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1489,11 +1489,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Child listener should be back");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[[ref child:@"a"] removeAllObservers];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1501,10 +1501,10 @@
XCTAssertTrue(listens.count == 0, @"No more listeners");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
- }];
+ }];
}
- (void) testDedupeListensOnGrandchild {
@@ -1520,7 +1520,7 @@
[ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
}];
-
+
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
listens = [self dumpListensForRef:ref];
NSSet* expected = [self expectDefaultListenerAtPath:[FPath empty]];
@@ -1565,7 +1565,7 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected grandchild");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1582,7 +1582,7 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected two grandchildren");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1596,11 +1596,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected parent listener to override");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[ref removeAllObservers];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1612,11 +1612,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected grandchild listeners to return");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[[ref child:@"a/aa"] removeAllObservers];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1625,11 +1625,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Expected one listener");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[[ref child:@"a/bb"] removeAllObservers];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1637,7 +1637,7 @@
XCTAssertTrue(listens.count == 0, @"No more listeners");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1647,7 +1647,7 @@
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
__block NSSet* listens = [self dumpListensForRef:ref];
XCTAssertTrue(listens.count == 0, @"No Listens yet");
-
+
__block BOOL ready = NO;
FIRDatabaseQuery * aLim1 = [[ref child:@"a"] queryLimitedToLast:1];
FIRDatabaseHandle handle1 = [aLim1 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1660,11 +1660,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Single query");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
FIRDatabaseQuery * rootLim1 = [ref queryLimitedToLast:1];
FIRDatabaseHandle handle2 = [rootLim1 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1680,11 +1680,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Two queries");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
FIRDatabaseQuery * aLim5 = [[ref child:@"a"] queryLimitedToLast:5];
FIRDatabaseHandle handle3 = [aLim5 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1694,7 +1694,7 @@
FQueryParams* expectedParams1 = [[FQueryParams alloc] init];
expectedParams1 = [expectedParams1 limitTo:1];
NSSet* rootExpected = [self expectParams:expectedParams1 atPath:[FPath empty]];
-
+
FQueryParams* expectedParams2 = [[FQueryParams alloc] init];
expectedParams2 = [expectedParams2 limitTo:5];
NSSet* childExpected = [self expectParamssetValue:[NSSet setWithObjects:expectedParams1, expectedParams2, nil] atPath:[FPath pathWithString:@"/a"]];
@@ -1703,11 +1703,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Three queries");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[ref removeObserverWithHandle:handle2];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1720,11 +1720,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Two queries");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[aLim1 removeObserverWithHandle:handle1];
[aLim5 removeObserverWithHandle:handle3];
ready = NO;
@@ -1733,7 +1733,7 @@
XCTAssertTrue(listens.count == 0, @"No more listeners");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1743,7 +1743,7 @@
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
__block NSSet* listens = [self dumpListensForRef:ref];
XCTAssertTrue(listens.count == 0, @"No Listens yet");
-
+
__block BOOL ready = NO;
FIRDatabaseQuery * aLim1 = [[ref child:@"a"] queryLimitedToLast:1];
FIRDatabaseHandle handle1 = [aLim1 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1756,11 +1756,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Single query");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
FIRDatabaseQuery * bLim1 = [[ref child:@"b"] queryLimitedToLast:1];
FIRDatabaseHandle handle2 = [bLim1 observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -1776,11 +1776,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Two queries");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
FIRDatabaseHandle handle3 = [ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
}];
@@ -1790,11 +1790,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Parent should override");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
// remove in slightly random order
[aLim1 removeObserverWithHandle:handle1];
ready = NO;
@@ -1804,11 +1804,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Parent should override");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
[ref removeObserverWithHandle:handle3];
ready = NO;
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1819,11 +1819,11 @@
XCTAssertTrue([expected isEqualToSet:listens], @"Single query");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
[bLim1 removeObserverWithHandle:handle2];
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
@@ -1831,7 +1831,7 @@
XCTAssertTrue(listens.count == 0, @"No more listeners");
ready = YES;
});
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -1839,13 +1839,13 @@
-(void) testLimitWithMixOfNullAndNonNullPriorities {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* children = [[NSMutableArray alloc] init];
[[ref queryLimitedToLast:5] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
[children addObject:[snapshot key]];
}];
-
+
__block BOOL ready = NO;
NSDictionary* toSet = @{
@"Vikrum": @{@".priority": @1000, @"score": @1000, @"name": @"Vikrum"},
@@ -1855,23 +1855,23 @@
@"Sally": @{@".priority": @-7, @"score": @-7, @"name": @"Sally"},
@"Fred": @{@"score": @0, @"name": @"Fred"}
};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSArray* expected = @[@"Sally", @"James", @"Andrew", @"Mike", @"Vikrum"];
XCTAssertTrue([children isEqualToArray:expected], @"Null priority should be left out");
-
+
}
-(void) testLimitWithMixOfNullAndNonNullPrioritiesOnServerData {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
NSDictionary* toSet = @{
@"Vikrum": @{@".priority": @1000, @"score": @1000, @"name": @"Vikrum"},
@@ -1881,15 +1881,15 @@
@"Sally": @{@".priority": @-7, @"score": @-7, @"name": @"Sally"},
@"Fred": @{@"score": @0, @"name": @"Fred"}
};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
__block int count = 0;
NSMutableArray* children = [[NSMutableArray alloc] init];
@@ -1897,15 +1897,15 @@
[children addObject:[snapshot key]];
count++;
}];
-
+
[self waitUntil:^BOOL{
return count == 5;
}];
-
-
+
+
NSArray* expected = @[@"Sally", @"James", @"Andrew", @"Mike", @"Vikrum"];
XCTAssertTrue([children isEqualToArray:expected], @"Null priority should be left out");
-
+
}
// Skipping context tests. Context is not implemented on iOS
@@ -1915,9 +1915,9 @@
just the modified children? Not sure.
- (void) testHandleUpdateThatDeletesEntireWindow {
Firebase* ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* snaps = [[NSMutableArray alloc] init];
-
+
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
id val = [snapshot value];
if (val == nil) {
@@ -1926,25 +1926,25 @@
[snaps addObject:val];
}
}];
-
+
NSDictionary* toSet = @{
@"a": @{@".priority": @1, @".value": @1},
@"b": @{@".priority": @2, @".value": @2},
@"c": @{@".priority": @3, @".value": @3}
};
-
+
[ref setValue:toSet];
-
+
__block BOOL ready = NO;
toSet = @{@"b": [NSNull null], @"c": [NSNull null]};
[ref updateChildValues:toSet withCompletionBlock:^(NSError* err, Firebase* ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSArray* expected = @[@{@"b": @2, @"c": @3}, [NSNull null], @{@"a": @1}];
STAssertTrue([snaps isEqualToArray:expected], @"Expected %@ to equal %@", snaps, expected);
}
@@ -1952,41 +1952,41 @@
- (void) testHandlesAnOutOfViewQueryOnAChild {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block NSDictionary* parent = nil;
[[ref queryLimitedToLast:1] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
parent = [snapshot value];
}];
-
+
__block NSNumber* child = nil;
[[ref child:@"a"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
child = [snapshot value];
}];
-
+
__block BOOL ready = NO;
NSDictionary* toSet = @{@"a": @1, @"b": @2};
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSDictionary* parentExpected = @{@"b": @2};
NSNumber* childExpected = [NSNumber numberWithInt:1];
XCTAssertTrue([parent isEqualToDictionary:parentExpected], @"Expected last element");
XCTAssertTrue([child isEqualToNumber:childExpected], @"Expected value of a");
-
+
ready = NO;
[ref updateChildValues:@{@"c": @3} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
parentExpected = @{@"c": @3};
XCTAssertTrue([parent isEqualToDictionary:parentExpected], @"Expected last element");
XCTAssertTrue([child isEqualToNumber:childExpected], @"Expected value of a");
@@ -1994,50 +1994,50 @@
- (void) testHandlesAChildQueryGoingOutOfViewOfTheParent {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block NSDictionary* parent = nil;
[[ref queryLimitedToLast:1] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
parent = [snapshot value];
}];
-
+
__block NSNumber* child = nil;
[[ref child:@"a"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
child = [snapshot value];
}];
-
+
__block BOOL ready = NO;
NSDictionary* toSet = @{@"a": @1};
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
WAIT_FOR(ready);
-
+
NSDictionary* parentExpected = @{@"a": @1};
NSNumber* childExpected = [NSNumber numberWithInt:1];
XCTAssertTrue([parent isEqualToDictionary:parentExpected], @"Expected last element");
XCTAssertTrue([child isEqualToNumber:childExpected], @"Expected value of a");
-
+
ready = NO;
[[ref child:@"b"] setValue:@2 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
WAIT_FOR(ready);
-
+
parentExpected = @{@"b": @2};
XCTAssertTrue([parent isEqualToDictionary:parentExpected], @"Expected last element");
XCTAssertTrue([child isEqualToNumber:childExpected], @"Expected value of a");
-
+
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
parentExpected = @{@"a": @1};
XCTAssertTrue([parent isEqualToDictionary:parentExpected], @"Expected last element");
XCTAssertTrue([child isEqualToNumber:childExpected], @"Expected value of a");
@@ -2045,7 +2045,7 @@
- (void) testHandlesDivergingViews {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block NSDictionary* cVal = nil;
FIRDatabaseQuery * query = [[[ref queryOrderedByPriority] queryEndingAtValue:nil childKey:@"c"] queryLimitedToLast:1];
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -2063,24 +2063,24 @@
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSDictionary* expected = @{@"c": @3};
XCTAssertTrue([cVal isEqualToDictionary:expected], @"should be c");
XCTAssertTrue([dVal isEqualToDictionary:expected], @"should be c");
-
+
ready = NO;
[[ref child:@"d"] setValue:@4 withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([cVal isEqualToDictionary:expected], @"should be c");
expected = @{@"d": @4};
XCTAssertTrue([dVal isEqualToDictionary:expected], @"should be d");
@@ -2088,7 +2088,7 @@
- (void) testHandlesRemovingAQueriedElement {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block NSNumber* val = nil;
[[ref queryLimitedToLast:1] observeEventType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
id newVal = [snapshot value];
@@ -2096,27 +2096,27 @@
val = [snapshot value];
}
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([val isEqualToNumber:@2], @"Expected last element in window");
-
+
ready = NO;
[[ref child:@"b"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([val isEqualToNumber:@1], @"Should now be the next element in the window");
}
@@ -2131,16 +2131,16 @@
val = [snapshot value];
}
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([val isEqualToNumber:@1], @"Expected first element in window");
}
@@ -2156,50 +2156,50 @@
val = [snapshot value];
}
}];
-
+
__block BOOL ready = NO;
[ref setValue:@{@"a": @1, @"b": @2} withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([val isEqualToNumber:@1], @"Expected first element in window");
-
+
ready = NO;
[[ref child:@"a"] removeValueWithCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([val isEqualToNumber:@2], @"Expected next element in window");
}
// See case 1169
- (void) testStartAtWithTwoArgumentsWorks {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
NSMutableArray* children = [[NSMutableArray alloc] init];
-
+
NSDictionary* toSet = @{
@"Walker": @{@"name": @"Walker", @"score": @20, @".priority": @20},
@"Michael": @{@"name": @"Michael", @"score": @100, @".priority": @100}
};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
FIRDatabaseQuery * query = [[[ref queryOrderedByPriority] queryStartingAtValue:@20 childKey:@"Walker"] queryLimitedToFirst:2];
[query observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -2209,32 +2209,32 @@
}
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSArray* expected = @[@"Walker", @"Michael"];
XCTAssertTrue([children isEqualToArray:expected], @"Expected both children");
}
- (void) testHandlesMultipleQueriesOnSameNode {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
-
+
NSDictionary* toSet = @{
@"a": @1, @"b": @2, @"c": @3, @"d": @4, @"e": @5, @"f": @6
};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
__block BOOL called = NO;
[[ref queryLimitedToLast:2] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -2243,11 +2243,11 @@
called = YES;
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
__block NSDictionary* snap = nil;
// now do nested once calls
@@ -2258,95 +2258,95 @@
ready = YES;
}];
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSDictionary* expected = @{@"f": @6};
XCTAssertTrue([snap isEqualToDictionary:expected], @"Expected the correct data");
}
- (void) testHandlesOnceCalledOnNodeWithDefaultListener {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
-
+
NSDictionary* toSet = @{
@"a": @1, @"b": @2, @"c": @3, @"d": @4, @"e": @5, @"f": @6
};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
[ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
// we got the initial data
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
-
+
__block NSNumber* snap = nil;
[[ref queryLimitedToLast:1] observeSingleEventOfType:FIRDataEventTypeChildAdded withBlock:^(FIRDataSnapshot *snapshot) {
snap = [snapshot value];
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
XCTAssertTrue([snap isEqualToNumber:@6], @"Got once response");
}
- (void) testHandlesOnceCalledOnNodeWithDefaultListenerAndNonCompleteLimit {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL ready = NO;
-
+
NSDictionary* toSet = @{@"a": @1, @"b": @2, @"c": @3};
-
+
[ref setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
// do first listen
[ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
-
+
__block NSDictionary* snap = nil;
[[ref queryLimitedToLast:5] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
snap = [snapshot value];
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
NSDictionary* expected = @{@"a": @1, @"b": @2, @"c": @3};
XCTAssertTrue([snap isEqualToDictionary:expected], @"Got once response");
}
@@ -2355,19 +2355,19 @@
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * writer = tuple.one;
FIRDatabaseReference * reader = tuple.two;
-
+
__block BOOL ready = NO;
-
+
NSDictionary* toSet = @{@"a": @"a", @"b": @"b", @"c": @"c", @"d": @"d", @"e": @"e"};
-
+
[writer setValue:toSet withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
ready = YES;
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
-
+
ready = NO;
__block int count = 0;
@@ -2386,7 +2386,7 @@
ready = YES;
}
}];
-
+
[self waitUntil:^BOOL{
return ready;
}];
@@ -2394,7 +2394,7 @@
- (void) testEndingAtNameReturnsCorrectChildren {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSDictionary* toSet = @{
@"a": @"a",
@"b": @"b",
@@ -2633,9 +2633,9 @@
- (void) testItemsPulledIntoLimitCorrectly {
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
-
+
NSMutableArray* snaps = [[NSMutableArray alloc] init];
-
+
// Just so everything is cached locally.
[ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
@@ -2645,20 +2645,20 @@
id val = [snapshot value];
[snaps addObject:val];
}];
-
+
[ref setValue:@{
@"a": @{@".value": @1, @".priority": @1},
@"b": @{@".value": @2, @".priority": @2},
@"c": @{@".value": @3, @".priority": @3}
}];
-
+
__block BOOL ready = NO;
[[ref child:@"b"] setValue:[NSNull null] withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
ready = YES;
}];
WAIT_FOR(ready);
-
+
NSArray* expected = @[@{@"b": @2, @"c": @3}, @{@"a": @1, @"c": @3}];
XCTAssertEqualObjects(snaps, expected, @"Incorrect snapshots.");
}
@@ -2753,23 +2753,23 @@
// one-time listener. Event removal code path wasn't removing the listener because it stopped as soon as it
// found the default view. This left the zombie one-time listener and check failed on the second attempt to
// create a listener for the same path (asana#61028598952586).
-
+
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
__block BOOL done = NO;
-
+
[[ref child:@"child"] setValue:@{@"name": @"John"}];
[[[ref queryOrderedByChild:@"name"] queryEqualToValue:@"John"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
done = YES;
}];
WAIT_FOR(done);
-
+
done = NO;
[[[ref child:@"child"] child:@"favoriteToy"] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
done = YES;
}];
WAIT_FOR(done);
-
+
done = NO;
[[[ref child:@"child"] child:@"favoriteToy"] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
done = YES;
diff --git a/Example/Database/Tests/Integration/FIRDatabaseTests.m b/Example/Database/Tests/Integration/FIRDatabaseTests.m
index 8a5742d..d0d0909 100644
--- a/Example/Database/Tests/Integration/FIRDatabaseTests.m
+++ b/Example/Database/Tests/Integration/FIRDatabaseTests.m
@@ -168,7 +168,7 @@ static const NSInteger kFErrorCodeWriteCanceled = 3;
[self waitForEvents:ref];
XCTAssertEqual(engine.userWrites.count, (NSUInteger)0);
XCTAssertEqualObjects(order, (@[@"1", @"2", @"3", @"4"]));
-
+
[database goOnline];
}
diff --git a/Example/Database/Tests/Integration/FOrder.m b/Example/Database/Tests/Integration/FOrder.m
index e8c628b..0935f9a 100644
--- a/Example/Database/Tests/Integration/FOrder.m
+++ b/Example/Database/Tests/Integration/FOrder.m
@@ -29,7 +29,7 @@
for(int i = 0; i < 10; i++) {
[[node childByAutoId] setValue:[NSNumber numberWithInt:i]];
}
-
+
[super snapWaiter:node withBlock:^(FIRDataSnapshot * snapshot) {
int expected = 0;
for (FIRDataSnapshot * child in snapshot.children) {
@@ -44,15 +44,15 @@
- (void) testPushEnumerateManyPathsWriteAndCheckOrder {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
NSMutableArray* paths = [[NSMutableArray alloc] init];
-
+
for(int i = 0; i < 20; i++) {
[paths addObject:[node childByAutoId]];
}
-
+
for(int i = 0; i < 20; i++) {
[(FIRDatabaseReference *)[paths objectAtIndex:i] setValue:[NSNumber numberWithInt:i]];
}
-
+
[super snapWaiter:node withBlock:^(FIRDataSnapshot *snap) {
int expected = 0;
for (FIRDataSnapshot * child in snap.children) {
@@ -65,22 +65,22 @@
}
- (void) testPushDataReconnectReadBackAndVerifyOrder {
-
+
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
-
+
__block int expected = 0;
__block int nodesSet = 0;
FIRDatabaseReference * node = tuple.one;
for(int i = 0; i < 10; i++) {
[[node childByAutoId] setValue:[NSNumber numberWithInt:i] withCompletionBlock:^(NSError* err, FIRDatabaseReference * ref) {
nodesSet++;
- }];
+ }];
}
-
+
[self waitUntil:^BOOL{
return nodesSet == 10;
}];
-
+
__block BOOL done = NO;
[super snapWaiter:node withBlock:^(FIRDataSnapshot *snap) {
expected = 0;
@@ -92,15 +92,15 @@
}
done = YES;
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
-
+
done = NO;
-
+
XCTAssertTrue(nodesSet == 10, @"All of the nodes have been set");
-
+
[super snapWaiter:tuple.two withBlock:^(FIRDataSnapshot *snap) {
expected = 0;
for (FIRDataSnapshot * child in snap.children) {
@@ -115,7 +115,7 @@
- (void) testPushDataWithPrioritiesReconnectReadBackAndVerifyOrder {
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
-
+
__block int expected = 0;
__block int nodesSet = 0;
FIRDatabaseReference * node = tuple.one;
@@ -124,17 +124,17 @@
nodesSet = nodesSet + 1;
}];
}
-
+
[super snapWaiter:node withBlock:^(FIRDataSnapshot *snap) {
expected = 9;
-
+
for (FIRDataSnapshot * child in snap.children) {
XCTAssertEqualObjects([child value], [NSNumber numberWithInt:expected], @"Expected child value as per priority");
expected = expected - 1;
}
XCTAssertTrue(expected == -1, @"Saw the expected number of children");
}];
-
+
[self waitUntil:^BOOL{
return nodesSet == 10;
}];
@@ -153,7 +153,7 @@
- (void) testPushDataWithExponentialPrioritiesReconnectReadBackAndVerifyOrder {
FTupleFirebase* tuple = [FTestHelpers getRandomNodePair];
-
+
__block int expected = 0;
__block int nodesSet = 0;
FIRDatabaseReference * node = tuple.one;
@@ -162,19 +162,19 @@
nodesSet = nodesSet + 1;
}];
}
-
+
[super snapWaiter:node withBlock:^(FIRDataSnapshot *snap) {
expected = 9;
-
+
for (FIRDataSnapshot * child in snap.children) {
XCTAssertEqualObjects([child value], [NSNumber numberWithInt:expected], @"Expected child value as per priority");
expected = expected - 1;
}
XCTAssertTrue(expected == -1, @"Saw the expected number of children");
}];
-
+
WAIT_FOR(nodesSet == 10);
-
+
[super snapWaiter:tuple.two withBlock:^(FIRDataSnapshot *snap) {
expected = 9;
for (FIRDataSnapshot * child in snap.children) {
@@ -189,15 +189,15 @@
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
[node child:@"foo"];
[[node child:@"bar"] setValue:@"test"];
-
+
__block int items = 0;
[super snapWaiter:node withBlock:^(FIRDataSnapshot *snap) {
-
+
for (FIRDataSnapshot * child in snap.children) {
items = items + 1;
XCTAssertEqualObjects([child key], @"bar", @"Saw the child which had a value set and not the empty one");
}
-
+
XCTAssertTrue(items == 1, @"Saw only the one that was actually set.");
}];
}
@@ -235,7 +235,7 @@
- (void) testCanResetPriorityToNull {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[[node child:@"a"] setValue:@"a" andPriority:@1];
[[node child:@"b"] setValue:@"b" andPriority:@2];
@@ -275,15 +275,15 @@
- (void) testInsertingANodeUnderALeafPreservesItsPriority {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot * snap;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *s) {
snap = s;
}];
-
+
[node setValue:@"a" andPriority:@10];
[[node child:@"deeper"] setValue:@"deeper"];
-
+
[self waitUntil:^BOOL{
id result = [snap value];
NSDictionary* expected = @{@"deeper": @"deeper"};
@@ -317,16 +317,16 @@
@"alpha40", @"zed",
@"num40", @500
];
-
+
__block int setsCompleted = 0;
-
+
for (int i = 0; i < [nodeAndPriorities count]; i++) {
FIRDatabaseReference * n = [tuple.one child:[nodeAndPriorities objectAtIndex:i++]];
[n setValue:@1 andPriority:[nodeAndPriorities objectAtIndex:i] withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
setsCompleted = setsCompleted + 1;
}];
}
-
+
NSString* expected = @"noPriorityA, noPriorityB, noPriorityC, num10, num20, num30, num40, num41, num42, num50, num60, num70, num80, alpha10, alpha20, alpha30, alpha40, alpha41, alpha42, ";
[super snapWaiter:tuple.one withBlock:^(FIRDataSnapshot *snap) {
@@ -337,22 +337,22 @@
XCTAssertTrue([expected isEqualToString:output], @"Proper order");
}];
-
+
WAIT_FOR(setsCompleted == [nodeAndPriorities count] / 2);
-
+
[super snapWaiter:tuple.two withBlock:^(FIRDataSnapshot *snap) {
NSMutableString* output = [[NSMutableString alloc] init];
for (FIRDataSnapshot * n in snap.children) {
[output appendFormat:@"%@, ", [n key]];
}
-
+
XCTAssertTrue([expected isEqualToString:output], @"Proper order");
}];
}
- (void) testVerifyOrderOfIntegerNames {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
-
+
NSArray* keys = @[
@"foo",
@"bar",
@@ -365,31 +365,31 @@
@"003",
@"9"
];
-
+
__block int setsCompleted = 0;
-
+
for (int i = 0; i < [keys count]; i++) {
FIRDatabaseReference * n = [ref child:[keys objectAtIndex:i]];
[n setValue:@1 withCompletionBlock:^(NSError* error, FIRDatabaseReference * ref) {
setsCompleted = setsCompleted + 1;
}];
}
-
+
NSString* expected = @"0, 3, 03, 003, 5, 9, 20, 100, bar, foo, ";
-
+
[super snapWaiter:ref withBlock:^(FIRDataSnapshot *snap) {
NSMutableString* output = [[NSMutableString alloc] init];
for (FIRDataSnapshot * n in snap.children) {
[output appendFormat:@"%@, ", [n key]];
}
-
+
XCTAssertTrue([expected isEqualToString:output], @"Proper order");
}];
}
- (void) testPrevNameIsCorrectOnChildAddedEvent {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[node setValue:@{@"a": @1, @"b": @2, @"c": @3}];
@@ -406,15 +406,15 @@
}];
XCTAssertTrue([added isEqualToString:@"a (null), b a, c b, "], @"Proper order and prevname");
-
+
}
- (void) testPrevNameIsCorrectWhenAddingNewNodes {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
[node setValue:@{@"b": @2, @"c": @3, @"d": @4}];
-
+
NSMutableString* added = [[NSMutableString alloc] init];
__block int count = 0;
@@ -426,9 +426,9 @@
[self waitUntil:^BOOL{
return count == 3;
}];
-
+
XCTAssertTrue([added isEqualToString:@"b (null), c b, d c, "], @"Proper order and prevname");
-
+
[added setString:@""];
[[node child:@"a"] setValue:@1];
[self waitUntil:^BOOL{
@@ -608,36 +608,36 @@
- (void) testCanSetAValueWithPriZero {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot * snap = nil;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *s) {
snap = s;
}];
-
+
[node setValue:@"test" andPriority:@0];
-
+
[self waitUntil:^BOOL{
return snap != nil;
}];
-
+
XCTAssertEqualObjects([snap value], @"test", @"Proper value");
XCTAssertEqualObjects([snap priority], @0, @"Proper value");
}
- (void) testCanSetObjectWithPriZero {
FIRDatabaseReference * node = [FTestHelpers getRandomNode];
-
+
__block FIRDataSnapshot * snap = nil;
[node observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *s) {
snap = s;
}];
-
+
[node setValue:@{@"x": @"test", @"y": @7} andPriority:@0];
-
+
[self waitUntil:^BOOL{
return snap != nil;
}];
-
+
XCTAssertEqualObjects([[snap value] objectForKey:@"x"], @"test", @"Proper value");
XCTAssertEqualObjects([[snap value] objectForKey:@"y"], @7, @"Proper value");
XCTAssertEqualObjects([snap priority], @0, @"Proper value");
diff --git a/Example/Database/Tests/Integration/FOrderByTests.m b/Example/Database/Tests/Integration/FOrderByTests.m
index aea6b47..0017e53 100644
--- a/Example/Database/Tests/Integration/FOrderByTests.m
+++ b/Example/Database/Tests/Integration/FOrderByTests.m
@@ -24,7 +24,7 @@
- (void) testCanDefineAndUseAnIndex {
__block FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
-
+
NSArray *users = @[
@{@"name": @"Andrew", @"nuggets": @35},
@{@"name": @"Rob", @"nuggets": @40},
@@ -539,8 +539,8 @@
FTupleFirebase *refs = [FTestHelpers getRandomNodePair];
FIRDatabaseReference *writer = refs.one;
FIRDatabaseReference *reader = refs.two;
-
-
+
+
NSDictionary *initial = @{@"a": @{@"data": @"foo",
@"idx": @YES},
@"b": @{@"data": @"bar",
@@ -548,7 +548,7 @@
@"c": @{@"data": @"baz",
@"idx": @NO}};
[self waitForCompletionOf:writer setValue:initial];
-
+
FIRDatabaseQuery *query = [[reader queryOrderedByChild:@"idx"] queryEqualToValue:@YES];
NSDictionary* expected = @{@"a": @{@"data": @"foo",
@@ -557,12 +557,12 @@
@"idx": @YES}};
[self waitForExportValueOf:query toBe:expected];
-
+
NSDictionary *update = @{@"a/idx": @NO,
@"b/data": @"blah",
@"c/idx": @YES};
[self waitForCompletionOf:writer updateChildValues:update];
-
+
expected = @{@"b": @{@"data": @"blah",
@"idx": @YES},
@"c": @{@"data": @"baz",
diff --git a/Example/Database/Tests/Integration/FPersist.m b/Example/Database/Tests/Integration/FPersist.m
index 2326e08..9f8bf56 100644
--- a/Example/Database/Tests/Integration/FPersist.m
+++ b/Example/Database/Tests/Integration/FPersist.m
@@ -307,30 +307,30 @@
- (void)testDeltaSyncWorksWithUnfilteredQuery {
FIRDatabaseReference *writerRef = [FTestHelpers getRandomNode];
FDevice *device = [[FDevice alloc] initOnlineWithUrl:[writerRef description] ];
-
+
// List must be large enough to trigger delta sync.
NSMutableDictionary *longList = [[NSMutableDictionary alloc] init];
for(NSInteger i = 0; i < 50; i++) {
NSString *key = [[writerRef childByAutoId] key];
longList[key] = @{ @"order": @1, @"text": @"This is an awesome message!" };
}
-
+
[writerRef setValue:longList];
-
+
[device do:^(FIRDatabaseReference *ref) {
// Cache this location.
[self waitForValueOf:[ref queryOrderedByChild:@"order"] toBe:longList];
XCTAssertEqual(ref.repo.dataUpdateCount, 1L, @"Should have gotten one update.");
}];
[device restartOffline];
-
+
// Add a new child while the device is offline.
FIRDatabaseReference *newChildRef = [writerRef childByAutoId];
NSDictionary *newChild = @{ @"order": @50, @"text": @"This is a new appended child!" };
-
+
[self waitForCompletionOf:newChildRef setValue:newChild];
longList[[newChildRef key]] = newChild;
-
+
[device goOnline];
[device do:^(FIRDatabaseReference *ref) {
// Wait for updated value with new child.
diff --git a/Example/Database/Tests/Integration/FRealtime.m b/Example/Database/Tests/Integration/FRealtime.m
index e554bfe..5c7d186 100644
--- a/Example/Database/Tests/Integration/FRealtime.m
+++ b/Example/Database/Tests/Integration/FRealtime.m
@@ -57,7 +57,7 @@
FRepoInfo* repoInfo2 = [[FRepoInfo alloc] initWithHost:host2 isSecure:YES withNamespace:host2];
XCTAssertTrue([repoInfo2.host isEqualToString:host2], @"Got correct host");
XCTAssertTrue([repoInfo2.internalHost isEqualToString:host2], @"Got correct host");
-
+
repoInfo2.internalHost = internalHost2;
XCTAssertTrue([repoInfo2.internalHost isEqualToString:internalHost2], @"Got correct host");
diff --git a/Example/Database/Tests/Integration/FTransactionTest.m b/Example/Database/Tests/Integration/FTransactionTest.m
index b78615b..abaea94 100644
--- a/Example/Database/Tests/Integration/FTransactionTest.m
+++ b/Example/Database/Tests/Integration/FTransactionTest.m
@@ -955,7 +955,7 @@
FTupleFirebase* refs = [FTestHelpers getRandomNodePair];
FIRDatabaseReference * ref1 = refs.one;
FIRDatabaseReference * ref2 = refs.two;
-
+
__block BOOL done = NO;
[[ref1 child:@"y"] setValue:@"test" withCompletionBlock:^(NSError *error, FIRDatabaseReference * ref) {
[ref2 runTransactionBlock:^FIRTransactionResult *(FIRMutableData *currentData) {
@@ -973,7 +973,7 @@
}
}];
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -993,7 +993,7 @@
done = YES;
}];
}];
-
+
[self waitUntil:^BOOL{
return done;
}];
@@ -1092,7 +1092,7 @@
FIRDatabaseReference * writer = refs.one;
FIRDatabaseReference * reader = refs.two;
__block int done = 0;
-
+
NSMutableArray* readSnaps = [[NSMutableArray alloc] init];
NSMutableArray* writeSnaps = [[NSMutableArray alloc] init];
@@ -1113,20 +1113,20 @@
}
}
}];
-
+
[writer runTransactionBlock:^FIRTransactionResult *(FIRMutableData *currentData) {
[currentData setValue:[FIRServerValue timestamp]];
[currentData setPriority:[FIRServerValue timestamp]];
return [FIRTransactionResult successWithValue:currentData];
} andCompletionBlock:^(NSError *error, BOOL committed, FIRDataSnapshot *snapshot) {}];
-
+
[self waitUntil:^BOOL{
return done == 2;
}];
-
+
XCTAssertEqual((unsigned long)[readSnaps count], (unsigned long)1, @"Should have received one snapshot on reader");
XCTAssertEqual((unsigned long)[writeSnaps count], (unsigned long)2, @"Should have received two snapshots on writer");
-
+
FIRDataSnapshot * firstReadSnap = [readSnaps objectAtIndex:0];
FIRDataSnapshot * firstWriteSnap = [writeSnaps objectAtIndex:0];
FIRDataSnapshot * secondWriteSnap = [writeSnaps objectAtIndex:1];
@@ -1151,7 +1151,7 @@
[[ref queryLimitedToFirst:1] observeEventType:FIRDataEventTypeChildAdded andPreviousSiblingKeyWithBlock:^(FIRDataSnapshot *snapshot, NSString *prevName) {
} withCancelBlock:^(NSError *error) {
}];
-
+
[[ref child:@"a"] runTransactionBlock:^FIRTransactionResult *(FIRMutableData *currentData) {
return [FIRTransactionResult successWithValue:currentData];
} andCompletionBlock:^(NSError *error, BOOL committed, FIRDataSnapshot *snapshot) {
@@ -1161,7 +1161,7 @@
done = YES;
}];
}];
-
+
WAIT_FOR(done);
}
@@ -1206,7 +1206,7 @@
XCTAssertEqualObjects([snapshot value], @"it was null!", @"Transaction value should match remote null set");
done = YES;
}];
-
+
WAIT_FOR(done);
}
@@ -1249,7 +1249,7 @@
XCTAssertEqualObjects([snapshot value], @"it was null!", @"Transaction value should match remote null set");
done = YES;
}];
-
+
WAIT_FOR(done);
}
diff --git a/Example/Database/Tests/Unit/FIRDataSnapshotTests.m b/Example/Database/Tests/Unit/FIRDataSnapshotTests.m
index 2a442df..df950e2 100644
--- a/Example/Database/Tests/Unit/FIRDataSnapshotTests.m
+++ b/Example/Database/Tests/Unit/FIRDataSnapshotTests.m
@@ -34,14 +34,14 @@
- (void)setUp
{
[super setUp];
-
+
// Set-up code here.
}
- (void)tearDown
{
// Tear-down code here.
-
+
[super tearDown];
}
@@ -62,13 +62,13 @@
XCTAssertEqualObjects(x.val, @5, @"Values are the same");
XCTAssertEqualObjects(x.getPriority, [FSnapshotUtilities nodeFrom:@42], @"Priority is the same");
XCTAssertTrue([x isLeafNode], @"Node is a leaf");
-
+
x = [[FLeafNode alloc] initWithValue:@"test"];
XCTAssertEqualObjects(x.value, @"test", @"Check if leaf node is holding onto a string value");
-
+
x = [[FLeafNode alloc] initWithValue:[NSNumber numberWithBool:YES]];
XCTAssertTrue([x.value boolValue], @"Check if leaf node is holding onto a YES boolean");
-
+
x = [[FLeafNode alloc] initWithValue:[NSNumber numberWithBool:NO]];
XCTAssertFalse([x.value boolValue], @"Check if leaf node is holding onto a NO boolean");
}
@@ -76,11 +76,11 @@
- (void) testUpdatingPriorityWithoutChangingOld {
FLeafNode* x = [[FLeafNode alloc] initWithValue:@"test" withPriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]]];
FLeafNode* y = [x updatePriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:187]]];
-
+
// old node is the same
XCTAssertEqualObjects(x.value, @"test", @"Values of old node are the same");
XCTAssertEqualObjects(x.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]], @"Priority of old node is the same.");
-
+
// new node has the new priority but the old value
XCTAssertEqualObjects(y.value, @"test", @"Values of old node are the same");
XCTAssertEqualObjects(y.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:187]], @"Priority of new node is update");
@@ -89,10 +89,10 @@
- (void) testUpdateImmediateChildReturnsANewChildrenNode {
FLeafNode* x = [[FLeafNode alloc] initWithValue:@"test" withPriority:[FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]]];
FChildrenNode* y = [x updateImmediateChild:@"test" withNewChild:[[FLeafNode alloc] initWithValue:@"foo"]];
-
+
XCTAssertFalse([y isLeafNode], @"New node is no longer a leaf");
XCTAssertEqualObjects(y.getPriority, [FSnapshotUtilities nodeFrom:[NSNumber numberWithInt:42]], @"Priority of new node is update");
-
+
XCTAssertEqualObjects([[y getImmediateChild:@"test"] val], @"foo", @"Child node has the correct value");
}
@@ -130,7 +130,7 @@
FChildrenNode* x = [[FChildrenNode alloc] initWithChildren:children];
FLeafNode* newValue = [[FLeafNode alloc] initWithValue:@"new value"];
FChildrenNode* y = [x updateImmediateChild:@"test" withNewChild:newValue];
-
+
XCTAssertEqualObjects(x.children, children, @"Original object stays the same");
XCTAssertEqualObjects([y.children objectForKey:@"test"], newValue, @"New internal node with the proper new value");
XCTAssertEqualObjects([[y.children objectForKey:@"test"] val], @"new value", @"Check the payload");
@@ -149,10 +149,10 @@
- (void) testObjectTypes {
XCTAssertEqualObjects(@"string", [FUtilities getJavascriptType:@""], @"Check string type");
XCTAssertEqualObjects(@"string", [FUtilities getJavascriptType:@"moo"], @"Check string type");
-
+
XCTAssertEqualObjects(@"boolean", [FUtilities getJavascriptType:@YES], @"Check boolean type");
XCTAssertEqualObjects(@"boolean", [FUtilities getJavascriptType:@NO], @"Check boolean type");
-
+
XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@5], @"Check number type");
XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@5.5], @"Check number type");
XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@0], @"Check number type");
@@ -161,12 +161,12 @@
XCTAssertEqualObjects(@"number", [FUtilities getJavascriptType:@-2.11], @"Check number type");
}
-- (void) testNodeHashWorksCorrectly {
+- (void) testNodeHashWorksCorrectly {
id<FNode> node = [FSnapshotUtilities nodeFrom:@{ @"intNode" : @4,
@"doubleNode" : @4.5623,
@"stringNode" : @"hey guys",
@"boolNode" : @YES }];
-
+
XCTAssertEqualObjects(@"eVih19a6ZDz3NL32uVBtg9KSgQY=", [[node getImmediateChild:@"intNode"] dataHash], @"Check integer node");
XCTAssertEqualObjects(@"vf1CL0tIRwXXunHcG/irRECk3lY=", [[node getImmediateChild:@"doubleNode"] dataHash], @"Check double node");
XCTAssertEqualObjects(@"CUNLXWpCVoJE6z7z1vE57lGaKAU=", [[node getImmediateChild:@"stringNode"] dataHash], @"Check string node");
@@ -178,13 +178,13 @@
id<FNode> node = [FSnapshotUtilities nodeFrom:@{
@"root": @{ @"c": @{@".value": @99, @".priority": @"abc"}, @".priority" : @"def" }
}];
-
+
XCTAssertEqualObjects(@"Fm6tzN4CVEu5WxFDZUdTtqbTVaA=", [node dataHash], @"Check compound node");
}
- (void) testGetPredecessorChild {
id<FNode> node = [FSnapshotUtilities nodeFrom:@{@"d": @YES, @"a": @YES, @"g": @YES, @"c": @YES, @"e": @YES}];
-
+
XCTAssertNil([node predecessorChildKey:@"a"],
@"Check the first one sorted properly");
XCTAssertEqualObjects([node predecessorChildKey:@"c"],
@@ -206,13 +206,13 @@
}
- (void) testDataSnapshotHasChildrenWorks {
-
+
FIRDataSnapshot * snap = [self snapshotFor:@{}];
XCTAssertFalse([snap hasChildren], @"Empty dict has no children");
-
+
snap = [self snapshotFor:@5];
XCTAssertFalse([snap hasChildren], @"Leaf node has no children");
-
+
snap = [self snapshotFor:@{@"x": @5}];
XCTAssertTrue([snap hasChildren], @"Properly has children");
}
@@ -220,10 +220,10 @@
- (void) testDataSnapshotValWorks {
FIRDataSnapshot * snap = [self snapshotFor:@5];
XCTAssertEqualObjects([snap value], @5, @"Leaf node values are correct");
-
+
snap = [self snapshotFor:@{}];
XCTAssertTrue([snap value] == [NSNull null], @"Snapshot value is properly null");
-
+
NSDictionary* dict = @{
@"x": @5,
@"y": @{
@@ -232,18 +232,18 @@
@"yc": @{ @"yca" : @3}
}
};
-
+
snap = [self snapshotFor:dict];
XCTAssertTrue([dict isEqualToDictionary:[snap value]], @"Check if the dictionaries are the same");
}
- (void) testDataSnapshotChildWorks {
FIRDataSnapshot * snap = [self snapshotFor:@{@"x": @5, @"y": @{@"yy": @3, @"yz": @4}}];
-
+
XCTAssertEqualObjects([[snap childSnapshotForPath:@"x"] value], @5, @"Check x");
NSDictionary* dict = @{@"yy": @3, @"yz": @4};
XCTAssertTrue([[[snap childSnapshotForPath:@"y"] value] isEqualToDictionary:dict], @"Check y");
-
+
XCTAssertEqualObjects([[[snap childSnapshotForPath:@"y"] childSnapshotForPath:@"yy"] value], @3, @"Check y/yy");
XCTAssertEqualObjects([[snap childSnapshotForPath:@"y/yz"] value], @4, @"Check y/yz");
XCTAssertTrue([[snap childSnapshotForPath:@"z"] value] == [NSNull null], @"Check nonexistent z");
@@ -256,7 +256,7 @@
XCTAssertTrue([snap hasChild:@"x"], @"Has child");
XCTAssertTrue([snap hasChild:@"y/yy"], @"Has child");
-
+
XCTAssertFalse([snap hasChild:@"dinosaur dinosaucer"], @"No child");
XCTAssertFalse([[snap childSnapshotForPath:@"x"] hasChild:@"anything"], @"No child");
XCTAssertFalse([snap hasChild:@"x/anything/at/all"], @"No child");
@@ -264,25 +264,25 @@
- (void) testDataSnapshotNameWorks {
FIRDataSnapshot * snap = [self snapshotFor:@{@"a": @{@"b": @{@"c": @5}}}];
-
+
XCTAssertEqualObjects([[snap childSnapshotForPath:@"a"] key], @"a", @"Check child key");
XCTAssertEqualObjects([[snap childSnapshotForPath:@"a/b/c"] key], @"c", @"Check child key");
XCTAssertEqualObjects([[snap childSnapshotForPath:@"/a/b/c"] key], @"c", @"Check child key");
XCTAssertEqualObjects([[snap childSnapshotForPath:@"/a/b/c/"] key], @"c", @"Check child key");
- XCTAssertEqualObjects([[snap childSnapshotForPath:@"////a///b////c///"] key], @"c", @"Check child key");
+ XCTAssertEqualObjects([[snap childSnapshotForPath:@"////a///b////c///"] key], @"c", @"Check child key");
XCTAssertEqualObjects([[snap childSnapshotForPath:@"////"] key], [snap key], @"Check root key");
-
+
XCTAssertEqualObjects([[snap childSnapshotForPath:@"/z/q/r/v////m"] key], @"m", @"Should also work for nonexistent paths");
}
- (void) testDataSnapshotForEachWithNoPriorities {
FIRDataSnapshot * snap = [self snapshotFor:@{@"a": @1, @"z": @26, @"m": @13, @"n": @14, @"c": @3, @"b": @2, @"e": @5}];
-
+
NSMutableString* out = [[NSMutableString alloc] init];
for (FIRDataSnapshot * child in snap.children) {
[out appendFormat:@"%@:%@:", [child key], [child value] ];
}
-
+
XCTAssertTrue([out isEqualToString:@"a:1:b:2:c:3:e:5:m:13:n:14:z:26:"], @"Proper order");
}
@@ -296,12 +296,12 @@
@"b": @{@".value" : @2, @".priority": @25},
@"e": @{@".value" : @5, @".priority": @22},
}];
-
+
NSMutableString* out = [[NSMutableString alloc] init];
for (FIRDataSnapshot * child in snap.children) {
[out appendFormat:@"%@:%@:", [child key], [child value] ];
}
-
+
XCTAssertTrue([out isEqualToString:@"z:26:n:14:m:13:e:5:c:3:b:2:a:1:"], @"Proper order");
}
@@ -315,12 +315,12 @@
@"b": @{@".value" : @2, @".priority": @"25"},
@"e": @{@".value" : @5, @".priority": @"22"},
}];
-
+
NSMutableString* out = [[NSMutableString alloc] init];
for (FIRDataSnapshot * child in snap.children) {
[out appendFormat:@"%@:%@:", [child key], [child value] ];
}
-
+
XCTAssertTrue([out isEqualToString:@"z:26:n:14:m:13:e:5:c:3:b:2:a:1:"], @"Proper order");
}
@@ -334,14 +334,14 @@
@"b": @{@".value" : @2, @".priority": @"sixth"},
@"e": @{@".value" : @5, @".priority": @"seventh"},
}];
-
+
NSMutableString* output = [[NSMutableString alloc] init];
NSMutableArray* priorities = [[NSMutableArray alloc] init];
for (FIRDataSnapshot * child in snap.children) {
[output appendFormat:@"%@:%@:", child.key, child.value];
[priorities addObject:child.priority];
}
-
+
XCTAssertTrue([output isEqualToString:@"c:3:a:1:n:14:z:26:e:5:b:2:m:13:"], @"Proper order");
NSArray* expected = @[@"fifth", @"first", @"fourth", @"second", @"seventh", @"sixth", @"third"];
XCTAssertTrue([priorities isEqualToArray:expected], @"Correct priorities");
@@ -371,14 +371,14 @@
@"alpha40": @{@".value": @1, @".priority": @"zed" },
@"num40": @{@".value": @1, @".priority": @500 }
}];
-
+
NSMutableString* out = [[NSMutableString alloc] init];
for (FIRDataSnapshot * child in snap.children) {
[out appendFormat:@"%@, ", [child key]];
}
-
+
NSString* expected = @"noPriorityA, noPriorityB, noPriorityC, num20, num40, num42, num60, num70, num80, alpha10, alpha11, alpha12, alpha13, alpha14, alpha20, alpha30, alpha40, alpha41, alpha42, ";
-
+
XCTAssertTrue([expected isEqualToString:out], @"Proper ordering seen");
}
diff --git a/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m b/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m
index f26a913..560104a 100644
--- a/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m
+++ b/Example/Database/Tests/Unit/FLevelDBStorageEngineTests.m
@@ -495,7 +495,7 @@
id intValue = @247;
id longValue = @1542405709418655810;
id doubleValue = @0xFFFFFFFFFFFFFFFFUL; // This number can't be represented as a signed long.
-
+
id<FNode> expectedData = NODE((@{@"int": @247, @"long": longValue, @"double": doubleValue}));
FLevelDBStorageEngine *engine = [self cleanStorageEngine];
[engine updateServerCache:expectedData atPath:PATH(@"foo") merge:NO];
@@ -503,7 +503,7 @@
NSNumber* actualInt = [actualData val][@"int"];
NSNumber* actualLong = [actualData val][@"long"];
NSNumber* actualDouble = [actualData val][@"double"];
-
+
XCTAssertEqualObjects([actualInt stringValue], [intValue stringValue]);
XCTAssertEqual(CFNumberGetType((CFNumberRef)actualInt), kCFNumberSInt64Type);
XCTAssertEqualObjects([actualLong stringValue ], [longValue stringValue]);
diff --git a/Example/Database/Tests/Unit/FPathTests.m b/Example/Database/Tests/Unit/FPathTests.m
index 9b26a85..c70e3ab 100644
--- a/Example/Database/Tests/Unit/FPathTests.m
+++ b/Example/Database/Tests/Unit/FPathTests.m
@@ -25,7 +25,7 @@
XCTAssertTrue([[[FPath alloc] initWith:@"/a"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWith:@"/a/b"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
-
+
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b"]], @"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a"]], @"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/"]], @"contains should be correct");
@@ -34,7 +34,7 @@
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]], @"contains should be correct");
-
+
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/c/b"]], @"contains should be correct");
diff --git a/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m b/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m
index 6aee84d..396be06 100644
--- a/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m
+++ b/Example/Database/Tests/Unit/FTreeSortedDictionaryTests.m
@@ -75,7 +75,7 @@
FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]
insertKey:@1 withValue:@1]
insertKey:@2 withValue:@2];
-
+
XCTAssertEqualObjects([map get:@1], @1, @"Found first object");
XCTAssertEqualObjects([map get:@2], @2, @"Found second object");
XCTAssertNil([map get:@3], @"Properly not found object");
@@ -85,7 +85,7 @@
FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]
insertKey:@1 withValue:@1]
insertKey:@2 withValue:@2];
-
+
XCTAssertEqualObjects(map.root.key, @2, @"Check the root key");
XCTAssertEqualObjects(map.root.left.key, @1, @"Check the root.left key");
}
@@ -94,11 +94,11 @@
FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]
insertKey:@1 withValue:@1]
insertKey:@2 withValue:@2];
-
+
FImmutableSortedDictionary* newMap = [map removeKey:@1];
XCTAssertEqualObjects([newMap get:@2], @2, @"Found second object");
XCTAssertNil([newMap get:@1], @"Properly not found object");
-
+
// Make sure the original one is not mutated
XCTAssertEqualObjects([map get:@1], @1, @"Found first object");
XCTAssertEqualObjects([map get:@2], @2, @"Found second object");
@@ -121,21 +121,21 @@
XCTAssertNotNil([map get:@7], @"Found object");
XCTAssertNotNil([map get:@3], @"Found object");
XCTAssertNotNil([map get:@1], @"Found object");
-
-
+
+
FImmutableSortedDictionary* m1 = [map removeKey:@7];
FImmutableSortedDictionary* m2 = [map removeKey:@3];
FImmutableSortedDictionary* m3 = [map removeKey:@1];
-
+
XCTAssertNil([m1 get:@7], @"Removed object");
XCTAssertNotNil([m1 get:@3], @"Found object");
XCTAssertNotNil([m1 get:@1], @"Found object");
-
+
XCTAssertNil([m2 get:@3], @"Removed object");
XCTAssertNotNil([m2 get:@7], @"Found object");
XCTAssertNotNil([m2 get:@1], @"Found object");
-
-
+
+
XCTAssertNil([m3 get:@1], @"Removed object");
XCTAssertNotNil([m3 get:@7], @"Found object");
XCTAssertNotNil([m3 get:@3], @"Found object");
@@ -146,11 +146,11 @@
insertKey:@1 withValue:@1]
insertKey:@2 withValue:@2]
insertKey:@3 withValue:@3];
-
+
XCTAssertEqualObjects([map get:@1], @1, @"Found object");
XCTAssertEqualObjects([map get:@2], @2, @"Found object");
XCTAssertEqualObjects([map get:@3], @3, @"Found object");
-
+
FImmutableSortedDictionary* m1 = [map removeKey:@2];
XCTAssertEqualObjects([m1 get:@1], @1, @"Found object");
XCTAssertEqualObjects([m1 get:@3], @3, @"Found object");
@@ -159,23 +159,23 @@
- (void) testIncreasing {
int total = 100;
-
+
FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]];
-
+
for(int i = 0; i < total; i++) {
NSNumber* item = [NSNumber numberWithInt:i];
map = [map insertKey:item withValue:item];
}
-
+
XCTAssertTrue([map count] == 100, @"Check if all 100 objects are in the map");
XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
-
+
for(int i = 0; i < total; i++) {
NSNumber* item = [NSNumber numberWithInt:i];
map = [map removeKey:item];
}
-
+
XCTAssertTrue([map count] == 0, @"Check if all 100 objects were removed");
// We can't check the depth here because the map no longer contains values, so we check that it doesn't responsd to this check
XCTAssertTrue([map.root isMemberOfClass:[FLLRBEmptyNode class]], @"Root is an empty node");
@@ -187,8 +187,8 @@
insertKey:@1 withValue:@1]
insertKey:@2 withValue:@2]
insertKey:@3 withValue:@3];
-
-
+
+
XCTAssertEqualObjects(map.root.key, @2, @"Check root key");
XCTAssertEqualObjects(map.root.left.key, @1, @"Check the left key is correct");
XCTAssertEqualObjects(map.root.right.key, @3, @"Check the right key is correct");
@@ -208,7 +208,7 @@
insertKey:@71 withValue:@71]
insertKey:@42 withValue:@42]
insertKey:@88 withValue:@88];
-
+
XCTAssertTrue([map count] == 12, @"Check if all 12 objects are in the map");
XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
@@ -217,18 +217,18 @@
- (void) testRotateLeftLeavesTreeInAValidState {
FLLRBValueNode* node = [[FLLRBValueNode alloc] initWithKey:@4 withValue:@4 withColor:BLACK withLeft:
[[FLLRBValueNode alloc] initWithKey:@2 withValue:@2 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc]initWithKey:@7 withValue:@7 withColor:RED withLeft:[[FLLRBValueNode alloc ]initWithKey:@5 withValue:@5 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc] initWithKey:@8 withValue:@8 withColor:BLACK withLeft:nil withRight:nil]]];
-
+
FLLRBValueNode* node2 = [node performSelector:@selector(rotateLeft)];
-
+
XCTAssertTrue([node2 count] == 5, @"Make sure the count is correct");
XCTAssertTrue([node2 checkMaxDepth], @"Check proper structure");
}
- (void) testRotateRightLeavesTreeInAValidState {
FLLRBValueNode* node = [[FLLRBValueNode alloc] initWithKey:@7 withValue:@7 withColor:BLACK withLeft:[[FLLRBValueNode alloc] initWithKey:@4 withValue:@4 withColor:RED withLeft:[[FLLRBValueNode alloc] initWithKey:@2 withValue:@2 withColor:BLACK withLeft:nil withRight:nil] withRight:[[FLLRBValueNode alloc] initWithKey:@5 withValue:@5 withColor:BLACK withLeft:nil withRight:nil]] withRight:[[FLLRBValueNode alloc] initWithKey:@8 withValue:@8 withColor:BLACK withLeft:nil withRight:nil]];
-
+
FLLRBValueNode* node2 = [node performSelector:@selector(rotateRight)];
-
+
XCTAssertTrue([node2 count] == 5, @"Make sure the count is correct");
XCTAssertEqualObjects(node2.key, @4, @"Check roots key");
XCTAssertEqualObjects(node2.left.key, @2, @"Check first left child key");
@@ -245,18 +245,18 @@
insertKey:@4 withValue:@4]
insertKey:@7 withValue:@7]
insertKey:@9 withValue:@9];
-
+
XCTAssertTrue([map count] == 6, @"Check if all 6 objects are in the map");
XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
-
+
FTreeSortedDictionary* m2 = [[[map insertKey:@20 withValue:@20]
insertKey:@18 withValue:@18]
insertKey:@2 withValue:@2];
XCTAssertTrue([m2 count] == 9, @"Check if all 9 objects are in the map");
XCTAssertTrue([m2.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
XCTAssertTrue([(FLLRBValueNode *)m2.root checkMaxDepth], @"Checking valid depth and tree structure");
-
+
FTreeSortedDictionary* m3 = [[[[m2 insertKey:@71 withValue:@71]
insertKey:@42 withValue:@42]
insertKey:@88 withValue:@88]
@@ -270,16 +270,16 @@
FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]
insertKey:@10 withValue:@10]
insertKey:@10 withValue:@8];
-
+
XCTAssertEqualObjects([map get:@10], @8, @"Found first object");
}
- (void) testEmpty {
FTreeSortedDictionary* map = [[[[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]]
insertKey:@10 withValue:@10]
removeKey:@10];
-
+
XCTAssertTrue([map isEmpty], @"Properly empty");
-
+
}
- (void) testEmptyGet {
@@ -304,7 +304,7 @@
insertKey:@3 withValue:@3]
insertKey:@2 withValue:@2]
insertKey:@4 withValue:@4];
-
+
__block int next = 5;
[map enumerateKeysAndObjectsReverse:YES usingBlock:^(id key, id value, BOOL *stop) {
XCTAssertEqualObjects(key, [NSNumber numberWithInt:next], @"Properly equal");
@@ -317,18 +317,18 @@
int N = 100;
NSMutableArray* toInsert = [[NSMutableArray alloc] initWithCapacity:N];
NSMutableArray* toRemove = [[NSMutableArray alloc] initWithCapacity:N];
-
+
for(int i = 0; i < N; i++) {
[toInsert addObject:[NSNumber numberWithInt:i]];
[toRemove addObject:[NSNumber numberWithInt:i]];
}
-
-
+
+
[self shuffleArray:toInsert];
[self shuffleArray:toRemove];
-
+
FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]];
-
+
// add them to the dictionary
for(int i = 0; i < N; i++) {
map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]];
@@ -336,7 +336,7 @@
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
}
XCTAssertTrue([map count] == N, @"Check if all N objects are in the map");
-
+
// check the order is correct
__block int next = 0;
[map enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
@@ -345,9 +345,9 @@
next = next + 1;
}];
XCTAssertEqual(next, N, @"Check we traversed all of the items");
-
+
// remove them
-
+
for(int i = 0; i < N; i++) {
if([map.root isMemberOfClass:[FLLRBValueNode class]]) {
XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
@@ -355,8 +355,8 @@
}
map = [map removeKey:[toRemove objectAtIndex:i]];
}
-
-
+
+
XCTAssertEqual([map count], 0, @"Check we removed all of the items");
}
@@ -370,11 +370,11 @@
}
- (void) testBalanceProblem {
-
+
NSArray* toInsert = [[NSArray alloc] initWithObjects:@1,@7,@8,@5,@2,@6,@4,@0,@3, nil];
-
+
FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]];
-
+
// add them to the dictionary
for(int i = 0; i < [toInsert count]; i++) {
map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]];
@@ -382,7 +382,7 @@
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
}
XCTAssertTrue([map count] == [toInsert count], @"Check if all N objects are in the map");
-
+
// check the order is correct
__block int next = 0;
[map enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
@@ -391,11 +391,11 @@
next = next + 1;
}];
XCTAssertEqual(next, [[NSNumber numberWithUnsignedInteger:[toInsert count]] intValue], @"Check we traversed all of the items");
-
+
// removing one triggers the balance problem
-
+
map = [map removeKey:@5];
-
+
if([map.root isMemberOfClass:[FLLRBValueNode class]]) {
XCTAssertTrue([map.root isMemberOfClass:[FLLRBValueNode class]], @"Root is a value node");
XCTAssertTrue([(FLLRBValueNode *)map.root checkMaxDepth], @"Checking valid depth and tree structure");
@@ -410,7 +410,7 @@
insertKey:@4 withValue:@4]
insertKey:@7 withValue:@7]
insertKey:@9 withValue:@9];
-
+
XCTAssertNil([map getPredecessorKey:@1], @"First object doesn't have a predecessor");
XCTAssertEqualObjects([map getPredecessorKey:@3], @1, @"@1");
XCTAssertEqualObjects([map getPredecessorKey:@4], @3, @"@3");
@@ -424,18 +424,18 @@
int N = 100;
NSMutableArray* toInsert = [[NSMutableArray alloc] initWithCapacity:N];
NSMutableArray* toRemove = [[NSMutableArray alloc] initWithCapacity:N];
-
+
for(int i = 0; i < N; i++) {
[toInsert addObject:[NSNumber numberWithInt:i]];
[toRemove addObject:[NSNumber numberWithInt:i]];
}
-
-
+
+
[self shuffleArray:toInsert];
[self shuffleArray:toRemove];
-
+
FTreeSortedDictionary* map = [[FTreeSortedDictionary alloc] initWithComparator:[self defaultComparator]];
-
+
// add them to the dictionary
for(int i = 0; i < N; i++) {
map = [map insertKey:[toInsert objectAtIndex:i] withValue:[toInsert objectAtIndex:i]];
diff --git a/Example/Database/Tests/third_party/Base64.m b/Example/Database/Tests/third_party/Base64.m
index b3d73db..ef962ff 100644
--- a/Example/Database/Tests/third_party/Base64.m
+++ b/Example/Database/Tests/third_party/Base64.m
@@ -45,20 +45,20 @@
{
const char lookup[] =
{
- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 62, 99, 99, 99, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 99, 99, 99, 99, 99, 99,
- 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 99, 99, 99, 99, 99,
- 99, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 62, 99, 99, 99, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 99, 99, 99, 99, 99, 99,
+ 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 99, 99, 99, 99, 99,
+ 99, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 99, 99, 99, 99, 99
};
-
+
NSData *inputData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
long long inputLength = [inputData length];
const unsigned char *inputBytes = [inputData bytes];
-
+
long long maxOutputLength = (inputLength / 4 + 1) * 3;
NSMutableData *outputData = [NSMutableData dataWithLength:maxOutputLength];
unsigned char *outputBytes = (unsigned char *)[outputData mutableBytes];
@@ -74,19 +74,19 @@
accumulated[accumulator] = decoded;
if (accumulator == 3)
{
- outputBytes[outputLength++] = (accumulated[0] << 2) | (accumulated[1] >> 4);
- outputBytes[outputLength++] = (accumulated[1] << 4) | (accumulated[2] >> 2);
+ outputBytes[outputLength++] = (accumulated[0] << 2) | (accumulated[1] >> 4);
+ outputBytes[outputLength++] = (accumulated[1] << 4) | (accumulated[2] >> 2);
outputBytes[outputLength++] = (accumulated[2] << 6) | accumulated[3];
}
accumulator = (accumulator + 1) % 4;
}
}
-
+
//handle left-over data
if (accumulator > 0) outputBytes[outputLength] = (accumulated[0] << 2) | (accumulated[1] >> 4);
if (accumulator > 1) outputBytes[++outputLength] = (accumulated[1] << 4) | (accumulated[2] >> 2);
if (accumulator > 2) outputLength++;
-
+
//truncate data to match actual output length
outputData.length = outputLength;
return outputLength? outputData: nil;
@@ -96,16 +96,16 @@
{
//ensure wrapWidth is a multiple of 4
wrapWidth = (wrapWidth / 4) * 4;
-
+
const char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
+
long long inputLength = [self length];
const unsigned char *inputBytes = [self bytes];
-
+
long long maxOutputLength = (inputLength / 3 + 1) * 4;
maxOutputLength += wrapWidth? (maxOutputLength / wrapWidth) * 2: 0;
unsigned char *outputBytes = (unsigned char *)malloc(maxOutputLength);
-
+
long long i;
long long outputLength = 0;
for (i = 0; i < inputLength - 2; i += 3)
@@ -114,7 +114,7 @@
outputBytes[outputLength++] = lookup[((inputBytes[i] & 0x03) << 4) | ((inputBytes[i + 1] & 0xF0) >> 4)];
outputBytes[outputLength++] = lookup[((inputBytes[i + 1] & 0x0F) << 2) | ((inputBytes[i + 2] & 0xC0) >> 6)];
outputBytes[outputLength++] = lookup[inputBytes[i + 2] & 0x3F];
-
+
//add line break
if (wrapWidth && (outputLength + 2) % (wrapWidth + 2) == 0)
{
@@ -122,7 +122,7 @@
outputBytes[outputLength++] = '\n';
}
}
-
+
//handle left-over data
if (i == inputLength - 2)
{
@@ -140,7 +140,7 @@
outputBytes[outputLength++] = '=';
outputBytes[outputLength++] = '=';
}
-
+
if (outputLength >= 4)
{
//truncate data to match actual output length