Skip to content

Commit 680a7e6

Browse files
Adding Numeric Add
1 parent cda79a8 commit 680a7e6

33 files changed

Lines changed: 1027 additions & 46 deletions

Example/tvOSSample/tvOSSample/AuthViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import UIKit
1616
import FirebaseAuth
1717

1818
class AuthViewController: UIViewController {
19+
1920
// MARK: - User Interface
2021

2122
/// A stackview containing all of the buttons to providers (Email, OAuth, etc).

Example/tvOSSample/tvOSSample/EmailLoginViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protocol EmailLoginDelegate {
2121
}
2222

2323
class EmailLoginViewController: UIViewController {
24+
2425
// MARK: - Public Properties
2526

2627
var delegate: EmailLoginDelegate?

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
C80B10E79CDD7EF7843C321E /* type_traits_apple_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2A0CF41BA5AED6049B0BEB2C /* type_traits_apple_test.mm */; };
225225
C8D3CE2343E53223E6487F2C /* Pods_Firestore_Example_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5918805E993304321A05E82B /* Pods_Firestore_Example_iOS.framework */; };
226226
CA989C0E6020C372A62B7062 /* testutil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54A0352820A3B3BD003E0143 /* testutil.cc */; };
227+
D5B252EE3F4037405DB1ECE3 /* FIRNumericTransformTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = D5B25E7E7D6873CBA4571841 /* FIRNumericTransformTests.mm */; };
227228
D5B25CBF07F65E885C9D68AB /* perf_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = D5B2593BCB52957D62F1C9D3 /* perf_spec_test.json */; };
228229
D94A1862B8FB778225DB54A1 /* filesystem_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = F51859B394D01C0C507282F1 /* filesystem_test.cc */; };
229230
DD5976A45071455FF3FE74B8 /* string_win_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 79507DF8378D3C42F5B36268 /* string_win_test.cc */; };
@@ -546,6 +547,7 @@
546547
C8522DE226C467C54E6788D8 /* mutation_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = mutation_test.cc; sourceTree = "<group>"; };
547548
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
548549
D5B2593BCB52957D62F1C9D3 /* perf_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = perf_spec_test.json; sourceTree = "<group>"; };
550+
D5B25E7E7D6873CBA4571841 /* FIRNumericTransformTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRNumericTransformTests.mm; sourceTree = "<group>"; };
549551
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
550552
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
551553
DE0761F61F2FE68D003233AF /* BasicCompileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCompileTests.swift; sourceTree = "<group>"; };
@@ -1262,6 +1264,7 @@
12621264
5492E071202154D600B64F25 /* FIRTypeTests.mm */,
12631265
5492E06D202154D600B64F25 /* FIRValidationTests.mm */,
12641266
5492E06F202154D600B64F25 /* FIRWriteBatchTests.mm */,
1267+
D5B25E7E7D6873CBA4571841 /* FIRNumericTransformTests.mm */,
12651268
);
12661269
path = API;
12671270
sourceTree = "<group>";
@@ -2046,6 +2049,7 @@
20462049
B67BF44A216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */,
20472050
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */,
20482051
CA989C0E6020C372A62B7062 /* testutil.cc in Sources */,
2052+
D5B252EE3F4037405DB1ECE3 /* FIRNumericTransformTests.mm in Sources */,
20492053
);
20502054
runOnlyForDeploymentPostprocessing = 0;
20512055
};
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <FirebaseFirestore/FirebaseFirestore.h>
18+
19+
#import <XCTest/XCTest.h>
20+
21+
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
22+
23+
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
24+
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
25+
26+
@interface FIRNumericTransformTests : FSTIntegrationTestCase
27+
@end
28+
29+
@implementation FIRNumericTransformTests {
30+
// A document reference to read and write to.
31+
FIRDocumentReference *_docRef;
32+
33+
// Accumulator used to capture events during the test.
34+
FSTEventAccumulator<FIRDocumentSnapshot *> *_accumulator;
35+
36+
// Listener registration for a listener maintained during the course of the test.
37+
id<FIRListenerRegistration> _listenerRegistration;
38+
}
39+
40+
- (void)setUp {
41+
[super setUp];
42+
43+
_docRef = [self documentRef];
44+
_accumulator = [FSTEventAccumulator accumulatorForTest:self];
45+
_listenerRegistration =
46+
[_docRef addSnapshotListenerWithIncludeMetadataChanges:YES
47+
listener:_accumulator.valueEventHandler];
48+
49+
// Wait for initial nil snapshot to avoid potential races.
50+
FIRDocumentSnapshot *initialSnapshot = [_accumulator awaitEventWithName:@"initial event"];
51+
XCTAssertFalse(initialSnapshot.exists);
52+
}
53+
54+
- (void)tearDown {
55+
[_listenerRegistration remove];
56+
57+
[super tearDown];
58+
}
59+
60+
#pragma mark - Test Helpers
61+
62+
/** Writes some initial data and consumes the events generated. */
63+
- (void)writeInitialData:(NSDictionary<NSString *, id> *)data {
64+
[self writeDocumentRef:_docRef data:data];
65+
XCTAssertEqualObjects([_accumulator awaitLocalEvent].data, data);
66+
XCTAssertEqualObjects([_accumulator awaitRemoteEvent].data, data);
67+
}
68+
69+
- (void)expectLocalAndRemoteValue:(int64_t)expectedSum {
70+
FIRDocumentSnapshot *snap = [_accumulator awaitLocalEvent];
71+
XCTAssertEqual(@(expectedSum), snap[@"sum"]);
72+
snap = [_accumulator awaitRemoteEvent];
73+
XCTAssertEqual(@(expectedSum), snap[@"sum"]);
74+
}
75+
76+
- (void)expectApproximateLocalAndRemoteValue:(double)expectedSum {
77+
FIRDocumentSnapshot *snap = [_accumulator awaitLocalEvent];
78+
XCTAssertEqual(@(expectedSum), snap[@"sum"]);
79+
snap = [_accumulator awaitRemoteEvent];
80+
XCTAssertEqual(@(expectedSum), snap[@"sum"]);
81+
}
82+
83+
#pragma mark - Test Cases
84+
85+
- (void)testCreateDocumentWithIncrement {
86+
[self writeDocumentRef:_docRef
87+
data:@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1337]}];
88+
[self expectLocalAndRemoteValue:1337];
89+
}
90+
91+
- (void)testMergeOnNonExistingDocumentWithIncrement {
92+
[self mergeDocumentRef:_docRef
93+
data:@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1337]}];
94+
[self expectLocalAndRemoteValue:1337];
95+
}
96+
97+
- (void)testIntegerIncrementWithExistingInteger {
98+
[self writeInitialData:@{@"sum" : @1337}];
99+
[self updateDocumentRef:_docRef data:@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]}];
100+
[self expectLocalAndRemoteValue:13378];
101+
}
102+
103+
- (void)testDoubleIncrementWithExistingDouble {
104+
[self writeInitialData:@{@"sum" : @13.37}];
105+
[self updateDocumentRef:_docRef
106+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:0.1]}];
107+
[self expectApproximateLocalAndRemoteValue:13.47];
108+
}
109+
110+
- (void)testIntegerIncrementWithExistingDouble {
111+
[self writeInitialData:@{@"sum" : @13.37}];
112+
[self updateDocumentRef:_docRef data:@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]}];
113+
[self expectApproximateLocalAndRemoteValue:14.37];
114+
}
115+
116+
- (void)testDoubleIncrementWithExistingInteger {
117+
[self writeInitialData:@{@"sum" : @1337}];
118+
[self updateDocumentRef:_docRef
119+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:0.1]}];
120+
[self expectApproximateLocalAndRemoteValue:1337.1];
121+
}
122+
123+
- (void)testIntegerIncrementWithExistingString {
124+
[self writeInitialData:@{@"sum" : @"overwrite"}];
125+
[self updateDocumentRef:_docRef
126+
data:@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1337]}];
127+
[self expectLocalAndRemoteValue:1337];
128+
}
129+
130+
- (void)testDoubleIncrementWithExistingString {
131+
[self writeInitialData:@{@"sum" : @"overwrite"}];
132+
[self updateDocumentRef:_docRef
133+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:13.37]}];
134+
[self expectApproximateLocalAndRemoteValue:13.37];
135+
}
136+
137+
- (void)testMultipleDoubleIncrements {
138+
[self writeInitialData:@{@"sum" : @"0.0"}];
139+
140+
[self disableNetwork];
141+
142+
[self updateDocumentRef:_docRef
143+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:0.1]}];
144+
[self updateDocumentRef:_docRef
145+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:0.01]}];
146+
[self updateDocumentRef:_docRef
147+
data:@{@"sum" : [FIRFieldValue fieldValueForDoubleIncrement:0.01]}];
148+
149+
FIRDocumentSnapshot *snap = [_accumulator awaitLocalEvent];
150+
XCTAssertEqual(@(0.1), snap[@"sum"]);
151+
snap = [_accumulator awaitLocalEvent];
152+
XCTAssertEqual(@(0.11), snap[@"sum"]);
153+
snap = [_accumulator awaitLocalEvent];
154+
XCTAssertEqual(@(0.111), snap[@"sum"]);
155+
156+
[self enableNetwork];
157+
snap = [_accumulator awaitRemoteEvent];
158+
XCTAssertEqual(@(0.111), snap[@"sum"]);
159+
}
160+
161+
@end

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ - (void)testStreamingWrite {
218218
FSTSetMutation *mutation = [self setMutation];
219219
FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:23
220220
localWriteTime:[FIRTimestamp timestamp]
221+
baseMutations:@[]
221222
mutations:@[ mutation ]];
222223
[_testWorkerQueue dispatchAsync:^{
223224
[_remoteStore addBatchToWritePipeline:batch];

Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ - (void)testRemoveOrphanedDocuments {
433433
// serve to keep the mutated documents from being GC'd while the mutations are outstanding.
434434
_persistence.run("actually register the mutations", [&]() {
435435
FIRTimestamp *writeTime = [FIRTimestamp timestamp];
436-
[_mutationQueue addMutationBatchWithWriteTime:writeTime mutations:mutations];
436+
[_mutationQueue addMutationBatchWithWriteTime:writeTime baseMutations:@[] mutations:mutations];
437437
});
438438

439439
// Mark 5 documents eligible for GC. This simulates documents that were mutated then ack'd.

Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ - (void)setUp {
8080
}
8181

8282
- (void)testEncodesMutationBatch {
83+
FSTMutation *base = [[FSTPatchMutation alloc] initWithKey:FSTTestDocKey(@"bar/baz")
84+
fieldMask:FieldMask{testutil::Field("a")}
85+
value:FSTTestObjectValue(@{@"a" : @"b"})
86+
precondition:Precondition::Exists(true)];
8387
FSTMutation *set = FSTTestSetMutation(@"foo/bar", @{@"a" : @"b", @"num" : @1});
8488
FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:FSTTestDocKey(@"bar/baz")
8589
fieldMask:FieldMask{testutil::Field("a")}
@@ -91,8 +95,17 @@ - (void)testEncodesMutationBatch {
9195
FIRTimestamp *writeTime = [FIRTimestamp timestamp];
9296
FSTMutationBatch *model = [[FSTMutationBatch alloc] initWithBatchID:42
9397
localWriteTime:writeTime
98+
baseMutations:@[ base ]
9499
mutations:@[ set, patch, del ]];
95100

101+
GCFSWrite *baseProto = [GCFSWrite message];
102+
baseProto.update.name = @"projects/p/databases/d/documents/bar/baz";
103+
[baseProto.update.fields addEntriesFromDictionary:@{
104+
@"a" : [self.remoteSerializer encodedString:@"b"],
105+
}];
106+
[baseProto.updateMask.fieldPathsArray addObjectsFromArray:@[ @"a" ]];
107+
baseProto.currentDocument.exists = YES;
108+
96109
GCFSWrite *setProto = [GCFSWrite message];
97110
setProto.update.name = @"projects/p/databases/d/documents/foo/bar";
98111
[setProto.update.fields addEntriesFromDictionary:@{
@@ -118,13 +131,15 @@ - (void)testEncodesMutationBatch {
118131

119132
FSTPBWriteBatch *batchProto = [FSTPBWriteBatch message];
120133
batchProto.batchId = 42;
134+
[batchProto.baseWritesArray addObject:baseProto];
121135
[batchProto.writesArray addObjectsFromArray:@[ setProto, patchProto, delProto ]];
122136
batchProto.localWriteTime = writeTimeProto;
123137

124138
XCTAssertEqualObjects([self.serializer encodedMutationBatch:model], batchProto);
125139
FSTMutationBatch *decoded = [self.serializer decodedMutationBatch:batchProto];
126140
XCTAssertEqual(decoded.batchID, model.batchID);
127141
XCTAssertEqualObjects(decoded.localWriteTime, model.localWriteTime);
142+
XCTAssertEqualObjects(decoded.baseMutations, model.baseMutations);
128143
XCTAssertEqualObjects(decoded.mutations, model.mutations);
129144
XCTAssertEqual([decoded keys], [model keys]);
130145
}

0 commit comments

Comments
 (0)