diff options
author | zxu <zxu@google.com> | 2018-03-16 15:42:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-16 15:42:05 -0400 |
commit | 4e7296b080b9c8cea13e5e5eeee65f4312fb5e8a (patch) | |
tree | 87f175b1e1ac74632fee2ff7c52ccb9b5bc78014 /Firestore/Example/Tests/Model | |
parent | 1395c8202b236188b9e4e1bfc2a3e00244179593 (diff) |
port `DocumentKey` to non-container types of `Model/*` (#930)
* 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
* add converter function between two DocumentKey implementations
* add unit test
* address changes
* fix lint
* using DocumentKey in model except for the container types `FSTDocumentDictionary`, `FSTDocumentKeySet`, and `FSTDocumentVersionDictionary`
* change other place w.r.t. the use of `DocumentKey` in model
* update parameter of test helpers from NSString to string_view
* revert a temporary change used in debug
* address changes
Diffstat (limited to 'Firestore/Example/Tests/Model')
-rw-r--r-- | Firestore/Example/Tests/Model/FSTDocumentSetTests.mm | 10 | ||||
-rw-r--r-- | Firestore/Example/Tests/Model/FSTDocumentTests.mm | 31 | ||||
-rw-r--r-- | Firestore/Example/Tests/Model/FSTMutationTests.mm | 49 |
3 files changed, 46 insertions, 44 deletions
diff --git a/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm index d70c44d..65c4ddf 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm @@ -38,9 +38,9 @@ NS_ASSUME_NONNULL_BEGIN [super setUp]; _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); + _doc1 = FSTTestDoc("docs/1", 0, @{ @"sort" : @2 }, NO); + _doc2 = FSTTestDoc("docs/2", 0, @{ @"sort" : @3 }, NO); + _doc3 = FSTTestDoc("docs/3", 0, @{ @"sort" : @1 }, NO); } - (void)testCount { @@ -97,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testUpdates { FSTDocumentSet *set = FSTTestDocSet(_comp, @[ _doc1, _doc2, _doc3 ]); - FSTDocument *doc2Prime = FSTTestDoc(@"docs/2", 0, @{ @"sort" : @9 }, NO); + FSTDocument *doc2Prime = FSTTestDoc("docs/2", 0, @{ @"sort" : @9 }, NO); set = [set documentSetByAddingDocument:doc2Prime]; XCTAssertEqual([set count], 3); @@ -106,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testAddsDocsWithEqualComparisonValues { - FSTDocument *doc4 = FSTTestDoc(@"docs/4", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc4 = FSTTestDoc("docs/4", 0, @{ @"sort" : @2 }, NO); FSTDocumentSet *set = FSTTestDocSet(_comp, @[ _doc1, doc4 ]); XCTAssertEqualObjects([[set documentEnumerator] allObjects], (@[ _doc1, doc4 ])); diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.mm b/Firestore/Example/Tests/Model/FSTDocumentTests.mm index 0527852..24858c5 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.mm @@ -19,14 +19,15 @@ #import <XCTest/XCTest.h> #import "Firestore/Source/Core/FSTSnapshotVersion.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.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 @@ -36,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTDocumentTests - (void)testConstructor { - FSTDocumentKey *key = FSTTestDocKey(@"messages/first"); + DocumentKey key = testutil::Key("messages/first"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"a" : @1 }); FSTDocument *doc = @@ -49,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testExtractsFields { - FSTDocumentKey *key = FSTTestDocKey(@"rooms/eros"); + DocumentKey key = testutil::Key("rooms/eros"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"desc" : @"Discuss all the project related stuff", @@ -65,30 +66,30 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testIsEqual { - XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/second", 1, + FSTTestDoc("messages/second", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 2, + FSTTestDoc("messages/first", 2, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, YES)); - XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, YES), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, 5)); } diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.mm b/Firestore/Example/Tests/Model/FSTMutationTests.mm index 5b056fb..40ded40 100644 --- a/Firestore/Example/Tests/Model/FSTMutationTests.mm +++ b/Firestore/Example/Tests/Model/FSTMutationTests.mm @@ -20,14 +20,15 @@ #import <XCTest/XCTest.h> #import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#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; @interface FSTMutationTests : XCTestCase @end @@ -42,32 +43,32 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesSetsToDocuments { NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"bar" : @"bar-value"}); FSTMaybeDocument *setDoc = [set applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{@"bar" : @"bar-value"}; - XCTAssertEqualObjects(setDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(setDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testAppliesPatchesToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testDeletesValuesFromTheFieldMask { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value", @"baz" : @"baz-value"} }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); - FSTDocumentKey *key = FSTTestDocKey(@"collection/key"); + DocumentKey key = testutil::Key("collection/key"); FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:{testutil::Field("foo.bar")}]; FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask @@ -77,23 +78,23 @@ namespace testutil = firebase::firestore::testutil; [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"baz" : @"baz-value"} }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testPatchesPrimitiveValue { NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testPatchingDeletedDocumentsDoesNothing { - FSTMaybeDocument *baseDoc = FSTTestDeletedDoc(@"collection/key", 0); + FSTMaybeDocument *baseDoc = FSTTestDeletedDoc("collection/key", 0); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"bar"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; @@ -102,7 +103,7 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesLocalTransformsToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *transform = FSTTestTransformMutation(@"collection/key", @[ @"foo.bar" ]); FSTMaybeDocument *transformedDoc = @@ -128,7 +129,7 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesServerAckedTransformsToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *transform = FSTTestTransformMutation(@"collection/key", @[ @"foo.bar" ]); @@ -144,22 +145,22 @@ namespace testutil = firebase::firestore::testutil; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : _timestamp.approximateDateValue}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(transformedDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(transformedDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } - (void)testDeleteDeletes { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *mutation = FSTTestDeleteMutation(@"collection/key"); FSTMaybeDocument *result = [mutation applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; - XCTAssertEqualObjects(result, FSTTestDeletedDoc(@"collection/key", 0)); + XCTAssertEqualObjects(result, FSTTestDeletedDoc("collection/key", 0)); } - (void)testSetWithMutationResult { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"foo" : @"new-bar"}); FSTMutationResult *mutationResult = @@ -170,12 +171,12 @@ namespace testutil = firebase::firestore::testutil; mutationResult:mutationResult]; NSDictionary *expectedData = @{@"foo" : @"new-bar"}; - XCTAssertEqualObjects(setDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(setDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } - (void)testPatchWithMutationResult { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"new-bar"}, {}); FSTMutationResult *mutationResult = @@ -186,7 +187,7 @@ namespace testutil = firebase::firestore::testutil; mutationResult:mutationResult]; NSDictionary *expectedData = @{@"foo" : @"new-bar"}; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } #define ASSERT_VERSION_TRANSITION(mutation, base, expected) \ @@ -204,11 +205,11 @@ namespace testutil = firebase::firestore::testutil; * Tests the transition table documented in FSTMutation.h. */ - (void)testTransitions { - FSTDocument *docV0 = FSTTestDoc(@"collection/key", 0, @{}, NO); - FSTDeletedDocument *deletedV0 = FSTTestDeletedDoc(@"collection/key", 0); + FSTDocument *docV0 = FSTTestDoc("collection/key", 0, @{}, NO); + FSTDeletedDocument *deletedV0 = FSTTestDeletedDoc("collection/key", 0); - FSTDocument *docV3 = FSTTestDoc(@"collection/key", 3, @{}, NO); - FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc(@"collection/key", 3); + FSTDocument *docV3 = FSTTestDoc("collection/key", 3, @{}, NO); + FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc("collection/key", 3); FSTMutation *setMutation = FSTTestSetMutation(@"collection/key", @{}); FSTMutation *patchMutation = FSTTestPatchMutation("collection/key", {}, {}); |