From 26095ecf39d5b0a9619ffdf08beb341eb05dc008 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Tue, 12 Dec 2017 11:03:00 -0500 Subject: [PATCH 01/18] add bone code for new isEqual and unit test for old isEqual * add bone code for `FIRCollectionReference`, `FIRDocumentSnapshot`, `FIRFieldValue`, `FIRQuerySnapshot`, `FIRSnapshotMetadata`; * change inconsistenciness of `FIRFieldPath.isEqual` implementation; * add unit test (and file) for `FIRDocumentReferenceTest.m`, `FIRFieldPathTest.m`, `FIRQueryTests.testEquals`; `FIRGeoPoint` already has test and Blob is internal type. --- .../Firestore.xcodeproj/project.pbxproj | 8 +++ .../Tests/API/FIRDocumentReferenceTests.m | 58 +++++++++++++++++++ .../Example/Tests/API/FIRFieldPathTests.m | 47 +++++++++++++++ Firestore/Example/Tests/API/FIRQueryTests.m | 25 ++++++++ .../Source/API/FIRCollectionReference.mm | 16 +++++ Firestore/Source/API/FIRDocumentSnapshot.m | 16 +++++ Firestore/Source/API/FIRFieldPath.m | 4 +- Firestore/Source/API/FIRFieldValue.m | 16 +++++ Firestore/Source/API/FIRQuerySnapshot.m | 16 +++++ Firestore/Source/API/FIRSnapshotMetadata.m | 16 +++++ 10 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRDocumentReferenceTests.m create mode 100644 Firestore/Example/Tests/API/FIRFieldPathTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 5657b955855..c40a34c57e7 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -61,6 +61,8 @@ 6ED54761B845349D43DB6B78 /* Pods_Firestore_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */; }; 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; + AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */; }; + AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -231,6 +233,8 @@ 8E002F4AD5D9B6197C940847 /* Firestore.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Firestore.podspec; path = ../Firestore.podspec; sourceTree = ""; }; 9D52E67EE96AA7E5D6F69748 /* Pods-Firestore_IntegrationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_IntegrationTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_IntegrationTests/Pods-Firestore_IntegrationTests.debug.xcconfig"; sourceTree = ""; }; 9EF477AD4B2B643FD320867A /* Pods-Firestore_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example/Pods-Firestore_Example.debug.xcconfig"; sourceTree = ""; }; + AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentReferenceTests.m; sourceTree = ""; }; + AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRFieldPathTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -585,6 +589,8 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */, + AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */, DE51B1841F0D48AC0013853F /* FIRGeoPointTests.m */, ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */, ); @@ -1212,6 +1218,7 @@ DE51B1E21F0D490D0013853F /* FSTMutationQueueTests.m in Sources */, DE51B1E81F0D490D0013853F /* FSTLevelDBKeyTests.mm in Sources */, DE51B1E31F0D490D0013853F /* FSTPersistenceTestHelpers.m in Sources */, + AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */, DE51B1CF1F0D48CD0013853F /* FSTQueryListenerTests.m in Sources */, DE51B1DA1F0D490D0013853F /* FSTLevelDBLocalStoreTests.m in Sources */, DE51B1FA1F0D492C0013853F /* FSTLevelDBSpecTests.m in Sources */, @@ -1220,6 +1227,7 @@ DE51B1CE1F0D48CD0013853F /* FSTEventManagerTests.m in Sources */, DE51B1E41F0D490D0013853F /* FSTQueryCacheTests.m in Sources */, DE51B1CD1F0D48CD0013853F /* FSTDatabaseInfoTests.m in Sources */, + AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */, DE51B1F21F0D49140013853F /* FSTPathTests.m in Sources */, 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */, DE51B1DD1F0D490D0013853F /* FSTLocalStoreTests.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m new file mode 100644 index 00000000000..86c2db9b6d1 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m @@ -0,0 +1,58 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRDocumentReference+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/Model/FSTDocumentKey.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRDocumentReferenceTests : XCTestCase +@end + +@implementation FIRDocumentReferenceTests + +- (void)testEquals { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTDocumentKey *keyFoo = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; + FSTDocumentKey *keyFooDup = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; + FSTDocumentKey *keyBar = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; + FIRDocumentReference *referenceFoo = + [FIRDocumentReference referenceWithKey:keyFoo firestore:firestore]; + FIRDocumentReference *referenceFooDup = + [FIRDocumentReference referenceWithKey:keyFooDup firestore:firestore]; + FIRDocumentReference *referenceBar = + [FIRDocumentReference referenceWithKey:keyBar firestore:firestore]; + XCTAssertEqualObjects(referenceFoo, referenceFooDup); + XCTAssertNotEqualObjects(referenceFoo, referenceBar); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Example/Tests/API/FIRFieldPathTests.m b/Firestore/Example/Tests/API/FIRFieldPathTests.m new file mode 100644 index 00000000000..65351109309 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRFieldPathTests.m @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRFieldPath+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/Model/FSTPath.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRFieldPathTests : XCTestCase +@end + +@implementation FIRFieldPathTests + +- (void)testEquals { + FSTFieldPath *pathFoo = [FSTFieldPath pathWithServerFormat:@"foo.ooo.oooo"]; + FSTFieldPath *pathFooDup = [FSTFieldPath pathWithServerFormat:@"foo.ooo.oooo"]; + FSTFieldPath *pathBar = [FSTFieldPath pathWithServerFormat:@"baa.aaa.aaar"]; + FIRFieldPath *foo = [[FIRFieldPath alloc] initPrivate:pathFoo]; + FIRFieldPath *fooDup = [[FIRFieldPath alloc] initPrivate:pathFooDup]; + FIRFieldPath *bar = [[FIRFieldPath alloc] initPrivate:pathBar]; + XCTAssertEqualObjects(foo, fooDup); + XCTAssertNotEqualObjects(foo, bar); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 366a6bf99fb..41509ff5ebb 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -32,6 +32,31 @@ @interface FIRQueryTests : XCTestCase @implementation FIRQueryTests +- (void)testEquals { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; + FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FIRQuery *queryFoo = + [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathFoo] firestore:firestore]; + FIRQuery *queryFooDup = + [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathFoo] firestore:firestore]; + FIRQuery *queryBar = + [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathBar] firestore:firestore]; + XCTAssertEqualObjects(queryFoo, queryFooDup); + XCTAssertNotEqualObjects(queryFoo, queryBar); + XCTAssertEqualObjects([queryFoo queryWhereField:@"f" isEqualTo:@1], + [queryFoo queryWhereField:@"f" isEqualTo:@1]); + XCTAssertNotEqualObjects([queryFoo queryWhereField:@"f" isEqualTo:@1], + [queryFoo queryWhereField:@"f" isEqualTo:@2]); +} + - (void)testFilteringWithPredicate { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index 92cccc6c860..d3540a7ee62 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -65,6 +65,22 @@ - (instancetype)initWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firest FSTFail(@"Use FIRCollectionReference initWithPath: initializer."); } +// NSObject Methods +- (BOOL)isEqual:(nullable id)other { + if (other == self) return YES; + if (!other || ![[other class] isEqual:[self class]]) return NO; + + return [self isEqualToReference:other]; +} + +- (BOOL)isEqualToReference:(nullable FIRCollectionReference *)reference { + if (self == reference) return YES; + if (reference == nil) return NO; + // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; + // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + return YES; +} + - (NSString *)collectionID { return [self.query.path lastSegment]; } diff --git a/Firestore/Source/API/FIRDocumentSnapshot.m b/Firestore/Source/API/FIRDocumentSnapshot.m index b78472e8baf..3c6f1bdd21c 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.m +++ b/Firestore/Source/API/FIRDocumentSnapshot.m @@ -76,6 +76,22 @@ - (instancetype)initWithFirestore:(FIRFirestore *)firestore return self; } +// NSObject Methods +- (BOOL)isEqual:(nullable id)other { + if (other == self) return YES; + if (!other || ![[other class] isEqual:[self class]]) return NO; + + return [self isEqualToSnapshot:other]; +} + +- (BOOL)isEqualToSnapshot:(nullable FIRDocumentSnapshot *)snapshot { + if (self == snapshot) return YES; + if (snapshot == nil) return NO; + // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; + // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + return YES; +} + @dynamic exists; - (BOOL)exists { diff --git a/Firestore/Source/API/FIRFieldPath.m b/Firestore/Source/API/FIRFieldPath.m index d0a70c02bf3..005044d353c 100644 --- a/Firestore/Source/API/FIRFieldPath.m +++ b/Firestore/Source/API/FIRFieldPath.m @@ -80,12 +80,12 @@ - (id)copyWithZone:(NSZone *__nullable)zone { return [[[self class] alloc] initPrivate:self.internalValue]; } -- (BOOL)isEqual:(id)object { +- (BOOL)isEqual:(nullable id)object { if (self == object) { return YES; } - if (![object isKindOfClass:[FIRFieldPath class]]) { + if (!object || ![object isKindOfClass:[FIRFieldPath class]]) { return NO; } diff --git a/Firestore/Source/API/FIRFieldValue.m b/Firestore/Source/API/FIRFieldValue.m index 7ae4fb0caaa..1742b8f746f 100644 --- a/Firestore/Source/API/FIRFieldValue.m +++ b/Firestore/Source/API/FIRFieldValue.m @@ -83,6 +83,22 @@ - (instancetype)initPrivate { return self; } +// NSObject Methods +- (BOOL)isEqual:(nullable id)other { + if (other == self) return YES; + if (!other || ![[other class] isEqual:[self class]]) return NO; + + return [self isEqualToValue:other]; +} + +- (BOOL)isEqualToValue:(nullable FIRFieldValue *)value { + if (self == value) return YES; + if (value == nil) return NO; + // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; + // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + return YES; +} + + (instancetype)fieldValueForDelete { return [FSTDeleteFieldValue deleteFieldValue]; } diff --git a/Firestore/Source/API/FIRQuerySnapshot.m b/Firestore/Source/API/FIRQuerySnapshot.m index 6bc6761970b..33470f608b2 100644 --- a/Firestore/Source/API/FIRQuerySnapshot.m +++ b/Firestore/Source/API/FIRQuerySnapshot.m @@ -76,6 +76,22 @@ - (instancetype)initWithFirestore:(FIRFirestore *)firestore return self; } +// NSObject Methods +- (BOOL)isEqual:(nullable id)other { + if (other == self) return YES; + if (!other || ![[other class] isEqual:[self class]]) return NO; + + return [self isEqualToSnapshot:other]; +} + +- (BOOL)isEqualToSnapshot:(nullable FIRQuerySnapshot *)snapshot { + if (self == snapshot) return YES; + if (snapshot == nil) return NO; + // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; + // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + return YES; +} + @dynamic empty; - (FIRQuery *)query { diff --git a/Firestore/Source/API/FIRSnapshotMetadata.m b/Firestore/Source/API/FIRSnapshotMetadata.m index 224015f0a88..798a8701b3f 100644 --- a/Firestore/Source/API/FIRSnapshotMetadata.m +++ b/Firestore/Source/API/FIRSnapshotMetadata.m @@ -44,6 +44,22 @@ - (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCa return self; } +// NSObject Methods +- (BOOL)isEqual:(nullable id)other { + if (other == self) return YES; + if (!other || ![[other class] isEqual:[self class]]) return NO; + + return [self isEqualToMetadata:other]; +} + +- (BOOL)isEqualToMetadata:(nullable FIRSnapshotMetadata *)metadata { + if (self == metadata) return YES; + if (metadata == nil) return NO; + // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; + // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + return YES; +} + @end NS_ASSUME_NONNULL_END From 0686f8862bf724d9e6b506eaa58a5087dd803117 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 11:08:26 -0500 Subject: [PATCH 02/18] Implement isEqual for FIRCollectionReference adding the working code and unit test. --- .../Firestore.xcodeproj/project.pbxproj | 4 ++ .../Tests/API/FIRCollectionReferenceTests.m | 57 +++++++++++++++++++ .../Source/API/FIRCollectionReference.mm | 6 +- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRCollectionReferenceTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index c40a34c57e7..6bcf3a30211 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -63,6 +63,7 @@ 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */; }; AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */; }; + AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -235,6 +236,7 @@ 9EF477AD4B2B643FD320867A /* Pods-Firestore_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example/Pods-Firestore_Example.debug.xcconfig"; sourceTree = ""; }; AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentReferenceTests.m; sourceTree = ""; }; AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRFieldPathTests.m; sourceTree = ""; }; + AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRCollectionReferenceTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -589,6 +591,7 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */, AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */, AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */, DE51B1841F0D48AC0013853F /* FIRGeoPointTests.m */, @@ -1217,6 +1220,7 @@ DE51B1D91F0D490D0013853F /* FSTEagerGarbageCollectorTests.m in Sources */, DE51B1E21F0D490D0013853F /* FSTMutationQueueTests.m in Sources */, DE51B1E81F0D490D0013853F /* FSTLevelDBKeyTests.mm in Sources */, + AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */, DE51B1E31F0D490D0013853F /* FSTPersistenceTestHelpers.m in Sources */, AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */, DE51B1CF1F0D48CD0013853F /* FSTQueryListenerTests.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m new file mode 100644 index 00000000000..bfbc43d3c4e --- /dev/null +++ b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m @@ -0,0 +1,57 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRCollectionReference+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/Model/FSTPath.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRCollectionReferenceTests : XCTestCase +@end + +@implementation FIRCollectionReferenceTests + +- (void)testEquals { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; + FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FIRCollectionReference *referenceFoo = + [FIRCollectionReference referenceWithPath:pathFoo firestore:firestore]; + FIRCollectionReference *referenceFooDup = + [FIRCollectionReference referenceWithPath:pathFoo firestore:firestore]; + FIRCollectionReference *referenceBar = + [FIRCollectionReference referenceWithPath:pathBar firestore:firestore]; + XCTAssertEqualObjects(referenceFoo, referenceFooDup); + XCTAssertNotEqualObjects(referenceFoo, referenceBar); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index d3540a7ee62..bf1b1754cf7 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -15,6 +15,7 @@ */ #import "FIRCollectionReference.h" +#import "FIRFirestore.h" #include "Firestore/core/src/firebase/firestore/util/autoid.h" @@ -76,8 +77,9 @@ - (BOOL)isEqual:(nullable id)other { - (BOOL)isEqualToReference:(nullable FIRCollectionReference *)reference { if (self == reference) return YES; if (reference == nil) return NO; - // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; - // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + if (self.firestore != reference.firestore && ![self.firestore isEqual:reference.firestore]) + return NO; + if (self.query != reference.query && ![self.query isEqual:reference.query]) return NO; return YES; } From a3f37711b8384dd70ca9d18a649f64f7e56a85ab Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 11:35:03 -0500 Subject: [PATCH 03/18] implement isEqual for FIRSnapshotMetadata --- .../Firestore.xcodeproj/project.pbxproj | 4 ++ .../Tests/API/FIRSnapshotMetadataTests.m | 50 +++++++++++++++++++ Firestore/Source/API/FIRSnapshotMetadata.m | 4 +- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 6bcf3a30211..8c0dff44251 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ AB382F7C1FE02A1F007CA955 /* FIRDocumentReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */; }; AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */; }; AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */; }; + AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -237,6 +238,7 @@ AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentReferenceTests.m; sourceTree = ""; }; AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRFieldPathTests.m; sourceTree = ""; }; AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRCollectionReferenceTests.m; sourceTree = ""; }; + AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRSnapshotMetadataTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -591,6 +593,7 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */, AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */, AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */, AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */, @@ -1185,6 +1188,7 @@ DE51B2011F0D493E0013853F /* FSTHelpers.m in Sources */, DE51B1F61F0D491B0013853F /* FSTSerializerBetaTests.m in Sources */, DE51B1F01F0D49140013853F /* FSTFieldValueTests.m in Sources */, + AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */, 5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */, DE2EF0861F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m in Sources */, DE51B1DE1F0D490D0013853F /* FSTMemoryLocalStoreTests.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m new file mode 100644 index 00000000000..2d995439524 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRSnapshotMetadataTests : XCTestCase +@end + +@implementation FIRSnapshotMetadataTests + +- (void)testEquals { + FIRSnapshotMetadata *foo = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; + FIRSnapshotMetadata *fooDup = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; + FIRSnapshotMetadata *bar = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:NO]; + FIRSnapshotMetadata *baz = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:YES]; + XCTAssertEqualObjects(foo, fooDup); + XCTAssertNotEqualObjects(foo, bar); + XCTAssertNotEqualObjects(foo, baz); + XCTAssertNotEqualObjects(bar, baz); +} + +@end + +NS_ASSUME_NONNULL_END + diff --git a/Firestore/Source/API/FIRSnapshotMetadata.m b/Firestore/Source/API/FIRSnapshotMetadata.m index 798a8701b3f..274f7f67937 100644 --- a/Firestore/Source/API/FIRSnapshotMetadata.m +++ b/Firestore/Source/API/FIRSnapshotMetadata.m @@ -55,8 +55,8 @@ - (BOOL)isEqual:(nullable id)other { - (BOOL)isEqualToMetadata:(nullable FIRSnapshotMetadata *)metadata { if (self == metadata) return YES; if (metadata == nil) return NO; - // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; - // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + if (self.pendingWrites != metadata.pendingWrites) return NO; + if (self.fromCache != metadata.fromCache) return NO; return YES; } From 9b02f2269a870c3d9202c4505139d72b741c2b06 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 13:49:13 -0500 Subject: [PATCH 04/18] Implement isEqual for FIRDocumentSnapshot --- .../Firestore.xcodeproj/project.pbxproj | 4 + .../Tests/API/FIRDocumentSnapshotTests.m | 103 ++++++++++++++++++ Firestore/Source/API/FIRDocumentSnapshot.m | 10 +- 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 8c0dff44251..090bf1f2d68 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */; }; AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */; }; AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */; }; + AB99452A1FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -239,6 +240,7 @@ AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRFieldPathTests.m; sourceTree = ""; }; AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRCollectionReferenceTests.m; sourceTree = ""; }; AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRSnapshotMetadataTests.m; sourceTree = ""; }; + AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentSnapshotTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -593,6 +595,7 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */, AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */, AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */, AB382F7D1FE03059007CA955 /* FIRFieldPathTests.m */, @@ -1201,6 +1204,7 @@ DE51B1D11F0D48CD0013853F /* FSTTargetIDGeneratorTests.m in Sources */, DE51B1EF1F0D49140013853F /* FSTDocumentTests.m in Sources */, DE51B1DC1F0D490D0013853F /* FSTLocalSerializerTests.m in Sources */, + AB99452A1FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m in Sources */, DE51B1E71F0D490D0013853F /* FSTRemoteDocumentChangeBufferTests.m in Sources */, DE51B1E51F0D490D0013853F /* FSTReferenceSetTests.m in Sources */, DE51B1EA1F0D490D0013853F /* FSTLevelDBRemoteDocumentCacheTests.mm in Sources */, diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m new file mode 100644 index 00000000000..9a60f3cd501 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -0,0 +1,103 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/Core/FSTSnapshotVersion.h" +#import "Firestore/Source/Model/FSTDocument.h" +#import "Firestore/Source/Model/FSTDocumentKey.h" +#import "Firestore/Source/Model/FSTFieldValue.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRDocumentSnapshotTests : XCTestCase +@end + +@implementation FIRDocumentSnapshotTests + +- (void)testEquals { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTDocumentKey *keyFoo = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; + FSTDocumentKey *keyBar = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; + FSTObjectValue *dateFoo = FSTTestObjectValue(@{ @"a" : @1 }); + FSTObjectValue *dateBar = FSTTestObjectValue(@{ @"b" : @1 }); + FSTSnapshotVersion *version = FSTTestVersion(1); + FSTDocument *docFoo = [FSTDocument documentWithData:dateFoo + key:keyFoo + version:version + hasLocalMutations:NO]; + FSTDocument *docBar = [FSTDocument documentWithData:dateBar + key:keyBar + version:version + hasLocalMutations:NO]; + XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:nil + fromCache:YES], + [FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:nil + fromCache:YES]); + XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:docFoo + fromCache:YES], + [FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:docFoo + fromCache:YES]); + XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:nil + fromCache:YES], + [FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyBar + document:nil + fromCache:YES]); + XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:docFoo + fromCache:YES], + [FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:docBar + fromCache:YES]); + XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:nil + fromCache:YES], + [FIRDocumentSnapshot snapshotWithFirestore:firestore + documentKey:keyFoo + document:nil + fromCache:NO]); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRDocumentSnapshot.m b/Firestore/Source/API/FIRDocumentSnapshot.m index 3c6f1bdd21c..302dbf0eade 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.m +++ b/Firestore/Source/API/FIRDocumentSnapshot.m @@ -87,8 +87,14 @@ - (BOOL)isEqual:(nullable id)other { - (BOOL)isEqualToSnapshot:(nullable FIRDocumentSnapshot *)snapshot { if (self == snapshot) return YES; if (snapshot == nil) return NO; - // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; - // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + if (self.firestore != snapshot.firestore && ![self.firestore isEqual:snapshot.firestore]) + return NO; + if (self.internalKey != snapshot.internalKey && ![self.internalKey isEqual:snapshot.internalKey]) + return NO; + if (self.internalDocument != snapshot.internalDocument && + (!self.internalDocument || ![self.internalDocument isEqual:snapshot.internalDocument])) + return NO; + if (self.fromCache != snapshot.fromCache) return NO; return YES; } From d40c4c1c0d56ccc3951ade68dd780de02f8c23c7 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 14:16:45 -0500 Subject: [PATCH 05/18] Implement isEqual for FIRQuerySnapshot --- .../Firestore.xcodeproj/project.pbxproj | 4 + .../Example/Tests/API/FIRQuerySnapshotTests.m | 116 ++++++++++++++++++ Firestore/Source/API/FIRQuerySnapshot.m | 10 +- 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRQuerySnapshotTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 090bf1f2d68..52aab41bfc7 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ AB9945261FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */; }; AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */; }; AB99452A1FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */; }; + AB99452C1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -241,6 +242,7 @@ AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRCollectionReferenceTests.m; sourceTree = ""; }; AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRSnapshotMetadataTests.m; sourceTree = ""; }; AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentSnapshotTests.m; sourceTree = ""; }; + AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRQuerySnapshotTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -595,6 +597,7 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */, AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */, AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */, AB9945251FE2D71100DFC1E6 /* FIRCollectionReferenceTests.m */, @@ -1241,6 +1244,7 @@ DE51B1CD1F0D48CD0013853F /* FSTDatabaseInfoTests.m in Sources */, AB382F7E1FE03059007CA955 /* FIRFieldPathTests.m in Sources */, DE51B1F21F0D49140013853F /* FSTPathTests.m in Sources */, + AB99452C1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m in Sources */, 54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */, DE51B1DD1F0D490D0013853F /* FSTLocalStoreTests.m in Sources */, D5B25474286C9800CE42B8C2 /* FSTTestDispatchQueue.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m new file mode 100644 index 00000000000..1e643013945 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -0,0 +1,116 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" +#import "Firestore/Source/API/FIRQuery+Internal.h" +#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" +#import "Firestore/Source/Core/FSTQuery.h" +#import "Firestore/Source/Core/FSTSnapshotVersion.h" +#import "Firestore/Source/Core/FSTViewSnapshot.h" +#import "Firestore/Source/Model/FSTDocument.h" +#import "Firestore/Source/Model/FSTDocumentKey.h" +#import "Firestore/Source/Model/FSTDocumentSet.h" +#import "Firestore/Source/Model/FSTFieldValue.h" +#import "Firestore/Source/Model/FSTPath.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRQuerySnapshotTests : XCTestCase +@end + +@implementation FIRQuerySnapshotTests + +- (void)testEquals { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; + FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FSTQuery *queryFoo = [FSTQuery queryWithPath:pathFoo]; + FSTQuery *queryBar = [FSTQuery queryWithPath:pathBar]; + FIRSnapshotMetadata *metadataFoo = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; + FIRSnapshotMetadata *metadataBar = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO]; + FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:FSTDocumentComparatorByKey]; + FSTDocumentSet *oldDocuments = documents; + documents = [documents documentSetByAddingDocument:FSTTestDoc(@"c/a", 1, @{}, NO)]; + NSArray *documentChanges = + @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc(@"c/a", 1, @{}, NO) + type:FSTDocumentViewChangeTypeAdded] ]; + FSTViewSnapshot *snapshotFoo = [[FSTViewSnapshot alloc] initWithQuery:queryFoo + documents:documents + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:YES + hasPendingWrites:NO + syncStateChanged:YES]; + FSTViewSnapshot *snapshotBar = [[FSTViewSnapshot alloc] initWithQuery:queryBar + documents:documents + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:YES + hasPendingWrites:NO + syncStateChanged:YES]; + XCTAssertEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataFoo], + [FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataFoo]); + XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataFoo], + [FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryBar + snapshot:snapshotFoo + metadata:metadataFoo]); + XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataFoo], + [FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotBar + metadata:metadataFoo]); + XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataFoo], + [FIRQuerySnapshot snapshotWithFirestore:firestore + originalQuery:queryFoo + snapshot:snapshotFoo + metadata:metadataBar]); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRQuerySnapshot.m b/Firestore/Source/API/FIRQuerySnapshot.m index 33470f608b2..ab7994e0841 100644 --- a/Firestore/Source/API/FIRQuerySnapshot.m +++ b/Firestore/Source/API/FIRQuerySnapshot.m @@ -16,6 +16,7 @@ #import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" +#import "FIRFirestore.h" #import "FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRDocumentChange+Internal.h" #import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" @@ -87,8 +88,13 @@ - (BOOL)isEqual:(nullable id)other { - (BOOL)isEqualToSnapshot:(nullable FIRQuerySnapshot *)snapshot { if (self == snapshot) return YES; if (snapshot == nil) return NO; - // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; - // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; + if (self.firestore != snapshot.firestore && ![self.firestore isEqual:snapshot.firestore]) + return NO; + if (self.originalQuery != snapshot.originalQuery && + ![self.originalQuery isEqual:snapshot.originalQuery]) + return NO; + if (self.snapshot != snapshot.snapshot && ![self.snapshot isEqual:snapshot.snapshot]) return NO; + if (self.metadata != snapshot.metadata && ![self.metadata isEqual:snapshot.metadata]) return NO; return YES; } From ea5fdd7ec04efb6f67c4e8b1c23b44f10b893aeb Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 14:43:17 -0500 Subject: [PATCH 06/18] (un)implement `isEqual` for `FIRFieldValue` Since `FIRFieldValue` both types are singleton, we do not need override `isEqual`. Add test to test the default `NSObject` `isEqual` works just fine. --- .../Firestore.xcodeproj/project.pbxproj | 4 ++ .../Example/Tests/API/FIRFieldValueTests.m | 44 +++++++++++++++++++ Firestore/Source/API/FIRFieldValue.m | 16 ------- 3 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 Firestore/Example/Tests/API/FIRFieldValueTests.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 52aab41bfc7..b1d95ea678f 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -67,6 +67,7 @@ AB9945281FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */; }; AB99452A1FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */; }; AB99452C1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */; }; + AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; @@ -243,6 +244,7 @@ AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRSnapshotMetadataTests.m; sourceTree = ""; }; AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRDocumentSnapshotTests.m; sourceTree = ""; }; AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRQuerySnapshotTests.m; sourceTree = ""; }; + AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRFieldValueTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -597,6 +599,7 @@ DE51B1831F0D48AC0013853F /* API */ = { isa = PBXGroup; children = ( + AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */, AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */, AB9945291FE2F9EB00DFC1E6 /* FIRDocumentSnapshotTests.m */, AB9945271FE2DE0C00DFC1E6 /* FIRSnapshotMetadataTests.m */, @@ -1219,6 +1222,7 @@ DE51B1DB1F0D490D0013853F /* FSTLevelDBQueryCacheTests.m in Sources */, 54764FAB1FAA0C320085E60A /* string_util_test.cc in Sources */, 54E9282C1F339CAD00C1953E /* XCTestCase+Await.m in Sources */, + AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */, DE51B1DF1F0D490D0013853F /* FSTMemoryMutationQueueTests.m in Sources */, DE51B1F31F0D491B0013853F /* FSTDatastoreTests.m in Sources */, DE51B1D01F0D48CD0013853F /* FSTQueryTests.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRFieldValueTests.m b/Firestore/Example/Tests/API/FIRFieldValueTests.m new file mode 100644 index 00000000000..8ca3144aa37 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRFieldValueTests.m @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRFieldValue+Internal.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRFieldValueTests : XCTestCase +@end + +@implementation FIRFieldValueTests + +- (void)testEquals { + XCTAssertEqualObjects([FIRFieldValue fieldValueForDelete], [FIRFieldValue fieldValueForDelete]); + XCTAssertNotEqualObjects([FIRFieldValue fieldValueForDelete], nil); + XCTAssertEqualObjects([FIRFieldValue fieldValueForServerTimestamp], + [FIRFieldValue fieldValueForServerTimestamp]); + XCTAssertNotEqualObjects([FIRFieldValue fieldValueForServerTimestamp], nil); + XCTAssertNotEqualObjects([FIRFieldValue fieldValueForDelete], + [FIRFieldValue fieldValueForServerTimestamp]); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRFieldValue.m b/Firestore/Source/API/FIRFieldValue.m index 1742b8f746f..7ae4fb0caaa 100644 --- a/Firestore/Source/API/FIRFieldValue.m +++ b/Firestore/Source/API/FIRFieldValue.m @@ -83,22 +83,6 @@ - (instancetype)initPrivate { return self; } -// NSObject Methods -- (BOOL)isEqual:(nullable id)other { - if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; - - return [self isEqualToValue:other]; -} - -- (BOOL)isEqualToValue:(nullable FIRFieldValue *)value { - if (self == value) return YES; - if (value == nil) return NO; - // if (self.firestore != query.firestore && ![self.firestore isEqual:query.firestore]) return NO; - // if (self.query != query.query && ![self.query isEqual:query.query]) return NO; - return YES; -} - + (instancetype)fieldValueForDelete { return [FSTDeleteFieldValue deleteFieldValue]; } From 0c737297a0d33b8627f8036dce95ca41b62cc471 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Thu, 14 Dec 2017 14:44:56 -0500 Subject: [PATCH 07/18] fix style with `scripts/style.sh` --- .../Example/Tests/API/FIRDocumentSnapshotTests.m | 12 ++++-------- Firestore/Example/Tests/API/FIRQuerySnapshotTests.m | 10 +++++----- .../Example/Tests/API/FIRSnapshotMetadataTests.m | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index 9a60f3cd501..dcce28a8730 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -48,14 +48,10 @@ - (void)testEquals { FSTObjectValue *dateFoo = FSTTestObjectValue(@{ @"a" : @1 }); FSTObjectValue *dateBar = FSTTestObjectValue(@{ @"b" : @1 }); FSTSnapshotVersion *version = FSTTestVersion(1); - FSTDocument *docFoo = [FSTDocument documentWithData:dateFoo - key:keyFoo - version:version - hasLocalMutations:NO]; - FSTDocument *docBar = [FSTDocument documentWithData:dateBar - key:keyBar - version:version - hasLocalMutations:NO]; + FSTDocument *docFoo = + [FSTDocument documentWithData:dateFoo key:keyFoo version:version hasLocalMutations:NO]; + FSTDocument *docBar = + [FSTDocument documentWithData:dateBar key:keyBar version:version hasLocalMutations:NO]; XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore documentKey:keyFoo document:nil diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index 1e643013945..ef4b5365dbc 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -19,8 +19,8 @@ #import #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" #import "Firestore/Source/API/FIRQuery+Internal.h" +#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" @@ -54,15 +54,15 @@ - (void)testEquals { FSTQuery *queryFoo = [FSTQuery queryWithPath:pathFoo]; FSTQuery *queryBar = [FSTQuery queryWithPath:pathBar]; FIRSnapshotMetadata *metadataFoo = - [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; FIRSnapshotMetadata *metadataBar = - [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO]; + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO]; FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:FSTDocumentComparatorByKey]; FSTDocumentSet *oldDocuments = documents; documents = [documents documentSetByAddingDocument:FSTTestDoc(@"c/a", 1, @{}, NO)]; NSArray *documentChanges = - @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc(@"c/a", 1, @{}, NO) - type:FSTDocumentViewChangeTypeAdded] ]; + @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc(@"c/a", 1, @{}, NO) + type:FSTDocumentViewChangeTypeAdded] ]; FSTViewSnapshot *snapshotFoo = [[FSTViewSnapshot alloc] initWithQuery:queryFoo documents:documents oldDocuments:oldDocuments diff --git a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m index 2d995439524..87ad2be544b 100644 --- a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m +++ b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m @@ -47,4 +47,3 @@ - (void)testEquals { @end NS_ASSUME_NONNULL_END - From 4e774900666cb97ece49d1408af1757545ab00a9 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Fri, 15 Dec 2017 11:04:11 -0500 Subject: [PATCH 08/18] Implement hash for those with overridden isEqual without hash yet. --- .../Example/Tests/API/FIRCollectionReferenceTests.m | 3 +++ .../Example/Tests/API/FIRDocumentReferenceTests.m | 3 +++ .../Example/Tests/API/FIRDocumentSnapshotTests.m | 2 ++ Firestore/Example/Tests/API/FIRFieldPathTests.m | 3 +++ Firestore/Example/Tests/API/FIRFieldValueTests.m | 6 ++++++ Firestore/Example/Tests/API/FIRGeoPointTests.m | 11 +++++++++++ Firestore/Example/Tests/API/FIRQuerySnapshotTests.m | 2 ++ Firestore/Example/Tests/API/FIRQueryTests.m | 7 +++++++ .../Example/Tests/API/FIRSnapshotMetadataTests.m | 5 +++++ Firestore/Source/API/FIRCollectionReference.mm | 6 ++++++ Firestore/Source/API/FIRDocumentSnapshot.m | 8 ++++++++ Firestore/Source/API/FIRQuerySnapshot.m | 8 ++++++++ Firestore/Source/API/FIRSnapshotMetadata.m | 6 ++++++ Firestore/Source/Core/FSTView.m | 6 ++++++ 14 files changed, 76 insertions(+) diff --git a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m index bfbc43d3c4e..e015cea4b67 100644 --- a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m @@ -50,6 +50,9 @@ - (void)testEquals { [FIRCollectionReference referenceWithPath:pathBar firestore:firestore]; XCTAssertEqualObjects(referenceFoo, referenceFooDup); XCTAssertNotEqualObjects(referenceFoo, referenceBar); + + XCTAssertEqual([referenceFoo hash], [referenceFooDup hash]); + XCTAssertNotEqual([referenceFoo hash], [referenceBar hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m index 86c2db9b6d1..56f40d60e14 100644 --- a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m @@ -51,6 +51,9 @@ - (void)testEquals { [FIRDocumentReference referenceWithKey:keyBar firestore:firestore]; XCTAssertEqualObjects(referenceFoo, referenceFooDup); XCTAssertNotEqualObjects(referenceFoo, referenceBar); + + XCTAssertEqual([referenceFoo hash], [referenceFooDup hash]); + XCTAssertNotEqual([referenceFoo hash], [referenceBar hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index dcce28a8730..36c3c45010b 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -92,6 +92,8 @@ - (void)testEquals { documentKey:keyFoo document:nil fromCache:NO]); + + // Test hash (in)equality here as well. } @end diff --git a/Firestore/Example/Tests/API/FIRFieldPathTests.m b/Firestore/Example/Tests/API/FIRFieldPathTests.m index 65351109309..686104d558c 100644 --- a/Firestore/Example/Tests/API/FIRFieldPathTests.m +++ b/Firestore/Example/Tests/API/FIRFieldPathTests.m @@ -40,6 +40,9 @@ - (void)testEquals { FIRFieldPath *bar = [[FIRFieldPath alloc] initPrivate:pathBar]; XCTAssertEqualObjects(foo, fooDup); XCTAssertNotEqualObjects(foo, bar); + + XCTAssertEqual([foo hash], [fooDup hash]); + XCTAssertNotEqual([foo hash], [bar hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRFieldValueTests.m b/Firestore/Example/Tests/API/FIRFieldValueTests.m index 8ca3144aa37..8ce284d4816 100644 --- a/Firestore/Example/Tests/API/FIRFieldValueTests.m +++ b/Firestore/Example/Tests/API/FIRFieldValueTests.m @@ -37,6 +37,12 @@ - (void)testEquals { XCTAssertNotEqualObjects([FIRFieldValue fieldValueForServerTimestamp], nil); XCTAssertNotEqualObjects([FIRFieldValue fieldValueForDelete], [FIRFieldValue fieldValueForServerTimestamp]); + + XCTAssertEqual([[FIRFieldValue fieldValueForDelete] hash], [[FIRFieldValue fieldValueForDelete] hash]); + XCTAssertEqual([[FIRFieldValue fieldValueForServerTimestamp] hash], + [[FIRFieldValue fieldValueForServerTimestamp] hash]); + XCTAssertNotEqual([[FIRFieldValue fieldValueForDelete] hash], + [[FIRFieldValue fieldValueForServerTimestamp] hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRGeoPointTests.m b/Firestore/Example/Tests/API/FIRGeoPointTests.m index b505de06323..adce25cdebe 100644 --- a/Firestore/Example/Tests/API/FIRGeoPointTests.m +++ b/Firestore/Example/Tests/API/FIRGeoPointTests.m @@ -38,6 +38,17 @@ - (void)testEquals { [[FIRGeoPoint alloc] initWithLatitude:0 longitude:1]); XCTAssertNotEqualObjects([[FIRGeoPoint alloc] initWithLatitude:0 longitude:0], [[NSObject alloc] init]); + + XCTAssertEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], + [[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash]); + XCTAssertEqual([[[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56] hash], + [[[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56] hash]); + XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], + [[[FIRGeoPoint alloc] initWithLatitude:1 longitude:0] hash]); + XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], + [[[FIRGeoPoint alloc] initWithLatitude:0 longitude:1] hash]); + XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], + [[[NSObject alloc] init] hash]); } - (void)testComparison { diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index ef4b5365dbc..82a27ba9e0c 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -109,6 +109,8 @@ - (void)testEquals { originalQuery:queryFoo snapshot:snapshotFoo metadata:metadataBar]); + + // Also test hash (in)equality here. } @end diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 41509ff5ebb..3a26389cd55 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -55,6 +55,13 @@ - (void)testEquals { [queryFoo queryWhereField:@"f" isEqualTo:@1]); XCTAssertNotEqualObjects([queryFoo queryWhereField:@"f" isEqualTo:@1], [queryFoo queryWhereField:@"f" isEqualTo:@2]); + + XCTAssertEqual([queryFoo hash], [queryFooDup hash]); + XCTAssertNotEqual([queryFoo hash], [queryBar hash]); + XCTAssertEqual([[queryFoo queryWhereField:@"f" isEqualTo:@1] hash], + [[queryFoo queryWhereField:@"f" isEqualTo:@1] hash]); + XCTAssertNotEqual([[queryFoo queryWhereField:@"f" isEqualTo:@1] hash], + [[queryFoo queryWhereField:@"f" isEqualTo:@2] hash]); } - (void)testFilteringWithPredicate { diff --git a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m index 87ad2be544b..c9b8f475a96 100644 --- a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m +++ b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m @@ -42,6 +42,11 @@ - (void)testEquals { XCTAssertNotEqualObjects(foo, bar); XCTAssertNotEqualObjects(foo, baz); XCTAssertNotEqualObjects(bar, baz); + + XCTAssertEqual([foo hash], [fooDup hash]); + XCTAssertNotEqual([foo hash], [bar hash]); + XCTAssertNotEqual([foo hash], [baz hash]); + XCTAssertNotEqual([bar hash], [baz hash]); } @end diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index bf1b1754cf7..e82dfece194 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -83,6 +83,12 @@ - (BOOL)isEqualToReference:(nullable FIRCollectionReference *)reference { return YES; } +- (NSUInteger)hash { + NSUInteger hash = [self.firestore hash]; + hash = hash * 31u + [self.query hash]; + return hash; +} + - (NSString *)collectionID { return [self.query.path lastSegment]; } diff --git a/Firestore/Source/API/FIRDocumentSnapshot.m b/Firestore/Source/API/FIRDocumentSnapshot.m index 302dbf0eade..4d7714df4a6 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.m +++ b/Firestore/Source/API/FIRDocumentSnapshot.m @@ -98,6 +98,14 @@ - (BOOL)isEqualToSnapshot:(nullable FIRDocumentSnapshot *)snapshot { return YES; } +- (NSUInteger)hash { + NSUInteger hash = [self.firestore hash]; + hash = hash * 31u + [self.internalKey hash]; + hash = hash * 31u + [self.internalDocument hash]; + hash = hash * 31u + (self.fromCache ? 1 : 0); + return hash; +} + @dynamic exists; - (BOOL)exists { diff --git a/Firestore/Source/API/FIRQuerySnapshot.m b/Firestore/Source/API/FIRQuerySnapshot.m index ab7994e0841..118481e2cf5 100644 --- a/Firestore/Source/API/FIRQuerySnapshot.m +++ b/Firestore/Source/API/FIRQuerySnapshot.m @@ -98,6 +98,14 @@ - (BOOL)isEqualToSnapshot:(nullable FIRQuerySnapshot *)snapshot { return YES; } +- (NSUInteger)hash { + NSUInteger hash = [self.firestore hash]; + hash = hash * 31u + [self.originalQuery hash]; + hash = hash * 31u + [self.snapshot hash]; + hash = hash * 31u + [self.metadata hash]; + return hash; +} + @dynamic empty; - (FIRQuery *)query { diff --git a/Firestore/Source/API/FIRSnapshotMetadata.m b/Firestore/Source/API/FIRSnapshotMetadata.m index 274f7f67937..784b51c5f56 100644 --- a/Firestore/Source/API/FIRSnapshotMetadata.m +++ b/Firestore/Source/API/FIRSnapshotMetadata.m @@ -60,6 +60,12 @@ - (BOOL)isEqualToMetadata:(nullable FIRSnapshotMetadata *)metadata { return YES; } +- (NSUInteger)hash { + NSUInteger hash = self.pendingWrites ? 1 : 0; + hash = hash * 31u + (self.fromCache ? 1 : 0); + return hash; +} + @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Core/FSTView.m b/Firestore/Source/Core/FSTView.m index 9b44bf4fefb..ea27e2a9f11 100644 --- a/Firestore/Source/Core/FSTView.m +++ b/Firestore/Source/Core/FSTView.m @@ -94,6 +94,12 @@ - (BOOL)isEqual:(id)other { return self.type == otherChange.type && [self.key isEqual:otherChange.key]; } +- (NSUInteger)hash { + NSUInteger hash = self.type; + hash = hash * 31u + [self.key hash]; + return hash; +} + @end #pragma mark - FSTViewChange From 9a0117af81ad2404102d25d8416e01461ce5ce7a Mon Sep 17 00:00:00 2001 From: zxu123 Date: Fri, 15 Dec 2017 12:12:53 -0500 Subject: [PATCH 09/18] refactor to use test helper functions -- FSTTestFirestore, FSTTestPath, FSTTestDocKey --- .../Tests/API/FIRCollectionReferenceTests.m | 15 +++------ .../Tests/API/FIRDocumentReferenceTests.m | 17 +++------- .../Tests/API/FIRDocumentSnapshotTests.m | 25 +++++---------- .../Example/Tests/API/FIRFieldPathTests.m | 4 +-- .../Example/Tests/API/FIRQuerySnapshotTests.m | 19 +++-------- Firestore/Example/Tests/API/FIRQueryTests.m | 24 ++++---------- .../Tests/API/FIRSnapshotMetadataTests.m | 3 +- Firestore/Example/Tests/Core/FSTQueryTests.m | 2 +- .../Local/FSTEagerGarbageCollectorTests.m | 12 +++---- .../Tests/Local/FSTLocalSerializerTests.m | 2 +- .../Example/Tests/Local/FSTLocalStoreTests.m | 5 ++- .../Example/Tests/Local/FSTQueryCacheTests.m | 32 +++++++++---------- .../Tests/Local/FSTReferenceSetTests.m | 9 +++--- .../Example/Tests/Model/FSTDocumentTests.m | 12 +++---- .../Example/Tests/Model/FSTMutationTests.m | 2 +- .../Example/Tests/SpecTests/FSTSpecTests.m | 8 ++--- Firestore/Example/Tests/Util/FSTHelpers.h | 4 +++ Firestore/Example/Tests/Util/FSTHelpers.m | 23 +++++++++---- 18 files changed, 92 insertions(+), 126 deletions(-) diff --git a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m index e015cea4b67..05ebfc24c39 100644 --- a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m @@ -14,12 +14,10 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import +#import "FirebaseFirestore/FIRCollectionReference.h" #import "Firestore/Source/API/FIRCollectionReference+Internal.h" -#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" @@ -34,14 +32,9 @@ @implementation FIRCollectionReferenceTests - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; - FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FIRFirestore *firestore = FSTTestFirestore(); + FSTResourcePath *pathFoo = FSTTestPath(@"foo"); + FSTResourcePath *pathBar = FSTTestPath(@"bar"); FIRCollectionReference *referenceFoo = [FIRCollectionReference referenceWithPath:pathFoo firestore:firestore]; FIRCollectionReference *referenceFooDup = diff --git a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m index 56f40d60e14..35307bafa90 100644 --- a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m @@ -14,12 +14,10 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import +#import "FirebaseFirestore/FIRDocumentReference.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" -#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" @@ -34,15 +32,10 @@ @implementation FIRDocumentReferenceTests - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTDocumentKey *keyFoo = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; - FSTDocumentKey *keyFooDup = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; - FSTDocumentKey *keyBar = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; + FIRFirestore *firestore = FSTTestFirestore(); + FSTDocumentKey *keyFoo = FSTTestDocKey(@"rooms/foo"); + FSTDocumentKey *keyFooDup = FSTTestDocKey(@"rooms/foo"); + FSTDocumentKey *keyBar = FSTTestDocKey(@"rooms/bar"); FIRDocumentReference *referenceFoo = [FIRDocumentReference referenceWithKey:keyFoo firestore:firestore]; FIRDocumentReference *referenceFooDup = diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index 36c3c45010b..cfda8edbe71 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -14,12 +14,10 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import +#import "FirebaseFirestore/FIRDocumentSnapshot.h" #import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" -#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" @@ -37,21 +35,14 @@ @implementation FIRDocumentSnapshotTests - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTDocumentKey *keyFoo = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; - FSTDocumentKey *keyBar = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; - FSTObjectValue *dateFoo = FSTTestObjectValue(@{ @"a" : @1 }); - FSTObjectValue *dateBar = FSTTestObjectValue(@{ @"b" : @1 }); + FIRFirestore *firestore = FSTTestFirestore(); + FSTDocumentKey *keyFoo = FSTTestDocKey(@"rooms/foo"); + FSTDocumentKey *keyBar = FSTTestDocKey(@"rooms/bar"); + FSTObjectValue *dataFoo = FSTTestObjectValue(@{ @"a" : @1 }); + FSTObjectValue *dataBar = FSTTestObjectValue(@{ @"b" : @1 }); FSTSnapshotVersion *version = FSTTestVersion(1); - FSTDocument *docFoo = - [FSTDocument documentWithData:dateFoo key:keyFoo version:version hasLocalMutations:NO]; - FSTDocument *docBar = - [FSTDocument documentWithData:dateBar key:keyBar version:version hasLocalMutations:NO]; + FSTDocument *docFoo = FSTTestDoc(@"rooms/foo", 1, @{ @"a" : @1 }, NO); + FSTDocument *docBar = FSTTestDoc(@"rooms/bar", 1, @{ @"b" : @1 }, NO); XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore documentKey:keyFoo document:nil diff --git a/Firestore/Example/Tests/API/FIRFieldPathTests.m b/Firestore/Example/Tests/API/FIRFieldPathTests.m index 686104d558c..e5053db6331 100644 --- a/Firestore/Example/Tests/API/FIRFieldPathTests.m +++ b/Firestore/Example/Tests/API/FIRFieldPathTests.m @@ -14,12 +14,10 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import +#import "FirebaseFirestore/FIRFieldPath.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" -#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index 82a27ba9e0c..a63c0a9fed0 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -14,21 +14,15 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import -#import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FIRQuery+Internal.h" +#import "FirebaseFirestore/FIRQuerySnapshot.h" #import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" #import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Core/FSTViewSnapshot.h" #import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" @@ -43,14 +37,9 @@ @implementation FIRQuerySnapshotTests - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; - FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FIRFirestore *firestore = FSTTestFirestore(); + FSTResourcePath *pathFoo = FSTTestPath(@"foo"); + FSTResourcePath *pathBar = FSTTestPath(@"bar"); FSTQuery *queryFoo = [FSTQuery queryWithPath:pathFoo]; FSTQuery *queryBar = [FSTQuery queryWithPath:pathBar]; FIRSnapshotMetadata *metadataFoo = diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 3a26389cd55..71b374a01ea 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -14,11 +14,9 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import -#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "FirebaseFirestore/FIRQuery.h" #import "Firestore/Source/API/FIRQuery+Internal.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Model/FSTPath.h" @@ -35,14 +33,9 @@ @implementation FIRQueryTests - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTResourcePath *pathFoo = [FSTResourcePath pathWithString:@"foo"]; - FSTResourcePath *pathBar = [FSTResourcePath pathWithString:@"bar"]; + FIRFirestore *firestore = FSTTestFirestore(); + FSTResourcePath *pathFoo = FSTTestPath(@"foo"); + FSTResourcePath *pathBar = FSTTestPath(@"bar"); FIRQuery *queryFoo = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathFoo] firestore:firestore]; FIRQuery *queryFooDup = @@ -67,13 +60,8 @@ - (void)testEquals { - (void)testFilteringWithPredicate { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. - FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - FSTResourcePath *path = [FSTResourcePath pathWithString:@"foo"]; + FIRFirestore *firestore = FSTTestFirestore(); + FSTResourcePath *path = FSTTestPath(@"foo"); FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] firestore:firestore]; FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1]; FIRQuery *query2 = [query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f<=1"]]; diff --git a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m index c9b8f475a96..2c8d4291d1a 100644 --- a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m +++ b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m @@ -14,10 +14,9 @@ * limitations under the License. */ -@import FirebaseFirestore; - #import +#import "FirebaseFirestore/FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.m b/Firestore/Example/Tests/Core/FSTQueryTests.m index 1fd0e8befb1..ab397421c19 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.m +++ b/Firestore/Example/Tests/Core/FSTQueryTests.m @@ -110,7 +110,7 @@ - (void)testMatchesCorrectlyForShallowAncestorQuery { } - (void)testEmptyFieldsAreAllowedForQueries { - FSTResourcePath *queryPath = [FSTResourcePath pathWithString:@"rooms/eros/messages"]; + FSTResourcePath *queryPath = FSTTestPath(@"rooms/eros/messages"); FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); diff --git a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m index 1dd6d626b8d..53f02021e01 100644 --- a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m +++ b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m @@ -35,7 +35,7 @@ - (void)testAddOrRemoveReferences { FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; [gc addGarbageSource:referenceSet]; - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"]; + FSTDocumentKey *key = FSTTestDocKey(@"foo/bar"); [referenceSet addReferenceToKey:key forID:1]; FSTAssertEqualSets([gc collectGarbage], @[]); XCTAssertFalse([referenceSet isEmpty]); @@ -50,9 +50,9 @@ - (void)testRemoveAllReferencesForID { FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; [gc addGarbageSource:referenceSet]; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"]; - FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); + FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); + FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); [referenceSet addReferenceToKey:key1 forID:1]; [referenceSet addReferenceToKey:key2 forID:1]; [referenceSet addReferenceToKey:key3 forID:2]; @@ -77,12 +77,12 @@ - (void)testTwoReferenceSetsAtTheSameTime { [gc addGarbageSource:localViews]; [gc addGarbageSource:mutations]; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); [remoteTargets addReferenceToKey:key1 forID:1]; [localViews addReferenceToKey:key1 forID:1]; [mutations addReferenceToKey:key1 forID:10]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"]; + FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); [mutations addReferenceToKey:key2 forID:10]; XCTAssertFalse([remoteTargets isEmpty]); diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m index 90f9ca37434..27c3dc35fe9 100644 --- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m +++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m @@ -70,7 +70,7 @@ - (void)setUp { - (void)testEncodesMutationBatch { FSTMutation *set = FSTTestSetMutation(@"foo/bar", @{ @"a" : @"b", @"num" : @1 }); FSTMutation *patch = [[FSTPatchMutation alloc] - initWithKey:[FSTDocumentKey keyWithPathString:@"bar/baz"] + initWithKey:FSTTestDocKey(@"bar/baz") fieldMask:[[FSTFieldMask alloc] initWithFields:@[ FSTTestFieldPath(@"a") ]] value:FSTTestObjectValue( @{ @"a" : @"b", diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m index 245e1c43e8e..d3c5d71f70a 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m @@ -196,8 +196,7 @@ - (void)collectGarbage { NSEnumerator *keyPathEnumerator = keyPaths.objectEnumerator; \ [actual enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey * actualKey, \ FSTMaybeDocument * value, BOOL * stop) { \ - FSTDocumentKey *expectedKey = \ - [FSTDocumentKey keyWithPathString:[keyPathEnumerator nextObject]]; \ + FSTDocumentKey *expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \ XCTAssertEqualObjects(actualKey, expectedKey); \ XCTAssertTrue([value isKindOfClass:[FSTDeletedDocument class]]); \ }]; \ @@ -215,7 +214,7 @@ - (void)collectGarbage { /** Asserts that the given local store does not contain the given document. */ #define FSTAssertNotContains(keyPathString) \ do { \ - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:keyPathString]; \ + FSTDocumentKey *key = FSTTestDocKey(keyPathString); \ FSTMaybeDocument *actual = [self.localStore readDocument:key]; \ XCTAssertNil(actual); \ } while (0) diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m index 1fed440f2de..d545af92f05 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m @@ -141,8 +141,8 @@ - (void)testRemoveQueryRemovesMatchingKeysToo { FSTQueryData *rooms = [self queryDataWithQuery:_queryRooms targetID:1 version:1]; [self addQueryData:rooms]; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/foo"); + FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/bar"); [self addMatchingKey:key1 forTargetID:rooms.targetID]; [self addMatchingKey:key2 forTargetID:rooms.targetID]; @@ -157,7 +157,7 @@ - (void)testRemoveQueryRemovesMatchingKeysToo { - (void)testAddOrRemoveMatchingKeys { if ([self isTestBaseClass]) return; - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"]; + FSTDocumentKey *key = FSTTestDocKey(@"foo/bar"); XCTAssertFalse([self.queryCache containsKey:key]); @@ -177,9 +177,9 @@ - (void)testAddOrRemoveMatchingKeys { - (void)testRemoveMatchingKeysForTargetID { if ([self isTestBaseClass]) return; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"]; - FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); + FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); + FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); [self addMatchingKey:key1 forTargetID:1]; [self addMatchingKey:key2 forTargetID:1]; @@ -207,15 +207,15 @@ - (void)testRemoveEmitsGarbageEvents { FSTAssertEqualSets([garbageCollector collectGarbage], @[]); FSTQueryData *rooms = [self queryDataWithQuery:FSTTestQuery(@"rooms") targetID:1 version:1]; - FSTDocumentKey *room1 = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; - FSTDocumentKey *room2 = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; + FSTDocumentKey *room1 = FSTTestDocKey(@"rooms/bar"); + FSTDocumentKey *room2 = FSTTestDocKey(@"rooms/foo"); [self addQueryData:rooms]; [self addMatchingKey:room1 forTargetID:rooms.targetID]; [self addMatchingKey:room2 forTargetID:rooms.targetID]; FSTQueryData *halls = [self queryDataWithQuery:FSTTestQuery(@"halls") targetID:2 version:1]; - FSTDocumentKey *hall1 = [FSTDocumentKey keyWithPathString:@"halls/bar"]; - FSTDocumentKey *hall2 = [FSTDocumentKey keyWithPathString:@"halls/foo"]; + FSTDocumentKey *hall1 = FSTTestDocKey(@"halls/bar"); + FSTDocumentKey *hall2 = FSTTestDocKey(@"halls/foo"); [self addQueryData:halls]; [self addMatchingKey:hall1 forTargetID:halls.targetID]; [self addMatchingKey:hall2 forTargetID:halls.targetID]; @@ -235,9 +235,9 @@ - (void)testRemoveEmitsGarbageEvents { - (void)testMatchingKeysForTargetID { if ([self isTestBaseClass]) return; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"]; - FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); + FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); + FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); [self addMatchingKey:key1 forTargetID:1]; [self addMatchingKey:key2 forTargetID:1]; @@ -259,8 +259,8 @@ - (void)testHighestTargetID { FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"rooms") targetID:1 purpose:FSTQueryPurposeListen]; - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"rooms/bar"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"rooms/foo"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/bar"); + FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/foo"); [self addQueryData:query1]; [self addMatchingKey:key1 forTargetID:1]; [self addMatchingKey:key2 forTargetID:1]; @@ -268,7 +268,7 @@ - (void)testHighestTargetID { FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"halls") targetID:2 purpose:FSTQueryPurposeListen]; - FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"halls/foo"]; + FSTDocumentKey *key3 = FSTTestDocKey(@"halls/foo"); [self addQueryData:query2]; [self addMatchingKey:key3 forTargetID:2]; XCTAssertEqual([self.queryCache highestTargetID], 2); diff --git a/Firestore/Example/Tests/Local/FSTReferenceSetTests.m b/Firestore/Example/Tests/Local/FSTReferenceSetTests.m index 0b852a206de..802117a9eb7 100644 --- a/Firestore/Example/Tests/Local/FSTReferenceSetTests.m +++ b/Firestore/Example/Tests/Local/FSTReferenceSetTests.m @@ -18,6 +18,7 @@ #import +#import "Firestore/Example/Tests/Util/FSTHelpers.h" #import "Firestore/Source/Model/FSTDocumentKey.h" NS_ASSUME_NONNULL_BEGIN @@ -28,7 +29,7 @@ @interface FSTReferenceSetTests : XCTestCase @implementation FSTReferenceSetTests - (void)testAddOrRemoveReferences { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"]; + FSTDocumentKey *key = FSTTestDocKey(@"foo/bar"); FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; XCTAssertTrue([referenceSet isEmpty]); @@ -53,9 +54,9 @@ - (void)testAddOrRemoveReferences { } - (void)testRemoveAllReferencesForTargetID { - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"]; - FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); + FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); + FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; [referenceSet addReferenceToKey:key1 forID:1]; diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.m b/Firestore/Example/Tests/Model/FSTDocumentTests.m index e56ab3416cf..197edaac92a 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.m +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.m @@ -33,20 +33,20 @@ @interface FSTDocumentTests : XCTestCase @implementation FSTDocumentTests - (void)testConstructor { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"messages/first"]; + FSTDocumentKey *key = FSTTestDocKey(@"messages/first"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"a" : @1 }); FSTDocument *doc = [FSTDocument documentWithData:data key:key version:version hasLocalMutations:NO]; - XCTAssertEqualObjects(doc.key, [FSTDocumentKey keyWithPathString:@"messages/first"]); + XCTAssertEqualObjects(doc.key, FSTTestDocKey(@"messages/first")); XCTAssertEqualObjects(doc.version, version); XCTAssertEqualObjects(doc.data, data); XCTAssertEqual(doc.hasLocalMutations, NO); } - (void)testExtractsFields { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"rooms/eros"]; + FSTDocumentKey *key = FSTTestDocKey(@"rooms/eros"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"desc" : @"Discuss all the project related stuff", @@ -62,8 +62,8 @@ - (void)testExtractsFields { } - (void)testIsEqual { - FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"messages/first"]; - FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"messages/second"]; + FSTDocumentKey *key1 = FSTTestDocKey(@"messages/first"); + FSTDocumentKey *key2 = FSTTestDocKey(@"messages/second"); FSTObjectValue *data1 = FSTTestObjectValue(@{ @"a" : @1 }); FSTObjectValue *data2 = FSTTestObjectValue(@{ @"b" : @1 }); FSTSnapshotVersion *version1 = FSTTestVersion(1); @@ -77,7 +77,7 @@ - (void)testIsEqual { XCTAssertEqualObjects( doc1, [FSTDocument documentWithData:FSTTestObjectValue( @{ @"a" : @1 }) - key:[FSTDocumentKey keyWithPathString:@"messages/first"] + key:FSTTestDocKey(@"messages/first") version:version1 hasLocalMutations:NO]); diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.m b/Firestore/Example/Tests/Model/FSTMutationTests.m index 678755e991a..50315c81292 100644 --- a/Firestore/Example/Tests/Model/FSTMutationTests.m +++ b/Firestore/Example/Tests/Model/FSTMutationTests.m @@ -64,7 +64,7 @@ - (void)testDeletesValuesFromTheFieldMask { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value", @"baz" : @"baz-value"} }; FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"collection/key"]; + FSTDocumentKey *key = FSTTestDocKey(@"collection/key"); FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:@[ FSTTestFieldPath(@"foo.bar") ]]; FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m index 2c1b8db9860..895b022bc6a 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m @@ -103,11 +103,11 @@ - (BOOL)isTestBaseClass { - (nullable FSTQuery *)parseQuery:(id)querySpec { if ([querySpec isKindOfClass:[NSString class]]) { - return [FSTQuery queryWithPath:[FSTResourcePath pathWithString:querySpec]]; + return [FSTQuery queryWithPath:FSTTestPath(querySpec)]; } else if ([querySpec isKindOfClass:[NSDictionary class]]) { NSDictionary *queryDict = (NSDictionary *)querySpec; NSString *path = queryDict[@"path"]; - __block FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithString:path]]; + __block FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(path)]; if (queryDict[@"limit"]) { NSNumber *limit = queryDict[@"limit"]; query = [query queryBySettingLimit:limit.integerValue]; @@ -237,7 +237,7 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity snapshot:(NSNumber *_Nullable) } } else if (watchEntity[@"doc"]) { NSArray *docSpec = watchEntity[@"doc"]; - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:docSpec[0]]; + FSTDocumentKey *key = FSTTestDocKey(docSpec[0]); FSTObjectValue *value = FSTTestObjectValue(docSpec[2]); FSTSnapshotVersion *version = [self parseVersion:docSpec[1]]; FSTMaybeDocument *doc = @@ -249,7 +249,7 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity snapshot:(NSNumber *_Nullable) document:doc]; [self.driver receiveWatchChange:change snapshotVersion:[self parseVersion:watchSnapshot]]; } else if (watchEntity[@"key"]) { - FSTDocumentKey *docKey = [FSTDocumentKey keyWithPathString:watchEntity[@"key"]]; + FSTDocumentKey *docKey = FSTTestDocKey(watchEntity[@"key"]); FSTWatchChange *change = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[] removedTargetIDs:watchEntity[@"removedTargets"] diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index 91ccbcf8c7f..efcdeca5bb5 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -21,6 +21,7 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKeySet.h" +@class FIRFirestore; @class FIRGeoPoint; @class FSTDeleteMutation; @class FSTDeletedDocument; @@ -134,6 +135,9 @@ extern "C" { XCTAssertTrue(__didThrow, ##__VA_ARGS__); \ }) +/** A convenience method for creating dummy FIRFirestore for tests. */ +FIRFirestore *FSTTestFirestore(); + /** Creates a new FSTTimestamp from components. Note that year, month, and day are all one-based. */ FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second); diff --git a/Firestore/Example/Tests/Util/FSTHelpers.m b/Firestore/Example/Tests/Util/FSTHelpers.m index f01bddbc647..5df55c13266 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.m +++ b/Firestore/Example/Tests/Util/FSTHelpers.m @@ -17,8 +17,10 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" #import "FirebaseFirestore/FIRFieldPath.h" +#import "FirebaseFirestore/FIRFirestore.h" #import "FirebaseFirestore/FIRGeoPoint.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" @@ -45,6 +47,15 @@ static const int kMicrosPerSec = 1000000; static const int kMillisPerSec = 1000; +FIRFirestore *FSTTestFirestore() { + return [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; +} + FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) { NSDate *date = FSTTestDate(year, month, day, hour, minute, second); return [FSTTimestamp timestampWithDate:date]; @@ -138,7 +149,7 @@ FSTTestSnapshotVersion version, NSDictionary *data, BOOL hasMutations) { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:path]; + FSTDocumentKey *key = FSTTestDocKey(path); return [FSTDocument documentWithData:FSTTestObjectValue(data) key:key version:FSTTestVersion(version) @@ -146,7 +157,7 @@ } FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version) { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:path]; + FSTDocumentKey *key = FSTTestDocKey(path); return [FSTDeletedDocument documentWithKey:key version:FSTTestVersion(version)]; } @@ -229,7 +240,7 @@ NSComparator FSTTestDocComparator(NSString *fieldPath) { } FSTSetMutation *FSTTestSetMutation(NSString *path, NSDictionary *values) { - return [[FSTSetMutation alloc] initWithKey:[FSTDocumentKey keyWithPathString:path] + return [[FSTSetMutation alloc] initWithKey:FSTTestDocKey(path) value:FSTTestObjectValue(values) precondition:[FSTPrecondition none]]; } @@ -274,7 +285,7 @@ NSComparator FSTTestDocComparator(NSString *fieldPath) { } FSTDeleteMutation *FSTTestDeleteMutation(NSString *path) { - return [[FSTDeleteMutation alloc] initWithKey:[FSTDocumentKey keyWithPathString:path] + return [[FSTDeleteMutation alloc] initWithKey:FSTTestDocKey(path) precondition:[FSTPrecondition none]]; } @@ -334,12 +345,12 @@ NSComparator FSTTestDocComparator(NSString *fieldPath) { NSArray *removedKeys) { FSTDocumentKeySet *added = [FSTDocumentKeySet keySet]; for (NSString *keyPath in addedKeys) { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:keyPath]; + FSTDocumentKey *key = FSTTestDocKey(keyPath); added = [added setByAddingObject:key]; } FSTDocumentKeySet *removed = [FSTDocumentKeySet keySet]; for (NSString *keyPath in removedKeys) { - FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:keyPath]; + FSTDocumentKey *key = FSTTestDocKey(keyPath); removed = [removed setByAddingObject:key]; } return [FSTLocalViewChanges changesForQuery:query addedKeys:added removedKeys:removed]; From 09b38047d9940df320f8c6f6aa75f538e6a1b0a2 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Fri, 15 Dec 2017 14:34:08 -0500 Subject: [PATCH 10/18] refactor using test helper `FSTTestDocSnapshot`, `FSTTestFieldPath`, `FSTTestQuery`, `FSTTestDoc` --- .../Tests/API/FIRDocumentSnapshotTests.m | 75 +++++--------- .../Example/Tests/API/FIRFieldPathTests.m | 9 +- .../Example/Tests/API/FIRQuerySnapshotTests.m | 6 +- Firestore/Example/Tests/API/FIRQueryTests.m | 11 +-- .../Example/Tests/Core/FSTEventManagerTests.m | 10 +- .../Tests/Core/FSTQueryListenerTests.m | 24 ++--- Firestore/Example/Tests/Core/FSTQueryTests.m | 99 +++++++++---------- .../Example/Tests/Core/FSTViewSnapshotTest.m | 2 +- .../Example/Tests/Local/FSTLocalStoreTests.m | 16 +-- .../Tests/Local/FSTMutationQueueTests.m | 2 +- .../Example/Tests/Local/FSTQueryCacheTests.m | 4 +- .../Tests/Local/FSTRemoteDocumentCacheTests.m | 2 +- .../Example/Tests/Model/FSTDocumentTests.m | 37 +++---- .../Tests/Remote/FSTSerializerBetaTests.m | 20 ++-- .../Example/Tests/SpecTests/FSTSpecTests.m | 4 +- Firestore/Example/Tests/Util/FSTHelpers.h | 11 ++- Firestore/Example/Tests/Util/FSTHelpers.m | 35 +++++-- 17 files changed, 169 insertions(+), 198 deletions(-) diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index cfda8edbe71..b8e2ee6547b 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -33,58 +33,31 @@ @interface FIRDocumentSnapshotTests : XCTestCase @implementation FIRDocumentSnapshotTests - (void)testEquals { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. - FIRFirestore *firestore = FSTTestFirestore(); - FSTDocumentKey *keyFoo = FSTTestDocKey(@"rooms/foo"); - FSTDocumentKey *keyBar = FSTTestDocKey(@"rooms/bar"); - FSTObjectValue *dataFoo = FSTTestObjectValue(@{ @"a" : @1 }); - FSTObjectValue *dataBar = FSTTestObjectValue(@{ @"b" : @1 }); - FSTSnapshotVersion *version = FSTTestVersion(1); - FSTDocument *docFoo = FSTTestDoc(@"rooms/foo", 1, @{ @"a" : @1 }, NO); - FSTDocument *docBar = FSTTestDoc(@"rooms/bar", 1, @{ @"b" : @1 }, NO); - XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:nil - fromCache:YES], - [FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:nil - fromCache:YES]); - XCTAssertEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:docFoo - fromCache:YES], - [FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:docFoo - fromCache:YES]); - XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:nil - fromCache:YES], - [FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyBar - document:nil - fromCache:YES]); - XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:docFoo - fromCache:YES], - [FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:docBar - fromCache:YES]); - XCTAssertNotEqualObjects([FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:nil - fromCache:YES], - [FIRDocumentSnapshot snapshotWithFirestore:firestore - documentKey:keyFoo - document:nil - fromCache:NO]); + XCTAssertEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO), + FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO)); + XCTAssertEqualObjects(FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO), + FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO)); + XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO), + FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO)); + XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO), + FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); + XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, YES, NO), + FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); + XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, YES), + FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); - // Test hash (in)equality here as well. + XCTAssertEqual([FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO) hash], + [FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO) hash]); + XCTAssertEqual([FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash], + [FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash]); + XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO) hash], + [FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash]); + XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO) hash], + [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); + XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, YES, NO) hash], + [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); + XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, YES) hash], + [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRFieldPathTests.m b/Firestore/Example/Tests/API/FIRFieldPathTests.m index e5053db6331..f8177c840ea 100644 --- a/Firestore/Example/Tests/API/FIRFieldPathTests.m +++ b/Firestore/Example/Tests/API/FIRFieldPathTests.m @@ -30,12 +30,9 @@ @interface FIRFieldPathTests : XCTestCase @implementation FIRFieldPathTests - (void)testEquals { - FSTFieldPath *pathFoo = [FSTFieldPath pathWithServerFormat:@"foo.ooo.oooo"]; - FSTFieldPath *pathFooDup = [FSTFieldPath pathWithServerFormat:@"foo.ooo.oooo"]; - FSTFieldPath *pathBar = [FSTFieldPath pathWithServerFormat:@"baa.aaa.aaar"]; - FIRFieldPath *foo = [[FIRFieldPath alloc] initPrivate:pathFoo]; - FIRFieldPath *fooDup = [[FIRFieldPath alloc] initPrivate:pathFooDup]; - FIRFieldPath *bar = [[FIRFieldPath alloc] initPrivate:pathBar]; + FIRFieldPath *foo = [[FIRFieldPath alloc] initPrivate:FSTTestFieldPath(@"foo.ooo.oooo")]; + FIRFieldPath *fooDup = [[FIRFieldPath alloc] initPrivate:FSTTestFieldPath(@"foo.ooo.oooo")]; + FIRFieldPath *bar = [[FIRFieldPath alloc] initPrivate:FSTTestFieldPath(@"baa.aaa.aaar")]; XCTAssertEqualObjects(foo, fooDup); XCTAssertNotEqualObjects(foo, bar); diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index a63c0a9fed0..a8316d3eb14 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -38,10 +38,8 @@ - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. FIRFirestore *firestore = FSTTestFirestore(); - FSTResourcePath *pathFoo = FSTTestPath(@"foo"); - FSTResourcePath *pathBar = FSTTestPath(@"bar"); - FSTQuery *queryFoo = [FSTQuery queryWithPath:pathFoo]; - FSTQuery *queryBar = [FSTQuery queryWithPath:pathBar]; + FSTQuery *queryFoo = FSTTestQuery(@"foo"); + FSTQuery *queryBar = FSTTestQuery(@"bar"); FIRSnapshotMetadata *metadataFoo = [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; FIRSnapshotMetadata *metadataBar = diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 71b374a01ea..4777df428e9 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -34,14 +34,12 @@ - (void)testEquals { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. FIRFirestore *firestore = FSTTestFirestore(); - FSTResourcePath *pathFoo = FSTTestPath(@"foo"); - FSTResourcePath *pathBar = FSTTestPath(@"bar"); FIRQuery *queryFoo = - [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathFoo] firestore:firestore]; + [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; FIRQuery *queryFooDup = - [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathFoo] firestore:firestore]; + [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; FIRQuery *queryBar = - [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:pathBar] firestore:firestore]; + [FIRQuery referenceWithQuery:FSTTestQuery(@"bar") firestore:firestore]; XCTAssertEqualObjects(queryFoo, queryFooDup); XCTAssertNotEqualObjects(queryFoo, queryBar); XCTAssertEqualObjects([queryFoo queryWhereField:@"f" isEqualTo:@1], @@ -61,8 +59,7 @@ - (void)testFilteringWithPredicate { // Everything is dummy for unit test here. Filtering does not require any app // specific setting as far as we do not fetch data. FIRFirestore *firestore = FSTTestFirestore(); - FSTResourcePath *path = FSTTestPath(@"foo"); - FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] firestore:firestore]; + FIRQuery *query = [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1]; FIRQuery *query2 = [query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f<=1"]]; FIRQuery *query3 = diff --git a/Firestore/Example/Tests/Core/FSTEventManagerTests.m b/Firestore/Example/Tests/Core/FSTEventManagerTests.m index 99021cebed9..2ffd3dd538a 100644 --- a/Firestore/Example/Tests/Core/FSTEventManagerTests.m +++ b/Firestore/Example/Tests/Core/FSTEventManagerTests.m @@ -52,7 +52,7 @@ - (FSTQueryListener *)noopListenerForQuery:(FSTQuery *)query { } - (void)testHandlesManyListenersPerQuery { - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo/bar")]; + FSTQuery *query = FSTTestQuery(@"foo/bar"); FSTQueryListener *listener1 = [self noopListenerForQuery:query]; FSTQueryListener *listener2 = [self noopListenerForQuery:query]; @@ -73,7 +73,7 @@ - (void)testHandlesManyListenersPerQuery { } - (void)testHandlesUnlistenOnUnknownListenerGracefully { - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo/bar")]; + FSTQuery *query = FSTTestQuery(@"foo/bar"); FSTQueryListener *listener = [self noopListenerForQuery:query]; FSTSyncEngine *syncEngineMock = OCMStrictClassMock([FSTSyncEngine class]); @@ -95,8 +95,8 @@ - (FSTQueryListener *)makeMockListenerForQuery:(FSTQuery *)query } - (void)testNotifiesListenersInTheRightOrder { - FSTQuery *query1 = [FSTQuery queryWithPath:FSTTestPath(@"foo/bar")]; - FSTQuery *query2 = [FSTQuery queryWithPath:FSTTestPath(@"bar/baz")]; + FSTQuery *query1 = FSTTestQuery(@"foo/bar"); + FSTQuery *query2 = FSTTestQuery(@"bar/baz"); NSMutableArray *eventOrder = [NSMutableArray array]; FSTQueryListener *listener1 = [self makeMockListenerForQuery:query1 @@ -135,7 +135,7 @@ - (void)testNotifiesListenersInTheRightOrder { } - (void)testWillForwardOnlineStateChanges { - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo/bar")]; + FSTQuery *query = FSTTestQuery(@"foo/bar"); FSTQueryListener *fakeListener = OCMClassMock([FSTQueryListener class]); NSMutableArray *events = [NSMutableArray array]; OCMStub([fakeListener query]).andReturn(query); diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.m b/Firestore/Example/Tests/Core/FSTQueryListenerTests.m index 1bb7a47f558..381d3cc3a35 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.m +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.m @@ -45,7 +45,7 @@ - (void)testRaisesCollectionEvents { NSMutableArray *accum = [NSMutableArray array]; NSMutableArray *otherAccum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTDocument *doc2prime = @@ -88,7 +88,7 @@ - (void)testRaisesCollectionEvents { - (void)testRaisesErrorEvent { NSMutableArray *accum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms/Eros")]; + FSTQuery *query = FSTTestQuery(@"rooms/Eros"); FSTQueryListener *listener = [self listenToQuery:query handler:^(FSTViewSnapshot *snapshot, NSError *error) { @@ -104,7 +104,7 @@ - (void)testRaisesErrorEvent { - (void)testRaisesEventForEmptyCollectionAfterSync { NSMutableArray *accum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum]; @@ -126,7 +126,7 @@ - (void)testRaisesEventForEmptyCollectionAfterSync { - (void)testMutingAsyncListenerPreventsAllSubsequentEvents { NSMutableArray *accum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms/Eros")]; + FSTQuery *query = FSTTestQuery(@"rooms/Eros"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 3, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/Eros", 4, @{@"name" : @"Eros2"}, NO); @@ -166,7 +166,7 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified { NSMutableArray *filteredAccum = [NSMutableArray array]; NSMutableArray *fullAccum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); @@ -204,7 +204,7 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified { NSMutableArray *filteredAccum = [NSMutableArray array]; NSMutableArray *fullAccum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); @@ -253,7 +253,7 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified { - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges { NSMutableArray *fullAccum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, YES); FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); @@ -290,7 +290,7 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges { - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadataChangesIsFalse { NSMutableArray *filteredAccum = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); @@ -322,7 +322,7 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata - (void)testWillWaitForSyncIfOnline { NSMutableArray *events = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTQueryListener *listener = @@ -365,7 +365,7 @@ - (void)testWillWaitForSyncIfOnline { - (void)testWillRaiseInitialEventWhenGoingOffline { NSMutableArray *events = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTQueryListener *listener = @@ -411,7 +411,7 @@ - (void)testWillRaiseInitialEventWhenGoingOffline { - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs { NSMutableArray *events = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTQueryListener *listener = [self listenToQuery:query options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; @@ -437,7 +437,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs { - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs { NSMutableArray *events = [NSMutableArray array]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"rooms")]; + FSTQuery *query = FSTTestQuery(@"rooms"); FSTQueryListener *listener = [self listenToQuery:query options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.m b/Firestore/Example/Tests/Core/FSTQueryTests.m index ab397421c19..6f1f76f466e 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.m +++ b/Firestore/Example/Tests/Core/FSTQueryTests.m @@ -61,9 +61,7 @@ - (void)testConstructor { } - (void)testOrderBy { - FSTResourcePath *path = - [FSTResourcePath pathWithSegments:@[ @"rooms", @"Firestore", @"messages" ]]; - FSTQuery *query = [FSTQuery queryWithPath:path]; + FSTQuery *query = FSTTestQuery(@"rooms/Firestore/messages"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"length") ascending:NO]]; @@ -80,29 +78,25 @@ - (void)testOrderBy { } - (void)testMatchesBasedOnDocumentKey { - FSTResourcePath *queryKey = - [FSTResourcePath pathWithSegments:@[ @"rooms", @"eros", @"messages", @"1" ]]; FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // document query - FSTQuery *query = [FSTQuery queryWithPath:queryKey]; + FSTQuery *query = FSTTestQuery(@"rooms/eros/messages/1"); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); XCTAssertFalse([query matchesDocument:doc3]); } - (void)testMatchesCorrectlyForShallowAncestorQuery { - FSTResourcePath *queryPath = - [FSTResourcePath pathWithSegments:@[ @"rooms", @"eros", @"messages" ]]; FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc1Meta = FSTTestDoc(@"rooms/eros/messages/1/meta/1", 0, @{@"meta" : @"mv"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // shallow ancestor query - FSTQuery *query = [FSTQuery queryWithPath:queryPath]; + FSTQuery *query = FSTTestQuery(@"rooms/eros/messages"); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc1Meta]); XCTAssertTrue([query matchesDocument:doc2]); @@ -110,20 +104,19 @@ - (void)testMatchesCorrectlyForShallowAncestorQuery { } - (void)testEmptyFieldsAreAllowedForQueries { - FSTResourcePath *queryPath = FSTTestPath(@"rooms/eros/messages"); FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); - FSTQuery *query = [[FSTQuery queryWithPath:queryPath] + FSTQuery *query = [FSTTestQuery(@"rooms/eros/messages") queryByAddingFilter:FSTTestFilter(@"text", @"==", @"msg1")]; XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); } - (void)testMatchesPrimitiveValuesForFilters { - FSTQuery *query1 = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query1 = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; - FSTQuery *query2 = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query2 = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @1 }, NO); @@ -149,7 +142,7 @@ - (void)testMatchesPrimitiveValuesForFilters { } - (void)testNullFilter { - FSTQuery *query = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"==", [NSNull null])]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{@"sort" : [NSNull null]}, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); @@ -165,7 +158,7 @@ - (void)testNullFilter { } - (void)testNanFilter { - FSTQuery *query = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"==", @(NAN))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @(NAN) }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); @@ -181,9 +174,9 @@ - (void)testNanFilter { } - (void)testDoesNotMatchComplexObjectsForFilters { - FSTQuery *query1 = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query1 = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; - FSTQuery *query2 = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query2 = [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @2 }, NO); @@ -212,7 +205,7 @@ - (void)testDoesNotMatchComplexObjectsForFilters { } - (void)testDoesntRemoveComplexObjectsWithOrderBy { - FSTQuery *query1 = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]] + FSTQuery *query1 = [FSTTestQuery(@"collection") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort") ascending:YES]]; @@ -232,9 +225,7 @@ - (void)testDoesntRemoveComplexObjectsWithOrderBy { } - (void)testFiltersBasedOnArrayValue { - FSTQuery *baseQuery = - [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]]; - + FSTQuery *baseQuery = FSTTestQuery(@"collection"); FSTDocument *doc1 = FSTTestDoc(@"collection/doc", 0, @{ @"tags" : @[ @"foo", @1, @YES ] }, NO); NSArray> *matchingFilters = @@ -256,9 +247,7 @@ - (void)testFiltersBasedOnArrayValue { } - (void)testFiltersBasedOnObjectValue { - FSTQuery *baseQuery = - [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]]; - + FSTQuery *baseQuery = FSTTestQuery(@"collection"); FSTDocument *doc1 = FSTTestDoc(@"collection/doc", 0, @{ @"tags" : @{@"foo" : @"foo", @"a" : @0, @"b" : @YES, @"c" : @(NAN)} }, NO); @@ -310,10 +299,10 @@ - (void)assertCorrectComparisonsWithArray:(NSArray *)array comparator:(NSCompara } - (void)testSortsDocumentsInTheCorrectOrder { - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]]; + FSTQuery *query = FSTTestQuery(@"collection"); query = - [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort") - ascending:YES]]; + [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort") + ascending:YES]]; // clang-format off NSArray *docs = @[ @@ -339,7 +328,7 @@ - (void)testSortsDocumentsInTheCorrectOrder { } - (void)testSortsDocumentsUsingMultipleFields { - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]]; + FSTQuery *query = FSTTestQuery(@"collection"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort1") ascending:YES]]; @@ -366,7 +355,7 @@ - (void)testSortsDocumentsUsingMultipleFields { } - (void)testSortsDocumentsWithDescendingToo { - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"collection" ]]]; + FSTQuery *query = FSTTestQuery(@"collection"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort1") ascending:NO]]; @@ -393,40 +382,40 @@ - (void)testSortsDocumentsWithDescendingToo { } - (void)testEquality { - FSTQuery *q11 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q11 = FSTTestQuery(@"foo"); q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - FSTQuery *q12 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q12 = FSTTestQuery(@"foo"); q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - FSTQuery *q21 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; - FSTQuery *q22 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q21 = FSTTestQuery(@"foo"); + FSTQuery *q22 = FSTTestQuery(@"foo"); - FSTQuery *q31 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; - FSTQuery *q32 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; + FSTQuery *q31 = FSTTestQuery(@"foo/bar"); + FSTQuery *q32 = FSTTestQuery(@"foo/bar"); - FSTQuery *q41 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q41 = FSTTestQuery(@"foo"); q41 = [q41 queryByAddingSortBy:@"foo" ascending:YES]; q41 = [q41 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q42 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q42 = FSTTestQuery(@"foo"); q42 = [q42 queryByAddingSortBy:@"foo" ascending:YES]; q42 = [q42 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q43Diff = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q43Diff = FSTTestQuery(@"foo"); q43Diff = [q43Diff queryByAddingSortBy:@"bar" ascending:YES]; q43Diff = [q43Diff queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q51 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q51 = FSTTestQuery(@"foo"); q51 = [q51 queryByAddingSortBy:@"foo" ascending:YES]; q51 = [q51 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - FSTQuery *q52 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q52 = FSTTestQuery(@"foo"); q52 = [q52 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; q52 = [q52 queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q53Diff = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q53Diff = FSTTestQuery(@"foo"); q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter(@"bar", @">", @(2))]; q53Diff = [q53Diff queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q61 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q61 = FSTTestQuery(@"foo"); q61 = [q61 queryBySettingLimit:10]; // XCTAssertEqualObjects(q11, q12); // TODO(klimt): not canonical yet @@ -458,40 +447,40 @@ - (void)testEquality { } - (void)testUniqueIds { - FSTQuery *q11 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q11 = FSTTestQuery(@"foo"); q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - FSTQuery *q12 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q12 = FSTTestQuery(@"foo"); q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - FSTQuery *q21 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; - FSTQuery *q22 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q21 = FSTTestQuery(@"foo"); + FSTQuery *q22 = FSTTestQuery(@"foo"); - FSTQuery *q31 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; - FSTQuery *q32 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; + FSTQuery *q31 = FSTTestQuery(@"foo/bar"); + FSTQuery *q32 = FSTTestQuery(@"foo/bar"); - FSTQuery *q41 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q41 = FSTTestQuery(@"foo"); q41 = [q41 queryByAddingSortBy:@"foo" ascending:YES]; q41 = [q41 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q42 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q42 = FSTTestQuery(@"foo"); q42 = [q42 queryByAddingSortBy:@"foo" ascending:YES]; q42 = [q42 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q43Diff = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q43Diff = FSTTestQuery(@"foo"); q43Diff = [q43Diff queryByAddingSortBy:@"bar" ascending:YES]; q43Diff = [q43Diff queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q51 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q51 = FSTTestQuery(@"foo"); q51 = [q51 queryByAddingSortBy:@"foo" ascending:YES]; q51 = [q51 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - FSTQuery *q52 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q52 = FSTTestQuery(@"foo"); q52 = [q52 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; q52 = [q52 queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q53Diff = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q53Diff = FSTTestQuery(@"foo"); q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter(@"bar", @">", @(2))]; q53Diff = [q53Diff queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q61 = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *q61 = FSTTestQuery(@"foo"); q61 = [q61 queryBySettingLimit:10]; // XCTAssertEqual(q11.hash, q12.hash); // TODO(klimt): not canonical yet diff --git a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.m b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.m index 5d3787a949b..fe3e42d7e55 100644 --- a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.m +++ b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.m @@ -107,7 +107,7 @@ - (void)testTrack { } - (void)testViewSnapshotConstructor { - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"a" ]]]; + FSTQuery *query = FSTTestQuery(@"a"); FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:FSTDocumentComparatorByKey]; FSTDocumentSet *oldDocuments = documents; documents = [documents documentSetByAddingDocument:FSTTestDoc(@"c/a", 1, @{}, NO)]; diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m index d3c5d71f70a..4c8f285f147 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m @@ -260,7 +260,7 @@ - (void)testHandlesAckThenRejectThenRemoteEvent { if ([self isTestBaseClass]) return; // Start a query that requires acks to be held. - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); [self allocateQuery:query]; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; @@ -553,7 +553,7 @@ - (void)testCollectsGarbageAfterChangeBatchWithNoTargetIDs { - (void)testCollectsGarbageAfterChangeBatch { if ([self isTestBaseClass]) return; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -636,7 +636,7 @@ - (void)testCollectsGarbageAfterRejectedMutation { - (void)testPinsDocumentsInTheLocalView { if ([self isTestBaseClass]) return; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -684,7 +684,7 @@ - (void)testCanExecuteDocumentQueries { FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}), FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}) ]]; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; + FSTQuery *query = FSTTestQuery(@"foo/bar"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], @[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); } @@ -699,7 +699,7 @@ - (void)testCanExecuteCollectionQueries { FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}), FSTTestSetMutation(@"fooo/blah", @{@"fooo" : @"blah"}) ]]; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], (@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES), @@ -710,7 +710,7 @@ - (void)testCanExecuteCollectionQueries { - (void)testCanExecuteMixedCollectionQueries { if ([self isTestBaseClass]) return; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -735,7 +735,7 @@ - (void)testPersistsResumeTokens { // This test only works in the absence of the FSTEagerGarbageCollector. [self restartWithNoopGarbageCollector]; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]]; + FSTQuery *query = FSTTestQuery(@"foo/bar"); FSTQueryData *queryData = [self.localStore allocateQuery:query]; FSTBoxedTargetID *targetID = @(queryData.targetID); NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1000); @@ -769,7 +769,7 @@ - (void)testRemoteDocumentKeysForTarget { if ([self isTestBaseClass]) return; [self restartWithNoopGarbageCollector]; - FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]]; + FSTQuery *query = FSTTestQuery(@"foo"); [self allocateQuery:query]; FSTAssertTargetID(2); diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.m b/Firestore/Example/Tests/Local/FSTMutationQueueTests.m index f168ac95692..020a0a7425a 100644 --- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.m +++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.m @@ -301,7 +301,7 @@ - (void)testAllMutationBatchesAffectingQuery { [self.persistence commitGroup:group]; NSArray *expected = @[ batches[1], batches[2], batches[4] ]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo")]; + FSTQuery *query = FSTTestQuery(@"foo"); NSArray *matches = [self.mutationQueue allMutationBatchesAffectingQuery:query]; diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m index d545af92f05..f390df7cfb1 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m @@ -70,9 +70,9 @@ - (void)testCanonicalIDCollision { // Type information is currently lost in our canonicalID implementations so this currently an // easy way to force colliding canonicalIDs - FSTQuery *q1 = [[FSTQuery queryWithPath:FSTTestPath(@"a")] + FSTQuery *q1 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @(1))]; - FSTQuery *q2 = [[FSTQuery queryWithPath:FSTTestPath(@"a")] + FSTQuery *q2 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @"1")]; XCTAssertEqualObjects(q1.canonicalID, q2.canonicalID); diff --git a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m index 16fe3bffeda..d2406044469 100644 --- a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m +++ b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m @@ -112,7 +112,7 @@ - (void)testDocumentsMatchingQuery { [self setTestDocumentAtPath:@"b/2"]; [self setTestDocumentAtPath:@"c/1"]; - FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"b")]; + FSTQuery *query = FSTTestQuery(@"b"); FSTDocumentDictionary *results = [self.remoteDocumentCache documentsMatchingQuery:query]; NSArray *expected = @[ FSTTestDoc(@"b/1", kVersion, _kDocData, NO), FSTTestDoc(@"b/2", kVersion, _kDocData, NO) ]; diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.m b/Firestore/Example/Tests/Model/FSTDocumentTests.m index 197edaac92a..40ae2af4c0b 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.m +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.m @@ -62,38 +62,25 @@ - (void)testExtractsFields { } - (void)testIsEqual { - FSTDocumentKey *key1 = FSTTestDocKey(@"messages/first"); - FSTDocumentKey *key2 = FSTTestDocKey(@"messages/second"); - FSTObjectValue *data1 = FSTTestObjectValue(@{ @"a" : @1 }); - FSTObjectValue *data2 = FSTTestObjectValue(@{ @"b" : @1 }); - FSTSnapshotVersion *version1 = FSTTestVersion(1); - - FSTDocument *doc1 = - [FSTDocument documentWithData:data1 key:key1 version:version1 hasLocalMutations:NO]; - FSTDocument *doc2 = - [FSTDocument documentWithData:data1 key:key1 version:version1 hasLocalMutations:NO]; - - XCTAssertEqualObjects(doc1, doc2); XCTAssertEqualObjects( - doc1, [FSTDocument documentWithData:FSTTestObjectValue( - @{ @"a" : @1 }) - key:FSTTestDocKey(@"messages/first") - version:version1 - hasLocalMutations:NO]); - - FSTSnapshotVersion *version2 = FSTTestVersion(2); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO)); XCTAssertNotEqualObjects( - doc1, [FSTDocument documentWithData:data2 key:key1 version:version1 hasLocalMutations:NO]); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, @{ @"b" : @1 }, NO)); XCTAssertNotEqualObjects( - doc1, [FSTDocument documentWithData:data1 key:key2 version:version1 hasLocalMutations:NO]); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/second", 1, @{ @"b" : @1 }, NO)); XCTAssertNotEqualObjects( - doc1, [FSTDocument documentWithData:data1 key:key1 version:version2 hasLocalMutations:NO]); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 2, @{ @"a" : @1 }, NO)); XCTAssertNotEqualObjects( - doc1, [FSTDocument documentWithData:data1 key:key1 version:version1 hasLocalMutations:YES]); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, YES)); XCTAssertEqualObjects( - [FSTDocument documentWithData:data1 key:key1 version:version1 hasLocalMutations:YES], - [FSTDocument documentWithData:data1 key:key1 version:version1 hasLocalMutations:5]); + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, YES), + FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, 5)); } @end diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m index 528076f300d..36c301c35d4 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m @@ -428,7 +428,7 @@ - (void)testEncodesRelationFilter { #pragma mark - encodedQuery - (void)testEncodesFirstLevelKeyQueries { - FSTQuery *q = [FSTQuery queryWithPath:FSTTestPath(@"docs/1")]; + FSTQuery *q = FSTTestQuery(@"docs/1"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -439,7 +439,7 @@ - (void)testEncodesFirstLevelKeyQueries { } - (void)testEncodesFirstLevelAncestorQueries { - FSTQuery *q = [FSTQuery queryWithPath:FSTTestPath(@"messages")]; + FSTQuery *q = FSTTestQuery(@"messages"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -455,7 +455,7 @@ - (void)testEncodesFirstLevelAncestorQueries { } - (void)testEncodesNestedAncestorQueries { - FSTQuery *q = [FSTQuery queryWithPath:FSTTestPath(@"rooms/1/messages/10/attachments")]; + FSTQuery *q = FSTTestQuery(@"rooms/1/messages/10/attachments"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -471,7 +471,7 @@ - (void)testEncodesNestedAncestorQueries { } - (void)testEncodesSingleFiltersAtFirstLevelCollections { - FSTQuery *q = [[FSTQuery queryWithPath:FSTTestPath(@"docs")] + FSTQuery *q = [FSTTestQuery(@"docs") queryByAddingFilter:FSTTestFilter(@"prop", @"<", @(42))]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -495,7 +495,7 @@ - (void)testEncodesSingleFiltersAtFirstLevelCollections { } - (void)testEncodesMultipleFiltersOnDeeperCollections { - FSTQuery *q = [[[FSTQuery queryWithPath:FSTTestPath(@"rooms/1/messages/10/attachments")] + FSTQuery *q = [[FSTTestQuery(@"rooms/1/messages/10/attachments") queryByAddingFilter:FSTTestFilter(@"prop", @">=", @(42))] queryByAddingFilter:FSTTestFilter(@"author", @"==", @"dimond")]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -546,7 +546,7 @@ - (void)testEncodesNanFilter { - (void)unaryFilterTestWithValue:(id)value expectedUnaryOperator:(GCFSStructuredQuery_UnaryFilter_Operator) operator{ - FSTQuery *q = [[FSTQuery queryWithPath:FSTTestPath(@"docs")] + FSTQuery *q = [FSTTestQuery(@"docs") queryByAddingFilter:FSTTestFilter(@"prop", @"==", value)]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -567,7 +567,7 @@ - (void)unaryFilterTestWithValue:(id)value } - (void)testEncodesSortOrders { - FSTQuery *q = [[FSTQuery queryWithPath:FSTTestPath(@"docs")] + FSTQuery *q = [FSTTestQuery(@"docs") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"prop") ascending:YES]]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -587,7 +587,7 @@ - (void)testEncodesSortOrders { } - (void)testEncodesSortOrdersDescending { - FSTQuery *q = [[FSTQuery queryWithPath:FSTTestPath(@"rooms/1/messages/10/attachments")] + FSTQuery *q = [FSTTestQuery(@"rooms/1/messages/10/attachments") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"prop") ascending:NO]]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -607,7 +607,7 @@ - (void)testEncodesSortOrdersDescending { } - (void)testEncodesLimits { - FSTQuery *q = [[FSTQuery queryWithPath:FSTTestPath(@"docs")] queryBySettingLimit:26]; + FSTQuery *q = [FSTTestQuery(@"docs") queryBySettingLimit:26]; FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -624,7 +624,7 @@ - (void)testEncodesLimits { } - (void)testEncodesResumeTokens { - FSTQuery *q = [FSTQuery queryWithPath:FSTTestPath(@"docs")]; + FSTQuery *q = FSTTestQuery(@"docs"); FSTQueryData *model = [[FSTQueryData alloc] initWithQuery:q targetID:1 purpose:FSTQueryPurposeListen diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m index 895b022bc6a..38ab0e962fb 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m @@ -103,11 +103,11 @@ - (BOOL)isTestBaseClass { - (nullable FSTQuery *)parseQuery:(id)querySpec { if ([querySpec isKindOfClass:[NSString class]]) { - return [FSTQuery queryWithPath:FSTTestPath(querySpec)]; + return FSTTestQuery(querySpec); } else if ([querySpec isKindOfClass:[NSDictionary class]]) { NSDictionary *queryDict = (NSDictionary *)querySpec; NSString *path = queryDict[@"path"]; - __block FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(path)]; + __block FSTQuery *query = FSTTestQuery(path); if (queryDict[@"limit"]) { NSNumber *limit = queryDict[@"limit"]; query = [query queryBySettingLimit:limit.integerValue]; diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index efcdeca5bb5..6139bc767f1 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -21,6 +21,7 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKeySet.h" +@class FIRDocumentSnapshot; @class FIRFirestore; @class FIRGeoPoint; @class FSTDeleteMutation; @@ -135,7 +136,7 @@ extern "C" { XCTAssertTrue(__didThrow, ##__VA_ARGS__); \ }) -/** A convenience method for creating dummy FIRFirestore for tests. */ +/** A convenience method for creating dummy singleton FIRFirestore for tests. */ FIRFirestore *FSTTestFirestore(); /** Creates a new FSTTimestamp from components. Note that year, month, and day are all one-based. */ @@ -185,6 +186,14 @@ FSTDocument *FSTTestDoc(NSString *path, NSDictionary *data, BOOL hasMutations); +/** A convenience method for creating docs snapshots for tests. */ +FIRDocumentSnapshot *FSTTestDocSnapshot( + NSString *path, + FSTTestSnapshotVersion version, + NSDictionary *data, + BOOL hasMutations, + BOOL fromCache); + /** A convenience method for creating deleted docs for tests. */ FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version); diff --git a/Firestore/Example/Tests/Util/FSTHelpers.m b/Firestore/Example/Tests/Util/FSTHelpers.m index 5df55c13266..d4e2ac32550 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.m +++ b/Firestore/Example/Tests/Util/FSTHelpers.m @@ -14,8 +14,10 @@ * limitations under the License. */ +#import #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "FirebaseFirestore/FIRDocumentSnapshot.h" #import "FirebaseFirestore/FIRFieldPath.h" #import "FirebaseFirestore/FIRFirestore.h" #import "FirebaseFirestore/FIRGeoPoint.h" @@ -48,12 +50,18 @@ static const int kMillisPerSec = 1000; FIRFirestore *FSTTestFirestore() { - return [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; + static FIRFirestore *sharedInstance = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + sharedInstance = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + }); + return sharedInstance; } FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) { @@ -156,6 +164,19 @@ hasLocalMutations:hasMutations]; } +FIRDocumentSnapshot *FSTTestDocSnapshot( + NSString *path, + FSTTestSnapshotVersion version, + NSDictionary *data, + BOOL hasMutations, + BOOL fromCache) { + FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil; + return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore() + documentKey:FSTTestDocKey(path) + document:doc + fromCache:fromCache]; +} + FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version) { FSTDocumentKey *key = FSTTestDocKey(path); return [FSTDeletedDocument documentWithKey:key version:FSTTestVersion(version)]; @@ -225,7 +246,7 @@ } NSComparator FSTTestDocComparator(NSString *fieldPath) { - FSTQuery *query = [[FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"docs" ]]] + FSTQuery *query = [FSTTestQuery(@"docs") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(fieldPath) ascending:YES]]; return [query comparator]; From ed88900d2e9e5e64076357602260b420e1946841 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Fri, 15 Dec 2017 16:09:35 -0500 Subject: [PATCH 11/18] refactoring to use test helper method `FSTTestQuerySnapshot`, --- .../Example/Tests/API/FIRQuerySnapshotTests.m | 76 ++++--------------- Firestore/Example/Tests/Util/FSTHelpers.h | 21 +++-- Firestore/Example/Tests/Util/FSTHelpers.m | 39 ++++++++++ 3 files changed, 67 insertions(+), 69 deletions(-) diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index a8316d3eb14..0c7ebdc60b7 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -35,69 +35,19 @@ @interface FIRQuerySnapshotTests : XCTestCase @implementation FIRQuerySnapshotTests - (void)testEquals { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. - FIRFirestore *firestore = FSTTestFirestore(); - FSTQuery *queryFoo = FSTTestQuery(@"foo"); - FSTQuery *queryBar = FSTTestQuery(@"bar"); - FIRSnapshotMetadata *metadataFoo = - [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:YES fromCache:YES]; - FIRSnapshotMetadata *metadataBar = - [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO]; - FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:FSTDocumentComparatorByKey]; - FSTDocumentSet *oldDocuments = documents; - documents = [documents documentSetByAddingDocument:FSTTestDoc(@"c/a", 1, @{}, NO)]; - NSArray *documentChanges = - @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc(@"c/a", 1, @{}, NO) - type:FSTDocumentViewChangeTypeAdded] ]; - FSTViewSnapshot *snapshotFoo = [[FSTViewSnapshot alloc] initWithQuery:queryFoo - documents:documents - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:YES - hasPendingWrites:NO - syncStateChanged:YES]; - FSTViewSnapshot *snapshotBar = [[FSTViewSnapshot alloc] initWithQuery:queryBar - documents:documents - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:YES - hasPendingWrites:NO - syncStateChanged:YES]; - XCTAssertEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataFoo], - [FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataFoo]); - XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataFoo], - [FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryBar - snapshot:snapshotFoo - metadata:metadataFoo]); - XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataFoo], - [FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotBar - metadata:metadataFoo]); - XCTAssertNotEqualObjects([FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataFoo], - [FIRQuerySnapshot snapshotWithFirestore:firestore - originalQuery:queryFoo - snapshot:snapshotFoo - metadata:metadataBar]); - - // Also test hash (in)equality here. + FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"a":@1 } ], YES, YES); + FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"a":@1 } ], YES, YES); + FIRQuerySnapshot *bar = FSTTestQuerySnapshot(@"bar/foo", @[], @[ @{ @"a":@1 } ], YES, YES); + FIRQuerySnapshot *baz = FSTTestQuerySnapshot(@"foo/bar", @[ @{ @"a":@1 } ], @[], YES, YES); + FIRQuerySnapshot *qux = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"b":@1 } ], NO, YES); + FIRQuerySnapshot *quux = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"b":@1 } ], YES, NO); + NSArray *groups = @[ @[foo, fooDup], @[bar], @[baz], @[qux], @[quux]]; + FSTAssertEqualityGroups(groups); + + NSArray *hashGroups = @[ @[[NSNumber numberWithLong:[foo hash]], [NSNumber numberWithLong:[fooDup hash]] ], + @[ [NSNumber numberWithLong:[bar hash]] ], @[ [NSNumber numberWithLong:[baz hash]] ], + @[ [NSNumber numberWithLong:[qux hash]] ], @[ [NSNumber numberWithLong:[quux hash]] ]]; + FSTAssertEqualityGroups(hashGroups); } @end diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index 6139bc767f1..0290ea1e328 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -24,6 +24,7 @@ @class FIRDocumentSnapshot; @class FIRFirestore; @class FIRGeoPoint; +@class FIRQuerySnapshot; @class FSTDeleteMutation; @class FSTDeletedDocument; @class FSTDocument; @@ -186,13 +187,13 @@ FSTDocument *FSTTestDoc(NSString *path, NSDictionary *data, BOOL hasMutations); -/** A convenience method for creating docs snapshots for tests. */ +/** A convenience method for creating a doc snapshot for tests. */ FIRDocumentSnapshot *FSTTestDocSnapshot( - NSString *path, - FSTTestSnapshotVersion version, - NSDictionary *data, - BOOL hasMutations, - BOOL fromCache); + NSString *path, + FSTTestSnapshotVersion version, + NSDictionary *data, + BOOL hasMutations, + BOOL fromCache); /** A convenience method for creating deleted docs for tests. */ FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version); @@ -208,6 +209,14 @@ FSTDocumentKeyReference *FSTTestRef(NSString *projectID, NSString *databaseID, N /** A convenience method for creating a query for the given path (without any other filters). */ FSTQuery *FSTTestQuery(NSString *path); +/** A convenience method for creating a particular query snapshots for tests. */ +FIRQuerySnapshot *FSTTestQuerySnapshot( + NSString *path, + NSArray *> *oldData, + NSArray *> *dataToAdd, + BOOL hasPendingWrites, + BOOL fromCache); + /** * A convenience method to create a FSTFilter using a string representation for both field * and operator (<, <=, ==, >=, >). diff --git a/Firestore/Example/Tests/Util/FSTHelpers.m b/Firestore/Example/Tests/Util/FSTHelpers.m index d4e2ac32550..d098113fd49 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.m +++ b/Firestore/Example/Tests/Util/FSTHelpers.m @@ -15,12 +15,17 @@ */ #import +#import +#import +#import #import "Firestore/Example/Tests/Util/FSTHelpers.h" #import "FirebaseFirestore/FIRDocumentSnapshot.h" #import "FirebaseFirestore/FIRFieldPath.h" #import "FirebaseFirestore/FIRFirestore.h" #import "FirebaseFirestore/FIRGeoPoint.h" +#import "FirebaseFirestore/FIRQuerySnapshot.h" +#import "FirebaseFirestore/FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" @@ -203,6 +208,40 @@ return [FSTQuery queryWithPath:FSTTestPath(path)]; } +/** A convenience method for creating a query snapshots for tests. */ +FIRQuerySnapshot *FSTTestQuerySnapshot( + NSString *path, + NSArray *> *oldData, + NSArray *> *dataToAdd, + BOOL hasPendingWrites, + BOOL fromCache) { + FIRSnapshotMetadata *metadata = [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites + fromCache:fromCache]; + FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); + for (NSDictionary *data in oldData) { + oldDocuments = [oldDocuments documentSetByAddingDocument:FSTTestDoc(path, 1, data, hasPendingWrites)]; + } + FSTDocumentSet *newDocuments = oldDocuments; + NSArray *documentChanges = [NSArray array]; + for (NSDictionary *data in dataToAdd) { + FSTDocument *docToAdd = FSTTestDoc(path, 1, data, hasPendingWrites); + newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; + documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange changeWithDocument:docToAdd type:FSTDocumentViewChangeTypeAdded]]; + } + FSTViewSnapshot *viewSnapshot = + [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) + documents:newDocuments + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:fromCache + hasPendingWrites:hasPendingWrites + syncStateChanged:YES]; + return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() + originalQuery:FSTTestQuery(path) + snapshot:viewSnapshot + metadata:metadata]; +} + id FSTTestFilter(NSString *field, NSString *opString, id value) { FSTFieldPath *path = FSTTestFieldPath(field); FSTRelationFilterOperator op; From e4e3903b1b70d2187e74ace4f466fd9f28b7ab79 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Fri, 15 Dec 2017 16:46:50 -0500 Subject: [PATCH 12/18] remove unneccessary nil-check, check isKindOfClass instead of isEqual --- Firestore/Source/API/FIRCollectionReference.mm | 2 +- Firestore/Source/API/FIRDocumentReference.m | 2 +- Firestore/Source/API/FIRDocumentSnapshot.m | 3 ++- Firestore/Source/API/FIRFieldPath.m | 2 +- Firestore/Source/API/FIRQuery.m | 2 +- Firestore/Source/API/FIRQuerySnapshot.m | 2 +- Firestore/Source/API/FIRSnapshotMetadata.m | 2 +- Firestore/Source/Core/FSTQuery.m | 4 ++-- Firestore/Source/Local/FSTDocumentReference.m | 2 +- Firestore/Source/Model/FSTDatabaseID.m | 2 +- Firestore/Source/Model/FSTMutation.m | 2 +- Firestore/Source/Remote/FSTStream.m | 2 +- 12 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm index e82dfece194..70a14c2c103 100644 --- a/Firestore/Source/API/FIRCollectionReference.mm +++ b/Firestore/Source/API/FIRCollectionReference.mm @@ -69,7 +69,7 @@ - (instancetype)initWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firest // NSObject Methods - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToReference:other]; } diff --git a/Firestore/Source/API/FIRDocumentReference.m b/Firestore/Source/API/FIRDocumentReference.m index 6279b7ca68a..87e66318a03 100644 --- a/Firestore/Source/API/FIRDocumentReference.m +++ b/Firestore/Source/API/FIRDocumentReference.m @@ -116,7 +116,7 @@ - (instancetype)initWithKey:(FSTDocumentKey *)key firestore:(FIRFirestore *)fire - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToReference:other]; } diff --git a/Firestore/Source/API/FIRDocumentSnapshot.m b/Firestore/Source/API/FIRDocumentSnapshot.m index 4d7714df4a6..2ace30a4097 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.m +++ b/Firestore/Source/API/FIRDocumentSnapshot.m @@ -79,7 +79,8 @@ - (instancetype)initWithFirestore:(FIRFirestore *)firestore // NSObject Methods - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + // self class could be FIRDocumentSnapshot or subtype. So we compare with base type explicitly. + if (![other isKindOfClass:[FIRDocumentSnapshot class]]) return NO; return [self isEqualToSnapshot:other]; } diff --git a/Firestore/Source/API/FIRFieldPath.m b/Firestore/Source/API/FIRFieldPath.m index 005044d353c..f4e532f0b70 100644 --- a/Firestore/Source/API/FIRFieldPath.m +++ b/Firestore/Source/API/FIRFieldPath.m @@ -85,7 +85,7 @@ - (BOOL)isEqual:(nullable id)object { return YES; } - if (!object || ![object isKindOfClass:[FIRFieldPath class]]) { + if (![object isKindOfClass:[FIRFieldPath class]]) { return NO; } diff --git a/Firestore/Source/API/FIRQuery.m b/Firestore/Source/API/FIRQuery.m index 70bd51ecf13..924f5e871b7 100644 --- a/Firestore/Source/API/FIRQuery.m +++ b/Firestore/Source/API/FIRQuery.m @@ -107,7 +107,7 @@ - (instancetype)initWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firest - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToQuery:other]; } diff --git a/Firestore/Source/API/FIRQuerySnapshot.m b/Firestore/Source/API/FIRQuerySnapshot.m index 118481e2cf5..6ae9ee31c8b 100644 --- a/Firestore/Source/API/FIRQuerySnapshot.m +++ b/Firestore/Source/API/FIRQuerySnapshot.m @@ -80,7 +80,7 @@ - (instancetype)initWithFirestore:(FIRFirestore *)firestore // NSObject Methods - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToSnapshot:other]; } diff --git a/Firestore/Source/API/FIRSnapshotMetadata.m b/Firestore/Source/API/FIRSnapshotMetadata.m index 784b51c5f56..d957a8d99ff 100644 --- a/Firestore/Source/API/FIRSnapshotMetadata.m +++ b/Firestore/Source/API/FIRSnapshotMetadata.m @@ -47,7 +47,7 @@ - (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCa // NSObject Methods - (BOOL)isEqual:(nullable id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToMetadata:other]; } diff --git a/Firestore/Source/Core/FSTQuery.m b/Firestore/Source/Core/FSTQuery.m index 0bfd9178570..13657f73ff3 100644 --- a/Firestore/Source/Core/FSTQuery.m +++ b/Firestore/Source/Core/FSTQuery.m @@ -205,7 +205,7 @@ - (NSString *)description { - (BOOL)isEqual:(id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self.field isEqual:((FSTNullFilter *)other).field]; } @@ -246,7 +246,7 @@ - (NSString *)description { - (BOOL)isEqual:(id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self.field isEqual:((FSTNanFilter *)other).field]; } diff --git a/Firestore/Source/Local/FSTDocumentReference.m b/Firestore/Source/Local/FSTDocumentReference.m index 1631789ed19..25a5935cee5 100644 --- a/Firestore/Source/Local/FSTDocumentReference.m +++ b/Firestore/Source/Local/FSTDocumentReference.m @@ -34,7 +34,7 @@ - (instancetype)initWithKey:(FSTDocumentKey *)key ID:(int)ID { - (BOOL)isEqual:(id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; FSTDocumentReference *reference = (FSTDocumentReference *)other; diff --git a/Firestore/Source/Model/FSTDatabaseID.m b/Firestore/Source/Model/FSTDatabaseID.m index 4d0448ab693..bff5855c145 100644 --- a/Firestore/Source/Model/FSTDatabaseID.m +++ b/Firestore/Source/Model/FSTDatabaseID.m @@ -48,7 +48,7 @@ - (instancetype)initWithProject:(NSString *)projectID database:(NSString *)datab - (BOOL)isEqual:(id)other { if (other == self) return YES; - if (!other || ![[other class] isEqual:[self class]]) return NO; + if (![[other class] isEqual:[self class]]) return NO; return [self isEqualToDatabaseId:other]; } diff --git a/Firestore/Source/Model/FSTMutation.m b/Firestore/Source/Model/FSTMutation.m index 5b47280c31d..b6a05e2a0e9 100644 --- a/Firestore/Source/Model/FSTMutation.m +++ b/Firestore/Source/Model/FSTMutation.m @@ -97,7 +97,7 @@ - (instancetype)initWithPath:(FSTFieldPath *)path transform:(id Date: Mon, 18 Dec 2017 16:54:42 -0500 Subject: [PATCH 13/18] refactoring: adding `FSTAPIHelpers.{h,m}`, `FSTTest{Collection,Document}Ref`, better naming and style fix --- .../Firestore.xcodeproj/project.pbxproj | 8 ++ .../Tests/API/FIRCollectionReferenceTests.m | 18 +-- .../Tests/API/FIRDocumentReferenceTests.m | 19 +-- .../Tests/API/FIRDocumentSnapshotTests.m | 49 ++++--- .../Example/Tests/API/FIRFieldValueTests.m | 28 ++-- .../Example/Tests/API/FIRGeoPointTests.m | 38 +++-- .../Example/Tests/API/FIRQuerySnapshotTests.m | 36 +++-- Firestore/Example/Tests/API/FIRQueryTests.m | 18 +-- Firestore/Example/Tests/API/FSTAPIHelpers.h | 97 +++++++++++++ Firestore/Example/Tests/API/FSTAPIHelpers.m | 134 ++++++++++++++++++ Firestore/Example/Tests/Core/FSTQueryTests.m | 24 ++-- .../Example/Tests/Local/FSTLocalStoreTests.m | 12 +- .../Example/Tests/Local/FSTQueryCacheTests.m | 6 +- .../Example/Tests/Model/FSTDocumentTests.m | 42 +++--- .../Example/Tests/Model/FSTFieldValueTests.m | 1 + Firestore/Example/Tests/Util/FSTHelpers.h | 24 +--- Firestore/Example/Tests/Util/FSTHelpers.m | 74 +--------- Firestore/Source/API/FIRDocumentSnapshot.m | 2 +- 18 files changed, 385 insertions(+), 245 deletions(-) create mode 100644 Firestore/Example/Tests/API/FSTAPIHelpers.h create mode 100644 Firestore/Example/Tests/API/FSTAPIHelpers.m diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index b1d95ea678f..b7bf6f384db 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -69,6 +69,8 @@ AB99452C1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */; }; AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; + ABF341051FE860CA00C48322 /* FSTAPIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF341021FE8593500C48322 /* FSTAPIHelpers.m */; }; + ABF341061FE860CB00C48322 /* FSTAPIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF341021FE8593500C48322 /* FSTAPIHelpers.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */; }; @@ -246,6 +248,8 @@ AB99452B1FE3018D00DFC1E6 /* FIRQuerySnapshotTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRQuerySnapshotTests.m; sourceTree = ""; }; AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FIRFieldValueTests.m; sourceTree = ""; }; ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; + ABF341011FE858B500C48322 /* FSTAPIHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTAPIHelpers.h; sourceTree = ""; }; + ABF341021FE8593500C48322 /* FSTAPIHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FSTAPIHelpers.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; @@ -608,6 +612,8 @@ AB382F7B1FE02A1F007CA955 /* FIRDocumentReferenceTests.m */, DE51B1841F0D48AC0013853F /* FIRGeoPointTests.m */, ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */, + ABF341011FE858B500C48322 /* FSTAPIHelpers.h */, + ABF341021FE8593500C48322 /* FSTAPIHelpers.m */, ); path = API; sourceTree = ""; @@ -1187,6 +1193,7 @@ DE51B1FD1F0D492C0013853F /* FSTSpecTests.m in Sources */, ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */, DE51B2001F0D493A0013853F /* FSTComparisonTests.m in Sources */, + ABF341051FE860CA00C48322 /* FSTAPIHelpers.m in Sources */, DE51B1CC1F0D48C00013853F /* FIRGeoPointTests.m in Sources */, DE51B1E11F0D490D0013853F /* FSTMemoryRemoteDocumentCacheTests.m in Sources */, DE51B1FF1F0D493A0013853F /* FSTAssertTests.m in Sources */, @@ -1267,6 +1274,7 @@ 54E9282D1F339CAD00C1953E /* XCTestCase+Await.m in Sources */, DE03B2EC1F214BA200A30B9C /* FSTDatastoreTests.m in Sources */, 54E928251F33953400C1953E /* FSTEventAccumulator.m in Sources */, + ABF341061FE860CB00C48322 /* FSTAPIHelpers.m in Sources */, DE03B2ED1F214BA200A30B9C /* FSTSmokeTests.m in Sources */, DE03B2F31F214BAA00A30B9C /* FIRQueryTests.m in Sources */, DE03B35E1F21586C00A30B9C /* FSTHelpers.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m index 05ebfc24c39..73ae38d9085 100644 --- a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.m @@ -17,10 +17,8 @@ #import #import "FirebaseFirestore/FIRCollectionReference.h" -#import "Firestore/Source/API/FIRCollectionReference+Internal.h" -#import "Firestore/Source/Model/FSTPath.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -30,17 +28,9 @@ @interface FIRCollectionReferenceTests : XCTestCase @implementation FIRCollectionReferenceTests - (void)testEquals { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. - FIRFirestore *firestore = FSTTestFirestore(); - FSTResourcePath *pathFoo = FSTTestPath(@"foo"); - FSTResourcePath *pathBar = FSTTestPath(@"bar"); - FIRCollectionReference *referenceFoo = - [FIRCollectionReference referenceWithPath:pathFoo firestore:firestore]; - FIRCollectionReference *referenceFooDup = - [FIRCollectionReference referenceWithPath:pathFoo firestore:firestore]; - FIRCollectionReference *referenceBar = - [FIRCollectionReference referenceWithPath:pathBar firestore:firestore]; + FIRCollectionReference *referenceFoo = FSTTestCollectionRef(@"foo"); + FIRCollectionReference *referenceFooDup = FSTTestCollectionRef(@"foo"); + FIRCollectionReference *referenceBar = FSTTestCollectionRef(@"bar"); XCTAssertEqualObjects(referenceFoo, referenceFooDup); XCTAssertNotEqualObjects(referenceFoo, referenceBar); diff --git a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m index 35307bafa90..4e301d08a76 100644 --- a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.m @@ -17,10 +17,8 @@ #import #import "FirebaseFirestore/FIRDocumentReference.h" -#import "Firestore/Source/API/FIRDocumentReference+Internal.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -30,18 +28,9 @@ @interface FIRDocumentReferenceTests : XCTestCase @implementation FIRDocumentReferenceTests - (void)testEquals { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. - FIRFirestore *firestore = FSTTestFirestore(); - FSTDocumentKey *keyFoo = FSTTestDocKey(@"rooms/foo"); - FSTDocumentKey *keyFooDup = FSTTestDocKey(@"rooms/foo"); - FSTDocumentKey *keyBar = FSTTestDocKey(@"rooms/bar"); - FIRDocumentReference *referenceFoo = - [FIRDocumentReference referenceWithKey:keyFoo firestore:firestore]; - FIRDocumentReference *referenceFooDup = - [FIRDocumentReference referenceWithKey:keyFooDup firestore:firestore]; - FIRDocumentReference *referenceBar = - [FIRDocumentReference referenceWithKey:keyBar firestore:firestore]; + FIRDocumentReference *referenceFoo = FSTTestDocRef(@"rooms/foo"); + FIRDocumentReference *referenceFooDup = FSTTestDocRef(@"rooms/foo"); + FIRDocumentReference *referenceBar = FSTTestDocRef(@"rooms/bar"); XCTAssertEqualObjects(referenceFoo, referenceFooDup); XCTAssertNotEqualObjects(referenceFoo, referenceBar); diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index b8e2ee6547b..74cce5fc335 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -23,7 +23,7 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -33,31 +33,30 @@ @interface FIRDocumentSnapshotTests : XCTestCase @implementation FIRDocumentSnapshotTests - (void)testEquals { - XCTAssertEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO), - FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO)); - XCTAssertEqualObjects(FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO), - FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO)); - XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO), - FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO)); - XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO), - FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); - XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, YES, NO), - FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); - XCTAssertNotEqualObjects(FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, YES), - FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO)); + FIRDocumentSnapshot *base = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *nilData = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *differentData = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"b" : @1 }, NO, NO); + FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, YES, NO); + FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, YES); + XCTAssertEqualObjects(base, baseDup); + XCTAssertEqualObjects(nilData, nilDataDup); + XCTAssertNotEqualObjects(base, nilData); + XCTAssertNotEqualObjects(nilData, base); + XCTAssertNotEqualObjects(base, differentPath); + XCTAssertNotEqualObjects(base, differentData); + XCTAssertNotEqualObjects(base, hasMutations); + XCTAssertNotEqualObjects(base, fromCache); - XCTAssertEqual([FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO) hash], - [FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO) hash]); - XCTAssertEqual([FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash], - [FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash]); - XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO) hash], - [FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO) hash]); - XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO) hash], - [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); - XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, YES, NO) hash], - [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); - XCTAssertNotEqual([FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, YES) hash], - [FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"b" : @1 }, NO, NO) hash]); + XCTAssertEqual([base hash], [baseDup hash]); + XCTAssertEqual([nilData hash], [nilDataDup hash]); + XCTAssertNotEqual([base hash], [nilData hash]); + XCTAssertNotEqual([base hash], [differentPath hash]); + XCTAssertNotEqual([base hash], [differentData hash]); + XCTAssertNotEqual([base hash], [hasMutations hash]); + XCTAssertNotEqual([base hash], [fromCache hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRFieldValueTests.m b/Firestore/Example/Tests/API/FIRFieldValueTests.m index 8ce284d4816..862e965b594 100644 --- a/Firestore/Example/Tests/API/FIRFieldValueTests.m +++ b/Firestore/Example/Tests/API/FIRFieldValueTests.m @@ -20,7 +20,7 @@ #import "Firestore/Source/API/FIRFieldValue+Internal.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -30,19 +30,19 @@ @interface FIRFieldValueTests : XCTestCase @implementation FIRFieldValueTests - (void)testEquals { - XCTAssertEqualObjects([FIRFieldValue fieldValueForDelete], [FIRFieldValue fieldValueForDelete]); - XCTAssertNotEqualObjects([FIRFieldValue fieldValueForDelete], nil); - XCTAssertEqualObjects([FIRFieldValue fieldValueForServerTimestamp], - [FIRFieldValue fieldValueForServerTimestamp]); - XCTAssertNotEqualObjects([FIRFieldValue fieldValueForServerTimestamp], nil); - XCTAssertNotEqualObjects([FIRFieldValue fieldValueForDelete], - [FIRFieldValue fieldValueForServerTimestamp]); - - XCTAssertEqual([[FIRFieldValue fieldValueForDelete] hash], [[FIRFieldValue fieldValueForDelete] hash]); - XCTAssertEqual([[FIRFieldValue fieldValueForServerTimestamp] hash], - [[FIRFieldValue fieldValueForServerTimestamp] hash]); - XCTAssertNotEqual([[FIRFieldValue fieldValueForDelete] hash], - [[FIRFieldValue fieldValueForServerTimestamp] hash]); + FIRFieldValue *delete = [FIRFieldValue fieldValueForDelete]; + FIRFieldValue *deleteDup = [FIRFieldValue fieldValueForDelete]; + FIRFieldValue *serverTimestamp = [FIRFieldValue fieldValueForServerTimestamp]; + FIRFieldValue *serverTimestampDup = [FIRFieldValue fieldValueForServerTimestamp]; + XCTAssertEqualObjects(delete, deleteDup); + XCTAssertNotEqualObjects(delete, nil); + XCTAssertEqualObjects(serverTimestamp, serverTimestampDup); + XCTAssertNotEqualObjects(serverTimestamp, nil); + XCTAssertNotEqualObjects(delete, serverTimestamp); + + XCTAssertEqual([delete hash], [deleteDup hash]); + XCTAssertEqual([serverTimestamp hash], [serverTimestamp hash]); + XCTAssertNotEqual([delete hash], [serverTimestamp hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRGeoPointTests.m b/Firestore/Example/Tests/API/FIRGeoPointTests.m index adce25cdebe..9ea31bd7818 100644 --- a/Firestore/Example/Tests/API/FIRGeoPointTests.m +++ b/Firestore/Example/Tests/API/FIRGeoPointTests.m @@ -18,6 +18,7 @@ #import +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -28,27 +29,24 @@ @interface FIRGeoPointTests : XCTestCase @implementation FIRGeoPointTests - (void)testEquals { - XCTAssertEqualObjects([[FIRGeoPoint alloc] initWithLatitude:0 longitude:0], - [[FIRGeoPoint alloc] initWithLatitude:0 longitude:0]); - XCTAssertEqualObjects([[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56], - [[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56]); - XCTAssertNotEqualObjects([[FIRGeoPoint alloc] initWithLatitude:0 longitude:0], - [[FIRGeoPoint alloc] initWithLatitude:1 longitude:0]); - XCTAssertNotEqualObjects([[FIRGeoPoint alloc] initWithLatitude:0 longitude:0], - [[FIRGeoPoint alloc] initWithLatitude:0 longitude:1]); - XCTAssertNotEqualObjects([[FIRGeoPoint alloc] initWithLatitude:0 longitude:0], - [[NSObject alloc] init]); + FIRGeoPoint *foo = FSTTestGeoPoint(0, 0); + FIRGeoPoint *fooDup = FSTTestGeoPoint(0, 0); + FIRGeoPoint *bar = FSTTestGeoPoint(1.23, 4.56); + FIRGeoPoint *barDup = FSTTestGeoPoint(1.23, 4.56); + FIRGeoPoint *differentLatitude = FSTTestGeoPoint(1, 0); + FIRGeoPoint *differentLongitude = FSTTestGeoPoint(0, 1); + NSObject *object = [[NSObject alloc] init]; + XCTAssertEqualObjects(foo, fooDup); + XCTAssertEqualObjects(bar, barDup); + XCTAssertNotEqualObjects(foo, differentLatitude); + XCTAssertNotEqualObjects(foo, differentLongitude); + XCTAssertNotEqualObjects(foo, object); - XCTAssertEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], - [[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash]); - XCTAssertEqual([[[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56] hash], - [[[FIRGeoPoint alloc] initWithLatitude:1.23 longitude:4.56] hash]); - XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], - [[[FIRGeoPoint alloc] initWithLatitude:1 longitude:0] hash]); - XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], - [[[FIRGeoPoint alloc] initWithLatitude:0 longitude:1] hash]); - XCTAssertNotEqual([[[FIRGeoPoint alloc] initWithLatitude:0 longitude:0] hash], - [[[NSObject alloc] init] hash]); + XCTAssertEqual([foo hash], [fooDup hash]); + XCTAssertEqual([bar hash], [barDup hash]); + XCTAssertNotEqual([foo hash], [differentLatitude hash]); + XCTAssertNotEqual([foo hash], [differentLongitude hash]); + XCTAssertNotEqual([foo hash], [object hash]); } - (void)testComparison { diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index 0c7ebdc60b7..987c7d51cf4 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -25,7 +25,7 @@ #import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Model/FSTPath.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -35,19 +35,27 @@ @interface FIRQuerySnapshotTests : XCTestCase @implementation FIRQuerySnapshotTests - (void)testEquals { - FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"a":@1 } ], YES, YES); - FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"a":@1 } ], YES, YES); - FIRQuerySnapshot *bar = FSTTestQuerySnapshot(@"bar/foo", @[], @[ @{ @"a":@1 } ], YES, YES); - FIRQuerySnapshot *baz = FSTTestQuerySnapshot(@"foo/bar", @[ @{ @"a":@1 } ], @[], YES, YES); - FIRQuerySnapshot *qux = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"b":@1 } ], NO, YES); - FIRQuerySnapshot *quux = FSTTestQuerySnapshot(@"foo/bar", @[], @[ @{ @"b":@1 } ], YES, NO); - NSArray *groups = @[ @[foo, fooDup], @[bar], @[baz], @[qux], @[quux]]; - FSTAssertEqualityGroups(groups); - - NSArray *hashGroups = @[ @[[NSNumber numberWithLong:[foo hash]], [NSNumber numberWithLong:[fooDup hash]] ], - @[ [NSNumber numberWithLong:[bar hash]] ], @[ [NSNumber numberWithLong:[baz hash]] ], - @[ [NSNumber numberWithLong:[qux hash]] ], @[ [NSNumber numberWithLong:[quux hash]] ]]; - FSTAssertEqualityGroups(hashGroups); + FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot(@"bar", @{}, + @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot(@"foo", + @{ @"a" : @{@"b" : @1} }, @{}, YES, NO); + FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot(@"foo", @{}, + @{ @"a" : @{@"a" : @1} }, NO, NO); + FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot(@"foo", @{}, + @{ @"a" : @{@"a" : @1} }, YES, YES); + XCTAssertEqualObjects(foo, fooDup); + XCTAssertNotEqualObjects(foo, differentPath); + XCTAssertNotEqualObjects(foo, differentDoc); + XCTAssertNotEqualObjects(foo, noPendingWrites); + XCTAssertNotEqualObjects(foo, fromCache); + + XCTAssertEqual([foo hash], [fooDup hash]); + XCTAssertNotEqual([foo hash], [differentPath hash]); + XCTAssertNotEqual([foo hash], [differentDoc hash]); + XCTAssertNotEqual([foo hash], [noPendingWrites hash]); + XCTAssertNotEqual([foo hash], [fromCache hash]); } @end diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 4777df428e9..35f36a070ed 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -21,6 +21,7 @@ #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Model/FSTPath.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -31,15 +32,10 @@ @interface FIRQueryTests : XCTestCase @implementation FIRQueryTests - (void)testEquals { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. FIRFirestore *firestore = FSTTestFirestore(); - FIRQuery *queryFoo = - [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; - FIRQuery *queryFooDup = - [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; - FIRQuery *queryBar = - [FIRQuery referenceWithQuery:FSTTestQuery(@"bar") firestore:firestore]; + FIRQuery *queryFoo = [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; + FIRQuery *queryFooDup = [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; + FIRQuery *queryBar = [FIRQuery referenceWithQuery:FSTTestQuery(@"bar") firestore:firestore]; XCTAssertEqualObjects(queryFoo, queryFooDup); XCTAssertNotEqualObjects(queryFoo, queryBar); XCTAssertEqualObjects([queryFoo queryWhereField:@"f" isEqualTo:@1], @@ -50,14 +46,12 @@ - (void)testEquals { XCTAssertEqual([queryFoo hash], [queryFooDup hash]); XCTAssertNotEqual([queryFoo hash], [queryBar hash]); XCTAssertEqual([[queryFoo queryWhereField:@"f" isEqualTo:@1] hash], - [[queryFoo queryWhereField:@"f" isEqualTo:@1] hash]); + [[queryFoo queryWhereField:@"f" isEqualTo:@1] hash]); XCTAssertNotEqual([[queryFoo queryWhereField:@"f" isEqualTo:@1] hash], - [[queryFoo queryWhereField:@"f" isEqualTo:@2] hash]); + [[queryFoo queryWhereField:@"f" isEqualTo:@2] hash]); } - (void)testFilteringWithPredicate { - // Everything is dummy for unit test here. Filtering does not require any app - // specific setting as far as we do not fetch data. FIRFirestore *firestore = FSTTestFirestore(); FIRQuery *query = [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") firestore:firestore]; FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1]; diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h new file mode 100644 index 00000000000..f369d201901 --- /dev/null +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -0,0 +1,97 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "Firestore/Source/API/FIRDocumentReference+Internal.h" +#import "Firestore/Source/Core/FSTTypes.h" +#import "Firestore/Source/Model/FSTDocumentDictionary.h" +#import "Firestore/Source/Model/FSTDocumentKeySet.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +@class FIRCollectionReference; +@class FIRDocumentReference; +@class FIRDocumentSnapshot; +@class FIRFirestore; +@class FIRGeoPoint; +@class FIRQuerySnapshot; +@class FSTDeleteMutation; +@class FSTDeletedDocument; +@class FSTDocument; +@class FSTDocumentKeyReference; +@class FSTDocumentSet; +@class FSTFieldPath; +@class FSTFieldValue; +@class FSTLocalViewChanges; +@class FSTPatchMutation; +@class FSTQuery; +@class FSTRemoteEvent; +@class FSTResourceName; +@class FSTResourcePath; +@class FSTSetMutation; +@class FSTSnapshotVersion; +@class FSTSortOrder; +@class FSTTargetChange; +@class FSTTimestamp; +@class FSTTransformMutation; +@class FSTView; +@class FSTViewSnapshot; +@class FSTObjectValue; +@protocol FSTFilter; + +NS_ASSUME_NONNULL_BEGIN + +#if __cplusplus +extern "C" { +#endif + +/** A convenience method for creating dummy singleton FIRFirestore for tests. */ +FIRFirestore *FSTTestFirestore(); + +/** Creates a new GeoPoint from the latitude and longitude values */ +FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); + +/** A convenience method for creating a doc snapshot for tests. */ +FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, + FSTTestSnapshotVersion version, + NSDictionary *data, + BOOL hasMutations, + BOOL fromCache); + +/** A covenience method for creating a collection reference from a path string. */ +FIRCollectionReference *FSTTestCollectionRef(NSString *path); + +/** A covenience method for creating a document reference from a path string. */ +FIRDocumentReference *FSTTestDocRef(NSString *path); + +/** + * A convenience method for creating a particular query snapshot for tests. + * This function allows user to pass in snapshot of the query in the past as well as new rows to be + * added into the snapshot as for now. The current snapshot of the query consists both data. + */ +FIRQuerySnapshot *FSTTestQuerySnapshot( + NSString *path, + NSDictionary *> *oldData, + NSDictionary *> *dataToAdd, + BOOL hasPendingWrites, + BOOL fromCache); + +#if __cplusplus +} // extern "C" +#endif + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.m b/Firestore/Example/Tests/API/FSTAPIHelpers.m new file mode 100644 index 00000000000..6f61b5a166d --- /dev/null +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.m @@ -0,0 +1,134 @@ +/* + * Copyright 2017 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" +#import +#import +#import +#import +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +#import "FirebaseFirestore/FIRCollectionReference.h" +#import "FirebaseFirestore/FIRDocumentReference.h" +#import "FirebaseFirestore/FIRDocumentSnapshot.h" +#import "FirebaseFirestore/FIRFieldPath.h" +#import "FirebaseFirestore/FIRFirestore.h" +#import "FirebaseFirestore/FIRGeoPoint.h" +#import "FirebaseFirestore/FIRQuerySnapshot.h" +#import "FirebaseFirestore/FIRSnapshotMetadata.h" +#import "Firestore/Source/API/FIRCollectionReference+Internal.h" +#import "Firestore/Source/API/FIRDocumentReference+Internal.h" +#import "Firestore/Source/API/FIRFieldPath+Internal.h" +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/API/FSTUserDataConverter.h" +#import "Firestore/Source/Core/FSTQuery.h" +#import "Firestore/Source/Core/FSTSnapshotVersion.h" +#import "Firestore/Source/Core/FSTTimestamp.h" +#import "Firestore/Source/Core/FSTView.h" +#import "Firestore/Source/Local/FSTLocalViewChanges.h" +#import "Firestore/Source/Local/FSTQueryData.h" +#import "Firestore/Source/Model/FSTDatabaseID.h" +#import "Firestore/Source/Model/FSTDocument.h" +#import "Firestore/Source/Model/FSTDocumentKey.h" +#import "Firestore/Source/Model/FSTDocumentSet.h" +#import "Firestore/Source/Model/FSTFieldValue.h" +#import "Firestore/Source/Model/FSTMutation.h" +#import "Firestore/Source/Model/FSTPath.h" +#import "Firestore/Source/Remote/FSTRemoteEvent.h" +#import "Firestore/Source/Remote/FSTWatchChange.h" +#import "Firestore/Source/Util/FSTAssert.h" + +NS_ASSUME_NONNULL_BEGIN + +FIRFirestore *FSTTestFirestore() { + static FIRFirestore *sharedInstance = nil; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + sharedInstance = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + }); + return sharedInstance; +} + +FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude) { + return [[FIRGeoPoint alloc] initWithLatitude:latitude longitude:longitude]; +} + +FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, + FSTTestSnapshotVersion version, + NSDictionary *data, + BOOL hasMutations, + BOOL fromCache) { + FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil; + return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore() + documentKey:FSTTestDocKey(path) + document:doc + fromCache:fromCache]; +} + +FIRCollectionReference *FSTTestCollectionRef(NSString *path) { + return [FIRCollectionReference referenceWithPath:FSTTestPath(path) firestore:FSTTestFirestore()]; +} + +FIRDocumentReference *FSTTestDocRef(NSString *path) { + return [FIRDocumentReference referenceWithPath:FSTTestPath(path) firestore:FSTTestFirestore()]; +} + +/** A convenience method for creating a query snapshots for tests. */ +FIRQuerySnapshot *FSTTestQuerySnapshot( + NSString *path, + NSDictionary *> *oldData, + NSDictionary *> *dataToAdd, + BOOL hasPendingWrites, + BOOL fromCache) { + FIRSnapshotMetadata *metadata = + [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites fromCache:fromCache]; + FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); + for (NSString *key in oldData) { + oldDocuments = [oldDocuments + documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, + oldData[key], hasPendingWrites)]; + } + FSTDocumentSet *newDocuments = oldDocuments; + NSArray *documentChanges = [NSArray array]; + for (NSString *key in dataToAdd) { + FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, + dataToAdd[key], hasPendingWrites); + newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; + documentChanges = [documentChanges + arrayByAddingObject:[FSTDocumentViewChange + changeWithDocument:docToAdd + type:FSTDocumentViewChangeTypeAdded]]; + } + FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) + documents:newDocuments + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:fromCache + hasPendingWrites:hasPendingWrites + syncStateChanged:YES]; + return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() + originalQuery:FSTTestQuery(path) + snapshot:viewSnapshot + metadata:metadata]; +} + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.m b/Firestore/Example/Tests/Core/FSTQueryTests.m index 6f1f76f466e..3d2bd82f0a7 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.m +++ b/Firestore/Example/Tests/Core/FSTQueryTests.m @@ -114,10 +114,10 @@ - (void)testEmptyFieldsAreAllowedForQueries { } - (void)testMatchesPrimitiveValuesForFilters { - FSTQuery *query1 = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; - FSTQuery *query2 = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; + FSTQuery *query1 = + [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; + FSTQuery *query2 = + [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); @@ -158,8 +158,8 @@ - (void)testNullFilter { } - (void)testNanFilter { - FSTQuery *query = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @"==", @(NAN))]; + FSTQuery *query = + [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"==", @(NAN))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @(NAN) }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); FSTDocument *doc3 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @3.1 }, NO); @@ -174,10 +174,10 @@ - (void)testNanFilter { } - (void)testDoesNotMatchComplexObjectsForFilters { - FSTQuery *query1 = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; - FSTQuery *query2 = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; + FSTQuery *query1 = + [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; + FSTQuery *query2 = + [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @2 }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @[] }, NO); @@ -301,8 +301,8 @@ - (void)assertCorrectComparisonsWithArray:(NSArray *)array comparator:(NSCompara - (void)testSortsDocumentsInTheCorrectOrder { FSTQuery *query = FSTTestQuery(@"collection"); query = - [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort") - ascending:YES]]; + [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:FSTTestFieldPath(@"sort") + ascending:YES]]; // clang-format off NSArray *docs = @[ diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m index 4c8f285f147..45d1815065f 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m @@ -196,7 +196,7 @@ - (void)collectGarbage { NSEnumerator *keyPathEnumerator = keyPaths.objectEnumerator; \ [actual enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey * actualKey, \ FSTMaybeDocument * value, BOOL * stop) { \ - FSTDocumentKey *expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \ + FSTDocumentKey *expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \ XCTAssertEqualObjects(actualKey, expectedKey); \ XCTAssertTrue([value isKindOfClass:[FSTDeletedDocument class]]); \ }]; \ @@ -212,11 +212,11 @@ - (void)collectGarbage { } while (0) /** Asserts that the given local store does not contain the given document. */ -#define FSTAssertNotContains(keyPathString) \ - do { \ - FSTDocumentKey *key = FSTTestDocKey(keyPathString); \ - FSTMaybeDocument *actual = [self.localStore readDocument:key]; \ - XCTAssertNil(actual); \ +#define FSTAssertNotContains(keyPathString) \ + do { \ + FSTDocumentKey *key = FSTTestDocKey(keyPathString); \ + FSTMaybeDocument *actual = [self.localStore readDocument:key]; \ + XCTAssertNil(actual); \ } while (0) - (void)testMutationBatchKeys { diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m index f390df7cfb1..0b80bd9472e 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m @@ -70,10 +70,8 @@ - (void)testCanonicalIDCollision { // Type information is currently lost in our canonicalID implementations so this currently an // easy way to force colliding canonicalIDs - FSTQuery *q1 = [FSTTestQuery(@"a") - queryByAddingFilter:FSTTestFilter(@"foo", @"==", @(1))]; - FSTQuery *q2 = [FSTTestQuery(@"a") - queryByAddingFilter:FSTTestFilter(@"foo", @"==", @"1")]; + FSTQuery *q1 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @(1))]; + FSTQuery *q2 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @"1")]; XCTAssertEqualObjects(q1.canonicalID, q2.canonicalID); FSTQueryData *data1 = [self queryDataWithQuery:q1 targetID:1 version:1]; diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.m b/Firestore/Example/Tests/Model/FSTDocumentTests.m index 40ae2af4c0b..59f526dc1c5 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.m +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.m @@ -62,25 +62,31 @@ - (void)testExtractsFields { } - (void)testIsEqual { - XCTAssertEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/second", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 2, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, YES)); + XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO)); + XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, + @{ @"b" : @1 }, NO)); + XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/second", 1, + @{ @"b" : @1 }, NO)); + XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 2, + @{ @"a" : @1 }, NO)); + XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, NO), + FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, YES)); - XCTAssertEqualObjects( - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, YES), - FSTTestDoc(@"messages/first", 1, @{ @"a" : @1 }, 5)); + XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, YES), + FSTTestDoc(@"messages/first", 1, + @{ @"a" : @1 }, 5)); } @end diff --git a/Firestore/Example/Tests/Model/FSTFieldValueTests.m b/Firestore/Example/Tests/Model/FSTFieldValueTests.m index acf95f0d989..36e89c34d78 100644 --- a/Firestore/Example/Tests/Model/FSTFieldValueTests.m +++ b/Firestore/Example/Tests/Model/FSTFieldValueTests.m @@ -26,6 +26,7 @@ #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTPath.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" /** Helper to wrap the values in a set of equality groups using FSTTestFieldValue(). */ diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index 0290ea1e328..ec51d0513c7 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -21,6 +21,8 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKeySet.h" +@class FIRCollectionReference; +@class FIRDocumentReference; @class FIRDocumentSnapshot; @class FIRFirestore; @class FIRGeoPoint; @@ -137,9 +139,6 @@ extern "C" { XCTAssertTrue(__didThrow, ##__VA_ARGS__); \ }) -/** A convenience method for creating dummy singleton FIRFirestore for tests. */ -FIRFirestore *FSTTestFirestore(); - /** Creates a new FSTTimestamp from components. Note that year, month, and day are all one-based. */ FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second); @@ -151,9 +150,6 @@ NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int seco */ NSData *FSTTestData(int bytes, ...); -/** Creates a new GeoPoint from the latitude and longitude values */ -FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); - /** * Creates a new NSDateComponents from components. Note that year, month, and day are all * one-based. @@ -187,14 +183,6 @@ FSTDocument *FSTTestDoc(NSString *path, NSDictionary *data, BOOL hasMutations); -/** A convenience method for creating a doc snapshot for tests. */ -FIRDocumentSnapshot *FSTTestDocSnapshot( - NSString *path, - FSTTestSnapshotVersion version, - NSDictionary *data, - BOOL hasMutations, - BOOL fromCache); - /** A convenience method for creating deleted docs for tests. */ FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version); @@ -209,14 +197,6 @@ FSTDocumentKeyReference *FSTTestRef(NSString *projectID, NSString *databaseID, N /** A convenience method for creating a query for the given path (without any other filters). */ FSTQuery *FSTTestQuery(NSString *path); -/** A convenience method for creating a particular query snapshots for tests. */ -FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, - NSArray *> *oldData, - NSArray *> *dataToAdd, - BOOL hasPendingWrites, - BOOL fromCache); - /** * A convenience method to create a FSTFilter using a string representation for both field * and operator (<, <=, ==, >=, >). diff --git a/Firestore/Example/Tests/Util/FSTHelpers.m b/Firestore/Example/Tests/Util/FSTHelpers.m index d098113fd49..400ab6ef952 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.m +++ b/Firestore/Example/Tests/Util/FSTHelpers.m @@ -14,18 +14,22 @@ * limitations under the License. */ +#import "Firestore/Example/Tests/Util/FSTHelpers.h" #import +#import #import #import -#import -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#import "FirebaseFirestore/FIRCollectionReference.h" +#import "FirebaseFirestore/FIRDocumentReference.h" #import "FirebaseFirestore/FIRDocumentSnapshot.h" #import "FirebaseFirestore/FIRFieldPath.h" #import "FirebaseFirestore/FIRFirestore.h" #import "FirebaseFirestore/FIRGeoPoint.h" #import "FirebaseFirestore/FIRQuerySnapshot.h" #import "FirebaseFirestore/FIRSnapshotMetadata.h" +#import "Firestore/Source/API/FIRCollectionReference+Internal.h" +#import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" @@ -54,21 +58,6 @@ static const int kMicrosPerSec = 1000000; static const int kMillisPerSec = 1000; -FIRFirestore *FSTTestFirestore() { - static FIRFirestore *sharedInstance = nil; - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - sharedInstance = [[FIRFirestore alloc] initWithProjectID:@"abc" - database:@"abc" - persistenceKey:@"db123" - credentialsProvider:nil - workerDispatchQueue:nil - firebaseApp:nil]; - }); - return sharedInstance; -} - FSTTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) { NSDate *date = FSTTestDate(year, month, day, hour, minute, second); return [FSTTimestamp timestampWithDate:date]; @@ -96,10 +85,6 @@ return [data copy]; } -FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude) { - return [[FIRGeoPoint alloc] initWithLatitude:latitude longitude:longitude]; -} - NSDateComponents *FSTTestDateComponents( int year, int month, int day, int hour, int minute, int second) { NSDateComponents *comps = [[NSDateComponents alloc] init]; @@ -169,19 +154,6 @@ hasLocalMutations:hasMutations]; } -FIRDocumentSnapshot *FSTTestDocSnapshot( - NSString *path, - FSTTestSnapshotVersion version, - NSDictionary *data, - BOOL hasMutations, - BOOL fromCache) { - FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil; - return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore() - documentKey:FSTTestDocKey(path) - document:doc - fromCache:fromCache]; -} - FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version) { FSTDocumentKey *key = FSTTestDocKey(path); return [FSTDeletedDocument documentWithKey:key version:FSTTestVersion(version)]; @@ -208,40 +180,6 @@ return [FSTQuery queryWithPath:FSTTestPath(path)]; } -/** A convenience method for creating a query snapshots for tests. */ -FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, - NSArray *> *oldData, - NSArray *> *dataToAdd, - BOOL hasPendingWrites, - BOOL fromCache) { - FIRSnapshotMetadata *metadata = [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites - fromCache:fromCache]; - FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); - for (NSDictionary *data in oldData) { - oldDocuments = [oldDocuments documentSetByAddingDocument:FSTTestDoc(path, 1, data, hasPendingWrites)]; - } - FSTDocumentSet *newDocuments = oldDocuments; - NSArray *documentChanges = [NSArray array]; - for (NSDictionary *data in dataToAdd) { - FSTDocument *docToAdd = FSTTestDoc(path, 1, data, hasPendingWrites); - newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; - documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange changeWithDocument:docToAdd type:FSTDocumentViewChangeTypeAdded]]; - } - FSTViewSnapshot *viewSnapshot = - [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) - documents:newDocuments - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:fromCache - hasPendingWrites:hasPendingWrites - syncStateChanged:YES]; - return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() - originalQuery:FSTTestQuery(path) - snapshot:viewSnapshot - metadata:metadata]; -} - id FSTTestFilter(NSString *field, NSString *opString, id value) { FSTFieldPath *path = FSTTestFieldPath(field); FSTRelationFilterOperator op; diff --git a/Firestore/Source/API/FIRDocumentSnapshot.m b/Firestore/Source/API/FIRDocumentSnapshot.m index 2ace30a4097..7d90f32ac85 100644 --- a/Firestore/Source/API/FIRDocumentSnapshot.m +++ b/Firestore/Source/API/FIRDocumentSnapshot.m @@ -93,7 +93,7 @@ - (BOOL)isEqualToSnapshot:(nullable FIRDocumentSnapshot *)snapshot { if (self.internalKey != snapshot.internalKey && ![self.internalKey isEqual:snapshot.internalKey]) return NO; if (self.internalDocument != snapshot.internalDocument && - (!self.internalDocument || ![self.internalDocument isEqual:snapshot.internalDocument])) + ![self.internalDocument isEqual:snapshot.internalDocument]) return NO; if (self.fromCache != snapshot.fromCache) return NO; return YES; From 73f4c556420a42d208b785ab04fa42b011e04dff Mon Sep 17 00:00:00 2001 From: zxu123 Date: Mon, 18 Dec 2017 16:58:06 -0500 Subject: [PATCH 14/18] a file forgot in last commit --- .../Example/Tests/Remote/FSTSerializerBetaTests.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m index 36c301c35d4..61847b0e197 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.m @@ -44,6 +44,7 @@ #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTWatchChange.h" +#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -266,7 +267,8 @@ - (void)testEncodesNestedObjects { @"i" : @1, @"n" : [NSNull null], @"s" : @"foo", - @"a" : @[ @2, @"bar", @{@"b" : @NO} ], + @"a" : @[ @2, @"bar", + @{ @"b" : @NO } ], @"o" : @{ @"d" : @100, @"nested" : @{@"e" : @(LLONG_MIN)}, @@ -471,8 +473,7 @@ - (void)testEncodesNestedAncestorQueries { } - (void)testEncodesSingleFiltersAtFirstLevelCollections { - FSTQuery *q = [FSTTestQuery(@"docs") - queryByAddingFilter:FSTTestFilter(@"prop", @"<", @(42))]; + FSTQuery *q = [FSTTestQuery(@"docs") queryByAddingFilter:FSTTestFilter(@"prop", @"<", @(42))]; FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -546,8 +547,7 @@ - (void)testEncodesNanFilter { - (void)unaryFilterTestWithValue:(id)value expectedUnaryOperator:(GCFSStructuredQuery_UnaryFilter_Operator) operator{ - FSTQuery *q = [FSTTestQuery(@"docs") - queryByAddingFilter:FSTTestFilter(@"prop", @"==", value)]; + FSTQuery *q = [FSTTestQuery(@"docs") queryByAddingFilter:FSTTestFilter(@"prop", @"==", value)]; FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; From 0df38d839654b48e86e35f0d8d49df8bdeacb89f Mon Sep 17 00:00:00 2001 From: zxu123 Date: Tue, 19 Dec 2017 12:11:58 -0500 Subject: [PATCH 15/18] mainly clean up import and some minor refactoring --- .../Firestore.xcodeproj/project.pbxproj | 2 - .../Tests/API/FIRDocumentSnapshotTests.m | 5 -- .../Example/Tests/API/FIRFieldValueTests.m | 4 +- .../Example/Tests/API/FIRGeoPointTests.m | 16 ++--- .../Example/Tests/API/FIRQuerySnapshotTests.m | 6 -- Firestore/Example/Tests/API/FIRQueryTests.m | 1 - .../Tests/API/FIRSnapshotMetadataTests.m | 2 - Firestore/Example/Tests/API/FSTAPIHelpers.h | 60 ++++++------------- Firestore/Example/Tests/API/FSTAPIHelpers.m | 44 ++++---------- Firestore/Example/Tests/Util/FSTHelpers.h | 12 ++-- Firestore/Example/Tests/Util/FSTHelpers.m | 20 ++----- 11 files changed, 43 insertions(+), 129 deletions(-) diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index b7bf6f384db..5b34f19185c 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -70,7 +70,6 @@ AB99452E1FE30AC800DFC1E6 /* FIRFieldValueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AB99452D1FE30AC800DFC1E6 /* FIRFieldValueTests.m */; }; ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; ABF341051FE860CA00C48322 /* FSTAPIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF341021FE8593500C48322 /* FSTAPIHelpers.m */; }; - ABF341061FE860CB00C48322 /* FSTAPIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF341021FE8593500C48322 /* FSTAPIHelpers.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */; }; @@ -1274,7 +1273,6 @@ 54E9282D1F339CAD00C1953E /* XCTestCase+Await.m in Sources */, DE03B2EC1F214BA200A30B9C /* FSTDatastoreTests.m in Sources */, 54E928251F33953400C1953E /* FSTEventAccumulator.m in Sources */, - ABF341061FE860CB00C48322 /* FSTAPIHelpers.m in Sources */, DE03B2ED1F214BA200A30B9C /* FSTSmokeTests.m in Sources */, DE03B2F31F214BAA00A30B9C /* FIRQueryTests.m in Sources */, DE03B35E1F21586C00A30B9C /* FSTHelpers.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index 74cce5fc335..b0f61827a78 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -17,11 +17,6 @@ #import #import "FirebaseFirestore/FIRDocumentSnapshot.h" -#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" -#import "Firestore/Source/Core/FSTSnapshotVersion.h" -#import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" diff --git a/Firestore/Example/Tests/API/FIRFieldValueTests.m b/Firestore/Example/Tests/API/FIRFieldValueTests.m index 862e965b594..8c9db99cb0b 100644 --- a/Firestore/Example/Tests/API/FIRFieldValueTests.m +++ b/Firestore/Example/Tests/API/FIRFieldValueTests.m @@ -18,9 +18,7 @@ #import -#import "Firestore/Source/API/FIRFieldValue+Internal.h" - -#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" +#import "FirebaseFirestore/FIRFieldValue.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/API/FIRGeoPointTests.m b/Firestore/Example/Tests/API/FIRGeoPointTests.m index 9ea31bd7818..8abda108bbb 100644 --- a/Firestore/Example/Tests/API/FIRGeoPointTests.m +++ b/Firestore/Example/Tests/API/FIRGeoPointTests.m @@ -18,7 +18,6 @@ #import -#import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" NS_ASSUME_NONNULL_BEGIN @@ -29,24 +28,17 @@ @interface FIRGeoPointTests : XCTestCase @implementation FIRGeoPointTests - (void)testEquals { - FIRGeoPoint *foo = FSTTestGeoPoint(0, 0); - FIRGeoPoint *fooDup = FSTTestGeoPoint(0, 0); - FIRGeoPoint *bar = FSTTestGeoPoint(1.23, 4.56); - FIRGeoPoint *barDup = FSTTestGeoPoint(1.23, 4.56); - FIRGeoPoint *differentLatitude = FSTTestGeoPoint(1, 0); - FIRGeoPoint *differentLongitude = FSTTestGeoPoint(0, 1); - NSObject *object = [[NSObject alloc] init]; + FIRGeoPoint *foo = FSTTestGeoPoint(1.23, 4.56); + FIRGeoPoint *fooDup = FSTTestGeoPoint(1.23, 4.56); + FIRGeoPoint *differentLatitude = FSTTestGeoPoint(1.23, 0); + FIRGeoPoint *differentLongitude = FSTTestGeoPoint(0, 4.56); XCTAssertEqualObjects(foo, fooDup); - XCTAssertEqualObjects(bar, barDup); XCTAssertNotEqualObjects(foo, differentLatitude); XCTAssertNotEqualObjects(foo, differentLongitude); - XCTAssertNotEqualObjects(foo, object); XCTAssertEqual([foo hash], [fooDup hash]); - XCTAssertEqual([bar hash], [barDup hash]); XCTAssertNotEqual([foo hash], [differentLatitude hash]); XCTAssertNotEqual([foo hash], [differentLongitude hash]); - XCTAssertNotEqual([foo hash], [object hash]); } - (void)testComparison { diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m index 987c7d51cf4..4637c497dfc 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.m @@ -17,12 +17,6 @@ #import #import "FirebaseFirestore/FIRQuerySnapshot.h" -#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" -#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" -#import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Core/FSTViewSnapshot.h" -#import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m index 35f36a070ed..1b5236d21b5 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.m +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -22,7 +22,6 @@ #import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m index 2c8d4291d1a..cf507657d6e 100644 --- a/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m +++ b/Firestore/Example/Tests/API/FIRSnapshotMetadataTests.m @@ -19,8 +19,6 @@ #import "FirebaseFirestore/FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" - NS_ASSUME_NONNULL_BEGIN @interface FIRSnapshotMetadataTests : XCTestCase diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index f369d201901..2220cf61720 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -16,43 +16,13 @@ #import -#import "Firestore/Source/API/FIRDocumentReference+Internal.h" -#import "Firestore/Source/Core/FSTTypes.h" -#import "Firestore/Source/Model/FSTDocumentDictionary.h" -#import "Firestore/Source/Model/FSTDocumentKeySet.h" +#import "FirebaseFirestore/FIRCollectionReference.h" +#import "FirebaseFirestore/FIRDocumentSnapshot.h" +#import "FirebaseFirestore/FIRFirestore.h" +#import "FirebaseFirestore/FIRQuerySnapshot.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" -@class FIRCollectionReference; -@class FIRDocumentReference; -@class FIRDocumentSnapshot; -@class FIRFirestore; -@class FIRGeoPoint; -@class FIRQuerySnapshot; -@class FSTDeleteMutation; -@class FSTDeletedDocument; -@class FSTDocument; -@class FSTDocumentKeyReference; -@class FSTDocumentSet; -@class FSTFieldPath; -@class FSTFieldValue; -@class FSTLocalViewChanges; -@class FSTPatchMutation; -@class FSTQuery; -@class FSTRemoteEvent; -@class FSTResourceName; -@class FSTResourcePath; -@class FSTSetMutation; -@class FSTSnapshotVersion; -@class FSTSortOrder; -@class FSTTargetChange; -@class FSTTimestamp; -@class FSTTransformMutation; -@class FSTView; -@class FSTViewSnapshot; -@class FSTObjectValue; -@protocol FSTFilter; - NS_ASSUME_NONNULL_BEGIN #if __cplusplus @@ -62,9 +32,6 @@ extern "C" { /** A convenience method for creating dummy singleton FIRFirestore for tests. */ FIRFirestore *FSTTestFirestore(); -/** Creates a new GeoPoint from the latitude and longitude values */ -FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); - /** A convenience method for creating a doc snapshot for tests. */ FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, FSTTestSnapshotVersion version, @@ -72,21 +39,28 @@ FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, BOOL hasMutations, BOOL fromCache); -/** A covenience method for creating a collection reference from a path string. */ +/** A convenience method for creating a collection reference from a path string. */ FIRCollectionReference *FSTTestCollectionRef(NSString *path); -/** A covenience method for creating a document reference from a path string. */ +/** A convenience method for creating a document reference from a path string. */ FIRDocumentReference *FSTTestDocRef(NSString *path); /** * A convenience method for creating a particular query snapshot for tests. - * This function allows user to pass in snapshot of the query in the past as well as new rows to be - * added into the snapshot as for now. The current snapshot of the query consists both data. + * + * @param path To be used in constructing the query. + * @param oldDocs Provides data to construct the query snapshot in the past. It maps each key to a document. The key + * is the document's path relative to the query path. + * @param DocsToAdd Specifies data to be added into the query snapshot as of now. It maps each key to a document. The + * key is the document's path relative to the query path. + * @param hasPendingWrites Whether the query snapshot has pending writes to the server. + * @param fromCache Whether the query snapshot is cache result. + * @returns A query snapshot that consists of both sets of documents. */ FIRQuerySnapshot *FSTTestQuerySnapshot( NSString *path, - NSDictionary *> *oldData, - NSDictionary *> *dataToAdd, + NSDictionary *> *oldDocs, + NSDictionary *> *DocsToAdd, BOOL hasPendingWrites, BOOL fromCache); diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.m b/Firestore/Example/Tests/API/FSTAPIHelpers.m index 6f61b5a166d..f2f6e531602 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.m +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.m @@ -15,41 +15,21 @@ */ #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" -#import -#import -#import -#import -#import "Firestore/Example/Tests/Util/FSTHelpers.h" -#import "FirebaseFirestore/FIRCollectionReference.h" #import "FirebaseFirestore/FIRDocumentReference.h" -#import "FirebaseFirestore/FIRDocumentSnapshot.h" -#import "FirebaseFirestore/FIRFieldPath.h" -#import "FirebaseFirestore/FIRFirestore.h" -#import "FirebaseFirestore/FIRGeoPoint.h" -#import "FirebaseFirestore/FIRQuerySnapshot.h" #import "FirebaseFirestore/FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRCollectionReference+Internal.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" -#import "Firestore/Source/API/FIRFieldPath+Internal.h" +#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FSTUserDataConverter.h" +#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h" +#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" #import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Core/FSTSnapshotVersion.h" -#import "Firestore/Source/Core/FSTTimestamp.h" -#import "Firestore/Source/Core/FSTView.h" -#import "Firestore/Source/Local/FSTLocalViewChanges.h" -#import "Firestore/Source/Local/FSTQueryData.h" -#import "Firestore/Source/Model/FSTDatabaseID.h" +#import "Firestore/Source/Core/FSTViewSnapshot.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTPath.h" -#import "Firestore/Source/Remote/FSTRemoteEvent.h" -#import "Firestore/Source/Remote/FSTWatchChange.h" -#import "Firestore/Source/Util/FSTAssert.h" NS_ASSUME_NONNULL_BEGIN @@ -68,10 +48,6 @@ return sharedInstance; } -FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude) { - return [[FIRGeoPoint alloc] initWithLatitude:latitude longitude:longitude]; -} - FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, FSTTestSnapshotVersion version, NSDictionary *data, @@ -95,23 +71,23 @@ /** A convenience method for creating a query snapshots for tests. */ FIRQuerySnapshot *FSTTestQuerySnapshot( NSString *path, - NSDictionary *> *oldData, - NSDictionary *> *dataToAdd, + NSDictionary *> *oldDocs, + NSDictionary *> *DocsToAdd, BOOL hasPendingWrites, BOOL fromCache) { FIRSnapshotMetadata *metadata = [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites fromCache:fromCache]; FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); - for (NSString *key in oldData) { + for (NSString *key in oldDocs) { oldDocuments = [oldDocuments documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - oldData[key], hasPendingWrites)]; + oldDocs[key], hasPendingWrites)]; } FSTDocumentSet *newDocuments = oldDocuments; NSArray *documentChanges = [NSArray array]; - for (NSString *key in dataToAdd) { + for (NSString *key in DocsToAdd) { FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - dataToAdd[key], hasPendingWrites); + DocsToAdd[key], hasPendingWrites); newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index ec51d0513c7..04450f61a38 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -16,17 +16,11 @@ #import -#import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKeySet.h" -@class FIRCollectionReference; -@class FIRDocumentReference; -@class FIRDocumentSnapshot; -@class FIRFirestore; @class FIRGeoPoint; -@class FIRQuerySnapshot; @class FSTDeleteMutation; @class FSTDeletedDocument; @class FSTDocument; @@ -38,7 +32,6 @@ @class FSTPatchMutation; @class FSTQuery; @class FSTRemoteEvent; -@class FSTResourceName; @class FSTResourcePath; @class FSTSetMutation; @class FSTSnapshotVersion; @@ -150,6 +143,11 @@ NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int seco */ NSData *FSTTestData(int bytes, ...); +// Note that FIRGeoPoint is a model class in addition to an API class, so we put this helper here instead of +// FSTAPIHelpers.h +/** Creates a new GeoPoint from the latitude and longitude values */ +FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); + /** * Creates a new NSDateComponents from components. Note that year, month, and day are all * one-based. diff --git a/Firestore/Example/Tests/Util/FSTHelpers.m b/Firestore/Example/Tests/Util/FSTHelpers.m index 400ab6ef952..f2b3605e550 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.m +++ b/Firestore/Example/Tests/Util/FSTHelpers.m @@ -15,28 +15,16 @@ */ #import "Firestore/Example/Tests/Util/FSTHelpers.h" -#import -#import -#import -#import - -#import "FirebaseFirestore/FIRCollectionReference.h" -#import "FirebaseFirestore/FIRDocumentReference.h" -#import "FirebaseFirestore/FIRDocumentSnapshot.h" + #import "FirebaseFirestore/FIRFieldPath.h" -#import "FirebaseFirestore/FIRFirestore.h" #import "FirebaseFirestore/FIRGeoPoint.h" -#import "FirebaseFirestore/FIRQuerySnapshot.h" -#import "FirebaseFirestore/FIRSnapshotMetadata.h" -#import "Firestore/Source/API/FIRCollectionReference+Internal.h" -#import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" -#import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Core/FSTTimestamp.h" #import "Firestore/Source/Core/FSTView.h" +#import "Firestore/Source/Core/FSTViewSnapshot.h" #import "Firestore/Source/Local/FSTLocalViewChanges.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Model/FSTDatabaseID.h" @@ -85,6 +73,10 @@ return [data copy]; } +FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude) { + return [[FIRGeoPoint alloc] initWithLatitude:latitude longitude:longitude]; +} + NSDateComponents *FSTTestDateComponents( int year, int month, int day, int hour, int minute, int second) { NSDateComponents *comps = [[NSDateComponents alloc] init]; From a2fc4a0a211c71d1c28600d04710ad2b0b7c745a Mon Sep 17 00:00:00 2001 From: zxu123 Date: Tue, 19 Dec 2017 12:13:18 -0500 Subject: [PATCH 16/18] fix style via style.sh --- Firestore/Example/Tests/API/FSTAPIHelpers.h | 8 ++++---- Firestore/Example/Tests/Util/FSTHelpers.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index 2220cf61720..fad0a18c2a0 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -49,10 +49,10 @@ FIRDocumentReference *FSTTestDocRef(NSString *path); * A convenience method for creating a particular query snapshot for tests. * * @param path To be used in constructing the query. - * @param oldDocs Provides data to construct the query snapshot in the past. It maps each key to a document. The key - * is the document's path relative to the query path. - * @param DocsToAdd Specifies data to be added into the query snapshot as of now. It maps each key to a document. The - * key is the document's path relative to the query path. + * @param oldDocs Provides data to construct the query snapshot in the past. It maps each key to a + * document. The key is the document's path relative to the query path. + * @param DocsToAdd Specifies data to be added into the query snapshot as of now. It maps each key + * to a document. The key is the document's path relative to the query path. * @param hasPendingWrites Whether the query snapshot has pending writes to the server. * @param fromCache Whether the query snapshot is cache result. * @returns A query snapshot that consists of both sets of documents. diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index 04450f61a38..4dbf91011d6 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -143,8 +143,8 @@ NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int seco */ NSData *FSTTestData(int bytes, ...); -// Note that FIRGeoPoint is a model class in addition to an API class, so we put this helper here instead of -// FSTAPIHelpers.h +// Note that FIRGeoPoint is a model class in addition to an API class, so we put this helper here +// instead of FSTAPIHelpers.h /** Creates a new GeoPoint from the latitude and longitude values */ FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); From 5714e7de3b54815fea54e9079f204d2d19e32624 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Tue, 19 Dec 2017 12:59:23 -0500 Subject: [PATCH 17/18] minor style fix --- Firestore/Example/Tests/API/FSTAPIHelpers.h | 12 +++++++----- Firestore/Example/Tests/API/FSTAPIHelpers.m | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index fad0a18c2a0..dcd8209c9b0 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -49,10 +49,12 @@ FIRDocumentReference *FSTTestDocRef(NSString *path); * A convenience method for creating a particular query snapshot for tests. * * @param path To be used in constructing the query. - * @param oldDocs Provides data to construct the query snapshot in the past. It maps each key to a - * document. The key is the document's path relative to the query path. - * @param DocsToAdd Specifies data to be added into the query snapshot as of now. It maps each key - * to a document. The key is the document's path relative to the query path. + * @param oldDocs Provides the prior set of documents in the QuerySnapshot. Each dictionary entry + * maps to a document, with the key being the document id, and the value being the document + * contents. + * @param docsToAdd Specifies data to be added into the query snapshot as of now. Each dictionary + * entry maps to a document, with the key being the document id, and the value being the document + * contents. * @param hasPendingWrites Whether the query snapshot has pending writes to the server. * @param fromCache Whether the query snapshot is cache result. * @returns A query snapshot that consists of both sets of documents. @@ -60,7 +62,7 @@ FIRDocumentReference *FSTTestDocRef(NSString *path); FIRQuerySnapshot *FSTTestQuerySnapshot( NSString *path, NSDictionary *> *oldDocs, - NSDictionary *> *DocsToAdd, + NSDictionary *> *docsToAdd, BOOL hasPendingWrites, BOOL fromCache); diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.m b/Firestore/Example/Tests/API/FSTAPIHelpers.m index f2f6e531602..ce0a890c69d 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.m +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.m @@ -72,7 +72,7 @@ FIRQuerySnapshot *FSTTestQuerySnapshot( NSString *path, NSDictionary *> *oldDocs, - NSDictionary *> *DocsToAdd, + NSDictionary *> *docsToAdd, BOOL hasPendingWrites, BOOL fromCache) { FIRSnapshotMetadata *metadata = @@ -85,9 +85,9 @@ } FSTDocumentSet *newDocuments = oldDocuments; NSArray *documentChanges = [NSArray array]; - for (NSString *key in DocsToAdd) { + for (NSString *key in docsToAdd) { FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - DocsToAdd[key], hasPendingWrites); + docsToAdd[key], hasPendingWrites); newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange From 3fbd94d007e42fa24ee00f326a009bc78a368980 Mon Sep 17 00:00:00 2001 From: zxu123 Date: Tue, 19 Dec 2017 13:08:50 -0500 Subject: [PATCH 18/18] add pragma ignored -Wnonnull --- Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m | 3 +++ Firestore/Example/Tests/API/FSTAPIHelpers.m | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m index b0f61827a78..e865928b383 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.m @@ -30,8 +30,11 @@ @implementation FIRDocumentSnapshotTests - (void)testEquals { FIRDocumentSnapshot *base = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonnull" FIRDocumentSnapshot *nilData = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); +#pragma clang diagnostic pop FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO); FIRDocumentSnapshot *differentData = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"b" : @1 }, NO, NO); FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, YES, NO); diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.m b/Firestore/Example/Tests/API/FSTAPIHelpers.m index ce0a890c69d..507e2ff72ea 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.m +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.m @@ -37,6 +37,8 @@ static FIRFirestore *sharedInstance = nil; static dispatch_once_t onceToken; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonnull" dispatch_once(&onceToken, ^{ sharedInstance = [[FIRFirestore alloc] initWithProjectID:@"abc" database:@"abc" @@ -45,6 +47,7 @@ workerDispatchQueue:nil firebaseApp:nil]; }); +#pragma clang diagnostic pop return sharedInstance; }