aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Local
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2017-12-19 13:47:04 -0500
committerGravatar GitHub <noreply@github.com>2017-12-19 13:47:04 -0500
commit9ddf3637ac984abfe16d4ebef6ff3947b4e946c1 (patch)
tree008d6eea9adc10675c79c7152703f4fd05af4cf9 /Firestore/Example/Tests/Local
parent52cdf0b25a12b5baed8546893634dab9c1a03e56 (diff)
Firestore `isEqual()` on Public Types (#569)
* add bone code for new isEqual and unit test for old isEqual * add bone code for `FIRCollectionReference`, `FIRDocumentSnapshot`, `FIRFieldValue`, `FIRQuerySnapshot`, `FIRSnapshotMetadata`; * change inconsistenciness of `FIRFieldPath.isEqual` implementation; * add unit test (and file) for `FIRDocumentReferenceTest.m`, `FIRFieldPathTest.m`, `FIRQueryTests.testEquals`; `FIRGeoPoint` already has test and Blob is internal type. * Implement isEqual for FIRCollectionReference adding the working code and unit test. * implement isEqual for FIRSnapshotMetadata * Implement isEqual for FIRDocumentSnapshot * Implement isEqual for FIRQuerySnapshot * (un)implement `isEqual` for `FIRFieldValue` Since `FIRFieldValue` both types are singleton, we do not need override `isEqual`. Add test to test the default `NSObject` `isEqual` works just fine. * fix style with `scripts/style.sh` * Implement hash for those with overridden isEqual without hash yet. * refactor to use test helper functions -- FSTTestFirestore, FSTTestPath, FSTTestDocKey * refactor using test helper `FSTTestDocSnapshot`, `FSTTestFieldPath`, `FSTTestQuery`, `FSTTestDoc` * refactoring to use test helper method `FSTTestQuerySnapshot`, * remove unneccessary nil-check, check isKindOfClass instead of isEqual * refactoring: adding `FSTAPIHelpers.{h,m}`, `FSTTest{Collection,Document}Ref`, better naming and style fix * a file forgot in last commit * mainly clean up import and some minor refactoring * fix style via style.sh * minor style fix * add pragma ignored -Wnonnull
Diffstat (limited to 'Firestore/Example/Tests/Local')
-rw-r--r--Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m12
-rw-r--r--Firestore/Example/Tests/Local/FSTLocalSerializerTests.m2
-rw-r--r--Firestore/Example/Tests/Local/FSTLocalStoreTests.m29
-rw-r--r--Firestore/Example/Tests/Local/FSTMutationQueueTests.m2
-rw-r--r--Firestore/Example/Tests/Local/FSTQueryCacheTests.m38
-rw-r--r--Firestore/Example/Tests/Local/FSTReferenceSetTests.m9
-rw-r--r--Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m2
7 files changed, 46 insertions, 48 deletions
diff --git a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m
index 1dd6d62..53f0202 100644
--- a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m
+++ b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.m
@@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
[gc addGarbageSource:referenceSet];
- FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"];
+ FSTDocumentKey *key = FSTTestDocKey(@"foo/bar");
[referenceSet addReferenceToKey:key forID:1];
FSTAssertEqualSets([gc collectGarbage], @[]);
XCTAssertFalse([referenceSet isEmpty]);
@@ -50,9 +50,9 @@ NS_ASSUME_NONNULL_BEGIN
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
[gc addGarbageSource:referenceSet];
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"];
- FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
+ FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah");
[referenceSet addReferenceToKey:key1 forID:1];
[referenceSet addReferenceToKey:key2 forID:1];
[referenceSet addReferenceToKey:key3 forID:2];
@@ -77,12 +77,12 @@ NS_ASSUME_NONNULL_BEGIN
[gc addGarbageSource:localViews];
[gc addGarbageSource:mutations];
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
[remoteTargets addReferenceToKey:key1 forID:1];
[localViews addReferenceToKey:key1 forID:1];
[mutations addReferenceToKey:key1 forID:10];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"];
+ FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
[mutations addReferenceToKey:key2 forID:10];
XCTAssertFalse([remoteTargets isEmpty]);
diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m
index 90f9ca3..27c3dc3 100644
--- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m
+++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.m
@@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testEncodesMutationBatch {
FSTMutation *set = FSTTestSetMutation(@"foo/bar", @{ @"a" : @"b", @"num" : @1 });
FSTMutation *patch = [[FSTPatchMutation alloc]
- initWithKey:[FSTDocumentKey keyWithPathString:@"bar/baz"]
+ initWithKey:FSTTestDocKey(@"bar/baz")
fieldMask:[[FSTFieldMask alloc] initWithFields:@[ FSTTestFieldPath(@"a") ]]
value:FSTTestObjectValue(
@{ @"a" : @"b",
diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m
index 245e1c4..45d1815 100644
--- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.m
+++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.m
@@ -196,8 +196,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
NSEnumerator<NSString *> *keyPathEnumerator = keyPaths.objectEnumerator; \
[actual enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey * actualKey, \
FSTMaybeDocument * value, BOOL * stop) { \
- FSTDocumentKey *expectedKey = \
- [FSTDocumentKey keyWithPathString:[keyPathEnumerator nextObject]]; \
+ FSTDocumentKey *expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \
XCTAssertEqualObjects(actualKey, expectedKey); \
XCTAssertTrue([value isKindOfClass:[FSTDeletedDocument class]]); \
}]; \
@@ -213,11 +212,11 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
} while (0)
/** Asserts that the given local store does not contain the given document. */
-#define FSTAssertNotContains(keyPathString) \
- do { \
- FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:keyPathString]; \
- FSTMaybeDocument *actual = [self.localStore readDocument:key]; \
- XCTAssertNil(actual); \
+#define FSTAssertNotContains(keyPathString) \
+ do { \
+ FSTDocumentKey *key = FSTTestDocKey(keyPathString); \
+ FSTMaybeDocument *actual = [self.localStore readDocument:key]; \
+ XCTAssertNil(actual); \
} while (0)
- (void)testMutationBatchKeys {
@@ -261,7 +260,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
if ([self isTestBaseClass]) return;
// Start a query that requires acks to be held.
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
[self allocateQuery:query];
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
@@ -554,7 +553,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
- (void)testCollectsGarbageAfterChangeBatch {
if ([self isTestBaseClass]) return;
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
@@ -637,7 +636,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
- (void)testPinsDocumentsInTheLocalView {
if ([self isTestBaseClass]) return;
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
@@ -685,7 +684,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}),
FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"})
]];
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo/bar");
FSTDocumentDictionary *docs = [self.localStore executeQuery:query];
XCTAssertEqualObjects([docs values], @[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
}
@@ -700,7 +699,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}),
FSTTestSetMutation(@"fooo/blah", @{@"fooo" : @"blah"})
]];
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
FSTDocumentDictionary *docs = [self.localStore executeQuery:query];
XCTAssertEqualObjects([docs values], (@[
FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES),
@@ -711,7 +710,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
- (void)testCanExecuteMixedCollectionQueries {
if ([self isTestBaseClass]) return;
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
@@ -736,7 +735,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
// This test only works in the absence of the FSTEagerGarbageCollector.
[self restartWithNoopGarbageCollector];
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo", @"bar" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo/bar");
FSTQueryData *queryData = [self.localStore allocateQuery:query];
FSTBoxedTargetID *targetID = @(queryData.targetID);
NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1000);
@@ -770,7 +769,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation,
if ([self isTestBaseClass]) return;
[self restartWithNoopGarbageCollector];
- FSTQuery *query = [FSTQuery queryWithPath:[FSTResourcePath pathWithSegments:@[ @"foo" ]]];
+ FSTQuery *query = FSTTestQuery(@"foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.m b/Firestore/Example/Tests/Local/FSTMutationQueueTests.m
index f168ac9..020a0a7 100644
--- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.m
+++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.m
@@ -301,7 +301,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.persistence commitGroup:group];
NSArray<FSTMutationBatch *> *expected = @[ batches[1], batches[2], batches[4] ];
- FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"foo")];
+ FSTQuery *query = FSTTestQuery(@"foo");
NSArray<FSTMutationBatch *> *matches =
[self.mutationQueue allMutationBatchesAffectingQuery:query];
diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m
index 1fed440..0b80bd9 100644
--- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.m
+++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.m
@@ -70,10 +70,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 = [[FSTQuery queryWithPath:FSTTestPath(@"a")]
- queryByAddingFilter:FSTTestFilter(@"foo", @"==", @(1))];
- FSTQuery *q2 = [[FSTQuery queryWithPath:FSTTestPath(@"a")]
- queryByAddingFilter:FSTTestFilter(@"foo", @"==", @"1")];
+ FSTQuery *q1 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @(1))];
+ FSTQuery *q2 = [FSTTestQuery(@"a") queryByAddingFilter:FSTTestFilter(@"foo", @"==", @"1")];
XCTAssertEqualObjects(q1.canonicalID, q2.canonicalID);
FSTQueryData *data1 = [self queryDataWithQuery:q1 targetID:1 version:1];
@@ -141,8 +139,8 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryData *rooms = [self queryDataWithQuery:_queryRooms targetID:1 version:1];
[self addQueryData:rooms];
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"rooms/foo"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"rooms/bar"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/foo");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/bar");
[self addMatchingKey:key1 forTargetID:rooms.targetID];
[self addMatchingKey:key2 forTargetID:rooms.targetID];
@@ -157,7 +155,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testAddOrRemoveMatchingKeys {
if ([self isTestBaseClass]) return;
- FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"];
+ FSTDocumentKey *key = FSTTestDocKey(@"foo/bar");
XCTAssertFalse([self.queryCache containsKey:key]);
@@ -177,9 +175,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testRemoveMatchingKeysForTargetID {
if ([self isTestBaseClass]) return;
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"];
- FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
+ FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah");
[self addMatchingKey:key1 forTargetID:1];
[self addMatchingKey:key2 forTargetID:1];
@@ -207,15 +205,15 @@ NS_ASSUME_NONNULL_BEGIN
FSTAssertEqualSets([garbageCollector collectGarbage], @[]);
FSTQueryData *rooms = [self queryDataWithQuery:FSTTestQuery(@"rooms") targetID:1 version:1];
- FSTDocumentKey *room1 = [FSTDocumentKey keyWithPathString:@"rooms/bar"];
- FSTDocumentKey *room2 = [FSTDocumentKey keyWithPathString:@"rooms/foo"];
+ FSTDocumentKey *room1 = FSTTestDocKey(@"rooms/bar");
+ FSTDocumentKey *room2 = FSTTestDocKey(@"rooms/foo");
[self addQueryData:rooms];
[self addMatchingKey:room1 forTargetID:rooms.targetID];
[self addMatchingKey:room2 forTargetID:rooms.targetID];
FSTQueryData *halls = [self queryDataWithQuery:FSTTestQuery(@"halls") targetID:2 version:1];
- FSTDocumentKey *hall1 = [FSTDocumentKey keyWithPathString:@"halls/bar"];
- FSTDocumentKey *hall2 = [FSTDocumentKey keyWithPathString:@"halls/foo"];
+ FSTDocumentKey *hall1 = FSTTestDocKey(@"halls/bar");
+ FSTDocumentKey *hall2 = FSTTestDocKey(@"halls/foo");
[self addQueryData:halls];
[self addMatchingKey:hall1 forTargetID:halls.targetID];
[self addMatchingKey:hall2 forTargetID:halls.targetID];
@@ -235,9 +233,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testMatchingKeysForTargetID {
if ([self isTestBaseClass]) return;
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"];
- FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
+ FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah");
[self addMatchingKey:key1 forTargetID:1];
[self addMatchingKey:key2 forTargetID:1];
@@ -259,8 +257,8 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryData *query1 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"rooms")
targetID:1
purpose:FSTQueryPurposeListen];
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"rooms/bar"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"rooms/foo"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/bar");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/foo");
[self addQueryData:query1];
[self addMatchingKey:key1 forTargetID:1];
[self addMatchingKey:key2 forTargetID:1];
@@ -268,7 +266,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryData *query2 = [[FSTQueryData alloc] initWithQuery:FSTTestQuery(@"halls")
targetID:2
purpose:FSTQueryPurposeListen];
- FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"halls/foo"];
+ FSTDocumentKey *key3 = FSTTestDocKey(@"halls/foo");
[self addQueryData:query2];
[self addMatchingKey:key3 forTargetID:2];
XCTAssertEqual([self.queryCache highestTargetID], 2);
diff --git a/Firestore/Example/Tests/Local/FSTReferenceSetTests.m b/Firestore/Example/Tests/Local/FSTReferenceSetTests.m
index 0b852a2..802117a 100644
--- a/Firestore/Example/Tests/Local/FSTReferenceSetTests.m
+++ b/Firestore/Example/Tests/Local/FSTReferenceSetTests.m
@@ -18,6 +18,7 @@
#import <XCTest/XCTest.h>
+#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
NS_ASSUME_NONNULL_BEGIN
@@ -28,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation FSTReferenceSetTests
- (void)testAddOrRemoveReferences {
- FSTDocumentKey *key = [FSTDocumentKey keyWithPathString:@"foo/bar"];
+ FSTDocumentKey *key = FSTTestDocKey(@"foo/bar");
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
XCTAssertTrue([referenceSet isEmpty]);
@@ -53,9 +54,9 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)testRemoveAllReferencesForTargetID {
- FSTDocumentKey *key1 = [FSTDocumentKey keyWithPathString:@"foo/bar"];
- FSTDocumentKey *key2 = [FSTDocumentKey keyWithPathString:@"foo/baz"];
- FSTDocumentKey *key3 = [FSTDocumentKey keyWithPathString:@"foo/blah"];
+ FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
+ FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
+ FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah");
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
[referenceSet addReferenceToKey:key1 forID:1];
diff --git a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m
index 16fe3bf..d240604 100644
--- a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m
+++ b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.m
@@ -112,7 +112,7 @@ static const int kVersion = 42;
[self setTestDocumentAtPath:@"b/2"];
[self setTestDocumentAtPath:@"c/1"];
- FSTQuery *query = [FSTQuery queryWithPath:FSTTestPath(@"b")];
+ FSTQuery *query = FSTTestQuery(@"b");
FSTDocumentDictionary *results = [self.remoteDocumentCache documentsMatchingQuery:query];
NSArray *expected =
@[ FSTTestDoc(@"b/1", kVersion, _kDocData, NO), FSTTestDoc(@"b/2", kVersion, _kDocData, NO) ];