diff options
author | zxu <zxu@google.com> | 2018-03-14 08:57:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 08:57:31 -0400 |
commit | 9e815620e9f7f43b42e03db4e5118d7ad03ddee7 (patch) | |
tree | 86f362bad99281325fca7ee3ae116b6a0f36d511 /Firestore/Example | |
parent | d4d73ea53ecdf1e8ade3d00921419645dd5d66f7 (diff) |
grand PR to port the remaining paths (FieldPath and ResourcePath). (#865)
* naively remove FSTPath import and source/test files.
* port FieldPath, part I
* port FieldPath, part II
* port ResourcePath, part I
* port ResourcePath, part II
* the grand commit to fix build errors
* use testutil:: helper instead of those from FSTHelpers
* fix test and lint
* use c_str in errmsg directly
* fix
* fix
* make code clean
* fix integration test I missed
* fix to avoid naming collision in preprocessor
* address changes
* address changes
* address changes
* fix: fieldMask are actually shared with different context.
* address changes
* address changes
Diffstat (limited to 'Firestore/Example')
30 files changed, 368 insertions, 577 deletions
diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 92b4b7b..3b1c328 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -98,7 +98,6 @@ 5492E0B12021552D00B64F25 /* FSTRemoteDocumentCacheTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E09C2021552D00B64F25 /* FSTRemoteDocumentCacheTests.mm */; }; 5492E0B92021555100B64F25 /* FSTDocumentKeyTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B22021555000B64F25 /* FSTDocumentKeyTests.mm */; }; 5492E0BA2021555100B64F25 /* FSTDocumentSetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B32021555100B64F25 /* FSTDocumentSetTests.mm */; }; - 5492E0BC2021555100B64F25 /* FSTPathTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B52021555100B64F25 /* FSTPathTests.mm */; }; 5492E0BD2021555100B64F25 /* FSTDocumentTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B62021555100B64F25 /* FSTDocumentTests.mm */; }; 5492E0BE2021555100B64F25 /* FSTMutationTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B72021555100B64F25 /* FSTMutationTests.mm */; }; 5492E0BF2021555100B64F25 /* FSTFieldValueTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0B82021555100B64F25 /* FSTFieldValueTests.mm */; }; @@ -313,7 +312,6 @@ 5492E09C2021552D00B64F25 /* FSTRemoteDocumentCacheTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTRemoteDocumentCacheTests.mm; sourceTree = "<group>"; }; 5492E0B22021555000B64F25 /* FSTDocumentKeyTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTDocumentKeyTests.mm; sourceTree = "<group>"; }; 5492E0B32021555100B64F25 /* FSTDocumentSetTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTDocumentSetTests.mm; sourceTree = "<group>"; }; - 5492E0B52021555100B64F25 /* FSTPathTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTPathTests.mm; sourceTree = "<group>"; }; 5492E0B62021555100B64F25 /* FSTDocumentTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTDocumentTests.mm; sourceTree = "<group>"; }; 5492E0B72021555100B64F25 /* FSTMutationTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTMutationTests.mm; sourceTree = "<group>"; }; 5492E0B82021555100B64F25 /* FSTFieldValueTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTFieldValueTests.mm; sourceTree = "<group>"; }; @@ -758,7 +756,6 @@ 5492E0B62021555100B64F25 /* FSTDocumentTests.mm */, 5492E0B82021555100B64F25 /* FSTFieldValueTests.mm */, 5492E0B72021555100B64F25 /* FSTMutationTests.mm */, - 5492E0B52021555100B64F25 /* FSTPathTests.mm */, ); path = Model; sourceTree = "<group>"; @@ -1466,7 +1463,6 @@ B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */, 5492E0CA2021557E00B64F25 /* FSTWatchChangeTests.mm in Sources */, 5492E063202154B900B64F25 /* FSTViewSnapshotTest.mm in Sources */, - 5492E0BC2021555100B64F25 /* FSTPathTests.mm in Sources */, 5492E0B02021552D00B64F25 /* FSTWriteGroupTests.mm in Sources */, 5492E058202154AB00B64F25 /* FSTAPIHelpers.mm in Sources */, AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */, diff --git a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.mm b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.mm index 547078f..cb99d24 100644 --- a/Firestore/Example/Tests/API/FIRCollectionReferenceTests.mm +++ b/Firestore/Example/Tests/API/FIRCollectionReferenceTests.mm @@ -28,9 +28,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRCollectionReferenceTests - (void)testEquals { - FIRCollectionReference *referenceFoo = FSTTestCollectionRef(@"foo"); - FIRCollectionReference *referenceFooDup = FSTTestCollectionRef(@"foo"); - FIRCollectionReference *referenceBar = FSTTestCollectionRef(@"bar"); + 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.mm b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.mm index cc2b431..4124cd0 100644 --- a/Firestore/Example/Tests/API/FIRDocumentReferenceTests.mm +++ b/Firestore/Example/Tests/API/FIRDocumentReferenceTests.mm @@ -28,9 +28,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRDocumentReferenceTests - (void)testEquals { - FIRDocumentReference *referenceFoo = FSTTestDocRef(@"rooms/foo"); - FIRDocumentReference *referenceFooDup = FSTTestDocRef(@"rooms/foo"); - FIRDocumentReference *referenceBar = FSTTestDocRef(@"rooms/bar"); + 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/FIRFieldPathTests.mm b/Firestore/Example/Tests/API/FIRFieldPathTests.mm index 679ea89..50d37c1 100644 --- a/Firestore/Example/Tests/API/FIRFieldPathTests.mm +++ b/Firestore/Example/Tests/API/FIRFieldPathTests.mm @@ -19,10 +19,13 @@ #import <XCTest/XCTest.h> #import "Firestore/Source/API/FIRFieldPath+Internal.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; + NS_ASSUME_NONNULL_BEGIN @interface FIRFieldPathTests : XCTestCase @@ -31,9 +34,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRFieldPathTests - (void)testEquals { - 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")]; + FIRFieldPath *foo = [[FIRFieldPath alloc] initPrivate:testutil::Field("foo.ooo.oooo")]; + FIRFieldPath *fooDup = [[FIRFieldPath alloc] initPrivate:testutil::Field("foo.ooo.oooo")]; + FIRFieldPath *bar = [[FIRFieldPath alloc] initPrivate:testutil::Field("baa.aaa.aaar")]; XCTAssertEqualObjects(foo, fooDup); XCTAssertNotEqualObjects(foo, bar); diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm index 067425a..bb8110b 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm @@ -18,8 +18,6 @@ #import <XCTest/XCTest.h> -#import "Firestore/Source/Model/FSTPath.h" - #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/API/FIRQueryTests.mm b/Firestore/Example/Tests/API/FIRQueryTests.mm index 83f90be..c02c92c 100644 --- a/Firestore/Example/Tests/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/API/FIRQueryTests.mm @@ -20,7 +20,6 @@ #import "Firestore/Source/API/FIRQuery+Internal.h" #import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" @@ -33,9 +32,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)testEquals { 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], @@ -53,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testFilteringWithPredicate { FIRFirestore *firestore = FSTTestFirestore(); - FIRQuery *query = [FIRQuery referenceWithQuery:FSTTestQuery(@"foo") 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/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index 0729af0..4edd7d5 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -41,10 +41,10 @@ FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, BOOL fromCache); /** A convenience method for creating a collection reference from a path string. */ -FIRCollectionReference *FSTTestCollectionRef(NSString *path); +FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path); /** A convenience method for creating a document reference from a path string. */ -FIRDocumentReference *FSTTestDocRef(NSString *path); +FIRDocumentReference *FSTTestDocRef(const absl::string_view path); /** * A convenience method for creating a particular query snapshot for tests. diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.mm b/Firestore/Example/Tests/API/FSTAPIHelpers.mm index d091842..c180dc4 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.mm +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.mm @@ -31,7 +31,12 @@ #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Model/FSTPath.h" + +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; +namespace util = firebase::firestore::util; NS_ASSUME_NONNULL_BEGIN @@ -65,12 +70,14 @@ FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, fromCache:fromCache]; } -FIRCollectionReference *FSTTestCollectionRef(NSString *path) { - return [FIRCollectionReference referenceWithPath:FSTTestPath(path) firestore:FSTTestFirestore()]; +FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path) { + return [FIRCollectionReference referenceWithPath:testutil::Resource(path) + firestore:FSTTestFirestore()]; } -FIRDocumentReference *FSTTestDocRef(NSString *path) { - return [FIRDocumentReference referenceWithPath:FSTTestPath(path) firestore:FSTTestFirestore()]; +FIRDocumentReference *FSTTestDocRef(const absl::string_view path) { + return [FIRDocumentReference referenceWithPath:testutil::Resource(path) + firestore:FSTTestFirestore()]; } /** A convenience method for creating a query snapshots for tests. */ @@ -99,15 +106,16 @@ FIRQuerySnapshot *FSTTestQuerySnapshot( changeWithDocument:docToAdd type:FSTDocumentViewChangeTypeAdded]]; } - FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) - documents:newDocuments - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:fromCache - hasPendingWrites:hasPendingWrites - syncStateChanged:YES]; + FSTViewSnapshot *viewSnapshot = + [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(util::MakeStringView(path)) + documents:newDocuments + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:fromCache + hasPendingWrites:hasPendingWrites + syncStateChanged:YES]; return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() - originalQuery:FSTTestQuery(path) + originalQuery:FSTTestQuery(util::MakeStringView(path)) snapshot:viewSnapshot metadata:metadata]; } diff --git a/Firestore/Example/Tests/Core/FSTEventManagerTests.mm b/Firestore/Example/Tests/Core/FSTEventManagerTests.mm index f5f7b5b..952d01f 100644 --- a/Firestore/Example/Tests/Core/FSTEventManagerTests.mm +++ b/Firestore/Example/Tests/Core/FSTEventManagerTests.mm @@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testHandlesManyListenersPerQuery { - FSTQuery *query = FSTTestQuery(@"foo/bar"); + FSTQuery *query = FSTTestQuery("foo/bar"); FSTQueryListener *listener1 = [self noopListenerForQuery:query]; FSTQueryListener *listener2 = [self noopListenerForQuery:query]; @@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testHandlesUnlistenOnUnknownListenerGracefully { - FSTQuery *query = FSTTestQuery(@"foo/bar"); + FSTQuery *query = FSTTestQuery("foo/bar"); FSTQueryListener *listener = [self noopListenerForQuery:query]; FSTSyncEngine *syncEngineMock = OCMStrictClassMock([FSTSyncEngine class]); @@ -95,8 +95,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testNotifiesListenersInTheRightOrder { - FSTQuery *query1 = FSTTestQuery(@"foo/bar"); - FSTQuery *query2 = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testWillForwardOnlineStateChanges { - FSTQuery *query = FSTTestQuery(@"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.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm index 1b26360..55c4219 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array]; NSMutableArray<FSTViewSnapshot *> *otherAccum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRaisesErrorEvent { NSMutableArray<NSError *> *accum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"rooms/Eros"); + FSTQuery *query = FSTTestQuery("rooms/Eros"); FSTQueryListener *listener = [self listenToQuery:query handler:^(FSTViewSnapshot *snapshot, NSError *error) { @@ -104,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRaisesEventForEmptyCollectionAfterSync { NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"rooms"); + FSTQuery *query = FSTTestQuery("rooms"); FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum]; @@ -126,7 +126,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testMutingAsyncListenerPreventsAllSubsequentEvents { NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array]; NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array]; NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges { NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadataChangesIsFalse { NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testWillWaitForSyncIfOnline { NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testWillRaiseInitialEventWhenGoingOffline { NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"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 @@ NS_ASSUME_NONNULL_BEGIN - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs { NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"rooms"); + FSTQuery *query = FSTTestQuery("rooms"); FSTQueryListener *listener = [self listenToQuery:query options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; @@ -437,7 +437,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs { NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array]; - FSTQuery *query = FSTTestQuery(@"rooms"); + FSTQuery *query = FSTTestQuery("rooms"); FSTQueryListener *listener = [self listenToQuery:query options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.mm b/Firestore/Example/Tests/Core/FSTQueryTests.mm index 5f6d279..8b5b524 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryTests.mm @@ -21,7 +21,6 @@ #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" @@ -30,6 +29,7 @@ #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +#include "absl/strings/string_view.h" namespace testutil = firebase::firestore::testutil; namespace util = firebase::firestore::util; @@ -41,16 +41,14 @@ NS_ASSUME_NONNULL_BEGIN /** Convenience methods for building test queries. */ @interface FSTQuery (Tests) -- (FSTQuery *)queryByAddingSortBy:(NSString *)key ascending:(BOOL)ascending; +- (FSTQuery *)queryByAddingSortBy:(const absl::string_view)key ascending:(BOOL)ascending; @end @implementation FSTQuery (Tests) -- (FSTQuery *)queryByAddingSortBy:(NSString *)key ascending:(BOOL)ascending { - return [self - queryByAddingSortOrder:[FSTSortOrder - sortOrderWithFieldPath:testutil::Field(util::MakeStringView(key)) - ascending:ascending]]; +- (FSTQuery *)queryByAddingSortBy:(const absl::string_view)key ascending:(BOOL)ascending { + return [self queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field(key) + ascending:ascending]]; } @end @@ -61,9 +59,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTQueryTests - (void)testConstructor { - FSTResourcePath *path = - [FSTResourcePath pathWithSegments:@[ @"rooms", @"Firestore", @"messages", @"0001" ]]; - FSTQuery *query = [FSTQuery queryWithPath:[path toCPPResourcePath]]; + const ResourcePath path{"rooms", "Firestore", "messages", "0001"}; + FSTQuery *query = [FSTQuery queryWithPath:path]; XCTAssertNotNil(query); XCTAssertEqual(query.sortOrders.count, 1); @@ -74,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testOrderBy { - FSTQuery *query = FSTTestQuery(@"rooms/Firestore/messages"); + FSTQuery *query = FSTTestQuery("rooms/Firestore/messages"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("length") ascending:NO]]; @@ -96,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // document query - FSTQuery *query = FSTTestQuery(@"rooms/eros/messages/1"); + FSTQuery *query = FSTTestQuery("rooms/eros/messages/1"); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); XCTAssertFalse([query matchesDocument:doc3]); @@ -109,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // shallow ancestor query - FSTQuery *query = FSTTestQuery(@"rooms/eros/messages"); + FSTQuery *query = FSTTestQuery("rooms/eros/messages"); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc1Meta]); XCTAssertTrue([query matchesDocument:doc2]); @@ -120,17 +117,17 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); - FSTQuery *query = [FSTTestQuery(@"rooms/eros/messages") - queryByAddingFilter:FSTTestFilter(@"text", @"==", @"msg1")]; + FSTQuery *query = [FSTTestQuery("rooms/eros/messages") + queryByAddingFilter:FSTTestFilter("text", @"==", @"msg1")]; XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); } - (void)testMatchesPrimitiveValuesForFilters { FSTQuery *query1 = - [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; + [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @">=", @(2))]; FSTQuery *query2 = - [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; + [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"<=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); @@ -155,8 +152,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testNullFilter { - FSTQuery *query = [FSTTestQuery(@"collection") - queryByAddingFilter:FSTTestFilter(@"sort", @"==", [NSNull null])]; + 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); FSTDocument *doc3 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @3.1 }, NO); @@ -172,7 +169,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testNanFilter { FSTQuery *query = - [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"==", @(NAN))]; + [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); @@ -188,9 +185,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)testDoesNotMatchComplexObjectsForFilters { FSTQuery *query1 = - [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @"<=", @(2))]; + [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"<=", @(2))]; FSTQuery *query2 = - [FSTTestQuery(@"collection") queryByAddingFilter:FSTTestFilter(@"sort", @">=", @(2))]; + [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @">=", @(2))]; FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @2 }, NO); FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @[] }, NO); @@ -218,7 +215,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testDoesntRemoveComplexObjectsWithOrderBy { - FSTQuery *query1 = [FSTTestQuery(@"collection") + FSTQuery *query1 = [FSTTestQuery("collection") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("sort") ascending:YES]]; @@ -238,16 +235,16 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testFiltersBasedOnArrayValue { - FSTQuery *baseQuery = FSTTestQuery(@"collection"); + FSTQuery *baseQuery = FSTTestQuery("collection"); FSTDocument *doc1 = FSTTestDoc(@"collection/doc", 0, @{ @"tags" : @[ @"foo", @1, @YES ] }, NO); NSArray<id<FSTFilter>> *matchingFilters = - @[ FSTTestFilter(@"tags", @"==", @[ @"foo", @1, @YES ]) ]; + @[ FSTTestFilter("tags", @"==", @[ @"foo", @1, @YES ]) ]; NSArray<id<FSTFilter>> *nonMatchingFilters = @[ - FSTTestFilter(@"tags", @"==", @"foo"), - FSTTestFilter(@"tags", @"==", @[ @"foo", @1 ]), - FSTTestFilter(@"tags", @"==", @[ @"foo", @YES, @1 ]), + FSTTestFilter("tags", @"==", @"foo"), + FSTTestFilter("tags", @"==", @[ @"foo", @1 ]), + FSTTestFilter("tags", @"==", @[ @"foo", @YES, @1 ]), ]; for (id<FSTFilter> filter in matchingFilters) { @@ -260,27 +257,27 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testFiltersBasedOnObjectValue { - FSTQuery *baseQuery = FSTTestQuery(@"collection"); + FSTQuery *baseQuery = FSTTestQuery("collection"); FSTDocument *doc1 = FSTTestDoc(@"collection/doc", 0, @{ @"tags" : @{@"foo" : @"foo", @"a" : @0, @"b" : @YES, @"c" : @(NAN)} }, NO); NSArray<id<FSTFilter>> *matchingFilters = @[ - FSTTestFilter(@"tags", @"==", + FSTTestFilter("tags", @"==", @{ @"foo" : @"foo", @"a" : @0, @"b" : @YES, @"c" : @(NAN) }), - FSTTestFilter(@"tags", @"==", + FSTTestFilter("tags", @"==", @{ @"b" : @YES, @"a" : @0, @"foo" : @"foo", @"c" : @(NAN) }), - FSTTestFilter(@"tags.foo", @"==", @"foo") + FSTTestFilter("tags.foo", @"==", @"foo") ]; NSArray<id<FSTFilter>> *nonMatchingFilters = @[ - FSTTestFilter(@"tags", @"==", @"foo"), FSTTestFilter(@"tags", @"==", @{ + FSTTestFilter("tags", @"==", @"foo"), FSTTestFilter("tags", @"==", @{ @"foo" : @"foo", @"a" : @0, @"b" : @YES, @@ -312,7 +309,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testSortsDocumentsInTheCorrectOrder { - FSTQuery *query = FSTTestQuery(@"collection"); + FSTQuery *query = FSTTestQuery("collection"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("sort") ascending:YES]]; @@ -340,7 +337,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testSortsDocumentsUsingMultipleFields { - FSTQuery *query = FSTTestQuery(@"collection"); + FSTQuery *query = FSTTestQuery("collection"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("sort1") ascending:YES]]; @@ -367,7 +364,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testSortsDocumentsWithDescendingToo { - FSTQuery *query = FSTTestQuery(@"collection"); + FSTQuery *query = FSTTestQuery("collection"); query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("sort1") ascending:NO]]; @@ -394,40 +391,40 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEquality { - FSTQuery *q11 = FSTTestQuery(@"foo"); - q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - FSTQuery *q12 = FSTTestQuery(@"foo"); - q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - - FSTQuery *q21 = FSTTestQuery(@"foo"); - FSTQuery *q22 = FSTTestQuery(@"foo"); - - FSTQuery *q31 = FSTTestQuery(@"foo/bar"); - FSTQuery *q32 = FSTTestQuery(@"foo/bar"); - - FSTQuery *q41 = FSTTestQuery(@"foo"); - q41 = [q41 queryByAddingSortBy:@"foo" ascending:YES]; - q41 = [q41 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q42 = FSTTestQuery(@"foo"); - q42 = [q42 queryByAddingSortBy:@"foo" ascending:YES]; - q42 = [q42 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q43Diff = FSTTestQuery(@"foo"); - q43Diff = [q43Diff queryByAddingSortBy:@"bar" ascending:YES]; - q43Diff = [q43Diff queryByAddingSortBy:@"foo" ascending:YES]; - - FSTQuery *q51 = FSTTestQuery(@"foo"); - q51 = [q51 queryByAddingSortBy:@"foo" ascending:YES]; - q51 = [q51 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - FSTQuery *q52 = FSTTestQuery(@"foo"); - q52 = [q52 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - q52 = [q52 queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q53Diff = FSTTestQuery(@"foo"); - q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter(@"bar", @">", @(2))]; - q53Diff = [q53Diff queryByAddingSortBy:@"bar" ascending:YES]; - - FSTQuery *q61 = FSTTestQuery(@"foo"); + FSTQuery *q11 = FSTTestQuery("foo"); + q11 = [q11 queryByAddingFilter:FSTTestFilter("i1", @"<", @(2))]; + q11 = [q11 queryByAddingFilter:FSTTestFilter("i2", @"==", @(3))]; + FSTQuery *q12 = FSTTestQuery("foo"); + q12 = [q12 queryByAddingFilter:FSTTestFilter("i2", @"==", @(3))]; + q12 = [q12 queryByAddingFilter:FSTTestFilter("i1", @"<", @(2))]; + + FSTQuery *q21 = FSTTestQuery("foo"); + FSTQuery *q22 = FSTTestQuery("foo"); + + FSTQuery *q31 = FSTTestQuery("foo/bar"); + FSTQuery *q32 = FSTTestQuery("foo/bar"); + + FSTQuery *q41 = FSTTestQuery("foo"); + q41 = [q41 queryByAddingSortBy:"foo" ascending:YES]; + q41 = [q41 queryByAddingSortBy:"bar" ascending:YES]; + FSTQuery *q42 = FSTTestQuery("foo"); + q42 = [q42 queryByAddingSortBy:"foo" ascending:YES]; + q42 = [q42 queryByAddingSortBy:"bar" ascending:YES]; + FSTQuery *q43Diff = FSTTestQuery("foo"); + q43Diff = [q43Diff queryByAddingSortBy:"bar" ascending:YES]; + q43Diff = [q43Diff queryByAddingSortBy:"foo" ascending:YES]; + + FSTQuery *q51 = FSTTestQuery("foo"); + q51 = [q51 queryByAddingSortBy:"foo" ascending:YES]; + q51 = [q51 queryByAddingFilter:FSTTestFilter("foo", @">", @(2))]; + FSTQuery *q52 = FSTTestQuery("foo"); + q52 = [q52 queryByAddingFilter:FSTTestFilter("foo", @">", @(2))]; + q52 = [q52 queryByAddingSortBy:"foo" ascending:YES]; + FSTQuery *q53Diff = FSTTestQuery("foo"); + q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter("bar", @">", @(2))]; + q53Diff = [q53Diff queryByAddingSortBy:"bar" ascending:YES]; + + FSTQuery *q61 = FSTTestQuery("foo"); q61 = [q61 queryBySettingLimit:10]; // XCTAssertEqualObjects(q11, q12); // TODO(klimt): not canonical yet @@ -459,40 +456,40 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testUniqueIds { - FSTQuery *q11 = FSTTestQuery(@"foo"); - q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - q11 = [q11 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - FSTQuery *q12 = FSTTestQuery(@"foo"); - q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i2", @"==", @(3))]; - q12 = [q12 queryByAddingFilter:FSTTestFilter(@"i1", @"<", @(2))]; - - FSTQuery *q21 = FSTTestQuery(@"foo"); - FSTQuery *q22 = FSTTestQuery(@"foo"); - - FSTQuery *q31 = FSTTestQuery(@"foo/bar"); - FSTQuery *q32 = FSTTestQuery(@"foo/bar"); - - FSTQuery *q41 = FSTTestQuery(@"foo"); - q41 = [q41 queryByAddingSortBy:@"foo" ascending:YES]; - q41 = [q41 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q42 = FSTTestQuery(@"foo"); - q42 = [q42 queryByAddingSortBy:@"foo" ascending:YES]; - q42 = [q42 queryByAddingSortBy:@"bar" ascending:YES]; - FSTQuery *q43Diff = FSTTestQuery(@"foo"); - q43Diff = [q43Diff queryByAddingSortBy:@"bar" ascending:YES]; - q43Diff = [q43Diff queryByAddingSortBy:@"foo" ascending:YES]; - - FSTQuery *q51 = FSTTestQuery(@"foo"); - q51 = [q51 queryByAddingSortBy:@"foo" ascending:YES]; - q51 = [q51 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - FSTQuery *q52 = FSTTestQuery(@"foo"); - q52 = [q52 queryByAddingFilter:FSTTestFilter(@"foo", @">", @(2))]; - q52 = [q52 queryByAddingSortBy:@"foo" ascending:YES]; - FSTQuery *q53Diff = FSTTestQuery(@"foo"); - q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter(@"bar", @">", @(2))]; - q53Diff = [q53Diff queryByAddingSortBy:@"bar" ascending:YES]; - - FSTQuery *q61 = FSTTestQuery(@"foo"); + FSTQuery *q11 = FSTTestQuery("foo"); + q11 = [q11 queryByAddingFilter:FSTTestFilter("i1", @"<", @(2))]; + q11 = [q11 queryByAddingFilter:FSTTestFilter("i2", @"==", @(3))]; + FSTQuery *q12 = FSTTestQuery("foo"); + q12 = [q12 queryByAddingFilter:FSTTestFilter("i2", @"==", @(3))]; + q12 = [q12 queryByAddingFilter:FSTTestFilter("i1", @"<", @(2))]; + + FSTQuery *q21 = FSTTestQuery("foo"); + FSTQuery *q22 = FSTTestQuery("foo"); + + FSTQuery *q31 = FSTTestQuery("foo/bar"); + FSTQuery *q32 = FSTTestQuery("foo/bar"); + + FSTQuery *q41 = FSTTestQuery("foo"); + q41 = [q41 queryByAddingSortBy:"foo" ascending:YES]; + q41 = [q41 queryByAddingSortBy:"bar" ascending:YES]; + FSTQuery *q42 = FSTTestQuery("foo"); + q42 = [q42 queryByAddingSortBy:"foo" ascending:YES]; + q42 = [q42 queryByAddingSortBy:"bar" ascending:YES]; + FSTQuery *q43Diff = FSTTestQuery("foo"); + q43Diff = [q43Diff queryByAddingSortBy:"bar" ascending:YES]; + q43Diff = [q43Diff queryByAddingSortBy:"foo" ascending:YES]; + + FSTQuery *q51 = FSTTestQuery("foo"); + q51 = [q51 queryByAddingSortBy:"foo" ascending:YES]; + q51 = [q51 queryByAddingFilter:FSTTestFilter("foo", @">", @(2))]; + FSTQuery *q52 = FSTTestQuery("foo"); + q52 = [q52 queryByAddingFilter:FSTTestFilter("foo", @">", @(2))]; + q52 = [q52 queryByAddingSortBy:"foo" ascending:YES]; + FSTQuery *q53Diff = FSTTestQuery("foo"); + q53Diff = [q53Diff queryByAddingFilter:FSTTestFilter("bar", @">", @(2))]; + q53Diff = [q53Diff queryByAddingSortBy:"bar" ascending:YES]; + + FSTQuery *q61 = FSTTestQuery("foo"); q61 = [q61 queryBySettingLimit:10]; // XCTAssertEqual(q11.hash, q12.hash); // TODO(klimt): not canonical yet @@ -524,52 +521,55 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testImplicitOrderBy { - FSTQuery *baseQuery = FSTTestQuery(@"foo"); + FSTQuery *baseQuery = FSTTestQuery("foo"); // Default is ascending - XCTAssertEqualObjects(baseQuery.sortOrders, @[ FSTTestOrderBy(kDocumentKeyPath, @"asc") ]); + XCTAssertEqualObjects(baseQuery.sortOrders, + @[ FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc") ]); // Explicit key ordering is respected XCTAssertEqualObjects( - [baseQuery queryByAddingSortOrder:FSTTestOrderBy(kDocumentKeyPath, @"asc")].sortOrders, - @[ FSTTestOrderBy(kDocumentKeyPath, @"asc") ]); + [baseQuery queryByAddingSortOrder:FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc")] + .sortOrders, + @[ FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc") ]); XCTAssertEqualObjects( - [baseQuery queryByAddingSortOrder:FSTTestOrderBy(kDocumentKeyPath, @"desc")].sortOrders, - @[ FSTTestOrderBy(kDocumentKeyPath, @"desc") ]); + [baseQuery queryByAddingSortOrder:FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc")] + .sortOrders, + @[ FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc") ]); XCTAssertEqualObjects( - [[baseQuery queryByAddingSortOrder:FSTTestOrderBy(@"foo", @"asc")] - queryByAddingSortOrder:FSTTestOrderBy(kDocumentKeyPath, @"asc")] + [[baseQuery queryByAddingSortOrder:FSTTestOrderBy("foo", @"asc")] + queryByAddingSortOrder:FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc")] .sortOrders, - (@[ FSTTestOrderBy(@"foo", @"asc"), FSTTestOrderBy(kDocumentKeyPath, @"asc") ])); + (@[ FSTTestOrderBy("foo", @"asc"), FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc") ])); XCTAssertEqualObjects( - [[baseQuery queryByAddingSortOrder:FSTTestOrderBy(@"foo", @"asc")] - queryByAddingSortOrder:FSTTestOrderBy(kDocumentKeyPath, @"desc")] + [[baseQuery queryByAddingSortOrder:FSTTestOrderBy("foo", @"asc")] + queryByAddingSortOrder:FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc")] .sortOrders, - (@[ FSTTestOrderBy(@"foo", @"asc"), FSTTestOrderBy(kDocumentKeyPath, @"desc") ])); + (@[ FSTTestOrderBy("foo", @"asc"), FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc") ])); // Inequality filters add order bys XCTAssertEqualObjects( - [baseQuery queryByAddingFilter:FSTTestFilter(@"foo", @"<", @5)].sortOrders, - (@[ FSTTestOrderBy(@"foo", @"asc"), FSTTestOrderBy(kDocumentKeyPath, @"asc") ])); + [baseQuery queryByAddingFilter:FSTTestFilter("foo", @"<", @5)].sortOrders, + (@[ FSTTestOrderBy("foo", @"asc"), FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc") ])); // Descending order by applies to implicit key ordering XCTAssertEqualObjects( - [baseQuery queryByAddingSortOrder:FSTTestOrderBy(@"foo", @"desc")].sortOrders, - (@[ FSTTestOrderBy(@"foo", @"desc"), FSTTestOrderBy(kDocumentKeyPath, @"desc") ])); - XCTAssertEqualObjects([[baseQuery queryByAddingSortOrder:FSTTestOrderBy(@"foo", @"asc")] - queryByAddingSortOrder:FSTTestOrderBy(@"bar", @"desc")] + [baseQuery queryByAddingSortOrder:FSTTestOrderBy("foo", @"desc")].sortOrders, + (@[ FSTTestOrderBy("foo", @"desc"), FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc") ])); + XCTAssertEqualObjects([[baseQuery queryByAddingSortOrder:FSTTestOrderBy("foo", @"asc")] + queryByAddingSortOrder:FSTTestOrderBy("bar", @"desc")] .sortOrders, (@[ - FSTTestOrderBy(@"foo", @"asc"), FSTTestOrderBy(@"bar", @"desc"), - FSTTestOrderBy(kDocumentKeyPath, @"desc") + FSTTestOrderBy("foo", @"asc"), FSTTestOrderBy("bar", @"desc"), + FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"desc") ])); - XCTAssertEqualObjects([[baseQuery queryByAddingSortOrder:FSTTestOrderBy(@"foo", @"desc")] - queryByAddingSortOrder:FSTTestOrderBy(@"bar", @"asc")] + XCTAssertEqualObjects([[baseQuery queryByAddingSortOrder:FSTTestOrderBy("foo", @"desc")] + queryByAddingSortOrder:FSTTestOrderBy("bar", @"asc")] .sortOrders, (@[ - FSTTestOrderBy(@"foo", @"desc"), FSTTestOrderBy(@"bar", @"asc"), - FSTTestOrderBy(kDocumentKeyPath, @"asc") + FSTTestOrderBy("foo", @"desc"), FSTTestOrderBy("bar", @"asc"), + FSTTestOrderBy(FieldPath::kDocumentKeyPath, @"asc") ])); } diff --git a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm index fe3e42d..c503684 100644 --- a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm +++ b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm @@ -21,7 +21,6 @@ #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" @@ -107,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testViewSnapshotConstructor { - FSTQuery *query = FSTTestQuery(@"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/Core/FSTViewTests.mm b/Firestore/Example/Tests/Core/FSTViewTests.mm index 7df8195..1e3ec1a 100644 --- a/Firestore/Example/Tests/Core/FSTViewTests.mm +++ b/Firestore/Example/Tests/Core/FSTViewTests.mm @@ -25,7 +25,6 @@ #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/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" diff --git a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm index 49e572a..0ad30fd 100644 --- a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm @@ -132,7 +132,7 @@ } - (void)testPathsWithEmptySegmentsFail { - // We're only testing using collectionWithPath since the validation happens in FSTPath which is + // We're only testing using collectionWithPath since the validation happens in BasePath which is // shared by all methods that accept paths. // leading / trailing slashes are okay. diff --git a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm index 77581d4..9ce3d30 100644 --- a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm +++ b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm @@ -31,7 +31,6 @@ #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTDatastore.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Source/Remote/FSTRemoteStore.h" diff --git a/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm index 998d23d..f23b7c5 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm @@ -18,10 +18,14 @@ #import <XCTest/XCTest.h> -#import "Firestore/Source/Model/FSTPath.h" - #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace util = firebase::firestore::util; +namespace testutil = firebase::firestore::testutil; + NS_ASSUME_NONNULL_BEGIN @interface FSTLevelDBKeyTests : XCTestCase @@ -37,7 +41,8 @@ static std::string RemoteDocKey(NSString *pathString) { } static std::string RemoteDocKeyPrefix(NSString *pathString) { - return [FSTLevelDBRemoteDocumentKey keyPrefixWithResourcePath:FSTTestPath(pathString)]; + return [FSTLevelDBRemoteDocumentKey + keyPrefixWithResourcePath:testutil::Resource(util::MakeStringView(pathString))]; } static std::string DocMutationKey(NSString *userID, NSString *key, FSTBatchID batchID) { @@ -199,7 +204,7 @@ static std::string DocTargetKey(NSString *key, FSTTargetID targetID) { @"[document_mutation: userID=user1 incomplete key]"); auto key = [FSTLevelDBDocumentMutationKey keyPrefixWithUserID:@"user1" - resourcePath:FSTTestPath(@"foo/bar")]; + resourcePath:testutil::Resource("foo/bar")]; FSTAssertExpectedKeyDescription(key, @"[document_mutation: userID=user1 key=foo/bar incomplete key]"); diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm index 1793b23..87242fa 100644 --- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm @@ -36,14 +36,15 @@ #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DatabaseId; NS_ASSUME_NONNULL_BEGIN @@ -77,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN FSTMutation *set = FSTTestSetMutation(@"foo/bar", @{ @"a" : @"b", @"num" : @1 }); FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:FSTTestDocKey(@"bar/baz") - fieldMask:[[FSTFieldMask alloc] initWithFields:@[ FSTTestFieldPath(@"a") ]] + fieldMask:[[FSTFieldMask alloc] initWithFields:{testutil::Field("a")}] value:FSTTestObjectValue( @{ @"a" : @"b", @"num" : @1 }) @@ -156,7 +157,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesQueryData { - FSTQuery *query = FSTTestQuery(@"room"); + FSTQuery *query = FSTTestQuery("room"); FSTTargetID targetID = 42; FSTSnapshotVersion *version = FSTTestVersion(1039); NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1039); diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm index 393f77b..5a386b6 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm @@ -30,7 +30,6 @@ #import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Source/Remote/FSTWatchChange.h" #import "Firestore/Source/Util/FSTClasses.h" @@ -263,7 +262,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, if ([self isTestBaseClass]) return; // Start a query that requires acks to be held. - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); [self allocateQuery:query]; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; @@ -342,7 +341,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testHandlesPatchWithoutPriorDocument { if ([self isTestBaseClass]) return; - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertNotContains(@"foo/bar"); @@ -354,7 +353,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testHandlesPatchMutationThenDocumentThenAck { if ([self isTestBaseClass]) return; - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertNotContains(@"foo/bar"); @@ -371,7 +370,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testHandlesPatchMutationThenAckThenDocument { if ([self isTestBaseClass]) return; - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertNotContains(@"foo/bar"); @@ -456,7 +455,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, YES) ]); FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, YES)); - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); @@ -479,7 +478,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutations:@[ FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}), - FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil) + FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {}) ]]; FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); @@ -493,7 +492,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self acknowledgeMutationWithVersion:1]; FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO)); - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self rejectMutation]; @@ -507,7 +506,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutations:@[ FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}), FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"}), - FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil) + FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {}) ]]; FSTAssertChanged((@[ @@ -525,7 +524,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); @@ -556,7 +555,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testCollectsGarbageAfterChangeBatch { if ([self isTestBaseClass]) return; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -577,7 +576,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO), @[ @1 ], @[])]; - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})]; [self writeMutation:FSTTestDeleteMutation(@"foo/baz")]; [self collectGarbage]; @@ -609,7 +608,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO), @[ @1 ], @[])]; - [self writeMutation:FSTTestPatchMutation(@"foo/bar", @{@"foo" : @"bar"}, nil)]; + [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})]; [self writeMutation:FSTTestDeleteMutation(@"foo/baz")]; [self collectGarbage]; @@ -639,7 +638,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testPinsDocumentsInTheLocalView { if ([self isTestBaseClass]) return; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -687,7 +686,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}), FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}) ]]; - FSTQuery *query = FSTTestQuery(@"foo/bar"); + FSTQuery *query = FSTTestQuery("foo/bar"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], @[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); } @@ -702,7 +701,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}), FSTTestSetMutation(@"fooo/blah", @{@"fooo" : @"blah"}) ]]; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], (@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES), @@ -713,7 +712,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testCanExecuteMixedCollectionQueries { if ([self isTestBaseClass]) return; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); [self allocateQuery:query]; FSTAssertTargetID(2); @@ -738,7 +737,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, // This test only works in the absence of the FSTEagerGarbageCollector. [self restartWithNoopGarbageCollector]; - FSTQuery *query = FSTTestQuery(@"foo/bar"); + FSTQuery *query = FSTTestQuery("foo/bar"); FSTQueryData *queryData = [self.localStore allocateQuery:query]; FSTBoxedTargetID *targetID = @(queryData.targetID); NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1000); @@ -772,7 +771,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, if ([self isTestBaseClass]) return; [self restartWithNoopGarbageCollector]; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); [self allocateQuery:query]; FSTAssertTargetID(2); diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm index f5294d5..57572ec 100644 --- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm @@ -259,8 +259,8 @@ NS_ASSUME_NONNULL_BEGIN @{ @"a" : @1 }), FSTTestSetMutation(@"foo/bar", @{ @"a" : @1 }), - FSTTestPatchMutation(@"foo/bar", - @{ @"b" : @1 }, nil), + FSTTestPatchMutation("foo/bar", + @{ @"b" : @1 }, {}), FSTTestSetMutation(@"foo/bar/suffix/key", @{ @"a" : @1 }), FSTTestSetMutation(@"foo/baz", @@ -296,8 +296,8 @@ NS_ASSUME_NONNULL_BEGIN @{ @"a" : @1 }), FSTTestSetMutation(@"foo/bar", @{ @"a" : @1 }), - FSTTestPatchMutation(@"foo/bar", - @{ @"b" : @1 }, nil), + FSTTestPatchMutation("foo/bar", + @{ @"b" : @1 }, {}), FSTTestSetMutation(@"foo/bar/suffix/key", @{ @"a" : @1 }), FSTTestSetMutation(@"foo/baz", @@ -319,7 +319,7 @@ NS_ASSUME_NONNULL_BEGIN [self.persistence commitGroup:group]; NSArray<FSTMutationBatch *> *expected = @[ batches[1], batches[2], batches[4] ]; - FSTQuery *query = FSTTestQuery(@"foo"); + FSTQuery *query = FSTTestQuery("foo"); NSArray<FSTMutationBatch *> *matches = [self.mutationQueue allMutationBatchesAffectingQuery:query]; diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm index 5cdfd66..0618e9c 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setUp { [super setUp]; - _queryRooms = FSTTestQuery(@"rooms"); + _queryRooms = FSTTestQuery("rooms"); _previousSequenceNumber = 1000; _previousTargetID = 500; _previousSnapshotVersion = 100; @@ -76,8 +76,8 @@ NS_ASSUME_NONNULL_BEGIN // 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]; @@ -215,14 +215,14 @@ NS_ASSUME_NONNULL_BEGIN [garbageCollector addGarbageSource:self.queryCache]; FSTAssertEqualSets([garbageCollector collectGarbage], @[]); - FSTQueryData *rooms = [self queryDataWithQuery:FSTTestQuery(@"rooms")]; + FSTQueryData *rooms = [self queryDataWithQuery:FSTTestQuery("rooms")]; 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")]; + FSTQueryData *halls = [self queryDataWithQuery:FSTTestQuery("halls")]; FSTDocumentKey *hall1 = FSTTestDocKey(@"halls/bar"); FSTDocumentKey *hall2 = FSTTestDocKey(@"halls/foo"); [self addQueryData:halls]; @@ -263,12 +263,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)testHighestListenSequenceNumber { if ([self isTestBaseClass]) return; - FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"rooms") + FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("rooms") targetID:1 listenSequenceNumber:10 purpose:FSTQueryPurposeListen]; [self addQueryData:query1]; - FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"halls") + FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("halls") targetID:2 listenSequenceNumber:20 purpose:FSTQueryPurposeListen]; @@ -280,7 +280,7 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqual([self.queryCache highestListenSequenceNumber], 20); // A query with an empty result set still counts. - FSTQueryData *query3 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"garages") + FSTQueryData *query3 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("garages") targetID:42 listenSequenceNumber:100 purpose:FSTQueryPurposeListen]; @@ -305,7 +305,7 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqual([self.queryCache highestTargetID], 0); - FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"rooms") + FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("rooms") targetID:1 listenSequenceNumber:10 purpose:FSTQueryPurposeListen]; @@ -315,7 +315,7 @@ NS_ASSUME_NONNULL_BEGIN [self addMatchingKey:key1 forTargetID:1]; [self addMatchingKey:key2 forTargetID:1]; - FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"halls") + FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("halls") targetID:2 listenSequenceNumber:20 purpose:FSTQueryPurposeListen]; @@ -329,7 +329,7 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqual([self.queryCache highestTargetID], 2); // A query with an empty result set still counts. - FSTQueryData *query3 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"garages") + FSTQueryData *query3 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery("garages") targetID:42 listenSequenceNumber:100 purpose:FSTQueryPurposeListen]; diff --git a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm index d240604..d056488 100644 --- a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm @@ -112,7 +112,7 @@ static const int kVersion = 42; [self setTestDocumentAtPath:@"b/2"]; [self setTestDocumentAtPath:@"c/1"]; - FSTQuery *query = FSTTestQuery(@"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/FSTDocumentSetTests.mm b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm index fbaa5d6..d70c44d 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm @@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setUp { [super setUp]; - _comp = FSTTestDocComparator(@"sort"); + _comp = FSTTestDocComparator("sort"); _doc1 = FSTTestDoc(@"docs/1", 0, @{ @"sort" : @2 }, NO); _doc2 = FSTTestDoc(@"docs/2", 0, @{ @"sort" : @3 }, NO); _doc3 = FSTTestDoc(@"docs/3", 0, @{ @"sort" : @1 }, NO); diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.mm b/Firestore/Example/Tests/Model/FSTDocumentTests.mm index 59f526d..0527852 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.mm @@ -21,10 +21,13 @@ #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; + NS_ASSUME_NONNULL_BEGIN @interface FSTDocumentTests : XCTestCase @@ -55,9 +58,9 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc = [FSTDocument documentWithData:data key:key version:version hasLocalMutations:NO]; - XCTAssertEqualObjects([doc fieldForPath:FSTTestFieldPath(@"desc")], + XCTAssertEqualObjects([doc fieldForPath:testutil::Field("desc")], [FSTStringValue stringValue:@"Discuss all the project related stuff"]); - XCTAssertEqualObjects([doc fieldForPath:FSTTestFieldPath(@"owner.title")], + XCTAssertEqualObjects([doc fieldForPath:testutil::Field("owner.title")], [FSTStringValue stringValue:@"scallywag"]); } diff --git a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm index 03dfa66..1a207f4 100644 --- a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm +++ b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm @@ -23,14 +23,15 @@ #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #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" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +namespace testutil = firebase::firestore::testutil; namespace util = firebase::firestore::util; using firebase::firestore::model::DatabaseId; @@ -301,20 +302,20 @@ union DoubleBits { FSTObjectValue *obj = FSTTestObjectValue(@{ @"foo" : @{@"a" : @YES, @"b" : @"string"} }); FSTAssertIsKindOfClass(obj, FSTObjectValue); - FSTAssertIsKindOfClass([obj valueForPath:FSTTestFieldPath(@"foo")], FSTObjectValue); - XCTAssertEqualObjects([obj valueForPath:FSTTestFieldPath(@"foo.a")], [FSTBooleanValue trueValue]); - XCTAssertEqualObjects([obj valueForPath:FSTTestFieldPath(@"foo.b")], + FSTAssertIsKindOfClass([obj valueForPath:testutil::Field("foo")], FSTObjectValue); + XCTAssertEqualObjects([obj valueForPath:testutil::Field("foo.a")], [FSTBooleanValue trueValue]); + XCTAssertEqualObjects([obj valueForPath:testutil::Field("foo.b")], [FSTStringValue stringValue:@"string"]); - XCTAssertNil([obj valueForPath:FSTTestFieldPath(@"foo.a.b")]); - XCTAssertNil([obj valueForPath:FSTTestFieldPath(@"bar")]); - XCTAssertNil([obj valueForPath:FSTTestFieldPath(@"bar.a")]); + XCTAssertNil([obj valueForPath:testutil::Field("foo.a.b")]); + XCTAssertNil([obj valueForPath:testutil::Field("bar")]); + XCTAssertNil([obj valueForPath:testutil::Field("bar.a")]); } - (void)testOverwritesExistingFields { FSTObjectValue *old = FSTTestObjectValue(@{@"a" : @"old"}); FSTObjectValue *mod = - [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:FSTTestFieldPath(@"a")]; + [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:testutil::Field("a")]; // Should return a new object, leaving the old one unmodified. XCTAssertNotEqual(old, mod); @@ -325,13 +326,13 @@ union DoubleBits { - (void)testAddsNewFields { FSTObjectValue *empty = [FSTObjectValue objectValue]; FSTObjectValue *mod = - [empty objectBySettingValue:FSTTestFieldValue(@"mod") forPath:FSTTestFieldPath(@"a")]; + [empty objectBySettingValue:FSTTestFieldValue(@"mod") forPath:testutil::Field("a")]; XCTAssertNotEqual(empty, mod); XCTAssertEqualObjects(empty, FSTTestFieldValue(@{})); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{@"a" : @"mod"})); FSTObjectValue *old = mod; - mod = [old objectBySettingValue:FSTTestFieldValue(@1) forPath:FSTTestFieldPath(@"b")]; + mod = [old objectBySettingValue:FSTTestFieldValue(@1) forPath:testutil::Field("b")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue(@{@"a" : @"mod"})); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @"mod", @"b" : @1 })); @@ -340,7 +341,7 @@ union DoubleBits { - (void)testImplicitlyCreatesObjects { FSTObjectValue *old = FSTTestObjectValue(@{@"a" : @"old"}); FSTObjectValue *mod = - [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:FSTTestFieldPath(@"b.c.d")]; + [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:testutil::Field("b.c.d")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue(@{@"a" : @"old"})); XCTAssertEqualObjects(mod, FSTTestFieldValue( @@ -351,7 +352,7 @@ union DoubleBits { - (void)testCanOverwritePrimitivesWithObjects { FSTObjectValue *old = FSTTestObjectValue(@{ @"a" : @{@"b" : @"old"} }); FSTObjectValue *mod = - [old objectBySettingValue:FSTTestFieldValue(@{@"b" : @"mod"}) forPath:FSTTestFieldPath(@"a")]; + [old objectBySettingValue:FSTTestFieldValue(@{@"b" : @"mod"}) forPath:testutil::Field("a")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue(@{ @"a" : @{@"b" : @"old"} })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @"mod"} })); @@ -360,7 +361,7 @@ union DoubleBits { - (void)testAddsToNestedObjects { FSTObjectValue *old = FSTTestObjectValue(@{ @"a" : @{@"b" : @"old"} }); FSTObjectValue *mod = - [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:FSTTestFieldPath(@"a.c")]; + [old objectBySettingValue:FSTTestFieldValue(@"mod") forPath:testutil::Field("a.c")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue(@{ @"a" : @{@"b" : @"old"} })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @"old", @"c" : @"mod"} })); @@ -368,12 +369,12 @@ union DoubleBits { - (void)testDeletesKeys { FSTObjectValue *old = FSTTestObjectValue(@{ @"a" : @1, @"b" : @2 }); - FSTObjectValue *mod = [old objectByDeletingPath:FSTTestFieldPath(@"a")]; + FSTObjectValue *mod = [old objectByDeletingPath:testutil::Field("a")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue(@{ @"a" : @1, @"b" : @2 })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"b" : @2 })); - FSTObjectValue *empty = [mod objectByDeletingPath:FSTTestFieldPath(@"b")]; + FSTObjectValue *empty = [mod objectByDeletingPath:testutil::Field("b")]; XCTAssertNotEqual(mod, empty); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"b" : @2 })); XCTAssertEqualObjects(empty, FSTTestFieldValue(@{})); @@ -381,15 +382,15 @@ union DoubleBits { - (void)testDeletesHandleMissingKeys { FSTObjectValue *old = FSTTestObjectValue(@{ @"a" : @{@"b" : @1, @"c" : @2} }); - FSTObjectValue *mod = [old objectByDeletingPath:FSTTestFieldPath(@"b")]; + FSTObjectValue *mod = [old objectByDeletingPath:testutil::Field("b")]; XCTAssertEqualObjects(old, mod); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @1, @"c" : @2} })); - mod = [old objectByDeletingPath:FSTTestFieldPath(@"a.d")]; + mod = [old objectByDeletingPath:testutil::Field("a.d")]; XCTAssertEqualObjects(old, mod); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @1, @"c" : @2} })); - mod = [old objectByDeletingPath:FSTTestFieldPath(@"a.b.c")]; + mod = [old objectByDeletingPath:testutil::Field("a.b.c")]; XCTAssertEqualObjects(old, mod); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @1, @"c" : @2} })); } @@ -397,19 +398,19 @@ union DoubleBits { - (void)testDeletesNestedKeys { FSTObjectValue *old = FSTTestObjectValue( @{ @"a" : @{@"b" : @1, @"c" : @{@"d" : @2, @"e" : @3}} }); - FSTObjectValue *mod = [old objectByDeletingPath:FSTTestFieldPath(@"a.c.d")]; + FSTObjectValue *mod = [old objectByDeletingPath:testutil::Field("a.c.d")]; XCTAssertNotEqual(old, mod); XCTAssertEqualObjects(old, FSTTestFieldValue( @{ @"a" : @{@"b" : @1, @"c" : @{@"d" : @2, @"e" : @3}} })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @1, @"c" : @{@"e" : @3}} })); old = mod; - mod = [old objectByDeletingPath:FSTTestFieldPath(@"a.c")]; + mod = [old objectByDeletingPath:testutil::Field("a.c")]; XCTAssertEqualObjects(old, FSTTestFieldValue(@{ @"a" : @{@"b" : @1, @"c" : @{@"e" : @3}} })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{ @"a" : @{@"b" : @1} })); old = mod; - mod = [old objectByDeletingPath:FSTTestFieldPath(@"a")]; + mod = [old objectByDeletingPath:testutil::Field("a")]; XCTAssertEqualObjects(old, FSTTestFieldValue(@{ @"a" : @{@"b" : @1} })); XCTAssertEqualObjects(mod, FSTTestFieldValue(@{})); } diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.mm b/Firestore/Example/Tests/Model/FSTMutationTests.mm index 1c1375c..5b056fb 100644 --- a/Firestore/Example/Tests/Model/FSTMutationTests.mm +++ b/Firestore/Example/Tests/Model/FSTMutationTests.mm @@ -22,10 +22,13 @@ #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; + @interface FSTMutationTests : XCTestCase @end @@ -52,8 +55,7 @@ NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); - FSTMutation *patch = - FSTTestPatchMutation(@"collection/key", @{@"foo.bar" : @"new-bar-value"}, nil); + FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; @@ -66,7 +68,7 @@ FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); FSTDocumentKey *key = FSTTestDocKey(@"collection/key"); - FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:@[ FSTTestFieldPath(@"foo.bar") ]]; + FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:{testutil::Field("foo.bar")}]; FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask value:[FSTObjectValue objectValue] @@ -82,8 +84,7 @@ NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"}; FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); - FSTMutation *patch = - FSTTestPatchMutation(@"collection/key", @{@"foo.bar" : @"new-bar-value"}, nil); + FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; @@ -93,7 +94,7 @@ - (void)testPatchingDeletedDocumentsDoesNothing { FSTMaybeDocument *baseDoc = FSTTestDeletedDoc(@"collection/key", 0); - FSTMutation *patch = FSTTestPatchMutation(@"collection/key", @{@"foo" : @"bar"}, nil); + FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"bar"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; XCTAssertEqualObjects(patchedDoc, baseDoc); @@ -115,7 +116,7 @@ [expectedData objectBySettingValue:[FSTServerTimestampValue serverTimestampValueWithLocalWriteTime:_timestamp previousValue:nil] - forPath:FSTTestFieldPath(@"foo.bar")]; + forPath:testutil::Field("foo.bar")]; FSTDocument *expectedDoc = [FSTDocument documentWithData:expectedData key:FSTTestDocKey(@"collection/key") @@ -176,7 +177,7 @@ NSDictionary *docData = @{@"foo" : @"bar"}; FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); - FSTMutation *patch = FSTTestPatchMutation(@"collection/key", @{@"foo" : @"new-bar"}, nil); + FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"new-bar"}, {}); FSTMutationResult *mutationResult = [[FSTMutationResult alloc] initWithVersion:FSTTestVersion(4) transformResults:nil]; FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc @@ -210,7 +211,7 @@ FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc(@"collection/key", 3); FSTMutation *setMutation = FSTTestSetMutation(@"collection/key", @{}); - FSTMutation *patchMutation = FSTTestPatchMutation(@"collection/key", @{}, nil); + FSTMutation *patchMutation = FSTTestPatchMutation("collection/key", {}, {}); FSTMutation *deleteMutation = FSTTestDeleteMutation(@"collection/key"); ASSERT_VERSION_TRANSITION(setMutation, docV3, docV3); diff --git a/Firestore/Example/Tests/Model/FSTPathTests.mm b/Firestore/Example/Tests/Model/FSTPathTests.mm deleted file mode 100644 index 388c5c3..0000000 --- a/Firestore/Example/Tests/Model/FSTPathTests.mm +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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/Util/FSTHelpers.h" -#import "Firestore/Source/Model/FSTPath.h" - -#import <XCTest/XCTest.h> - -NS_ASSUME_NONNULL_BEGIN - -@interface FSTFieldPathTests : XCTestCase -@end - -@implementation FSTFieldPathTests - -- (void)testConstructor { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - XCTAssertEqual(3, path.length); -} - -- (void)testIndexing { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - XCTAssertEqualObjects(@"rooms", path.firstSegment); - XCTAssertEqualObjects(@"rooms", [path segmentAtIndex:0]); - XCTAssertEqualObjects(@"rooms", path[0]); - - XCTAssertEqualObjects(@"Eros", [path segmentAtIndex:1]); - XCTAssertEqualObjects(@"Eros", path[1]); - - XCTAssertEqualObjects(@"messages", [path segmentAtIndex:2]); - XCTAssertEqualObjects(@"messages", path[2]); - XCTAssertEqualObjects(@"messages", path.lastSegment); -} - -- (void)testPathByRemovingFirstSegment { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - FSTFieldPath *same = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - FSTFieldPath *second = [FSTFieldPath pathWithSegments:@[ @"Eros", @"messages" ]]; - FSTFieldPath *third = [FSTFieldPath pathWithSegments:@[ @"messages" ]]; - FSTFieldPath *empty = [FSTFieldPath pathWithSegments:@[]]; - - XCTAssertEqualObjects(second, path.pathByRemovingFirstSegment); - XCTAssertEqualObjects(third, path.pathByRemovingFirstSegment.pathByRemovingFirstSegment); - XCTAssertEqualObjects( - empty, path.pathByRemovingFirstSegment.pathByRemovingFirstSegment.pathByRemovingFirstSegment); - // unmodified original - XCTAssertEqualObjects(same, path); -} - -- (void)testPathByRemovingLastSegment { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - FSTFieldPath *same = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - FSTFieldPath *second = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros" ]]; - FSTFieldPath *third = [FSTFieldPath pathWithSegments:@[ @"rooms" ]]; - FSTFieldPath *empty = [FSTFieldPath pathWithSegments:@[]]; - - XCTAssertEqualObjects(second, path.pathByRemovingLastSegment); - XCTAssertEqualObjects(third, path.pathByRemovingLastSegment.pathByRemovingLastSegment); - XCTAssertEqualObjects( - empty, path.pathByRemovingLastSegment.pathByRemovingLastSegment.pathByRemovingLastSegment); - // unmodified original - XCTAssertEqualObjects(same, path); -} - -- (void)testPathByAppendingSegment { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms" ]]; - FSTFieldPath *rooms = [FSTFieldPath pathWithSegments:@[ @"rooms" ]]; - FSTFieldPath *roomsEros = [FSTFieldPath pathWithSegments:@[ @"rooms", @"eros" ]]; - FSTFieldPath *roomsEros1 = [FSTFieldPath pathWithSegments:@[ @"rooms", @"eros", @"1" ]]; - - XCTAssertEqualObjects(roomsEros, [path pathByAppendingSegment:@"eros"]); - XCTAssertEqualObjects(roomsEros1, - [[path pathByAppendingSegment:@"eros"] pathByAppendingSegment:@"1"]); - // unmodified original - XCTAssertEqualObjects(rooms, path); - - FSTFieldPath *sub = [FSTTestFieldPath(@"rooms.eros.1") pathByRemovingFirstSegment]; - FSTFieldPath *appended = [sub pathByAppendingSegment:@"2"]; - XCTAssertEqualObjects(appended, FSTTestFieldPath(@"eros.1.2")); -} - -- (void)testPathComparison { - FSTFieldPath *path1 = [FSTFieldPath pathWithSegments:@[ @"a", @"b", @"c" ]]; - FSTFieldPath *path2 = [FSTFieldPath pathWithSegments:@[ @"a", @"b", @"c" ]]; - FSTFieldPath *path3 = [FSTFieldPath pathWithSegments:@[ @"x", @"y", @"z" ]]; - XCTAssertTrue([path1 isEqual:path2]); - XCTAssertFalse([path1 isEqual:path3]); - - FSTFieldPath *empty = [FSTFieldPath pathWithSegments:@[]]; - FSTFieldPath *a = [FSTFieldPath pathWithSegments:@[ @"a" ]]; - FSTFieldPath *b = [FSTFieldPath pathWithSegments:@[ @"b" ]]; - FSTFieldPath *ab = [FSTFieldPath pathWithSegments:@[ @"a", @"b" ]]; - - XCTAssertEqual(NSOrderedAscending, [empty compare:a]); - XCTAssertEqual(NSOrderedAscending, [a compare:b]); - XCTAssertEqual(NSOrderedAscending, [a compare:ab]); - - XCTAssertEqual(NSOrderedDescending, [a compare:empty]); - XCTAssertEqual(NSOrderedDescending, [b compare:a]); - XCTAssertEqual(NSOrderedDescending, [ab compare:a]); -} - -- (void)testIsPrefixOfPath { - FSTFieldPath *empty = [FSTFieldPath pathWithSegments:@[]]; - FSTFieldPath *a = [FSTFieldPath pathWithSegments:@[ @"a" ]]; - FSTFieldPath *ab = [FSTFieldPath pathWithSegments:@[ @"a", @"b" ]]; - FSTFieldPath *abc = [FSTFieldPath pathWithSegments:@[ @"a", @"b", @"c" ]]; - FSTFieldPath *b = [FSTFieldPath pathWithSegments:@[ @"b" ]]; - FSTFieldPath *ba = [FSTFieldPath pathWithSegments:@[ @"b", @"a" ]]; - - XCTAssertTrue([empty isPrefixOfPath:a]); - XCTAssertTrue([empty isPrefixOfPath:ab]); - XCTAssertTrue([empty isPrefixOfPath:abc]); - XCTAssertTrue([empty isPrefixOfPath:empty]); - XCTAssertTrue([empty isPrefixOfPath:b]); - XCTAssertTrue([empty isPrefixOfPath:ba]); - - XCTAssertTrue([a isPrefixOfPath:a]); - XCTAssertTrue([a isPrefixOfPath:ab]); - XCTAssertTrue([a isPrefixOfPath:abc]); - XCTAssertFalse([a isPrefixOfPath:empty]); - XCTAssertFalse([a isPrefixOfPath:b]); - XCTAssertFalse([a isPrefixOfPath:ba]); - - XCTAssertFalse([ab isPrefixOfPath:a]); - XCTAssertTrue([ab isPrefixOfPath:ab]); - XCTAssertTrue([ab isPrefixOfPath:abc]); - XCTAssertFalse([ab isPrefixOfPath:empty]); - XCTAssertFalse([ab isPrefixOfPath:b]); - XCTAssertFalse([ab isPrefixOfPath:ba]); - - XCTAssertFalse([abc isPrefixOfPath:a]); - XCTAssertFalse([abc isPrefixOfPath:ab]); - XCTAssertTrue([abc isPrefixOfPath:abc]); - XCTAssertFalse([abc isPrefixOfPath:empty]); - XCTAssertFalse([abc isPrefixOfPath:b]); - XCTAssertFalse([abc isPrefixOfPath:ba]); -} - -- (void)testInvalidPaths { - XCTAssertThrows(FSTTestFieldPath(@"")); - XCTAssertThrows(FSTTestFieldPath(@".")); - XCTAssertThrows(FSTTestFieldPath(@".foo")); - XCTAssertThrows(FSTTestFieldPath(@"foo.")); - XCTAssertThrows(FSTTestFieldPath(@"foo..bar")); -} - -#define ASSERT_ROUND_TRIP(str, segments) \ - do { \ - FSTFieldPath *path = [FSTFieldPath pathWithServerFormat:str]; \ - XCTAssertEqual([path length], segments); \ - NSString *canonical = [path canonicalString]; \ - XCTAssertEqualObjects(canonical, str); \ - } while (0); - -- (void)testCanonicalString { - ASSERT_ROUND_TRIP(@"foo", 1); - ASSERT_ROUND_TRIP(@"foo.bar", 2); - ASSERT_ROUND_TRIP(@"foo.bar.baz", 3); - ASSERT_ROUND_TRIP(@"`.foo\\\\`", 1); - ASSERT_ROUND_TRIP(@"`.foo\\\\`.`.foo`", 2); - ASSERT_ROUND_TRIP(@"foo.`\\``.bar", 3); - - FSTFieldPath *path = [FSTFieldPath pathWithServerFormat:@"foo\\.bar"]; - XCTAssertEqualObjects([path canonicalString], @"`foo.bar`"); - XCTAssertEqual(path.length, 1); -} - -#undef ASSERT_ROUND_TRIP - -- (void)testCanonicalStringOfSubstring { - FSTFieldPath *path = [FSTFieldPath pathWithServerFormat:@"foo.bar.baz"]; - XCTAssertEqualObjects([path canonicalString], @"foo.bar.baz"); - - FSTFieldPath *pathTail = [path pathByRemovingFirstSegment]; - XCTAssertEqualObjects([pathTail canonicalString], @"bar.baz"); - - FSTFieldPath *pathHead = [path pathByRemovingLastSegment]; - XCTAssertEqualObjects([pathHead canonicalString], @"foo.bar"); - - XCTAssertEqualObjects([[pathTail pathByRemovingLastSegment] canonicalString], @"bar"); - XCTAssertEqualObjects([[pathHead pathByRemovingFirstSegment] canonicalString], @"bar"); -} - -- (void)testRoundTrip { - FSTFieldPath *path = [FSTFieldPath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - XCTAssertEqualObjects(path, [FSTFieldPath fieldPathWithCPPFieldPath:[path toCPPFieldPath]]); - - const firebase::firestore::model::FieldPath cppPath{"rooms", "Eros", "messages"}; - XCTAssertEqual(cppPath, [[FSTFieldPath fieldPathWithCPPFieldPath:cppPath] toCPPFieldPath]); -} - -@end - -@interface FSTResourcePathTests : XCTestCase -@end - -@implementation FSTResourcePathTests - -- (void)testRoundTrip { - FSTResourcePath *path = [FSTResourcePath pathWithSegments:@[ @"rooms", @"Eros", @"messages" ]]; - XCTAssertEqualObjects(path, - [FSTResourcePath resourcePathWithCPPResourcePath:[path toCPPResourcePath]]); - - const firebase::firestore::model::ResourcePath cppPath{"rooms", "Eros", "messages"}; - XCTAssertEqual(cppPath, - [[FSTResourcePath resourcePathWithCPPResourcePath:cppPath] toCPPResourcePath]); -} - -@end -NS_ASSUME_NONNULL_END diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm index 5cd816f..4c3682f 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm @@ -40,7 +40,6 @@ #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTWatchChange.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" @@ -338,11 +337,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)testEncodesPatchMutation { FSTPatchMutation *mutation = - FSTTestPatchMutation(@"docs/1", + FSTTestPatchMutation("docs/1", @{ @"a" : @"b", @"num" : @1, @"some.de\\\\ep.th\\ing'" : @2 }, - nil); + {}); GCFSWrite *proto = [GCFSWrite message]; proto.update = [self.serializer encodedDocumentWithFields:mutation.value key:mutation.key]; proto.updateMask = [self.serializer encodedFieldMask:mutation.fieldMask]; @@ -406,7 +405,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesListenRequestLabels { - FSTQuery *query = FSTTestQuery(@"collection/key"); + FSTQuery *query = FSTTestQuery("collection/key"); FSTQueryData *queryData = [[FSTQueryData alloc] initWithQuery:query targetID:2 listenSequenceNumber:3 @@ -432,7 +431,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesRelationFilter { - FSTRelationFilter *input = FSTTestFilter(@"item.part.top", @"==", @"food"); + FSTRelationFilter *input = FSTTestFilter("item.part.top", @"==", @"food"); GCFSStructuredQuery_Filter *actual = [self.serializer encodedRelationFilter:input]; GCFSStructuredQuery_Filter *expected = [GCFSStructuredQuery_Filter message]; @@ -446,7 +445,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - encodedQuery - (void)testEncodesFirstLevelKeyQueries { - FSTQuery *q = FSTTestQuery(@"docs/1"); + FSTQuery *q = FSTTestQuery("docs/1"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -457,7 +456,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesFirstLevelAncestorQueries { - FSTQuery *q = FSTTestQuery(@"messages"); + FSTQuery *q = FSTTestQuery("messages"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -473,7 +472,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesNestedAncestorQueries { - FSTQuery *q = FSTTestQuery(@"rooms/1/messages/10/attachments"); + FSTQuery *q = FSTTestQuery("rooms/1/messages/10/attachments"); FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -489,7 +488,7 @@ NS_ASSUME_NONNULL_BEGIN } - (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]; @@ -512,9 +511,9 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesMultipleFiltersOnDeeperCollections { - FSTQuery *q = [[FSTTestQuery(@"rooms/1/messages/10/attachments") - queryByAddingFilter:FSTTestFilter(@"prop", @">=", @(42))] - queryByAddingFilter:FSTTestFilter(@"author", @"==", @"dimond")]; + FSTQuery *q = [[FSTTestQuery("rooms/1/messages/10/attachments") + queryByAddingFilter:FSTTestFilter("prop", @">=", @(42))] + queryByAddingFilter:FSTTestFilter("author", @"==", @"dimond")]; FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -562,7 +561,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)unaryFilterTestWithValue:(id)value expectedUnaryOperator:(GCFSStructuredQuery_UnaryFilter_Operator)op { - 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]; @@ -582,7 +581,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesSortOrders { - FSTQuery *q = [FSTTestQuery(@"docs") + FSTQuery *q = [FSTTestQuery("docs") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("prop") ascending:YES]]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -602,7 +601,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesSortOrdersDescending { - FSTQuery *q = [FSTTestQuery(@"rooms/1/messages/10/attachments") + FSTQuery *q = [FSTTestQuery("rooms/1/messages/10/attachments") queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("prop") ascending:NO]]; FSTQueryData *model = [self queryDataForQuery:q]; @@ -622,7 +621,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesLimits { - FSTQuery *q = [FSTTestQuery(@"docs") queryBySettingLimit:26]; + FSTQuery *q = [FSTTestQuery("docs") queryBySettingLimit:26]; FSTQueryData *model = [self queryDataForQuery:q]; GCFSTarget *expected = [GCFSTarget message]; @@ -639,7 +638,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesResumeTokens { - FSTQuery *q = FSTTestQuery(@"docs"); + FSTQuery *q = FSTTestQuery("docs"); FSTQueryData *model = [[FSTQueryData alloc] initWithQuery:q targetID:1 listenSequenceNumber:0 diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm index b00ea07..0f57b81 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm @@ -16,6 +16,8 @@ #import "Firestore/Example/Tests/SpecTests/FSTSpecTests.h" +#include <utility> + #import <FirebaseFirestore/FIRFirestoreErrors.h> #import <GRPCClient/GRPCCall.h> @@ -30,7 +32,6 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Remote/FSTExistenceFilter.h" #import "Firestore/Source/Remote/FSTWatchChange.h" #import "Firestore/Source/Util/FSTAssert.h" @@ -108,11 +109,11 @@ static NSString *const kNoIOSTag = @"no-ios"; - (nullable FSTQuery *)parseQuery:(id)querySpec { if ([querySpec isKindOfClass:[NSString class]]) { - return FSTTestQuery(querySpec); + return FSTTestQuery(util::MakeStringView((NSString *)querySpec)); } else if ([querySpec isKindOfClass:[NSDictionary class]]) { NSDictionary *queryDict = (NSDictionary *)querySpec; NSString *path = queryDict[@"path"]; - __block FSTQuery *query = FSTTestQuery(path); + __block FSTQuery *query = FSTTestQuery(util::MakeStringView(path)); if (queryDict[@"limit"]) { NSNumber *limit = queryDict[@"limit"]; query = [query queryBySettingLimit:limit.integerValue]; @@ -121,14 +122,16 @@ static NSString *const kNoIOSTag = @"no-ios"; NSArray *filters = queryDict[@"filters"]; [filters enumerateObjectsUsingBlock:^(NSArray *_Nonnull filter, NSUInteger idx, BOOL *_Nonnull stop) { - query = [query queryByAddingFilter:FSTTestFilter(filter[0], filter[1], filter[2])]; + query = [query queryByAddingFilter:FSTTestFilter(util::MakeStringView(filter[0]), filter[1], + filter[2])]; }]; } if (queryDict[@"orderBys"]) { NSArray *orderBys = queryDict[@"orderBys"]; [orderBys enumerateObjectsUsingBlock:^(NSArray *_Nonnull orderBy, NSUInteger idx, BOOL *_Nonnull stop) { - query = [query queryByAddingSortOrder:FSTTestOrderBy(orderBy[0], orderBy[1])]; + query = [query + queryByAddingSortOrder:FSTTestOrderBy(util::MakeStringView(orderBy[0]), orderBy[1])]; }]; } return query; @@ -174,7 +177,8 @@ static NSString *const kNoIOSTag = @"no-ios"; } - (void)doPatch:(NSArray *)patchSpec { - [self.driver writeUserMutation:FSTTestPatchMutation(patchSpec[0], patchSpec[1], nil)]; + [self.driver + writeUserMutation:FSTTestPatchMutation(util::MakeStringView(patchSpec[0]), patchSpec[1], {})]; } - (void)doDelete:(NSString *)key { diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index cc9f2ec..d86201b 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -16,10 +16,16 @@ #import <Foundation/Foundation.h> +#include <map> +#include <vector> + #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKeySet.h" +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/field_value.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "absl/strings/string_view.h" @class FIRGeoPoint; @@ -28,13 +34,11 @@ @class FSTDocument; @class FSTDocumentKeyReference; @class FSTDocumentSet; -@class FSTFieldPath; @class FSTFieldValue; @class FSTLocalViewChanges; @class FSTPatchMutation; @class FSTQuery; @class FSTRemoteEvent; -@class FSTResourcePath; @class FSTSetMutation; @class FSTSnapshotVersion; @class FSTSortOrder; @@ -121,18 +125,30 @@ extern "C" { } \ } while (0) +static NSString *kExceptionPrefix = @"FIRESTORE INTERNAL ASSERTION FAILED: "; + +// Remove possible exception-prefix. +inline NSString *FSTRemoveExceptionPrefix(NSString *exception) { + if ([exception hasPrefix:kExceptionPrefix]) { + return [exception substringFromIndex:kExceptionPrefix.length]; + } else { + return exception; + } +} + // Helper for validating API exceptions. -#define FSTAssertThrows(expression, exceptionReason, ...) \ - ({ \ - BOOL __didThrow = NO; \ - @try { \ - (void)(expression); \ - } @catch (NSException * exception) { \ - __didThrow = YES; \ - XCTAssertEqualObjects(exception.reason, exceptionReason); \ - } \ - XCTAssertTrue(__didThrow, ##__VA_ARGS__); \ - }) +#define FSTAssertThrows(expression, exceptionReason, ...) \ + do { \ + BOOL didThrow = NO; \ + @try { \ + (void)(expression); \ + } @catch (NSException * exception) { \ + didThrow = YES; \ + XCTAssertEqualObjects(FSTRemoveExceptionPrefix(exception.reason), \ + FSTRemoveExceptionPrefix(exceptionReason)); \ + } \ + XCTAssertTrue(didThrow, ##__VA_ARGS__); \ + } while (0) /** Creates a new FIRTimestamp from components. Note that year, month, and day are all one-based. */ FIRTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second); @@ -157,8 +173,6 @@ FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude); NSDateComponents *FSTTestDateComponents( int year, int month, int day, int hour, int minute, int second); -FSTFieldPath *FSTTestFieldPath(NSString *field); - /** Wraps a plain value into an FSTFieldValue instance. */ FSTFieldValue *FSTTestFieldValue(id _Nullable value); @@ -186,9 +200,6 @@ FSTDocument *FSTTestDoc(NSString *path, /** A convenience method for creating deleted docs for tests. */ FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version); -/** A convenience method for creating resource paths from a path string. */ -FSTResourcePath *FSTTestPath(NSString *path); - /** * A convenience method for creating a document reference from a path string. */ @@ -197,22 +208,22 @@ FSTDocumentKeyReference *FSTTestRef(const absl::string_view projectID, NSString *path); /** A convenience method for creating a query for the given path (without any other filters). */ -FSTQuery *FSTTestQuery(NSString *path); +FSTQuery *FSTTestQuery(const absl::string_view path); /** * A convenience method to create a FSTFilter using a string representation for both field * and operator (<, <=, ==, >=, >). */ -id<FSTFilter> FSTTestFilter(NSString *field, NSString *op, id value); +id<FSTFilter> FSTTestFilter(const absl::string_view field, NSString *op, id value); /** A convenience method for creating sort orders. */ -FSTSortOrder *FSTTestOrderBy(NSString *field, NSString *direction); +FSTSortOrder *FSTTestOrderBy(const absl::string_view field, NSString *direction); /** * Creates an NSComparator that will compare FSTDocuments by the given fieldPath string then by * key. */ -NSComparator FSTTestDocComparator(NSString *fieldPath); +NSComparator FSTTestDocComparator(const absl::string_view fieldPath); /** * Creates a FSTDocumentSet based on the given comparator, initially containing the given @@ -229,9 +240,10 @@ FSTViewSnapshot *_Nullable FSTTestApplyChanges(FSTView *view, FSTSetMutation *FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *values); /** Creates a patch mutation for the document key at the given path. */ -FSTPatchMutation *FSTTestPatchMutation(NSString *path, - NSDictionary<NSString *, id> *values, - NSArray<FSTFieldPath *> *_Nullable updateMask); +FSTPatchMutation *FSTTestPatchMutation( + const absl::string_view path, + NSDictionary<NSString *, id> *values, + const std::vector<firebase::firestore::model::FieldPath> &updateMask); FSTTransformMutation *FSTTestTransformMutation(NSString *path, NSArray<NSString *> *serverTimestampFields); diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index 00464bc..be02002 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -18,6 +18,8 @@ #include <inttypes.h> #include <list> +#include <map> +#include <vector> #import <FirebaseFirestore/FIRFieldPath.h> #import <FirebaseFirestore/FIRGeoPoint.h> @@ -36,18 +38,22 @@ #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" #include "Firestore/core/src/firebase/firestore/model/database_id.h" +#include "Firestore/core/src/firebase/firestore/model/field_value.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" namespace util = firebase::firestore::util; namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DatabaseId; +using firebase::firestore::model::FieldPath; +using firebase::firestore::model::FieldValue; +using firebase::firestore::model::ResourcePath; NS_ASSUME_NONNULL_BEGIN @@ -103,10 +109,6 @@ NSDateComponents *FSTTestDateComponents( return comps; } -FSTFieldPath *FSTTestFieldPath(NSString *field) { - return [FIRFieldPath pathWithDotSeparatedString:field].internalValue; -} - FSTFieldValue *FSTTestFieldValue(id _Nullable value) { // This owns the DatabaseIds since we do not have FirestoreClient instance to own them. static DatabaseId database_id{"project", DatabaseId::kDefault}; @@ -162,18 +164,6 @@ FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion ver return [FSTDeletedDocument documentWithKey:key version:FSTTestVersion(version)]; } -static NSArray<NSString *> *FSTTestSplitPath(NSString *path) { - if ([path isEqualToString:@""]) { - return @[]; - } else { - return [path componentsSeparatedByString:@"/"]; - } -} - -FSTResourcePath *FSTTestPath(NSString *path) { - return [FSTResourcePath pathWithSegments:FSTTestSplitPath(path)]; -} - FSTDocumentKeyReference *FSTTestRef(const absl::string_view projectID, const absl::string_view database, NSString *path) { @@ -184,12 +174,12 @@ FSTDocumentKeyReference *FSTTestRef(const absl::string_view projectID, databaseID:&database_ids.back()]; } -FSTQuery *FSTTestQuery(NSString *path) { - return [FSTQuery queryWithPath:[FSTTestPath(path) toCPPResourcePath]]; +FSTQuery *FSTTestQuery(const absl::string_view path) { + return [FSTQuery queryWithPath:testutil::Resource(path)]; } -id<FSTFilter> FSTTestFilter(NSString *field, NSString *opString, id value) { - FSTFieldPath *path = FSTTestFieldPath(field); +id<FSTFilter> FSTTestFilter(const absl::string_view field, NSString *opString, id value) { + const FieldPath path = testutil::Field(field); FSTRelationFilterOperator op; if ([opString isEqualToString:@"<"]) { op = FSTRelationFilterOperatorLessThan; @@ -208,17 +198,17 @@ id<FSTFilter> FSTTestFilter(NSString *field, NSString *opString, id value) { FSTFieldValue *data = FSTTestFieldValue(value); if ([data isEqual:[FSTDoubleValue nanValue]]) { FSTCAssert(op == FSTRelationFilterOperatorEqual, @"Must use == with NAN."); - return [[FSTNanFilter alloc] initWithField:[path toCPPFieldPath]]; + return [[FSTNanFilter alloc] initWithField:path]; } else if ([data isEqual:[FSTNullValue nullValue]]) { FSTCAssert(op == FSTRelationFilterOperatorEqual, @"Must use == with Null."); - return [[FSTNullFilter alloc] initWithField:[path toCPPFieldPath]]; + return [[FSTNullFilter alloc] initWithField:path]; } else { - return [FSTRelationFilter filterWithField:[path toCPPFieldPath] filterOperator:op value:data]; + return [FSTRelationFilter filterWithField:path filterOperator:op value:data]; } } -FSTSortOrder *FSTTestOrderBy(NSString *field, NSString *direction) { - FSTFieldPath *path = FSTTestFieldPath(field); +FSTSortOrder *FSTTestOrderBy(const absl::string_view field, NSString *direction) { + const FieldPath path = testutil::Field(field); BOOL ascending; if ([direction isEqualToString:@"asc"]) { ascending = YES; @@ -227,14 +217,13 @@ FSTSortOrder *FSTTestOrderBy(NSString *field, NSString *direction) { } else { FSTCFail(@"Unsupported direction: %@", direction); } - return [FSTSortOrder sortOrderWithFieldPath:[path toCPPFieldPath] ascending:ascending]; + return [FSTSortOrder sortOrderWithFieldPath:path ascending:ascending]; } -NSComparator FSTTestDocComparator(NSString *fieldPath) { - FSTQuery *query = [FSTTestQuery(@"docs") - queryByAddingSortOrder:[FSTSortOrder - sortOrderWithFieldPath:[FSTTestFieldPath(fieldPath) toCPPFieldPath] - ascending:YES]]; +NSComparator FSTTestDocComparator(const absl::string_view fieldPath) { + FSTQuery *query = [FSTTestQuery("docs") + queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field(fieldPath) + ascending:YES]]; return [query comparator]; } @@ -252,23 +241,23 @@ FSTSetMutation *FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> precondition:[FSTPrecondition none]]; } -FSTPatchMutation *FSTTestPatchMutation(NSString *path, +FSTPatchMutation *FSTTestPatchMutation(const absl::string_view path, NSDictionary<NSString *, id> *values, - NSArray<FSTFieldPath *> *_Nullable updateMask) { - BOOL merge = updateMask != nil; + const std::vector<FieldPath> &updateMask) { + BOOL merge = !updateMask.empty(); __block FSTObjectValue *objectValue = [FSTObjectValue objectValue]; - NSMutableArray<FSTFieldPath *> *fieldMaskPaths = [NSMutableArray array]; + __block std::vector<FieldPath> fieldMaskPaths{}; [values enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { - FSTFieldPath *path = FSTTestFieldPath(key); - [fieldMaskPaths addObject:path]; + const FieldPath path = testutil::Field(util::MakeStringView(key)); + fieldMaskPaths.push_back(path); if (![value isEqual:kDeleteSentinel]) { FSTFieldValue *parsedValue = FSTTestFieldValue(value); objectValue = [objectValue objectBySettingValue:parsedValue forPath:path]; } }]; - FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource([path UTF8String])]; + FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource(path)]; FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:merge ? updateMask : fieldMaskPaths]; return [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask @@ -279,10 +268,10 @@ FSTPatchMutation *FSTTestPatchMutation(NSString *path, // For now this only creates TransformMutations with server timestamps. FSTTransformMutation *FSTTestTransformMutation(NSString *path, NSArray<NSString *> *serverTimestampFields) { - FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource([path UTF8String])]; + FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource(util::MakeStringView(path))]; NSMutableArray<FSTFieldTransform *> *fieldTransforms = [NSMutableArray array]; for (NSString *field in serverTimestampFields) { - FSTFieldPath *fieldPath = FSTTestFieldPath(field); + const FieldPath fieldPath = testutil::Field(util::MakeStringView(field)); id<FSTTransformOperation> transformOp = [FSTServerTimestampTransform serverTimestampTransform]; FSTFieldTransform *transform = [[FSTFieldTransform alloc] initWithPath:fieldPath transform:transformOp]; |