diff options
Diffstat (limited to 'Firestore/Example/Tests/API')
-rw-r--r-- | Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm | 16 | ||||
-rw-r--r-- | Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm | 12 | ||||
-rw-r--r-- | Firestore/Example/Tests/API/FSTAPIHelpers.h | 6 | ||||
-rw-r--r-- | Firestore/Example/Tests/API/FSTAPIHelpers.mm | 33 |
4 files changed, 35 insertions, 32 deletions
diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm index 677d385..136fed6 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm @@ -28,14 +28,14 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRDocumentSnapshotTests - (void)testEquals { - FIRDocumentSnapshot *base = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *nilData = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); - FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); - FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *differentData = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"b" : @1 }, NO, NO); - FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, YES, NO); - FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, YES); + FIRDocumentSnapshot *base = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *nilData = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *differentData = FSTTestDocSnapshot("rooms/bar", 1, @{ @"b" : @1 }, NO, NO); + FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, YES, NO); + FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, YES); XCTAssertEqualObjects(base, baseDup); XCTAssertEqualObjects(nilData, nilDataDup); XCTAssertNotEqualObjects(base, nilData); diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm index bb8110b..f8c7d60 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm @@ -28,15 +28,15 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRQuerySnapshotTests - (void)testEquals { - FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot(@"bar", @{}, + FIRQuerySnapshot *foo = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot("bar", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot(@"foo", + FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot("foo", @{ @"a" : @{@"b" : @1} }, @{}, YES, NO); - FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot(@"foo", @{}, + FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, NO, NO); - FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot(@"foo", @{}, + FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, YES); XCTAssertEqualObjects(foo, fooDup); XCTAssertNotEqualObjects(foo, differentPath); diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index 4edd7d5..2325c22 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -18,6 +18,8 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "absl/strings/string_view.h" + @class FIRCollectionReference; @class FIRDocumentReference; @class FIRDocumentSnapshot; @@ -34,7 +36,7 @@ extern "C" { FIRFirestore *FSTTestFirestore(); /** A convenience method for creating a doc snapshot for tests. */ -FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, +FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary<NSString *, id> *_Nullable data, BOOL hasMutations, @@ -61,7 +63,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path); * @returns A query snapshot that consists of both sets of documents. */ FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, + const absl::string_view path, NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs, NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd, BOOL hasPendingWrites, diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.mm b/Firestore/Example/Tests/API/FSTAPIHelpers.mm index c180dc4..1ccf22e 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.mm +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.mm @@ -58,14 +58,14 @@ FIRFirestore *FSTTestFirestore() { return sharedInstance; } -FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, +FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary<NSString *, id> *_Nullable data, BOOL hasMutations, BOOL fromCache) { FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil; return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore() - documentKey:FSTTestDocKey(path) + documentKey:testutil::Key(path) document:doc fromCache:fromCache]; } @@ -82,7 +82,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path) { /** A convenience method for creating a query snapshots for tests. */ FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, + const absl::string_view path, NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs, NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd, BOOL hasPendingWrites, @@ -92,30 +92,31 @@ FIRQuerySnapshot *FSTTestQuerySnapshot( FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); for (NSString *key in oldDocs) { oldDocuments = [oldDocuments - documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - oldDocs[key], hasPendingWrites)]; + documentSetByAddingDocument:FSTTestDoc(util::MakeStringView([NSString + stringWithFormat:@"%s/%@", path.data(), key]), + 1, oldDocs[key], hasPendingWrites)]; } FSTDocumentSet *newDocuments = oldDocuments; NSArray<FSTDocumentViewChange *> *documentChanges = [NSArray array]; for (NSString *key in docsToAdd) { - FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - docsToAdd[key], hasPendingWrites); + FSTDocument *docToAdd = + FSTTestDoc(util::MakeStringView([NSString stringWithFormat:@"%s/%@", path.data(), key]), 1, + docsToAdd[key], hasPendingWrites); newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange changeWithDocument:docToAdd type:FSTDocumentViewChangeTypeAdded]]; } - FSTViewSnapshot *viewSnapshot = - [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(util::MakeStringView(path)) - documents:newDocuments - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:fromCache - hasPendingWrites:hasPendingWrites - syncStateChanged:YES]; + FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) + documents:newDocuments + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:fromCache + hasPendingWrites:hasPendingWrites + syncStateChanged:YES]; return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() - originalQuery:FSTTestQuery(util::MakeStringView(path)) + originalQuery:FSTTestQuery(path) snapshot:viewSnapshot metadata:metadata]; } |