diff options
Diffstat (limited to 'Firestore')
100 files changed, 912 insertions, 475 deletions
diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm index bc253d0..0454152 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm @@ -14,10 +14,9 @@ * limitations under the License. */ -#import "Firestore/Source/Core/FSTEventManager.h" - #import <XCTest/XCTest.h> +#import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTView.h" #import "Firestore/Source/Model/FSTDocument.h" diff --git a/Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h b/Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h index 6e7c45b..5d5c981 100644 --- a/Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h +++ b/Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h @@ -16,6 +16,8 @@ #import <Foundation/Foundation.h> +#include <map> + #import "Firestore/Source/Core/FSTSyncEngine.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" diff --git a/Firestore/Example/Tests/GoogleTest/FSTGoogleTestTests.mm b/Firestore/Example/Tests/GoogleTest/FSTGoogleTestTests.mm index 18dfaf3..ec14880 100644 --- a/Firestore/Example/Tests/GoogleTest/FSTGoogleTestTests.mm +++ b/Firestore/Example/Tests/GoogleTest/FSTGoogleTestTests.mm @@ -17,9 +17,9 @@ #import <XCTest/XCTest.h> #import <objc/runtime.h> -#include <gtest/gtest.h> +#import "Firestore/Source/Util/FSTAssert.h" -#include "Firestore/Source/Util/FSTAssert.h" +#include "gtest/gtest.h" /** * An XCTest test case that finds C++ test cases written in the GoogleTest framework, runs them, and diff --git a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm index 2cf530c..615b3f6 100644 --- a/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm +++ b/Firestore/Example/Tests/Local/FSTEagerGarbageCollectorTests.mm @@ -16,10 +16,10 @@ #import "Firestore/Source/Local/FSTEagerGarbageCollector.h" -#include <set> - #import <XCTest/XCTest.h> +#include <set> + #import "Firestore/Source/Local/FSTReferenceSet.h" #import "Firestore/Source/Model/FSTDocumentKey.h" diff --git a/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm index f23b7c5..c4b7e29 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBKeyTests.mm @@ -18,6 +18,8 @@ #import <XCTest/XCTest.h> +#include <string> + #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" diff --git a/Firestore/Example/Tests/Local/FSTLevelDBLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBLocalStoreTests.mm index 97e3c5b..29caa84 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBLocalStoreTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBLocalStoreTests.mm @@ -14,13 +14,10 @@ * limitations under the License. */ -#import "Firestore/Source/Local/FSTLocalStore.h" - -#import <XCTest/XCTest.h> +#import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h" #import "Firestore/Source/Local/FSTLevelDB.h" -#import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h" #import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm index 14910ce..3da8083 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm @@ -16,11 +16,15 @@ #import <XCTest/XCTest.h> +#include <memory> +#include <string> + #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" #import "Firestore/Source/Local/FSTLevelDB.h" #import "Firestore/Source/Local/FSTLevelDBKey.h" #import "Firestore/Source/Local/FSTLevelDBMigrations.h" #import "Firestore/Source/Local/FSTLevelDBQueryCache.h" + #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" #include "leveldb/db.h" diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm index cd8176e..60d9800 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm @@ -17,7 +17,8 @@ #import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" #import <XCTest/XCTest.h> -#include <leveldb/db.h> + +#include <string> #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" #import "Firestore/Source/Local/FSTLevelDB.h" @@ -28,6 +29,7 @@ #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" +#include "leveldb/db.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTLevelDBRemoteDocumentCacheTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBRemoteDocumentCacheTests.mm index d69e613..7baf1ef 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBRemoteDocumentCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBRemoteDocumentCacheTests.mm @@ -14,16 +14,15 @@ * limitations under the License. */ -#import "Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.h" - -#include <leveldb/db.h> +#include <string> +#import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h" +#import "Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.h" #import "Firestore/Source/Local/FSTLevelDB.h" #import "Firestore/Source/Local/FSTLevelDBKey.h" -#import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h" - #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" +#include "leveldb/db.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm index a32ce9f..29f5d6c 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBTransactionTests.mm @@ -14,15 +14,23 @@ * limitations under the License. */ +#import <XCTest/XCTest.h> + +#include <memory> +#include <string> + +// This is out of order to satisfy the linter, which doesn't realize this is +// the header corresponding to this test. +// TODO(wilhuff): move this to the top once the test filename matches #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" -#import <XCTest/XCTest.h> -#include <absl/strings/string_view.h> -#include <leveldb/db.h> #import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h" #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" + #include "Firestore/core/src/firebase/firestore/local/leveldb_key.h" +#include "absl/strings/string_view.h" +#include "leveldb/db.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm index d94925d..d810aa6 100644 --- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm @@ -41,11 +41,13 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.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; +using firebase::firestore::model::FieldMask; NS_ASSUME_NONNULL_BEGIN @@ -76,13 +78,13 @@ NS_ASSUME_NONNULL_BEGIN - (void)testEncodesMutationBatch { FSTMutation *set = FSTTestSetMutation(@"foo/bar", @{ @"a" : @"b", @"num" : @1 }); - FSTMutation *patch = [[FSTPatchMutation alloc] - initWithKey:FSTTestDocKey(@"bar/baz") - fieldMask:[[FSTFieldMask alloc] initWithFields:{testutil::Field("a")}] - value:FSTTestObjectValue( - @{ @"a" : @"b", - @"num" : @1 }) - precondition:[FSTPrecondition preconditionWithExists:YES]]; + FSTMutation *patch = + [[FSTPatchMutation alloc] initWithKey:FSTTestDocKey(@"bar/baz") + fieldMask:FieldMask{testutil::Field("a")} + value:FSTTestObjectValue( + @{ @"a" : @"b", + @"num" : @1 }) + precondition:[FSTPrecondition preconditionWithExists:YES]]; FSTMutation *del = FSTTestDeleteMutation(@"baz/quux"); FIRTimestamp *writeTime = [FIRTimestamp timestamp]; FSTMutationBatch *model = [[FSTMutationBatch alloc] initWithBatchID:42 diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.h b/Firestore/Example/Tests/Local/FSTLocalStoreTests.h index 8e06d82..e514954 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.h +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.h @@ -16,7 +16,9 @@ #import <XCTest/XCTest.h> -@class FSTLocalStore; +#import "Firestore/Source/Local/FSTLocalStore.h" + +@protocol FSTPersistence; NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTMemoryLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTMemoryLocalStoreTests.mm index b78239e..7708eed 100644 --- a/Firestore/Example/Tests/Local/FSTMemoryLocalStoreTests.mm +++ b/Firestore/Example/Tests/Local/FSTMemoryLocalStoreTests.mm @@ -14,13 +14,10 @@ * limitations under the License. */ -#import "Firestore/Source/Local/FSTLocalStore.h" - -#import <XCTest/XCTest.h> +#import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h" #import "Firestore/Source/Local/FSTMemoryPersistence.h" -#import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h" #import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm index b228657..5b5bdd1 100644 --- a/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTMutationQueueTests.mm @@ -17,6 +17,9 @@ #import "Firestore/Example/Tests/Local/FSTMutationQueueTests.h" #import <FirebaseFirestore/FIRTimestamp.h> + +#include <set> + #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Local/FSTEagerGarbageCollector.h" #import "Firestore/Source/Local/FSTMutationQueue.h" @@ -246,7 +249,6 @@ NS_ASSUME_NONNULL_BEGIN return newBatches; }); self.persistence.run("testNextMutationBatchAfterBatchIDSkipsAcknowledgedBatches", [&]() { - [self.mutationQueue acknowledgeBatch:batches[0] streamToken:nil]; XCTAssertEqualObjects([self.mutationQueue nextMutationBatchAfterBatchID:kFSTBatchIDUnknown], batches[1]); diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm index 956afa9..429a83a 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm @@ -16,6 +16,8 @@ #import "Firestore/Example/Tests/Local/FSTQueryCacheTests.h" +#include <set> + #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Local/FSTEagerGarbageCollector.h" diff --git a/Firestore/Example/Tests/Local/StringViewTests.mm b/Firestore/Example/Tests/Local/StringViewTests.mm index b30b43d..7c86924 100644 --- a/Firestore/Example/Tests/Local/StringViewTests.mm +++ b/Firestore/Example/Tests/Local/StringViewTests.mm @@ -17,7 +17,8 @@ #import "Firestore/Source/Local/StringView.h" #import <XCTest/XCTest.h> -#include <leveldb/slice.h> + +#include "leveldb/slice.h" using Firestore::StringView; diff --git a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm index 98504b5..d16a01d 100644 --- a/Firestore/Example/Tests/Model/FSTFieldValueTests.mm +++ b/Firestore/Example/Tests/Model/FSTFieldValueTests.mm @@ -22,7 +22,6 @@ #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" -#import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Example/Tests/API/FSTAPIHelpers.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.mm b/Firestore/Example/Tests/Model/FSTMutationTests.mm index 1f9193e..9024b22 100644 --- a/Firestore/Example/Tests/Model/FSTMutationTests.mm +++ b/Firestore/Example/Tests/Model/FSTMutationTests.mm @@ -25,10 +25,12 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::FieldMask; @interface FSTMutationTests : XCTestCase @end @@ -69,9 +71,8 @@ using firebase::firestore::model::DocumentKey; FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); DocumentKey key = testutil::Key("collection/key"); - FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:{testutil::Field("foo.bar")}]; FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key - fieldMask:mask + fieldMask:{testutil::Field("foo.bar")} value:[FSTObjectValue objectValue] precondition:[FSTPrecondition none]]; FSTMaybeDocument *patchedDoc = diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm index 64f4777..c0e9cad 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm @@ -23,6 +23,8 @@ #import <GRPCClient/GRPCCall.h> #import <XCTest/XCTest.h> +#include <vector> + #import "Firestore/Protos/objc/firestore/local/MaybeDocument.pbobjc.h" #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" #import "Firestore/Protos/objc/google/firestore/v1beta1/Common.pbobjc.h" @@ -46,12 +48,16 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.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; +using firebase::firestore::model::FieldMask; +using firebase::firestore::model::FieldTransform; NS_ASSUME_NONNULL_BEGIN @@ -63,9 +69,9 @@ NS_ASSUME_NONNULL_BEGIN - (GCFSValue *)encodedString:(NSString *)value; - (GCFSValue *)encodedDate:(NSDate *)value; -- (GCFSDocumentMask *)encodedFieldMask:(FSTFieldMask *)fieldMask; +- (GCFSDocumentMask *)encodedFieldMask:(const FieldMask &)fieldMask; - (NSMutableArray<GCFSDocumentTransform_FieldTransform *> *)encodedFieldTransforms: - (NSArray<FSTFieldTransform *> *)fieldTransforms; + (const std::vector<FieldTransform> &)fieldTransforms; - (GCFSStructuredQuery_Filter *)encodedRelationFilter:(FSTRelationFilter *)filter; @end diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm index f66e6c7..128f825 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm @@ -16,12 +16,12 @@ #import "Firestore/Example/Tests/SpecTests/FSTSpecTests.h" -#include <map> -#include <utility> - #import <FirebaseFirestore/FIRFirestoreErrors.h> #import <GRPCClient/GRPCCall.h> +#include <map> +#include <utility> + #import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm index 91140bf..f167ce5 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm @@ -16,12 +16,12 @@ #import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h" -#include <map> -#include <unordered_map> - #import <FirebaseFirestore/FIRFirestoreErrors.h> #import <GRPCClient/GRPCCall.h> +#include <map> +#include <unordered_map> + #import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index 5751739..2e1082e 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -16,15 +16,16 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" -#include <inttypes.h> -#include <list> -#include <map> -#include <vector> - #import <FirebaseFirestore/FIRFieldPath.h> #import <FirebaseFirestore/FIRGeoPoint.h> #import <FirebaseFirestore/FIRTimestamp.h> +#include <cinttypes> +#include <list> +#include <map> +#include <utility> +#include <vector> + #import "Firestore/Source/API/FIRFieldPath+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTQuery.h" @@ -44,18 +45,26 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.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/model/transform_operations.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +#include "absl/memory/memory.h" namespace util = firebase::firestore::util; namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DatabaseId; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::FieldMask; using firebase::firestore::model::FieldPath; +using firebase::firestore::model::FieldTransform; using firebase::firestore::model::FieldValue; using firebase::firestore::model::ResourcePath; +using firebase::firestore::model::ServerTimestampTransform; +using firebase::firestore::model::TransformOperation; NS_ASSUME_NONNULL_BEGIN @@ -260,8 +269,8 @@ FSTPatchMutation *FSTTestPatchMutation(const absl::string_view path, } }]; - FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource(path)]; - FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:merge ? updateMask : fieldMaskPaths]; + DocumentKey key = testutil::Key(path); + FieldMask mask(merge ? updateMask : fieldMaskPaths); return [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask value:objectValue @@ -272,15 +281,13 @@ FSTPatchMutation *FSTTestPatchMutation(const absl::string_view path, FSTTransformMutation *FSTTestTransformMutation(NSString *path, NSArray<NSString *> *serverTimestampFields) { FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource(util::MakeStringView(path))]; - NSMutableArray<FSTFieldTransform *> *fieldTransforms = [NSMutableArray array]; + std::vector<FieldTransform> fieldTransforms; for (NSString *field in serverTimestampFields) { - const FieldPath fieldPath = testutil::Field(util::MakeStringView(field)); - id<FSTTransformOperation> transformOp = [FSTServerTimestampTransform serverTimestampTransform]; - FSTFieldTransform *transform = - [[FSTFieldTransform alloc] initWithPath:fieldPath transform:transformOp]; - [fieldTransforms addObject:transform]; + FieldPath fieldPath = testutil::Field(util::MakeStringView(field)); + auto transformOp = absl::make_unique<ServerTimestampTransform>(ServerTimestampTransform::Get()); + fieldTransforms.emplace_back(std::move(fieldPath), std::move(transformOp)); } - return [[FSTTransformMutation alloc] initWithKey:key fieldTransforms:fieldTransforms]; + return [[FSTTransformMutation alloc] initWithKey:key fieldTransforms:std::move(fieldTransforms)]; } FSTDeleteMutation *FSTTestDeleteMutation(NSString *path) { diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm index 611bcc8..79163da 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm @@ -16,14 +16,15 @@ #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" -#include <memory> -#include <utility> - #import <FirebaseCore/FIRLogger.h> #import <FirebaseFirestore/FirebaseFirestore-umbrella.h> #import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+Tests.h> +#include <memory> +#include <string> +#include <utility> + #include "Firestore/core/src/firebase/firestore/auth/empty_credentials_provider.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/util/autoid.h" diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm index cc52d45..67e401d 100644 --- a/Firestore/Source/API/FIRDocumentReference.mm +++ b/Firestore/Source/API/FIRDocumentReference.mm @@ -16,11 +16,11 @@ #import "FIRDocumentReference.h" +#import <GRPCClient/GRPCCall.h> + #include <memory> #include <utility> -#import <GRPCClient/GRPCCall.h> - #import "FIRFirestoreErrors.h" #import "FIRSnapshotMetadata.h" #import "Firestore/Source/API/FIRCollectionReference+Internal.h" diff --git a/Firestore/Source/API/FIRFieldPath.mm b/Firestore/Source/API/FIRFieldPath.mm index c651160..d0d8714 100644 --- a/Firestore/Source/API/FIRFieldPath.mm +++ b/Firestore/Source/API/FIRFieldPath.mm @@ -14,13 +14,14 @@ * limitations under the License. */ -#import "Firestore/Source/API/FIRFieldPath+Internal.h" +#import "FIRFieldPath.h" #include <functional> #include <string> #include <utility> #include <vector> +#import "Firestore/Source/API/FIRFieldPath+Internal.h" #import "Firestore/Source/Util/FSTUsageValidation.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" diff --git a/Firestore/Source/API/FIRFirestore.mm b/Firestore/Source/API/FIRFirestore.mm index 45d67cf..fe461d6 100644 --- a/Firestore/Source/API/FIRFirestore.mm +++ b/Firestore/Source/API/FIRFirestore.mm @@ -16,14 +16,14 @@ #import "FIRFirestore.h" -#include <memory> -#include <utility> - #import <FirebaseCore/FIRApp.h> #import <FirebaseCore/FIRAppInternal.h> #import <FirebaseCore/FIRLogger.h> #import <FirebaseCore/FIROptions.h> +#include <memory> +#include <utility> + #import "FIRFirestoreSettings.h" #import "Firestore/Source/API/FIRCollectionReference+Internal.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" @@ -31,7 +31,6 @@ #import "Firestore/Source/API/FIRTransaction+Internal.h" #import "Firestore/Source/API/FIRWriteBatch+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" - #import "Firestore/Source/Core/FSTFirestoreClient.h" #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" diff --git a/Firestore/Source/API/FIRFirestoreVersion.mm b/Firestore/Source/API/FIRFirestoreVersion.mm index b1fe480..8ebe814 100644 --- a/Firestore/Source/API/FIRFirestoreVersion.mm +++ b/Firestore/Source/API/FIRFirestoreVersion.mm @@ -14,6 +14,8 @@ * limitations under the License. */ +#import "Firestore/Source/API/FIRFirestoreVersion.h" + #ifndef FIRFirestore_VERSION #error "FIRFirestore_VERSION is not defined: add -DFIRFirestore_VERSION=... to the build invocation" #endif diff --git a/Firestore/Source/API/FSTUserDataConverter.h b/Firestore/Source/API/FSTUserDataConverter.h index 3b178be..a2f947a 100644 --- a/Firestore/Source/API/FSTUserDataConverter.h +++ b/Firestore/Source/API/FSTUserDataConverter.h @@ -16,14 +16,16 @@ #import <Foundation/Foundation.h> +#include <vector> + #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" @class FIRSetOptions; @class FSTObjectValue; -@class FSTFieldMask; @class FSTFieldValue; -@class FSTFieldTransform; @class FSTMutation; @class FSTPrecondition; @class FSTSnapshotVersion; @@ -36,13 +38,20 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithData:(FSTObjectValue *)data - fieldMask:(nullable FSTFieldMask *)fieldMask - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms + fieldTransforms: + (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms + NS_DESIGNATED_INITIALIZER; + +- (instancetype)initWithData:(FSTObjectValue *)data + fieldMask:(firebase::firestore::model::FieldMask)fieldMask + fieldTransforms: + (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms NS_DESIGNATED_INITIALIZER; +- (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms; + @property(nonatomic, strong, readonly) FSTObjectValue *data; -@property(nonatomic, strong, readonly, nullable) FSTFieldMask *fieldMask; -@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms; +@property(nonatomic, assign, readonly) BOOL isPatch; /** * Converts the parsed document data into 1 or 2 mutations (depending on whether there are any @@ -59,13 +68,15 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithData:(FSTObjectValue *)data - fieldMask:(FSTFieldMask *)fieldMask - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms + fieldMask:(firebase::firestore::model::FieldMask)fieldMask + fieldTransforms: + (std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms NS_DESIGNATED_INITIALIZER; +- (const firebase::firestore::model::FieldMask &)fieldMask; +- (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms; + @property(nonatomic, strong, readonly) FSTObjectValue *data; -@property(nonatomic, strong, readonly) FSTFieldMask *fieldMask; -@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms; /** * Converts the parsed update data into 1 or 2 mutations (depending on whether there are any diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm index 7ee16de..2eee878 100644 --- a/Firestore/Source/API/FSTUserDataConverter.mm +++ b/Firestore/Source/API/FSTUserDataConverter.mm @@ -35,14 +35,21 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "absl/memory/memory.h" namespace util = firebase::firestore::util; using firebase::firestore::model::DatabaseId; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::FieldMask; using firebase::firestore::model::FieldPath; +using firebase::firestore::model::FieldTransform; +using firebase::firestore::model::ServerTimestampTransform; +using firebase::firestore::model::TransformOperation; NS_ASSUME_NONNULL_BEGIN @@ -50,25 +57,45 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__"; #pragma mark - FSTParsedSetData -@implementation FSTParsedSetData +@implementation FSTParsedSetData { + FieldMask _fieldMask; + std::vector<FieldTransform> _fieldTransforms; +} + +- (instancetype)initWithData:(FSTObjectValue *)data + fieldTransforms:(std::vector<FieldTransform>)fieldTransforms { + self = [super init]; + if (self) { + _data = data; + _fieldTransforms = std::move(fieldTransforms); + _isPatch = NO; + } + return self; +} + - (instancetype)initWithData:(FSTObjectValue *)data - fieldMask:(nullable FSTFieldMask *)fieldMask - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms { + fieldMask:(FieldMask)fieldMask + fieldTransforms:(std::vector<FieldTransform>)fieldTransforms { self = [super init]; if (self) { _data = data; - _fieldMask = fieldMask; - _fieldTransforms = fieldTransforms; + _fieldMask = std::move(fieldMask); + _fieldTransforms = std::move(fieldTransforms); + _isPatch = YES; } return self; } +- (const std::vector<FieldTransform> &)fieldTransforms { + return _fieldTransforms; +} + - (NSArray<FSTMutation *> *)mutationsWithKey:(const DocumentKey &)key precondition:(FSTPrecondition *)precondition { NSMutableArray<FSTMutation *> *mutations = [NSMutableArray array]; - if (self.fieldMask) { + if (self.isPatch) { [mutations addObject:[[FSTPatchMutation alloc] initWithKey:key - fieldMask:self.fieldMask + fieldMask:_fieldMask value:self.data precondition:precondition]]; } else { @@ -76,7 +103,7 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__"; value:self.data precondition:precondition]]; } - if (self.fieldTransforms.count > 0) { + if (!self.fieldTransforms.empty()) { [mutations addObject:[[FSTTransformMutation alloc] initWithKey:key fieldTransforms:self.fieldTransforms]]; } @@ -87,15 +114,19 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__"; #pragma mark - FSTParsedUpdateData -@implementation FSTParsedUpdateData +@implementation FSTParsedUpdateData { + FieldMask _fieldMask; + std::vector<FieldTransform> _fieldTransforms; +} + - (instancetype)initWithData:(FSTObjectValue *)data - fieldMask:(FSTFieldMask *)fieldMask - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms { + fieldMask:(FieldMask)fieldMask + fieldTransforms:(std::vector<FieldTransform>)fieldTransforms { self = [super init]; if (self) { _data = data; - _fieldMask = fieldMask; - _fieldTransforms = fieldTransforms; + _fieldMask = std::move(fieldMask); + _fieldTransforms = std::move(fieldTransforms); } return self; } @@ -107,13 +138,21 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__"; fieldMask:self.fieldMask value:self.data precondition:precondition]]; - if (self.fieldTransforms.count > 0) { + if (!self.fieldTransforms.empty()) { [mutations addObject:[[FSTTransformMutation alloc] initWithKey:key fieldTransforms:self.fieldTransforms]]; } return mutations; } +- (const firebase::firestore::model::FieldMask &)fieldMask { + return _fieldMask; +} + +- (const std::vector<FieldTransform> &)fieldTransforms { + return _fieldTransforms; +} + @end /** @@ -142,7 +181,6 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { * conditions apply during parsing and providing better error messages. */ @property(nonatomic, assign) FSTUserDataSource dataSource; -@property(nonatomic, strong, readonly) NSMutableArray<FSTFieldTransform *> *fieldTransforms; - (instancetype)init NS_UNAVAILABLE; /** @@ -160,7 +198,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { - (instancetype)initWithSource:(FSTUserDataSource)dataSource path:(std::unique_ptr<FieldPath>)path arrayElement:(BOOL)arrayElement - fieldTransforms:(NSMutableArray<FSTFieldTransform *> *)fieldTransforms + fieldTransforms:(std::shared_ptr<std::vector<FieldTransform>>)fieldTransforms fieldMask:(std::shared_ptr<std::vector<FieldPath>>)fieldMask NS_DESIGNATED_INITIALIZER; @@ -178,16 +216,22 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { - (void)appendToFieldMaskWithFieldPath:(FieldPath)fieldPath; +- (const std::vector<FieldTransform> *)fieldTransforms; + +- (void)appendToFieldTransformsWithFieldPath:(FieldPath)fieldPath + transformOperation: + (std::unique_ptr<TransformOperation>)transformOperation; @end @implementation FSTParseContext { /** The current path being parsed. */ // TODO(b/34871131): path should never be nullptr, but we don't support array paths right now. std::unique_ptr<FieldPath> _path; - // _fieldMask is shared across all active context objects to accumulate the result. For example, - // the result of calling any of contextForField, contextForFieldPath and contextForArrayIndex - // shares the ownership of _fieldMask. + // _fieldMask and _fieldTransforms are shared across all active context objects to accumulate the + // result. For example, the result of calling any of contextForField, contextForFieldPath and + // contextForArrayIndex shares the ownership of _fieldMask and _fieldTransforms. std::shared_ptr<std::vector<FieldPath>> _fieldMask; + std::shared_ptr<std::vector<FieldTransform>> _fieldTransforms; } + (instancetype)contextWithSource:(FSTUserDataSource)dataSource @@ -196,7 +240,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { [[FSTParseContext alloc] initWithSource:dataSource path:std::move(path) arrayElement:NO - fieldTransforms:[NSMutableArray array] + fieldTransforms:std::make_shared<std::vector<FieldTransform>>() fieldMask:std::make_shared<std::vector<FieldPath>>()]; [context validatePath]; return context; @@ -205,13 +249,13 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { - (instancetype)initWithSource:(FSTUserDataSource)dataSource path:(std::unique_ptr<FieldPath>)path arrayElement:(BOOL)arrayElement - fieldTransforms:(NSMutableArray<FSTFieldTransform *> *)fieldTransforms + fieldTransforms:(std::shared_ptr<std::vector<FieldTransform>>)fieldTransforms fieldMask:(std::shared_ptr<std::vector<FieldPath>>)fieldMask { if (self = [super init]) { _dataSource = dataSource; _path = std::move(path); _arrayElement = arrayElement; - _fieldTransforms = fieldTransforms; + _fieldTransforms = std::move(fieldTransforms); _fieldMask = std::move(fieldMask); } return self; @@ -225,7 +269,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { FSTParseContext *context = [[FSTParseContext alloc] initWithSource:self.dataSource path:std::move(path) arrayElement:NO - fieldTransforms:self.fieldTransforms + fieldTransforms:_fieldTransforms fieldMask:_fieldMask]; [context validatePathSegment:fieldName]; return context; @@ -239,7 +283,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { FSTParseContext *context = [[FSTParseContext alloc] initWithSource:self.dataSource path:std::move(path) arrayElement:NO - fieldTransforms:self.fieldTransforms + fieldTransforms:_fieldTransforms fieldMask:_fieldMask]; [context validatePath]; return context; @@ -250,7 +294,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { return [[FSTParseContext alloc] initWithSource:self.dataSource path:nil arrayElement:YES - fieldTransforms:self.fieldTransforms + fieldTransforms:_fieldTransforms fieldMask:_fieldMask]; } @@ -309,6 +353,16 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { _fieldMask->push_back(std::move(fieldPath)); } +- (const std::vector<FieldTransform> *)fieldTransforms { + return _fieldTransforms.get(); +} + +- (void)appendToFieldTransformsWithFieldPath:(FieldPath)fieldPath + transformOperation: + (std::unique_ptr<TransformOperation>)transformOperation { + _fieldTransforms->emplace_back(std::move(fieldPath), std::move(transformOperation)); +} + @end #pragma mark - FSTDocumentKeyReference @@ -364,10 +418,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())]; FSTObjectValue *updateData = (FSTObjectValue *)[self parseData:input context:context]; - return [[FSTParsedSetData alloc] - initWithData:updateData - fieldMask:[[FSTFieldMask alloc] initWithFields:*context.fieldMask] - fieldTransforms:context.fieldTransforms]; + return [[FSTParsedSetData alloc] initWithData:updateData + fieldMask:FieldMask{*context.fieldMask} + fieldTransforms:*context.fieldTransforms]; } - (FSTParsedSetData *)parsedSetData:(id)input { @@ -382,9 +435,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())]; FSTObjectValue *updateData = (FSTObjectValue *)[self parseData:input context:context]; - return [[FSTParsedSetData alloc] initWithData:updateData - fieldMask:nil - fieldTransforms:context.fieldTransforms]; + return + [[FSTParsedSetData alloc] initWithData:updateData fieldTransforms:*context.fieldTransforms]; } - (FSTParsedUpdateData *)parsedUpdateData:(id)input { @@ -428,10 +480,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { } }]; - FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:fieldMaskPaths]; return [[FSTParsedUpdateData alloc] initWithData:updateData - fieldMask:mask - fieldTransforms:context.fieldTransforms]; + fieldMask:FieldMask{fieldMaskPaths} + fieldTransforms:*context.fieldTransforms]; } - (FSTFieldValue *)parsedQueryValue:(id)input { @@ -440,7 +491,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())]; FSTFieldValue *_Nullable parsed = [self parseData:input context:context]; FSTAssert(parsed, @"Parsed data should not be nil."); - FSTAssert(context.fieldTransforms.count == 0, @"Field transforms should have been disallowed."); + FSTAssert(context.fieldTransforms->empty(), @"Field transforms should have been disallowed."); return parsed; } @@ -639,10 +690,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { @"FieldValue.serverTimestamp() is not currently supported inside arrays%@", [context fieldDescription]); } - [context.fieldTransforms - addObject:[[FSTFieldTransform alloc] - initWithPath:*context.path - transform:[FSTServerTimestampTransform serverTimestampTransform]]]; + [context appendToFieldTransformsWithFieldPath:*context.path + transformOperation:absl::make_unique<ServerTimestampTransform>( + ServerTimestampTransform::Get())]; // Return nil so this value is omitted from the parsed result. return nil; diff --git a/Firestore/Source/Core/FSTFirestoreClient.mm b/Firestore/Source/Core/FSTFirestoreClient.mm index c0d38ca..33d1903 100644 --- a/Firestore/Source/Core/FSTFirestoreClient.mm +++ b/Firestore/Source/Core/FSTFirestoreClient.mm @@ -16,7 +16,8 @@ #import "Firestore/Source/Core/FSTFirestoreClient.h" -#import <future> +#include <future> // NOLINT(build/c++11) +#include <memory> #import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTSyncEngine.h" diff --git a/Firestore/Source/Core/FSTListenSequence.mm b/Firestore/Source/Core/FSTListenSequence.mm index 6f50d35..6a9f9ae 100644 --- a/Firestore/Source/Core/FSTListenSequence.mm +++ b/Firestore/Source/Core/FSTListenSequence.mm @@ -14,7 +14,7 @@ * limitations under the License. */ -#import "FSTListenSequence.h" +#import "Firestore/Source/Core/FSTListenSequence.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Core/FSTQuery.mm b/Firestore/Source/Core/FSTQuery.mm index 811ad03..8f49c26 100644 --- a/Firestore/Source/Core/FSTQuery.mm +++ b/Firestore/Source/Core/FSTQuery.mm @@ -17,6 +17,7 @@ #import "Firestore/Source/Core/FSTQuery.h" #include <memory> +#include <string> #include <utility> #import "Firestore/Source/API/FIRFirestore+Internal.h" diff --git a/Firestore/Source/Core/FSTSyncEngine.mm b/Firestore/Source/Core/FSTSyncEngine.mm index 673991c..0a4fc94 100644 --- a/Firestore/Source/Core/FSTSyncEngine.mm +++ b/Firestore/Source/Core/FSTSyncEngine.mm @@ -16,11 +16,12 @@ #import "Firestore/Source/Core/FSTSyncEngine.h" +#import <GRPCClient/GRPCCall.h> + #include <map> +#include <set> #include <unordered_map> -#import <GRPCClient/GRPCCall.h> - #import "FIRFirestoreErrors.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" diff --git a/Firestore/Source/Core/FSTTransaction.h b/Firestore/Source/Core/FSTTransaction.h index 676ada9..581a5fa 100644 --- a/Firestore/Source/Core/FSTTransaction.h +++ b/Firestore/Source/Core/FSTTransaction.h @@ -24,8 +24,6 @@ @class FIRSetOptions; @class FSTDatastore; -@class FSTFieldMask; -@class FSTFieldTransform; @class FSTMaybeDocument; @class FSTObjectValue; @class FSTParsedSetData; diff --git a/Firestore/Source/Core/FSTTransaction.mm b/Firestore/Source/Core/FSTTransaction.mm index 9e67ed4..71c1f35 100644 --- a/Firestore/Source/Core/FSTTransaction.mm +++ b/Firestore/Source/Core/FSTTransaction.mm @@ -16,11 +16,11 @@ #import "Firestore/Source/Core/FSTTransaction.h" +#import <GRPCClient/GRPCCall.h> + #include <map> #include <vector> -#import <GRPCClient/GRPCCall.h> - #import "FIRFirestoreErrors.h" #import "FIRSetOptions.h" #import "Firestore/Source/API/FSTUserDataConverter.h" diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm index 4812228..fae85e7 100644 --- a/Firestore/Source/Local/FSTLevelDB.mm +++ b/Firestore/Source/Local/FSTLevelDB.mm @@ -16,7 +16,7 @@ #import "Firestore/Source/Local/FSTLevelDB.h" -#include <leveldb/db.h> +#include <memory> #import "FIRFirestoreErrors.h" #import "Firestore/Source/Local/FSTLevelDBMigrations.h" @@ -26,13 +26,14 @@ #import "Firestore/Source/Remote/FSTSerializerBeta.h" #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTLogger.h" -#include "absl/memory/memory.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "absl/memory/memory.h" +#include "leveldb/db.h" namespace util = firebase::firestore::util; using firebase::firestore::auth::User; diff --git a/Firestore/Source/Local/FSTLevelDBKey.h b/Firestore/Source/Local/FSTLevelDBKey.h index c7a64ee..5b234ec 100644 --- a/Firestore/Source/Local/FSTLevelDBKey.h +++ b/Firestore/Source/Local/FSTLevelDBKey.h @@ -16,6 +16,8 @@ #import <Foundation/Foundation.h> +#include <string> + #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Local/StringView.h" diff --git a/Firestore/Source/Local/FSTLevelDBMigrations.mm b/Firestore/Source/Local/FSTLevelDBMigrations.mm index cf06c9f..fefd0f7 100644 --- a/Firestore/Source/Local/FSTLevelDBMigrations.mm +++ b/Firestore/Source/Local/FSTLevelDBMigrations.mm @@ -14,16 +14,18 @@ * limitations under the License. */ -#include "Firestore/Source/Local/FSTLevelDBMigrations.h" +#import "Firestore/Source/Local/FSTLevelDBMigrations.h" -#include <absl/strings/match.h> -#include "leveldb/write_batch.h" +#include <string> #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" #import "Firestore/Source/Local/FSTLevelDBKey.h" #import "Firestore/Source/Local/FSTLevelDBQueryCache.h" #import "Firestore/Source/Util/FSTAssert.h" +#include "absl/strings/match.h" +#include "leveldb/write_batch.h" + NS_ASSUME_NONNULL_BEGIN // Current version of the schema defined in this file. diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 29acead..75c3cf6 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -16,13 +16,10 @@ #import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" +#include <memory> #include <set> #include <string> -#include <absl/strings/match.h> -#include <leveldb/db.h> -#include <leveldb/write_batch.h> - #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Local/FSTLevelDB.h" @@ -38,6 +35,9 @@ #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/src/firebase/firestore/util/string_util.h" +#include "absl/strings/match.h" +#include "leveldb/db.h" +#include "leveldb/write_batch.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index aa1ab41..5fde7d7 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -16,6 +16,9 @@ #import "Firestore/Source/Local/FSTLevelDBQueryCache.h" +#include <memory> +#include <string> + #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Local/FSTLevelDB.h" @@ -23,9 +26,9 @@ #import "Firestore/Source/Local/FSTLocalSerializer.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Util/FSTAssert.h" -#include "absl/strings/match.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "absl/strings/match.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm index 703fc69..f655e3a 100644 --- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm @@ -16,8 +16,6 @@ #import "Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.h" -#include <leveldb/db.h> -#include <leveldb/write_batch.h> #include <string> #import "Firestore/Protos/objc/firestore/local/MaybeDocument.pbobjc.h" @@ -29,8 +27,11 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Util/FSTAssert.h" + #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "leveldb/db.h" +#include "leveldb/write_batch.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Local/FSTLocalSerializer.mm b/Firestore/Source/Local/FSTLocalSerializer.mm index 1d9455d..61e173a 100644 --- a/Firestore/Source/Local/FSTLocalSerializer.mm +++ b/Firestore/Source/Local/FSTLocalSerializer.mm @@ -16,7 +16,7 @@ #import "Firestore/Source/Local/FSTLocalSerializer.h" -#include <inttypes.h> +#include <cinttypes> #import "Firestore/Protos/objc/firestore/local/MaybeDocument.pbobjc.h" #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm index 990e332..b5dfeec 100644 --- a/Firestore/Source/Local/FSTLocalStore.mm +++ b/Firestore/Source/Local/FSTLocalStore.mm @@ -16,6 +16,8 @@ #import "Firestore/Source/Local/FSTLocalStore.h" +#include <set> + #import "FIRTimestamp.h" #import "Firestore/Source/Core/FSTListenSequence.h" #import "Firestore/Source/Core/FSTQuery.h" diff --git a/Firestore/Source/Local/FSTNoOpGarbageCollector.mm b/Firestore/Source/Local/FSTNoOpGarbageCollector.mm index 451cde2..421d283 100644 --- a/Firestore/Source/Local/FSTNoOpGarbageCollector.mm +++ b/Firestore/Source/Local/FSTNoOpGarbageCollector.mm @@ -16,6 +16,8 @@ #import "Firestore/Source/Local/FSTNoOpGarbageCollector.h" +#include <set> + #include "Firestore/core/src/firebase/firestore/model/document_key.h" using firebase::firestore::model::DocumentKey; diff --git a/Firestore/Source/Local/StringView.h b/Firestore/Source/Local/StringView.h index 4e36cff..85afcaa 100644 --- a/Firestore/Source/Local/StringView.h +++ b/Firestore/Source/Local/StringView.h @@ -19,9 +19,10 @@ #import <Foundation/Foundation.h> -#include <leveldb/slice.h> #include <string> + #include "absl/strings/string_view.h" +#include "leveldb/slice.h" namespace Firestore { @@ -43,7 +44,7 @@ class StringView { // Creates a StringView from an NSString. When StringView is an argument type // into which an NSString* is passed, the caller should ensure that the // NSString is retained. - StringView(NSString *str) + StringView(NSString *str) // NOLINT(runtime/explicit) : data_([str UTF8String]), size_([str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) { } @@ -54,20 +55,24 @@ class StringView { // Creates a StringView from the given char* pointer but computes the size // with strlen. This is really only suitable for passing C string literals. - StringView(const char *data) : data_(data), size_(strlen(data)) { + StringView(const char *data) // NOLINT(runtime/explicit) + : data_(data), size_(strlen(data)) { } // Creates a StringView from the given slice. - StringView(leveldb::Slice slice) : data_(slice.data()), size_(slice.size()) { + StringView(leveldb::Slice slice) // NOLINT(runtime/explicit) + : data_(slice.data()), size_(slice.size()) { } // Creates a StringView from the absl::string_view. - StringView(absl::string_view s) : data_(s.data()), size_(s.size()) { + StringView(absl::string_view s) // NOLINT(runtime/explicit) + : data_(s.data()), size_(s.size()) { } // Creates a StringView from the given std::string. The string must be an // lvalue for the lifetime requirements to be satisfied. - StringView(const std::string &str) : data_(str.data()), size_(str.size()) { + StringView(const std::string &str) // NOLINT(runtime/explicit) + : data_(str.data()), size_(str.size()) { } // Converts this StringView to a Slice, which is an equivalent (and more diff --git a/Firestore/Source/Model/FSTDocumentKey.h b/Firestore/Source/Model/FSTDocumentKey.h index dbcff2c..a403117 100644 --- a/Firestore/Source/Model/FSTDocumentKey.h +++ b/Firestore/Source/Model/FSTDocumentKey.h @@ -17,6 +17,7 @@ #import <Foundation/Foundation.h> #include <initializer_list> +#include <string> #include "Firestore/core/src/firebase/firestore/model/resource_path.h" diff --git a/Firestore/Source/Model/FSTDocumentKey.mm b/Firestore/Source/Model/FSTDocumentKey.mm index cbe9c89..679d7a6 100644 --- a/Firestore/Source/Model/FSTDocumentKey.mm +++ b/Firestore/Source/Model/FSTDocumentKey.mm @@ -16,6 +16,7 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" +#include <string> #include <utility> #import "Firestore/Source/Core/FSTFirestoreClient.h" diff --git a/Firestore/Source/Model/FSTFieldValue.mm b/Firestore/Source/Model/FSTFieldValue.mm index 80bd11f..0d7c649 100644 --- a/Firestore/Source/Model/FSTFieldValue.mm +++ b/Firestore/Source/Model/FSTFieldValue.mm @@ -18,9 +18,6 @@ #import "FIRTimestamp.h" -#include "Firestore/core/src/firebase/firestore/util/comparison.h" -#include "Firestore/core/src/firebase/firestore/util/string_apple.h" - #import "Firestore/Source/API/FIRGeoPoint+Internal.h" #import "Firestore/Source/API/FIRSnapshotOptions+Internal.h" #import "Firestore/Source/Model/FSTDocumentKey.h" @@ -29,6 +26,7 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/util/comparison.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; diff --git a/Firestore/Source/Model/FSTMutation.h b/Firestore/Source/Model/FSTMutation.h index 4e4357d..38c35bf 100644 --- a/Firestore/Source/Model/FSTMutation.h +++ b/Firestore/Source/Model/FSTMutation.h @@ -16,10 +16,14 @@ #import <Foundation/Foundation.h> +#include <memory> #include <vector> #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" @class FSTDocument; @class FSTFieldValue; @@ -30,51 +34,6 @@ NS_ASSUME_NONNULL_BEGIN -#pragma mark - FSTFieldMask - -/** - * Provides a set of fields that can be used to partially patch a document. FieldMask is used in - * conjunction with ObjectValue. - * - * Examples: - * foo - Overwrites foo entirely with the provided value. If foo is not present in the companion - * ObjectValue, the field is deleted. - * foo.bar - Overwrites only the field bar of the object foo. If foo is not an object, foo is - * replaced with an object containing bar. - */ -@interface FSTFieldMask : NSObject -- (id)init __attribute__((unavailable("Use initWithFields:"))); - -/** - * Initializes the field mask with the given field paths. Caller is expected to either copy or - * or release the array of fields. - */ -- (instancetype)initWithFields:(std::vector<firebase::firestore::model::FieldPath>)fields - NS_DESIGNATED_INITIALIZER; - -- (const std::vector<firebase::firestore::model::FieldPath> &)fields; -@end - -#pragma mark - FSTFieldTransform - -/** Represents a transform within a TransformMutation. */ -@protocol FSTTransformOperation <NSObject> -@end - -/** Transforms a value into a server-generated timestamp. */ -@interface FSTServerTimestampTransform : NSObject <FSTTransformOperation> -+ (instancetype)serverTimestampTransform; -@end - -/** A field path and the FSTTransformOperation to perform upon it. */ -@interface FSTFieldTransform : NSObject -- (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithPath:(firebase::firestore::model::FieldPath)path - transform:(id<FSTTransformOperation>)transform NS_DESIGNATED_INITIALIZER; -- (const firebase::firestore::model::FieldPath &)path; -@property(nonatomic, strong, readonly) id<FSTTransformOperation> transform; -@end - #pragma mark - FSTPrecondition typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { @@ -132,7 +91,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { /** * The resulting fields returned from the backend after a FSTTransformMutation has been committed. - * Contains one FieldValue for each FSTFieldTransform that was in the mutation. + * Contains one FieldValue for each FieldTransform that was in the mutation. * * Will be nil if the mutation was not a FSTTransformMutation. */ @@ -267,7 +226,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE; /** - * Initializes a new patch mutation with an explicit FSTFieldMask and FSTObjectValue representing + * Initializes a new patch mutation with an explicit FieldMask and FSTObjectValue representing * the updates to perform * * @param key Identifies the location of the document to mutate. @@ -278,18 +237,18 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { * @param precondition The precondition for this mutation. */ - (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key - fieldMask:(FSTFieldMask *)fieldMask + fieldMask:(firebase::firestore::model::FieldMask)fieldMask value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER; -/** The fields and associated values to use when patching the document. */ -@property(nonatomic, strong, readonly) FSTObjectValue *value; - /** * A mask to apply to |value|, where only fields that are in both the fieldMask and the value * will be updated. */ -@property(nonatomic, strong, readonly) FSTFieldMask *fieldMask; +- (const firebase::firestore::model::FieldMask &)fieldMask; + +/** The fields and associated values to use when patching the document. */ +@property(nonatomic, strong, readonly) FSTObjectValue *value; @end @@ -313,14 +272,14 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { * Initializes a new transform mutation with the specified field transforms. * * @param key Identifies the location of the document to mutate. - * @param fieldTransforms A list of FSTFieldTransform objects to perform to the document. + * @param fieldTransforms A list of FieldTransform objects to perform to the document. */ - (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms + fieldTransforms:(std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms NS_DESIGNATED_INITIALIZER; /** The field transforms to use when transforming the document. */ -@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms; +- (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms; @end diff --git a/Firestore/Source/Model/FSTMutation.mm b/Firestore/Source/Model/FSTMutation.mm index 253a853..dd649a0 100644 --- a/Firestore/Source/Model/FSTMutation.mm +++ b/Firestore/Source/Model/FSTMutation.mm @@ -16,7 +16,10 @@ #import "Firestore/Source/Model/FSTMutation.h" +#include <memory> +#include <string> #include <utility> +#include <vector> #import "FIRTimestamp.h" @@ -27,113 +30,20 @@ #import "Firestore/Source/Util/FSTClasses.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::FieldMask; using firebase::firestore::model::FieldPath; +using firebase::firestore::model::FieldTransform; +using firebase::firestore::model::ServerTimestampTransform; +using firebase::firestore::model::TransformOperation; NS_ASSUME_NONNULL_BEGIN -#pragma mark - FSTFieldMask - -@implementation FSTFieldMask { - std::vector<FieldPath> _fields; -} - -- (instancetype)initWithFields:(std::vector<FieldPath>)fields { - if (self = [super init]) { - _fields = std::move(fields); - } - return self; -} - -- (BOOL)isEqual:(id)other { - if (other == self) { - return YES; - } - if (![other isKindOfClass:[FSTFieldMask class]]) { - return NO; - } - - FSTFieldMask *otherMask = (FSTFieldMask *)other; - return _fields == otherMask->_fields; -} - -- (NSUInteger)hash { - NSUInteger hashResult = 0; - for (const FieldPath &field : _fields) { - hashResult = hashResult * 31u + field.Hash(); - } - return hashResult; -} - -- (const std::vector<FieldPath> &)fields { - return _fields; -} -@end - -#pragma mark - FSTServerTimestampTransform - -@implementation FSTServerTimestampTransform - -+ (instancetype)serverTimestampTransform { - static FSTServerTimestampTransform *sharedInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [[FSTServerTimestampTransform alloc] init]; - }); - return sharedInstance; -} - -- (BOOL)isEqual:(id)other { - if (other == self) { - return YES; - } - return [other isKindOfClass:[FSTServerTimestampTransform class]]; -} - -- (NSUInteger)hash { - // arbitrary number since all instances are equal. - return 37; -} - -@end - -#pragma mark - FSTFieldTransform - -@implementation FSTFieldTransform { - FieldPath _path; -} - -- (instancetype)initWithPath:(FieldPath)path transform:(id<FSTTransformOperation>)transform { - self = [super init]; - if (self) { - _path = std::move(path); - _transform = transform; - } - return self; -} - -- (BOOL)isEqual:(id)other { - if (other == self) return YES; - if (![[other class] isEqual:[self class]]) return NO; - FSTFieldTransform *otherFieldTransform = other; - return self.path == otherFieldTransform.path && - [self.transform isEqual:otherFieldTransform.transform]; -} - -- (NSUInteger)hash { - NSUInteger hash = self.path.Hash(); - hash = hash * 31 + [self.transform hash]; - return hash; -} - -- (const firebase::firestore::model::FieldPath &)path { - return _path; -} - -@end - #pragma mark - FSTPrecondition @implementation FSTPrecondition @@ -354,20 +264,26 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - FSTPatchMutation -@implementation FSTPatchMutation +@implementation FSTPatchMutation { + FieldMask _fieldMask; +} - (instancetype)initWithKey:(DocumentKey)key - fieldMask:(FSTFieldMask *)fieldMask + fieldMask:(FieldMask)fieldMask value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition { self = [super initWithKey:std::move(key) precondition:precondition]; if (self) { - _fieldMask = fieldMask; + _fieldMask = std::move(fieldMask); _value = value; } return self; } +- (const firebase::firestore::model::FieldMask &)fieldMask { + return _fieldMask; +} + - (BOOL)isEqual:(id)other { if (other == self) { return YES; @@ -377,7 +293,7 @@ NS_ASSUME_NONNULL_BEGIN } FSTPatchMutation *otherMutation = (FSTPatchMutation *)other; - return [self.key isEqual:otherMutation.key] && [self.fieldMask isEqual:otherMutation.fieldMask] && + return [self.key isEqual:otherMutation.key] && self.fieldMask == otherMutation.fieldMask && [self.value isEqual:otherMutation.value] && [self.precondition isEqual:otherMutation.precondition]; } @@ -385,15 +301,15 @@ NS_ASSUME_NONNULL_BEGIN - (NSUInteger)hash { NSUInteger result = [self.key hash]; result = 31 * result + [self.precondition hash]; - result = 31 * result + [self.fieldMask hash]; + result = 31 * result + self.fieldMask.Hash(); result = 31 * result + [self.value hash]; return result; } - (NSString *)description { - return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%@ value=%@ precondition=%@>", - self.key.ToString().c_str(), self.fieldMask, self.value, - self.precondition]; + return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%s value=%@ precondition=%@>", + self.key.ToString().c_str(), self.fieldMask.ToString().c_str(), + self.value, self.precondition]; } - (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc @@ -434,7 +350,7 @@ NS_ASSUME_NONNULL_BEGIN - (FSTObjectValue *)patchObjectValue:(FSTObjectValue *)objectValue { FSTObjectValue *result = objectValue; - for (const FieldPath &fieldPath : self.fieldMask.fields) { + for (const FieldPath &fieldPath : self.fieldMask) { FSTFieldValue *newValue = [self.value valueForPath:fieldPath]; if (newValue) { result = [result objectBySettingValue:newValue forPath:fieldPath]; @@ -447,20 +363,27 @@ NS_ASSUME_NONNULL_BEGIN @end -@implementation FSTTransformMutation +@implementation FSTTransformMutation { + /** The field transforms to use when transforming the document. */ + std::vector<FieldTransform> _fieldTransforms; +} - (instancetype)initWithKey:(DocumentKey)key - fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms { + fieldTransforms:(std::vector<FieldTransform>)fieldTransforms { // NOTE: We set a precondition of exists: true as a safety-check, since we always combine // FSTTransformMutations with a FSTSetMutation or FSTPatchMutation which (if successful) should // end up with an existing document. if (self = [super initWithKey:std::move(key) precondition:[FSTPrecondition preconditionWithExists:YES]]) { - _fieldTransforms = fieldTransforms; + _fieldTransforms = std::move(fieldTransforms); } return self; } +- (const std::vector<FieldTransform> &)fieldTransforms { + return _fieldTransforms; +} + - (BOOL)isEqual:(id)other { if (other == self) { return YES; @@ -471,20 +394,26 @@ NS_ASSUME_NONNULL_BEGIN FSTTransformMutation *otherMutation = (FSTTransformMutation *)other; return [self.key isEqual:otherMutation.key] && - [self.fieldTransforms isEqual:otherMutation.fieldTransforms] && + self.fieldTransforms == otherMutation.fieldTransforms && [self.precondition isEqual:otherMutation.precondition]; } - (NSUInteger)hash { NSUInteger result = [self.key hash]; result = 31 * result + [self.precondition hash]; - result = 31 * result + [self.fieldTransforms hash]; + for (const auto &transform : self.fieldTransforms) { + result = 31 * result + transform.Hash(); + } return result; } - (NSString *)description { - return [NSString stringWithFormat:@"<FSTTransformMutation key=%s transforms=%@ precondition=%@>", - self.key.ToString().c_str(), self.fieldTransforms, + std::string fieldTransforms; + for (const auto &transform : self.fieldTransforms) { + fieldTransforms += " " + transform.path().CanonicalString(); + } + return [NSString stringWithFormat:@"<FSTTransformMutation key=%s transforms=%s precondition=%@>", + self.key.ToString().c_str(), fieldTransforms.c_str(), self.precondition]; } @@ -534,19 +463,19 @@ NS_ASSUME_NONNULL_BEGIN (FSTMaybeDocument *_Nullable)baseDocument writeTime:(FIRTimestamp *)localWriteTime { NSMutableArray<FSTFieldValue *> *transformResults = [NSMutableArray array]; - for (FSTFieldTransform *fieldTransform in self.fieldTransforms) { - if ([fieldTransform.transform isKindOfClass:[FSTServerTimestampTransform class]]) { + for (const FieldTransform &fieldTransform : self.fieldTransforms) { + if (fieldTransform.transformation().type() == TransformOperation::Type::ServerTimestamp) { FSTFieldValue *previousValue = nil; if ([baseDocument isMemberOfClass:[FSTDocument class]]) { - previousValue = [((FSTDocument *)baseDocument) fieldForPath:fieldTransform.path]; + previousValue = [((FSTDocument *)baseDocument) fieldForPath:fieldTransform.path()]; } [transformResults addObject:[FSTServerTimestampValue serverTimestampValueWithLocalWriteTime:localWriteTime previousValue:previousValue]]; } else { - FSTFail(@"Encountered unknown transform: %@", fieldTransform); + FSTFail(@"Encountered unknown transform: %d type", fieldTransform.transformation().type()); } } return transformResults; @@ -554,17 +483,17 @@ NS_ASSUME_NONNULL_BEGIN - (FSTObjectValue *)transformObject:(FSTObjectValue *)objectValue transformResults:(NSArray<FSTFieldValue *> *)transformResults { - FSTAssert(transformResults.count == self.fieldTransforms.count, + FSTAssert(transformResults.count == self.fieldTransforms.size(), @"Transform results length mismatch."); - for (NSUInteger i = 0; i < self.fieldTransforms.count; i++) { - FSTFieldTransform *fieldTransform = self.fieldTransforms[i]; - id<FSTTransformOperation> transform = fieldTransform.transform; - FieldPath fieldPath = fieldTransform.path; - if ([transform isKindOfClass:[FSTServerTimestampTransform class]]) { + for (size_t i = 0; i < self.fieldTransforms.size(); i++) { + const FieldTransform &fieldTransform = self.fieldTransforms[i]; + const TransformOperation &transform = fieldTransform.transformation(); + const FieldPath &fieldPath = fieldTransform.path(); + if (transform.type() == TransformOperation::Type::ServerTimestamp) { objectValue = [objectValue objectBySettingValue:transformResults[i] forPath:fieldPath]; } else { - FSTFail(@"Encountered unknown transform: %@", transform); + FSTFail(@"Encountered unknown transform: %d type", transform.type()); } } return objectValue; diff --git a/Firestore/Source/Remote/FSTDatastore.mm b/Firestore/Source/Remote/FSTDatastore.mm index 501237f..b34f78f 100644 --- a/Firestore/Source/Remote/FSTDatastore.mm +++ b/Firestore/Source/Remote/FSTDatastore.mm @@ -16,12 +16,12 @@ #import "Firestore/Source/Remote/FSTDatastore.h" -#include <memory> -#include <vector> - #import <GRPCClient/GRPCCall+OAuth2.h> #import <ProtoRPC/ProtoRPC.h> +#include <memory> +#include <vector> + #import "FIRFirestoreErrors.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FIRFirestoreVersion.h" diff --git a/Firestore/Source/Remote/FSTRemoteStore.mm b/Firestore/Source/Remote/FSTRemoteStore.mm index 8892ffb..39d285a 100644 --- a/Firestore/Source/Remote/FSTRemoteStore.mm +++ b/Firestore/Source/Remote/FSTRemoteStore.mm @@ -16,7 +16,7 @@ #import "Firestore/Source/Remote/FSTRemoteStore.h" -#include <inttypes.h> +#include <cinttypes> #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" diff --git a/Firestore/Source/Remote/FSTSerializerBeta.mm b/Firestore/Source/Remote/FSTSerializerBeta.mm index 3a22a3f..1d9ad30 100644 --- a/Firestore/Source/Remote/FSTSerializerBeta.mm +++ b/Firestore/Source/Remote/FSTSerializerBeta.mm @@ -16,10 +16,12 @@ #import "Firestore/Source/Remote/FSTSerializerBeta.h" -#include <inttypes.h> - #import <GRPCClient/GRPCCall.h> -#import "FIRTimestamp.h" + +#include <cinttypes> +#include <string> +#include <utility> +#include <vector> #import "Firestore/Protos/objc/google/firestore/v1beta1/Common.pbobjc.h" #import "Firestore/Protos/objc/google/firestore/v1beta1/Document.pbobjc.h" @@ -31,6 +33,7 @@ #import "FIRFirestoreErrors.h" #import "FIRGeoPoint.h" +#import "FIRTimestamp.h" #import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Local/FSTQueryData.h" @@ -44,15 +47,23 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "absl/memory/memory.h" namespace util = firebase::firestore::util; using firebase::firestore::model::DatabaseId; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::FieldMask; using firebase::firestore::model::FieldPath; +using firebase::firestore::model::FieldTransform; using firebase::firestore::model::ResourcePath; +using firebase::firestore::model::ServerTimestampTransform; +using firebase::firestore::model::TransformOperation; NS_ASSUME_NONNULL_BEGIN @@ -539,49 +550,48 @@ NS_ASSUME_NONNULL_BEGIN } } -- (GCFSDocumentMask *)encodedFieldMask:(FSTFieldMask *)fieldMask { +- (GCFSDocumentMask *)encodedFieldMask:(const FieldMask &)fieldMask { GCFSDocumentMask *mask = [GCFSDocumentMask message]; - for (const FieldPath &field : fieldMask.fields) { + for (const FieldPath &field : fieldMask) { [mask.fieldPathsArray addObject:util::WrapNSString(field.CanonicalString())]; } return mask; } -- (FSTFieldMask *)decodedFieldMask:(GCFSDocumentMask *)fieldMask { - std::vector<FieldPath> fields{}; +- (FieldMask)decodedFieldMask:(GCFSDocumentMask *)fieldMask { + std::vector<FieldPath> fields; fields.reserve(fieldMask.fieldPathsArray_Count); for (NSString *path in fieldMask.fieldPathsArray) { fields.push_back(FieldPath::FromServerFormat(util::MakeStringView(path))); } - return [[FSTFieldMask alloc] initWithFields:std::move(fields)]; + return FieldMask(std::move(fields)); } - (NSMutableArray<GCFSDocumentTransform_FieldTransform *> *)encodedFieldTransforms: - (NSArray<FSTFieldTransform *> *)fieldTransforms { + (const std::vector<FieldTransform> &)fieldTransforms { NSMutableArray *protos = [NSMutableArray array]; - for (FSTFieldTransform *fieldTransform in fieldTransforms) { - FSTAssert([fieldTransform.transform isKindOfClass:[FSTServerTimestampTransform class]], - @"Unknown transform: %@", fieldTransform.transform); + for (const FieldTransform &fieldTransform : fieldTransforms) { + FSTAssert(fieldTransform.transformation().type() == TransformOperation::Type::ServerTimestamp, + @"Unknown transform: %d type", fieldTransform.transformation().type()); GCFSDocumentTransform_FieldTransform *proto = [GCFSDocumentTransform_FieldTransform message]; - proto.fieldPath = util::WrapNSString(fieldTransform.path.CanonicalString()); + proto.fieldPath = util::WrapNSString(fieldTransform.path().CanonicalString()); proto.setToServerValue = GCFSDocumentTransform_FieldTransform_ServerValue_RequestTime; [protos addObject:proto]; } return protos; } -- (NSArray<FSTFieldTransform *> *)decodedFieldTransforms: +- (std::vector<FieldTransform>)decodedFieldTransforms: (NSArray<GCFSDocumentTransform_FieldTransform *> *)protos { - NSMutableArray<FSTFieldTransform *> *fieldTransforms = [NSMutableArray array]; + std::vector<FieldTransform> fieldTransforms; + fieldTransforms.reserve(protos.count); for (GCFSDocumentTransform_FieldTransform *proto in protos) { FSTAssert( proto.setToServerValue == GCFSDocumentTransform_FieldTransform_ServerValue_RequestTime, @"Unknown transform setToServerValue: %d", proto.setToServerValue); - [fieldTransforms - addObject:[[FSTFieldTransform alloc] - initWithPath:FieldPath::FromServerFormat( - util::MakeStringView(proto.fieldPath)) - transform:[FSTServerTimestampTransform serverTimestampTransform]]]; + fieldTransforms.emplace_back( + FieldPath::FromServerFormat(util::MakeStringView(proto.fieldPath)), + absl::make_unique<ServerTimestampTransform>(ServerTimestampTransform::Get())); } return fieldTransforms; } diff --git a/Firestore/Source/Remote/FSTStream.mm b/Firestore/Source/Remote/FSTStream.mm index f65230b..a96feae 100644 --- a/Firestore/Source/Remote/FSTStream.mm +++ b/Firestore/Source/Remote/FSTStream.mm @@ -14,8 +14,6 @@ * limitations under the License. */ -#import "Firestore/Source/Remote/FSTDatastore.h" - #import <GRPCClient/GRPCCall+OAuth2.h> #import <GRPCClient/GRPCCall.h> @@ -24,6 +22,7 @@ #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTBufferedWriter.h" +#import "Firestore/Source/Remote/FSTDatastore.h" #import "Firestore/Source/Remote/FSTExponentialBackoff.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" #import "Firestore/Source/Remote/FSTStream.h" diff --git a/Firestore/Source/Util/FSTAssert.h b/Firestore/Source/Util/FSTAssert.h index 77bbb1d..610d306 100644 --- a/Firestore/Source/Util/FSTAssert.h +++ b/Firestore/Source/Util/FSTAssert.h @@ -14,7 +14,7 @@ * limitations under the License. */ -#include <Foundation/Foundation.h> +#import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Util/FSTUsageValidation.h b/Firestore/Source/Util/FSTUsageValidation.h index a80dafa..05933ea 100644 --- a/Firestore/Source/Util/FSTUsageValidation.h +++ b/Firestore/Source/Util/FSTUsageValidation.h @@ -14,7 +14,7 @@ * limitations under the License. */ -#include <Foundation/Foundation.h> +#import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/Source/Util/FSTUsageValidation.mm b/Firestore/Source/Util/FSTUsageValidation.mm index 82128f4..93abf87 100644 --- a/Firestore/Source/Util/FSTUsageValidation.mm +++ b/Firestore/Source/Util/FSTUsageValidation.mm @@ -14,7 +14,7 @@ * limitations under the License. */ -#include <Foundation/Foundation.h> +#import "Firestore/Source/Util/FSTUsageValidation.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Firestore/core/include/firebase/firestore/timestamp.h b/Firestore/core/include/firebase/firestore/timestamp.h index 2ee1c46..1736981 100644 --- a/Firestore/core/include/firebase/firestore/timestamp.h +++ b/Firestore/core/include/firebase/firestore/timestamp.h @@ -17,12 +17,13 @@ #ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_ #define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_ -#include <stdint.h> -#include <time.h> +#include <cstdint> +#include <ctime> +#include <string> + #if !defined(_STLPORT_VERSION) #include <chrono> // NOLINT(build/c++11) #endif // !defined(_STLPORT_VERSION) -#include <string> namespace firebase { diff --git a/Firestore/core/src/firebase/firestore/geo_point.cc b/Firestore/core/src/firebase/firestore/geo_point.cc index fb01023..1ed5126 100644 --- a/Firestore/core/src/firebase/firestore/geo_point.cc +++ b/Firestore/core/src/firebase/firestore/geo_point.cc @@ -16,10 +16,12 @@ #include "Firestore/core/include/firebase/firestore/geo_point.h" -#include <math.h> +#include <cmath> #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +using std::isnan; + namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h index 5ed16b3..ef6f54e 100644 --- a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h +++ b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h @@ -144,6 +144,7 @@ class SortedMap : public impl::SortedMapBase { case Tag::Tree: return SortedMap{tree_.insert(key, value)}; } + FIREBASE_UNREACHABLE(); } /** @@ -159,6 +160,7 @@ class SortedMap : public impl::SortedMapBase { case Tag::Tree: return SortedMap{tree_.erase(key)}; } + FIREBASE_UNREACHABLE(); } /** Returns true if the map contains no elements. */ @@ -169,6 +171,7 @@ class SortedMap : public impl::SortedMapBase { case Tag::Tree: return tree_.empty(); } + FIREBASE_UNREACHABLE(); } /** Returns the number of items in this map. */ @@ -179,6 +182,7 @@ class SortedMap : public impl::SortedMapBase { case Tag::Tree: return tree_.size(); } + FIREBASE_UNREACHABLE(); } private: diff --git a/Firestore/core/src/firebase/firestore/immutable/sorted_map_base.h b/Firestore/core/src/firebase/firestore/immutable/sorted_map_base.h index accb5ef..cfb19c1 100644 --- a/Firestore/core/src/firebase/firestore/immutable/sorted_map_base.h +++ b/Firestore/core/src/firebase/firestore/immutable/sorted_map_base.h @@ -17,7 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_IMMUTABLE_SORTED_MAP_BASE_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_IMMUTABLE_SORTED_MAP_BASE_H_ -#include <stdint.h> +#include <cstdint> namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h b/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h index e3102e7..dfe270d 100644 --- a/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h +++ b/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h @@ -17,9 +17,8 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_IMMUTABLE_TREE_SORTED_MAP_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_IMMUTABLE_TREE_SORTED_MAP_H_ -#include <assert.h> - #include <algorithm> +#include <cassert> #include <functional> #include <memory> #include <utility> diff --git a/Firestore/core/src/firebase/firestore/local/leveldb_transaction.cc b/Firestore/core/src/firebase/firestore/local/leveldb_transaction.cc index d84d441..f998550 100644 --- a/Firestore/core/src/firebase/firestore/local/leveldb_transaction.cc +++ b/Firestore/core/src/firebase/firestore/local/leveldb_transaction.cc @@ -16,12 +16,11 @@ #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" -#include <leveldb/write_batch.h> - #include "Firestore/core/src/firebase/firestore/local/leveldb_key.h" #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" #include "absl/memory/memory.h" +#include "leveldb/write_batch.h" using leveldb::DB; using leveldb::ReadOptions; diff --git a/Firestore/core/src/firebase/firestore/local/leveldb_transaction.h b/Firestore/core/src/firebase/firestore/local/leveldb_transaction.h index 56a9a77..a6ddce2 100644 --- a/Firestore/core/src/firebase/firestore/local/leveldb_transaction.h +++ b/Firestore/core/src/firebase/firestore/local/leveldb_transaction.h @@ -17,16 +17,16 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LEVELDB_TRANSACTION_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LEVELDB_TRANSACTION_H_ -#include <absl/strings/string_view.h> -#include <leveldb/db.h> - -#include <stdint.h> +#include <cstdint> #include <map> #include <memory> #include <set> #include <string> #include <utility> +#include "absl/strings/string_view.h" +#include "leveldb/db.h" + #if __OBJC__ #import <Protobuf/GPBProtocolBuffers.h> #endif diff --git a/Firestore/core/src/firebase/firestore/model/CMakeLists.txt b/Firestore/core/src/firebase/firestore/model/CMakeLists.txt index 78f5cd6..de783ad 100644 --- a/Firestore/core/src/firebase/firestore/model/CMakeLists.txt +++ b/Firestore/core/src/firebase/firestore/model/CMakeLists.txt @@ -22,8 +22,10 @@ cc_library( document.h document_key.cc document_key.h + field_mask.h field_path.cc field_path.h + field_transform.h field_value.cc field_value.h maybe_document.cc @@ -34,6 +36,7 @@ cc_library( resource_path.h snapshot_version.cc snapshot_version.h + transform_operations.h types.h DEPENDS absl_strings diff --git a/Firestore/core/src/firebase/firestore/model/database_id.h b/Firestore/core/src/firebase/firestore/model/database_id.h index 2ad1332..e1feca9 100644 --- a/Firestore/core/src/firebase/firestore/model/database_id.h +++ b/Firestore/core/src/firebase/firestore/model/database_id.h @@ -17,8 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_DATABASE_ID_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_DATABASE_ID_H_ -#include <stdint.h> - +#include <cstdint> #include <string> #include "absl/strings/string_view.h" diff --git a/Firestore/core/src/firebase/firestore/model/field_mask.h b/Firestore/core/src/firebase/firestore/model/field_mask.h new file mode 100644 index 0000000..a9f509a --- /dev/null +++ b/Firestore/core/src/firebase/firestore/model/field_mask.h @@ -0,0 +1,97 @@ +/* + * Copyright 2018 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. + */ + +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_MASK_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_MASK_H_ + +#include <initializer_list> +#include <string> +#include <utility> +#include <vector> + +#include "Firestore/core/src/firebase/firestore/model/field_path.h" + +namespace firebase { +namespace firestore { +namespace model { + +/** + * Provides a set of fields that can be used to partially patch a document. + * FieldMask is used in conjunction with FieldValue of Object type. + * + * Examples: + * foo - Overwrites foo entirely with the provided value. If foo is not + * present in the companion FieldValue, the field is deleted. + * foo.bar - Overwrites only the field bar of the object foo. If foo is not an + * object, foo is replaced with an object containing bar. + */ +class FieldMask { + public: + using const_iterator = std::vector<FieldPath>::const_iterator; + + FieldMask(std::initializer_list<FieldPath> list) : fields_{list} { + } + explicit FieldMask(const std::vector<FieldPath>& fields) : fields_{fields} { + } + explicit FieldMask(std::vector<FieldPath>&& fields) + : fields_{std::move(fields)} { + } + + const_iterator begin() const { + return fields_.begin(); + } + const_iterator end() const { + return fields_.end(); + } + + std::string ToString() const { + // Ideally, one should use a string builder. Since this is only non-critical + // code for logging and debugging, the logic is kept simple here. + std::string result("{ "); + for (const FieldPath& field : fields_) { + result += field.CanonicalString() + " "; + } + return result + "}"; + } + +#if defined(__OBJC__) + FieldMask() { + } + + NSUInteger Hash() const { + NSUInteger hashResult = 0; + for (const FieldPath& field : fields_) { + hashResult = hashResult * 31u + field.Hash(); + } + return hashResult; + } +#endif + + friend bool operator==(const FieldMask& lhs, const FieldMask& rhs); + + private: + std::vector<FieldPath> fields_; +}; + +inline bool operator==(const FieldMask& lhs, const FieldMask& rhs) { + return lhs.fields_ == rhs.fields_; +} + +} // namespace model +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_MASK_H_ diff --git a/Firestore/core/src/firebase/firestore/model/field_transform.h b/Firestore/core/src/firebase/firestore/model/field_transform.h new file mode 100644 index 0000000..a1dd96c --- /dev/null +++ b/Firestore/core/src/firebase/firestore/model/field_transform.h @@ -0,0 +1,70 @@ +/* + * Copyright 2018 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. + */ + +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_TRANSFORM_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_TRANSFORM_H_ + +#include <memory> +#include <utility> + +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" + +namespace firebase { +namespace firestore { +namespace model { + +/** A field path and the TransformOperation to perform upon it. */ +class FieldTransform { + public: + FieldTransform(FieldPath path, + std::unique_ptr<TransformOperation> transformation) noexcept + : path_{std::move(path)}, transformation_{std::move(transformation)} { + } + + const FieldPath& path() const { + return path_; + } + + const TransformOperation& transformation() const { + return *transformation_.get(); + } + + bool operator==(const FieldTransform& other) const { + return path_ == other.path_ && *transformation_ == *other.transformation_; + } + +#if defined(__OBJC__) + // For Objective-C++ hash; to be removed after migration. + // Do NOT use in C++ code. + NSUInteger Hash() const { + NSUInteger hash = path_.Hash(); + hash = hash * 31 + transformation_->Hash(); + return hash; + } +#endif // defined(__OBJC__) + + private: + FieldPath path_; + // Shared by copies of the same FieldTransform. + std::shared_ptr<const TransformOperation> transformation_; +}; + +} // namespace model +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_TRANSFORM_H_ diff --git a/Firestore/core/src/firebase/firestore/model/field_value.cc b/Firestore/core/src/firebase/firestore/model/field_value.cc index 2c1af53..1a40331 100644 --- a/Firestore/core/src/firebase/firestore/model/field_value.cc +++ b/Firestore/core/src/firebase/firestore/model/field_value.cc @@ -16,9 +16,8 @@ #include "Firestore/core/src/firebase/firestore/model/field_value.h" -#include <math.h> - #include <algorithm> +#include <cmath> #include <memory> #include <utility> #include <vector> diff --git a/Firestore/core/src/firebase/firestore/model/field_value.h b/Firestore/core/src/firebase/firestore/model/field_value.h index c42d533..c70e332 100644 --- a/Firestore/core/src/firebase/firestore/model/field_value.h +++ b/Firestore/core/src/firebase/firestore/model/field_value.h @@ -17,8 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_VALUE_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_VALUE_H_ -#include <stdint.h> - +#include <cstdint> #include <map> #include <memory> #include <string> diff --git a/Firestore/core/src/firebase/firestore/model/transform_operations.h b/Firestore/core/src/firebase/firestore/model/transform_operations.h new file mode 100644 index 0000000..6ff4dbc --- /dev/null +++ b/Firestore/core/src/firebase/firestore/model/transform_operations.h @@ -0,0 +1,97 @@ +/* + * Copyright 2018 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. + */ + +#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TRANSFORM_OPERATIONS_H_ +#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TRANSFORM_OPERATIONS_H_ + +namespace firebase { +namespace firestore { +namespace model { + +// TODO(zxu123): We might want to refactor transform_operations.h into several +// files when the number of different types of operations grows gigantically. +// For now, put the interface and the only operation here. + +/** Represents a transform within a TransformMutation. */ +class TransformOperation { + public: + /** All the different kinds to TransformOperation. */ + enum class Type { + ServerTimestamp, + Test, // Purely for test purpose. + }; + + virtual ~TransformOperation() { + } + + /** Returns the actual type. */ + virtual Type type() const = 0; + + /** Returns whether the two are equal. */ + virtual bool operator==(const TransformOperation& other) const = 0; + + /** Returns whether the two are not equal. */ + bool operator!=(const TransformOperation& other) const { + return !operator==(other); + } + +#if defined(__OBJC__) + // For Objective-C++ hash; to be removed after migration. + // Do NOT use in C++ code. + virtual NSUInteger Hash() const = 0; +#endif // defined(__OBJC__) +}; + +/** Transforms a value into a server-generated timestamp. */ +class ServerTimestampTransform : public TransformOperation { + public: + ~ServerTimestampTransform() override { + } + + Type type() const override { + return Type::ServerTimestamp; + } + + bool operator==(const TransformOperation& other) const override { + // All ServerTimestampTransform objects are equal. + return other.type() == Type::ServerTimestamp; + } + + static const ServerTimestampTransform& Get() { + static ServerTimestampTransform shared_instance; + return shared_instance; + } + +#if defined(__OBJC__) + // For Objective-C++ hash; to be removed after migration. + // Do NOT use in C++ code. + NSUInteger Hash() const override { + // arbitrary number, the same as used in ObjC implementation, since all + // instances are equal. + return 37; + } +#endif // defined(__OBJC__) + + private: + ServerTimestampTransform() { + } +}; + +} // namespace model +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TRANSFORM_OPERATIONS_H_ diff --git a/Firestore/core/src/firebase/firestore/model/types.h b/Firestore/core/src/firebase/firestore/model/types.h index fc1b196..3f813be 100644 --- a/Firestore/core/src/firebase/firestore/model/types.h +++ b/Firestore/core/src/firebase/firestore/model/types.h @@ -17,7 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TYPES_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_TYPES_H_ -#include <stdint.h> +#include <cstdint> namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/remote/serializer.cc b/Firestore/core/src/firebase/firestore/remote/serializer.cc index 5483e1f..ff135fd 100644 --- a/Firestore/core/src/firebase/firestore/remote/serializer.cc +++ b/Firestore/core/src/firebase/firestore/remote/serializer.cc @@ -32,6 +32,7 @@ namespace remote { using firebase::firestore::model::FieldValue; using firebase::firestore::model::ObjectValue; +using firebase::firestore::util::Status; namespace { @@ -43,7 +44,7 @@ ObjectValue DecodeObject(pb_istream_t* stream); /** * Docs TODO(rsgowman). But currently, this just wraps the underlying nanopb - * pb_ostream_t. + * pb_ostream_t. Also doc how to check status. */ class Writer { public: @@ -105,7 +106,13 @@ class Writer { return stream_.bytes_written; } + Status status() const { + return status_; + } + private: + Status status_ = Status::OK(); + /** * Creates a new Writer, based on the given nanopb pb_ostream_t. Note that * a shallow copy will be taken. (Non-null pointers within this struct must @@ -166,10 +173,10 @@ Writer Writer::Wrap(std::vector<uint8_t>* out_bytes) { // together (probably within their own file rather than here). void Writer::WriteTag(pb_wire_type_t wiretype, uint32_t field_number) { - bool status = pb_encode_tag(&stream_, wiretype, field_number); - if (!status) { - // TODO(rsgowman): figure out error handling - abort(); + if (!status_.ok()) return; + + if (!pb_encode_tag(&stream_, wiretype, field_number)) { + FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); } } @@ -178,10 +185,10 @@ void Writer::WriteSize(size_t size) { } void Writer::WriteVarint(uint64_t value) { - bool status = pb_encode_varint(&stream_, value); - if (!status) { - // TODO(rsgowman): figure out error handling - abort(); + if (!status_.ok()) return; + + if (!pb_encode_varint(&stream_, value)) { + FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); } } @@ -196,8 +203,7 @@ void Writer::WriteVarint(uint64_t value) { */ uint64_t DecodeVarint(pb_istream_t* stream) { uint64_t varint_value; - bool status = pb_decode_varint(stream, &varint_value); - if (!status) { + if (!pb_decode_varint(stream, &varint_value)) { // TODO(rsgowman): figure out error handling abort(); } @@ -242,27 +248,25 @@ int64_t DecodeInteger(pb_istream_t* stream) { } void Writer::WriteString(const std::string& string_value) { - bool status = pb_encode_string( - &stream_, reinterpret_cast<const pb_byte_t*>(string_value.c_str()), - string_value.length()); - if (!status) { - // TODO(rsgowman): figure out error handling - abort(); + if (!status_.ok()) return; + + if (!pb_encode_string( + &stream_, reinterpret_cast<const pb_byte_t*>(string_value.c_str()), + string_value.length())) { + FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); } } std::string DecodeString(pb_istream_t* stream) { pb_istream_t substream; - bool status = pb_make_string_substream(stream, &substream); - if (!status) { + if (!pb_make_string_substream(stream, &substream)) { // TODO(rsgowman): figure out error handling abort(); } std::string result(substream.bytes_left, '\0'); - status = pb_read(&substream, reinterpret_cast<pb_byte_t*>(&result[0]), - substream.bytes_left); - if (!status) { + if (!pb_read(&substream, reinterpret_cast<pb_byte_t*>(&result[0]), + substream.bytes_left)) { // TODO(rsgowman): figure out error handling abort(); } @@ -330,8 +334,7 @@ FieldValue DecodeFieldValueImpl(pb_istream_t* stream) { pb_wire_type_t wire_type; uint32_t tag; bool eof; - bool status = pb_decode_tag(stream, &wire_type, &tag, &eof); - if (!status) { + if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) { // TODO(rsgowman): figure out error handling abort(); } @@ -380,31 +383,35 @@ FieldValue DecodeFieldValueImpl(pb_istream_t* stream) { void Writer::WriteNestedMessage( const std::function<void(Writer*)>& write_message_fn) { + if (!status_.ok()) return; + // First calculate the message size using a non-writing substream. Writer sizer = Writer::Sizing(); write_message_fn(&sizer); + status_ = sizer.status(); + if (!status_.ok()) return; size_t size = sizer.bytes_written(); // Write out the size to the output writer. WriteSize(size); + if (!status_.ok()) return; // If this stream is itself a sizing stream, then we don't need to actually // parse field_value a second time; just update the bytes_written via a call // to pb_write. (If we try to write the contents into a sizing stream, it'll // fail since sizing streams don't actually have any buffer space.) if (stream_.callback == nullptr) { - bool status = pb_write(&stream_, nullptr, size); - if (!status) { - // TODO(rsgowman): figure out error handling - abort(); + if (!pb_write(&stream_, nullptr, size)) { + FIREBASE_ASSERT_MESSAGE(false, PB_GET_ERROR(&stream_)); } return; } // Ensure the output stream has enough space if (stream_.bytes_written + size > stream_.max_size) { - // TODO(rsgowman): figure out error handling - abort(); + FIREBASE_ASSERT_MESSAGE( + false, + "Insufficient space in the output stream to write the given message"); } // Use a substream to verify that a callback doesn't write more than what it @@ -415,6 +422,8 @@ void Writer::WriteNestedMessage( /*max_size=*/size, /*bytes_written=*/0, /*errmsg=*/nullptr}); write_message_fn(&writer); + status_ = writer.status(); + if (!status_.ok()) return; stream_.bytes_written += writer.stream_.bytes_written; stream_.state = writer.stream_.state; @@ -422,8 +431,8 @@ void Writer::WriteNestedMessage( if (writer.bytes_written() != size) { // submsg size changed - // TODO(rsgowman): figure out error handling - abort(); + FIREBASE_ASSERT_MESSAGE( + false, "Parsing the nested message twice yielded different sizes"); } } @@ -431,8 +440,7 @@ FieldValue DecodeNestedFieldValue(pb_istream_t* stream) { // Implementation note: This is roughly modeled on pb_decode_delimited, // adjusted to account for the oneof in FieldValue. pb_istream_t substream; - bool status = pb_make_string_substream(stream, &substream); - if (!status) { + if (!pb_make_string_substream(stream, &substream)) { // TODO(rsgowman): figure out error handling abort(); } @@ -490,21 +498,23 @@ ObjectValue::Map::value_type DecodeFieldsEntry(pb_istream_t* stream) { pb_wire_type_t wire_type; uint32_t tag; bool eof; - bool status = pb_decode_tag(stream, &wire_type, &tag, &eof); + if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) { + abort(); + } // TODO(rsgowman): figure out error handling: We can do better than a failed // assertion. FIREBASE_ASSERT(tag == google_firestore_v1beta1_MapValue_FieldsEntry_key_tag); FIREBASE_ASSERT(wire_type == PB_WT_STRING); FIREBASE_ASSERT(!eof); - FIREBASE_ASSERT(status); std::string key = DecodeString(stream); - status = pb_decode_tag(stream, &wire_type, &tag, &eof); + if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) { + abort(); + } FIREBASE_ASSERT(tag == google_firestore_v1beta1_MapValue_FieldsEntry_value_tag); FIREBASE_ASSERT(wire_type == PB_WT_STRING); FIREBASE_ASSERT(!eof); - FIREBASE_ASSERT(status); FieldValue value = DecodeNestedFieldValue(stream); @@ -512,16 +522,15 @@ ObjectValue::Map::value_type DecodeFieldsEntry(pb_istream_t* stream) { } void EncodeObject(Writer* writer, const ObjectValue& object_value) { - writer->WriteNestedMessage([&object_value](Writer* writer) { + return writer->WriteNestedMessage([&object_value](Writer* writer) { // Write each FieldsEntry (i.e. key-value pair.) for (const auto& kv : object_value.internal_value) { writer->WriteTag(PB_WT_STRING, google_firestore_v1beta1_MapValue_FieldsEntry_key_tag); + writer->WriteNestedMessage( - [&kv](Writer* writer) { EncodeFieldsEntry(writer, kv); }); + [&kv](Writer* writer) { return EncodeFieldsEntry(writer, kv); }); } - - return true; }); } @@ -550,9 +559,8 @@ ObjectValue DecodeObject(pb_istream_t* stream) { }; map_value.fields.arg = &result; - bool status = pb_decode_delimited( - stream, google_firestore_v1beta1_MapValue_fields, &map_value); - if (!status) { + if (!pb_decode_delimited(stream, google_firestore_v1beta1_MapValue_fields, + &map_value)) { // TODO(rsgowman): figure out error handling abort(); } @@ -562,10 +570,11 @@ ObjectValue DecodeObject(pb_istream_t* stream) { } // namespace -void Serializer::EncodeFieldValue(const FieldValue& field_value, - std::vector<uint8_t>* out_bytes) { +Status Serializer::EncodeFieldValue(const FieldValue& field_value, + std::vector<uint8_t>* out_bytes) { Writer writer = Writer::Wrap(out_bytes); EncodeFieldValueImpl(&writer, field_value); + return writer.status(); } FieldValue Serializer::DecodeFieldValue(const uint8_t* bytes, size_t length) { diff --git a/Firestore/core/src/firebase/firestore/remote/serializer.h b/Firestore/core/src/firebase/firestore/remote/serializer.h index 10cacbc..3b2b667 100644 --- a/Firestore/core/src/firebase/firestore/remote/serializer.h +++ b/Firestore/core/src/firebase/firestore/remote/serializer.h @@ -17,13 +17,15 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_SERIALIZER_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_SERIALIZER_H_ -#include <stdint.h> -#include <stdlib.h> +#include <cstdint> +#include <cstdlib> #include <vector> #include "Firestore/Protos/nanopb/google/firestore/v1beta1/document.pb.h" #include "Firestore/core/src/firebase/firestore/model/field_value.h" #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +#include "Firestore/core/src/firebase/firestore/util/status.h" +#include "absl/base/attributes.h" namespace firebase { namespace firestore { @@ -70,7 +72,7 @@ class Serializer { // TODO(rsgowman): If we never support any output except to a vector, it may // make sense to have Serializer own the vector and provide an accessor rather // than asking the user to create it first. - static void EncodeFieldValue( + static util::Status EncodeFieldValue( const firebase::firestore::model::FieldValue& field_value, std::vector<uint8_t>* out_bytes); diff --git a/Firestore/core/src/firebase/firestore/util/assert_apple.mm b/Firestore/core/src/firebase/firestore/util/assert_apple.mm index 83b76e1..9b6a651 100644 --- a/Firestore/core/src/firebase/firestore/util/assert_apple.mm +++ b/Firestore/core/src/firebase/firestore/util/assert_apple.mm @@ -14,12 +14,10 @@ * limitations under the License. */ -#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" - #import <Foundation/Foundation.h> -#include <string.h> - +// TODO(wilhuff): match basenames so this can move up top +#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace firebase { diff --git a/Firestore/core/src/firebase/firestore/util/assert_stdio.cc b/Firestore/core/src/firebase/firestore/util/assert_stdio.cc index 1d2e333..e01e564 100644 --- a/Firestore/core/src/firebase/firestore/util/assert_stdio.cc +++ b/Firestore/core/src/firebase/firestore/util/assert_stdio.cc @@ -14,8 +14,7 @@ * limitations under the License. */ -#include <stdarg.h> - +#include <cstdarg> #include <stdexcept> #include <string> diff --git a/Firestore/core/src/firebase/firestore/util/bits.h b/Firestore/core/src/firebase/firestore/util/bits.h index 185273f..fec1228 100644 --- a/Firestore/core/src/firebase/firestore/util/bits.h +++ b/Firestore/core/src/firebase/firestore/util/bits.h @@ -22,7 +22,7 @@ // Munging bits in _signed_ integers is fraught with peril! For example, // -5 << n has undefined behavior (for some values of n). -#include <stdint.h> +#include <cstdint> class Bits_Port32_Test; class Bits_Port64_Test; diff --git a/Firestore/core/src/firebase/firestore/util/comparison.cc b/Firestore/core/src/firebase/firestore/util/comparison.cc index 4bef843..b346277 100644 --- a/Firestore/core/src/firebase/firestore/util/comparison.cc +++ b/Firestore/core/src/firebase/firestore/util/comparison.cc @@ -16,10 +16,11 @@ #include "Firestore/core/src/firebase/firestore/util/comparison.h" -#include <math.h> - +#include <cmath> #include <limits> +using std::isnan; + namespace firebase { namespace firestore { namespace util { diff --git a/Firestore/core/src/firebase/firestore/util/comparison.h b/Firestore/core/src/firebase/firestore/util/comparison.h index 6fd1e2b..23207f5 100644 --- a/Firestore/core/src/firebase/firestore/util/comparison.h +++ b/Firestore/core/src/firebase/firestore/util/comparison.h @@ -21,9 +21,9 @@ #import <Foundation/Foundation.h> #endif -#include <stdint.h> #include <sys/types.h> +#include <cstdint> #include <functional> #include <string> #include <vector> diff --git a/Firestore/core/src/firebase/firestore/util/firebase_assert.h b/Firestore/core/src/firebase/firestore/util/firebase_assert.h index 20c8429..6a9c2eb 100644 --- a/Firestore/core/src/firebase/firestore/util/firebase_assert.h +++ b/Firestore/core/src/firebase/firestore/util/firebase_assert.h @@ -20,7 +20,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_FIREBASE_ASSERT_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_FIREBASE_ASSERT_H_ -#include <stdlib.h> +#include <cstdlib> #include "Firestore/core/src/firebase/firestore/util/log.h" #include "absl/base/attributes.h" @@ -76,10 +76,6 @@ } \ } while (0) -// Assert with custom message that is not compiled out in release builds. -#define FIREBASE_ASSERT_MESSAGE(expression, ...) \ - FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(expression, expression, __VA_ARGS__) - // Assert condition is true otherwise display the specified expression, // message and abort. Compiled out of release builds. #if defined(NDEBUG) @@ -103,16 +99,18 @@ FIREBASE_DEV_ASSERT_MESSAGE_WITH_EXPRESSION(expression, expression, \ __VA_ARGS__) +// Indicates an area of the code that cannot be reached (except possibly due to +// undefined behaviour or other similar badness). The only reasonable thing to +// do in these cases is to immediately abort. +#define FIREBASE_UNREACHABLE() abort() + namespace firebase { namespace firestore { namespace util { // A no-return helper function. To raise an assertion, use Macro instead. -ABSL_ATTRIBUTE_NORETURN void FailAssert(const char* file, - const char* func, - const int line, - const char* format, - ...); +ABSL_ATTRIBUTE_NORETURN void FailAssert( + const char* file, const char* func, int line, const char* format, ...); } // namespace util } // namespace firestore diff --git a/Firestore/core/src/firebase/firestore/util/log.h b/Firestore/core/src/firebase/firestore/util/log.h index d0cff4d..1944596 100644 --- a/Firestore/core/src/firebase/firestore/util/log.h +++ b/Firestore/core/src/firebase/firestore/util/log.h @@ -17,7 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_LOG_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_LOG_H_ -#include <stdarg.h> +#include <cstdarg> namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/util/log_stdio.cc b/Firestore/core/src/firebase/firestore/util/log_stdio.cc index bca2dc9..b277406 100644 --- a/Firestore/core/src/firebase/firestore/util/log_stdio.cc +++ b/Firestore/core/src/firebase/firestore/util/log_stdio.cc @@ -16,7 +16,7 @@ #include "Firestore/core/src/firebase/firestore/util/log.h" -#include <stdio.h> +#include <cstdio> #include <string> namespace firebase { diff --git a/Firestore/core/src/firebase/firestore/util/ordered_code.cc b/Firestore/core/src/firebase/firestore/util/ordered_code.cc index 0eadf18..cb53b09 100644 --- a/Firestore/core/src/firebase/firestore/util/ordered_code.cc +++ b/Firestore/core/src/firebase/firestore/util/ordered_code.cc @@ -16,12 +16,11 @@ #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" -#include <absl/base/internal/endian.h> -#include <absl/base/internal/unaligned_access.h> -#include <absl/base/port.h> - #include "Firestore/core/src/firebase/firestore/util/bits.h" #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +#include "absl/base/internal/endian.h" +#include "absl/base/internal/unaligned_access.h" +#include "absl/base/port.h" #define UNALIGNED_LOAD32 ABSL_INTERNAL_UNALIGNED_LOAD32 #define UNALIGNED_LOAD64 ABSL_INTERNAL_UNALIGNED_LOAD64 diff --git a/Firestore/core/src/firebase/firestore/util/secure_random.h b/Firestore/core/src/firebase/firestore/util/secure_random.h index 95b41e1..f030b5e 100644 --- a/Firestore/core/src/firebase/firestore/util/secure_random.h +++ b/Firestore/core/src/firebase/firestore/util/secure_random.h @@ -17,7 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_SECURE_RANDOM_H_ -#include <stdint.h> +#include <cstdint> #include <limits> diff --git a/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc index 83f72b5..d7e9be3 100644 --- a/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc +++ b/Firestore/core/src/firebase/firestore/util/secure_random_arc4random.cc @@ -20,7 +20,7 @@ #if HAVE_ARC4RANDOM -#include <stdlib.h> +#include <cstdlib> namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/util/secure_random_openssl.cc b/Firestore/core/src/firebase/firestore/util/secure_random_openssl.cc index d3f6e63..e024846 100644 --- a/Firestore/core/src/firebase/firestore/util/secure_random_openssl.cc +++ b/Firestore/core/src/firebase/firestore/util/secure_random_openssl.cc @@ -20,8 +20,8 @@ #if HAVE_OPENSSL_RAND_H -#include <openssl/err.h> -#include <openssl/rand.h> +#include "openssl/err.h" +#include "openssl/rand.h" namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/util/string_printf.cc b/Firestore/core/src/firebase/firestore/util/string_printf.cc index 9c4e31c..c5483f4 100644 --- a/Firestore/core/src/firebase/firestore/util/string_printf.cc +++ b/Firestore/core/src/firebase/firestore/util/string_printf.cc @@ -16,7 +16,7 @@ #include "Firestore/core/src/firebase/firestore/util/string_printf.h" -#include <stdio.h> +#include <cstdio> namespace firebase { namespace firestore { diff --git a/Firestore/core/src/firebase/firestore/util/string_printf.h b/Firestore/core/src/firebase/firestore/util/string_printf.h index 10dfae9..553af66 100644 --- a/Firestore/core/src/firebase/firestore/util/string_printf.h +++ b/Firestore/core/src/firebase/firestore/util/string_printf.h @@ -17,8 +17,7 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_STRING_PRINTF_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_UTIL_STRING_PRINTF_H_ -#include <stdarg.h> - +#include <cstdarg> #include <string> #include "absl/base/attributes.h" diff --git a/Firestore/core/test/firebase/firestore/model/CMakeLists.txt b/Firestore/core/test/firebase/firestore/model/CMakeLists.txt index 2c2281f..3bac89d 100644 --- a/Firestore/core/test/firebase/firestore/model/CMakeLists.txt +++ b/Firestore/core/test/firebase/firestore/model/CMakeLists.txt @@ -18,12 +18,15 @@ cc_test( database_id_test.cc document_key_test.cc document_test.cc + field_mask_test.cc field_path_test.cc + field_transform_test.cc field_value_test.cc maybe_document_test.cc no_document_test.cc resource_path_test.cc snapshot_version_test.cc + transform_operations_test.cc DEPENDS firebase_firestore_model ) diff --git a/Firestore/core/test/firebase/firestore/model/field_mask_test.cc b/Firestore/core/test/firebase/firestore/model/field_mask_test.cc new file mode 100644 index 0000000..52d5951 --- /dev/null +++ b/Firestore/core/test/firebase/firestore/model/field_mask_test.cc @@ -0,0 +1,56 @@ +/* + * Copyright 2018 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. + */ + +#include "Firestore/core/src/firebase/firestore/model/field_mask.h" + +#include <vector> + +#include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "gtest/gtest.h" + +namespace firebase { +namespace firestore { +namespace model { + +TEST(FieldMask, ConstructorAndEqual) { + FieldMask mask_a{FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}; + std::vector<FieldPath> field_path_vector{FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}; + FieldMask mask_b{field_path_vector}; + FieldMask mask_c{std::vector<FieldPath>{FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}}; + EXPECT_EQ(mask_a, mask_b); + EXPECT_EQ(mask_b, mask_c); +} + +TEST(FieldMask, Getter) { + FieldMask mask{FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}; + EXPECT_EQ(std::vector<FieldPath>({FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}), + std::vector<FieldPath>(mask.begin(), mask.end())); +} + +TEST(FieldMask, ToString) { + FieldMask mask{FieldPath::FromServerFormat("foo"), + FieldPath::FromServerFormat("bar")}; + EXPECT_EQ("{ foo bar }", mask.ToString()); +} + +} // namespace model +} // namespace firestore +} // namespace firebase diff --git a/Firestore/core/test/firebase/firestore/model/field_transform_test.cc b/Firestore/core/test/firebase/firestore/model/field_transform_test.cc new file mode 100644 index 0000000..b66aeef --- /dev/null +++ b/Firestore/core/test/firebase/firestore/model/field_transform_test.cc @@ -0,0 +1,39 @@ +/* + * Copyright 2018 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. + */ + +#include "Firestore/core/src/firebase/firestore/model/field_transform.h" +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" + +#include "absl/memory/memory.h" +#include "gtest/gtest.h" + +namespace firebase { +namespace firestore { +namespace model { + +TEST(FieldTransform, Getter) { + FieldTransform transform(testutil::Field("foo"), + absl::make_unique<ServerTimestampTransform>( + ServerTimestampTransform::Get())); + + EXPECT_EQ(testutil::Field("foo"), transform.path()); + EXPECT_EQ(ServerTimestampTransform::Get(), transform.transformation()); +} + +} // namespace model +} // namespace firestore +} // namespace firebase diff --git a/Firestore/core/test/firebase/firestore/model/field_value_test.cc b/Firestore/core/test/firebase/firestore/model/field_value_test.cc index 40be2d5..08db76d 100644 --- a/Firestore/core/test/firebase/firestore/model/field_value_test.cc +++ b/Firestore/core/test/firebase/firestore/model/field_value_test.cc @@ -16,8 +16,7 @@ #include "Firestore/core/src/firebase/firestore/model/field_value.h" -#include <limits.h> - +#include <climits> #include <vector> #include "gtest/gtest.h" diff --git a/Firestore/core/test/firebase/firestore/model/transform_operations_test.cc b/Firestore/core/test/firebase/firestore/model/transform_operations_test.cc new file mode 100644 index 0000000..0ef95db --- /dev/null +++ b/Firestore/core/test/firebase/firestore/model/transform_operations_test.cc @@ -0,0 +1,51 @@ +/* + * Copyright 2018 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. + */ + +#include "Firestore/core/src/firebase/firestore/model/transform_operations.h" + +#include "gtest/gtest.h" + +namespace firebase { +namespace firestore { +namespace model { + +class DummyOperation : public TransformOperation { + public: + DummyOperation() { + } + + Type type() const override { + return Type::Test; + } + + bool operator==(const TransformOperation& other) const override { + return this == &other; + } +}; + +TEST(TransformOperations, ServerTimestamp) { + ServerTimestampTransform transform = ServerTimestampTransform::Get(); + EXPECT_EQ(TransformOperation::Type::ServerTimestamp, transform.type()); + + ServerTimestampTransform another = ServerTimestampTransform::Get(); + DummyOperation dummy; + EXPECT_EQ(transform, another); + EXPECT_NE(transform, dummy); +} + +} // namespace model +} // namespace firestore +} // namespace firebase diff --git a/Firestore/core/test/firebase/firestore/remote/datastore_test.cc b/Firestore/core/test/firebase/firestore/remote/datastore_test.cc index 42a9a8c..53e95a9 100644 --- a/Firestore/core/test/firebase/firestore/remote/datastore_test.cc +++ b/Firestore/core/test/firebase/firestore/remote/datastore_test.cc @@ -16,8 +16,9 @@ #include "Firestore/core/src/firebase/firestore/remote/datastore.h" -#include <grpc/grpc.h> -#include <gtest/gtest.h> +#include "grpc/grpc.h" + +#include "gtest/gtest.h" TEST(Datastore, CanLinkToGrpc) { // This test doesn't actually do anything interesting as far as actually diff --git a/Firestore/core/test/firebase/firestore/remote/serializer_test.cc b/Firestore/core/test/firebase/firestore/remote/serializer_test.cc index 862ac97..947c2fe 100644 --- a/Firestore/core/test/firebase/firestore/remote/serializer_test.cc +++ b/Firestore/core/test/firebase/firestore/remote/serializer_test.cc @@ -42,10 +42,12 @@ #include <vector> #include "Firestore/core/src/firebase/firestore/model/field_value.h" +#include "Firestore/core/src/firebase/firestore/util/status.h" #include "gtest/gtest.h" using firebase::firestore::model::FieldValue; using firebase::firestore::remote::Serializer; +using firebase::firestore::util::Status; TEST(Serializer, CanLinkToNanopb) { // This test doesn't actually do anything interesting as far as actually using @@ -67,7 +69,8 @@ class SerializerTest : public ::testing::Test { FieldValue::Type type) { EXPECT_EQ(type, model.type()); std::vector<uint8_t> actual_bytes; - serializer.EncodeFieldValue(model, &actual_bytes); + Status status = serializer.EncodeFieldValue(model, &actual_bytes); + EXPECT_TRUE(status.ok()); EXPECT_EQ(bytes, actual_bytes); FieldValue actual_model = serializer.DecodeFieldValue(bytes); EXPECT_EQ(type, actual_model.type()); diff --git a/Firestore/core/test/firebase/firestore/util/autoid_test.cc b/Firestore/core/test/firebase/firestore/util/autoid_test.cc index 079b990..808850b 100644 --- a/Firestore/core/test/firebase/firestore/util/autoid_test.cc +++ b/Firestore/core/test/firebase/firestore/util/autoid_test.cc @@ -16,9 +16,9 @@ #include "Firestore/core/src/firebase/firestore/util/autoid.h" -#include <ctype.h> +#include <cctype> -#include <gtest/gtest.h> +#include "gtest/gtest.h" using firebase::firestore::util::CreateAutoId; diff --git a/Firestore/core/test/firebase/firestore/util/comparison_test.cc b/Firestore/core/test/firebase/firestore/util/comparison_test.cc index ccb3011..a03aec8 100644 --- a/Firestore/core/test/firebase/firestore/util/comparison_test.cc +++ b/Firestore/core/test/firebase/firestore/util/comparison_test.cc @@ -16,9 +16,8 @@ #include "Firestore/core/src/firebase/firestore/util/comparison.h" -#include <inttypes.h> -#include <math.h> - +#include <cinttypes> +#include <cmath> #include <limits> #include "Firestore/core/src/firebase/firestore/util/string_printf.h" diff --git a/Firestore/core/test/firebase/firestore/util/secure_random_test.cc b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc index 0b7a51b..b0dfdd6 100644 --- a/Firestore/core/test/firebase/firestore/util/secure_random_test.cc +++ b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc @@ -16,7 +16,7 @@ #include "Firestore/core/src/firebase/firestore/util/secure_random.h" -#include <gtest/gtest.h> +#include "gtest/gtest.h" using firebase::firestore::util::SecureRandom; diff --git a/Firestore/core/test/firebase/firestore/util/string_printf_test.cc b/Firestore/core/test/firebase/firestore/util/string_printf_test.cc index 085be84..14cc9c8 100644 --- a/Firestore/core/test/firebase/firestore/util/string_printf_test.cc +++ b/Firestore/core/test/firebase/firestore/util/string_printf_test.cc @@ -16,7 +16,7 @@ #include "Firestore/core/src/firebase/firestore/util/string_printf.h" -#include <gtest/gtest.h> +#include "gtest/gtest.h" namespace firebase { namespace firestore { diff --git a/Firestore/core/test/firebase/firestore/util/string_util_test.cc b/Firestore/core/test/firebase/firestore/util/string_util_test.cc index f94596f..a85c849 100644 --- a/Firestore/core/test/firebase/firestore/util/string_util_test.cc +++ b/Firestore/core/test/firebase/firestore/util/string_util_test.cc @@ -16,7 +16,7 @@ #include "Firestore/core/src/firebase/firestore/util/string_util.h" -#include <gtest/gtest.h> +#include "gtest/gtest.h" namespace firebase { namespace firestore { |