diff options
Diffstat (limited to 'Firestore/Example/Tests')
3 files changed, 63 insertions, 47 deletions
diff --git a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm index 53f0202..2cf530c 100644 --- a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm +++ b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm @@ -16,12 +16,18 @@ #import "Firestore/Source/Local/FSTEagerGarbageCollector.h" +#include <set> + #import <XCTest/XCTest.h> #import "Firestore/Source/Local/FSTReferenceSet.h" #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; +using firebase::firestore::model::DocumentKey; NS_ASSUME_NONNULL_BEGIN @@ -35,13 +41,13 @@ NS_ASSUME_NONNULL_BEGIN FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; [gc addGarbageSource:referenceSet]; - FSTDocumentKey *key = FSTTestDocKey(@"foo/bar"); + DocumentKey key = testutil::Key("foo/bar"); [referenceSet addReferenceToKey:key forID:1]; - FSTAssertEqualSets([gc collectGarbage], @[]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({})); XCTAssertFalse([referenceSet isEmpty]); [referenceSet removeReferenceToKey:key forID:1]; - FSTAssertEqualSets([gc collectGarbage], @[ key ]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({key})); XCTAssertTrue([referenceSet isEmpty]); } @@ -50,20 +56,20 @@ NS_ASSUME_NONNULL_BEGIN FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init]; [gc addGarbageSource:referenceSet]; - FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); - FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); - FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); + DocumentKey key1 = testutil::Key("foo/bar"); + DocumentKey key2 = testutil::Key("foo/baz"); + DocumentKey key3 = testutil::Key("foo/blah"); [referenceSet addReferenceToKey:key1 forID:1]; [referenceSet addReferenceToKey:key2 forID:1]; [referenceSet addReferenceToKey:key3 forID:2]; XCTAssertFalse([referenceSet isEmpty]); [referenceSet removeReferencesForID:1]; - FSTAssertEqualSets([gc collectGarbage], (@[ key1, key2 ])); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({key1, key2})); XCTAssertFalse([referenceSet isEmpty]); [referenceSet removeReferencesForID:2]; - FSTAssertEqualSets([gc collectGarbage], @[ key3 ]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({key3})); XCTAssertTrue([referenceSet isEmpty]); } @@ -77,12 +83,12 @@ NS_ASSUME_NONNULL_BEGIN [gc addGarbageSource:localViews]; [gc addGarbageSource:mutations]; - FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); + DocumentKey key1 = testutil::Key("foo/bar"); [remoteTargets addReferenceToKey:key1 forID:1]; [localViews addReferenceToKey:key1 forID:1]; [mutations addReferenceToKey:key1 forID:10]; - FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); + DocumentKey key2 = testutil::Key("foo/baz"); [mutations addReferenceToKey:key2 forID:10]; XCTAssertFalse([remoteTargets isEmpty]); @@ -90,16 +96,16 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertFalse([mutations isEmpty]); [localViews removeReferencesForID:1]; - FSTAssertEqualSets([gc collectGarbage], @[]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({})); [remoteTargets removeReferencesForID:1]; - FSTAssertEqualSets([gc collectGarbage], @[]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({})); [mutations removeReferenceToKey:key1 forID:10]; - FSTAssertEqualSets([gc collectGarbage], @[ key1 ]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({key1})); [mutations removeReferenceToKey:key2 forID:10]; - FSTAssertEqualSets([gc collectGarbage], @[ key2 ]); + XCTAssertEqual([gc collectGarbage], std::set<DocumentKey>({key2})); XCTAssertTrue([remoteTargets isEmpty]); XCTAssertTrue([localViews isEmpty]); diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm index 57572ec..cad62cf 100644 --- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm @@ -28,8 +28,12 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +namespace testutil = firebase::firestore::testutil; using firebase::firestore::auth::User; +using firebase::firestore::model::DocumentKey; NS_ASSUME_NONNULL_BEGIN @@ -283,7 +287,7 @@ NS_ASSUME_NONNULL_BEGIN NSArray<FSTMutationBatch *> *expected = @[ batches[1], batches[2] ]; NSArray<FSTMutationBatch *> *matches = - [self.mutationQueue allMutationBatchesAffectingDocumentKey:FSTTestDocKey(@"foo/bar")]; + [self.mutationQueue allMutationBatchesAffectingDocumentKey:testutil::Key("foo/bar")]; XCTAssertEqualObjects(matches, expected); } @@ -395,28 +399,29 @@ NS_ASSUME_NONNULL_BEGIN ]]; [self removeMutationBatches:@[ batches[0] ]]; - NSSet<FSTDocumentKey *> *garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, @[]); + std::set<DocumentKey> garbage = [garbageCollector collectGarbage]; + XCTAssertEqual(garbage, std::set<DocumentKey>({})); [self removeMutationBatches:@[ batches[1] ]]; garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"foo/ba") ]); + XCTAssertEqual(garbage, std::set<DocumentKey>({testutil::Key("foo/ba")})); [self removeMutationBatches:@[ batches[5] ]]; garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"bar/baz") ]); + XCTAssertEqual(garbage, std::set<DocumentKey>({testutil::Key("bar/baz")})); [self removeMutationBatches:@[ batches[2], batches[3] ]]; garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, (@[ FSTTestDocKey(@"foo/bar"), FSTTestDocKey(@"foo/bar2") ])); + XCTAssertEqual(garbage, + std::set<DocumentKey>({testutil::Key("foo/bar"), testutil::Key("foo/bar2")})); [batches addObject:[self addMutationBatchWithKey:@"foo/bar/suffix/baz"]]; garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, @[]); + XCTAssertEqual(garbage, std::set<DocumentKey>({})); [self removeMutationBatches:@[ batches[4], batches[6] ]]; garbage = [garbageCollector collectGarbage]; - FSTAssertEqualSets(garbage, @[ FSTTestDocKey(@"foo/bar/suffix/baz") ]); + XCTAssertEqual(garbage, std::set<DocumentKey>({testutil::Key("foo/bar/suffix/baz")})); } - (void)testStreamToken { diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm index 6ef927d..5dd4b5d 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm @@ -22,11 +22,16 @@ #import "Firestore/Source/Local/FSTPersistence.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Local/FSTWriteGroup.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" #import "Firestore/third_party/Immutable/Tests/FSTImmutableSortedSet+Testing.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +namespace testutil = firebase::firestore::testutil; +using firebase::firestore::model::DocumentKey; + NS_ASSUME_NONNULL_BEGIN @implementation FSTQueryCacheTests { @@ -164,8 +169,8 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryData *rooms = [self queryDataWithQuery:_queryRooms]; [self.queryCache addQueryData:rooms group:group]; - FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/foo"); - FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/bar"); + DocumentKey key1 = testutil::Key("rooms/foo"); + DocumentKey key2 = testutil::Key("rooms/bar"); [self addMatchingKey:key1 forTargetID:rooms.targetID group:group]; [self addMatchingKey:key2 forTargetID:rooms.targetID group:group]; @@ -182,7 +187,7 @@ NS_ASSUME_NONNULL_BEGIN if ([self isTestBaseClass]) return; FSTWriteGroup *group = [self.persistence startGroupWithAction:@"AddOrRemoveMatchingKeys"]; - FSTDocumentKey *key = FSTTestDocKey(@"foo/bar"); + DocumentKey key = testutil::Key("foo/bar"); XCTAssertFalse([self.queryCache containsKey:key]); @@ -204,9 +209,9 @@ NS_ASSUME_NONNULL_BEGIN if ([self isTestBaseClass]) return; FSTWriteGroup *group = [self.persistence startGroupWithAction:@"RemoveMatchingKeysForTargetID"]; - FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); - FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); - FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); + DocumentKey key1 = testutil::Key("foo/bar"); + DocumentKey key2 = testutil::Key("foo/baz"); + DocumentKey key3 = testutil::Key("foo/blah"); [self addMatchingKey:key1 forTargetID:1 group:group]; [self addMatchingKey:key2 forTargetID:1 group:group]; @@ -233,32 +238,32 @@ NS_ASSUME_NONNULL_BEGIN FSTWriteGroup *group = [self.persistence startGroupWithAction:@"RemoveEmitsGarbageEvents"]; FSTEagerGarbageCollector *garbageCollector = [[FSTEagerGarbageCollector alloc] init]; [garbageCollector addGarbageSource:self.queryCache]; - FSTAssertEqualSets([garbageCollector collectGarbage], @[]); + XCTAssertEqual([garbageCollector collectGarbage], std::set<DocumentKey>({})); FSTQueryData *rooms = [self queryDataWithQuery:FSTTestQuery("rooms")]; - FSTDocumentKey *room1 = FSTTestDocKey(@"rooms/bar"); - FSTDocumentKey *room2 = FSTTestDocKey(@"rooms/foo"); + DocumentKey room1 = testutil::Key("rooms/bar"); + DocumentKey room2 = testutil::Key("rooms/foo"); [self.queryCache addQueryData:rooms group:group]; [self addMatchingKey:room1 forTargetID:rooms.targetID group:group]; [self addMatchingKey:room2 forTargetID:rooms.targetID group:group]; FSTQueryData *halls = [self queryDataWithQuery:FSTTestQuery("halls")]; - FSTDocumentKey *hall1 = FSTTestDocKey(@"halls/bar"); - FSTDocumentKey *hall2 = FSTTestDocKey(@"halls/foo"); + DocumentKey hall1 = testutil::Key("halls/bar"); + DocumentKey hall2 = testutil::Key("halls/foo"); [self.queryCache addQueryData:halls group:group]; [self addMatchingKey:hall1 forTargetID:halls.targetID group:group]; [self addMatchingKey:hall2 forTargetID:halls.targetID group:group]; - FSTAssertEqualSets([garbageCollector collectGarbage], @[]); + XCTAssertEqual([garbageCollector collectGarbage], std::set<DocumentKey>({})); [self removeMatchingKey:room1 forTargetID:rooms.targetID group:group]; - FSTAssertEqualSets([garbageCollector collectGarbage], @[ room1 ]); + XCTAssertEqual([garbageCollector collectGarbage], std::set<DocumentKey>({room1})); [self.queryCache removeQueryData:rooms group:group]; - FSTAssertEqualSets([garbageCollector collectGarbage], @[ room2 ]); + XCTAssertEqual([garbageCollector collectGarbage], std::set<DocumentKey>({room2})); [self.queryCache removeMatchingKeysForTargetID:halls.targetID group:group]; - FSTAssertEqualSets([garbageCollector collectGarbage], (@[ hall1, hall2 ])); + XCTAssertEqual([garbageCollector collectGarbage], std::set<DocumentKey>({hall1, hall2})); [self.persistence commitGroup:group]; } @@ -266,9 +271,9 @@ NS_ASSUME_NONNULL_BEGIN if ([self isTestBaseClass]) return; FSTWriteGroup *group = [self.persistence startGroupWithAction:@"MatchingKeysForTargetID"]; - FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar"); - FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz"); - FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah"); + DocumentKey key1 = testutil::Key("foo/bar"); + DocumentKey key2 = testutil::Key("foo/baz"); + DocumentKey key3 = testutil::Key("foo/blah"); [self addMatchingKey:key1 forTargetID:1 group:group]; [self addMatchingKey:key2 forTargetID:1 group:group]; @@ -335,8 +340,8 @@ NS_ASSUME_NONNULL_BEGIN targetID:1 listenSequenceNumber:10 purpose:FSTQueryPurposeListen]; - FSTDocumentKey *key1 = FSTTestDocKey(@"rooms/bar"); - FSTDocumentKey *key2 = FSTTestDocKey(@"rooms/foo"); + DocumentKey key1 = testutil::Key("rooms/bar"); + DocumentKey key2 = testutil::Key("rooms/foo"); [self.queryCache addQueryData:query1 group:group]; [self addMatchingKey:key1 forTargetID:1 group:group]; [self addMatchingKey:key2 forTargetID:1 group:group]; @@ -345,7 +350,7 @@ NS_ASSUME_NONNULL_BEGIN targetID:2 listenSequenceNumber:20 purpose:FSTQueryPurposeListen]; - FSTDocumentKey *key3 = FSTTestDocKey(@"halls/foo"); + DocumentKey key3 = testutil::Key("halls/foo"); [self.queryCache addQueryData:query2 group:group]; [self addMatchingKey:key3 forTargetID:2 group:group]; XCTAssertEqual([self.queryCache highestTargetID], 2); @@ -419,7 +424,7 @@ NS_ASSUME_NONNULL_BEGIN resumeToken:resumeToken]; } -- (void)addMatchingKey:(FSTDocumentKey *)key +- (void)addMatchingKey:(cons DocumentKey &)key forTargetID:(FSTTargetID)targetID group:(FSTWriteGroup *)group { FSTDocumentKeySet *keys = [FSTDocumentKeySet keySet]; @@ -427,7 +432,7 @@ NS_ASSUME_NONNULL_BEGIN [self.queryCache addMatchingKeys:keys forTargetID:targetID group:group]; } -- (void)removeMatchingKey:(FSTDocumentKey *)key +- (void)removeMatchingKey:(const DocumentKey &)key forTargetID:(FSTTargetID)targetID group:(FSTWriteGroup *)group { FSTDocumentKeySet *keys = [FSTDocumentKeySet keySet]; |