From 8037a4bf79b8ae49162c2b6f099d62ec17a7f283 Mon Sep 17 00:00:00 2001 From: Gil Date: Thu, 24 May 2018 11:00:23 -0700 Subject: Replace Objective-C assertions with C++ assertions (#1327) * Migrate FSTFail to HARD_FAIL * FSTCFail -> HARD_FAIL * FSTCAssert -> HARD_ASSERT * FSTAssert -> HARD_ASSERT * Replace FSTAssert with NSAssert in dead Objective-C code * Remove FSTAssert.h --- .../Example/Firestore.xcodeproj/project.pbxproj | 6 +- .../Example/Tests/Integration/FSTDatastoreTests.mm | 6 +- .../Example/Tests/Integration/FSTStreamTests.mm | 4 +- .../Example/Tests/SpecTests/FSTMockDatastore.mm | 19 ++-- Firestore/Example/Tests/SpecTests/FSTSpecTests.mm | 20 ++-- .../Tests/SpecTests/FSTSyncEngineTestDriver.mm | 18 ++-- Firestore/Example/Tests/Util/FSTAssertTests.mm | 105 --------------------- .../Example/Tests/Util/FSTEventAccumulator.mm | 8 +- Firestore/Example/Tests/Util/FSTHelpers.mm | 15 ++- 9 files changed, 44 insertions(+), 157 deletions(-) delete mode 100644 Firestore/Example/Tests/Util/FSTAssertTests.mm (limited to 'Firestore/Example') diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 836017b..ca8b598 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -43,7 +43,6 @@ 5492E03420213FFC00B64F25 /* FSTMemorySpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */; }; 5492E03520213FFC00B64F25 /* FSTSpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03020213FFC00B64F25 /* FSTSpecTests.mm */; }; 5492E03C2021401F00B64F25 /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; }; - 5492E03D2021401F00B64F25 /* FSTAssertTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0382021401E00B64F25 /* FSTAssertTests.mm */; }; 5492E03E2021401F00B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; }; 5492E03F2021401F00B64F25 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; }; 5492E041202143E700B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; }; @@ -257,7 +256,7 @@ 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = remote_store_spec_test.json; sourceTree = ""; }; 3C81DE3772628FE297055662 /* Pods-Firestore_Example_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS/Pods-Firestore_Example_iOS.debug.xcconfig"; sourceTree = ""; }; 3F0992A4B83C60841C52E960 /* Pods-Firestore_Example_iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS/Pods-Firestore_Example_iOS.release.xcconfig"; sourceTree = ""; }; - 444B7AB3F5A2929070CB1363 /* hard_assert_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = hard_assert_test.cc; sourceTree = ""; }; + 444B7AB3F5A2929070CB1363 /* hard_assert_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = hard_assert_test.cc; sourceTree = ""; }; 54131E9620ADE678001DF3FF /* string_format_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = string_format_test.cc; sourceTree = ""; }; 54511E8D209805F8005BD28F /* hashing_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hashing_test.cc; sourceTree = ""; }; 5467FAFF203E56F8009C9584 /* FIRFirestoreTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRFirestoreTests.mm; sourceTree = ""; }; @@ -275,7 +274,6 @@ 5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTMemorySpecTests.mm; sourceTree = ""; }; 5492E03020213FFC00B64F25 /* FSTSpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTSpecTests.mm; sourceTree = ""; }; 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "XCTestCase+Await.mm"; sourceTree = ""; }; - 5492E0382021401E00B64F25 /* FSTAssertTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTAssertTests.mm; sourceTree = ""; }; 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTEventAccumulator.mm; sourceTree = ""; }; 5492E03A2021401F00B64F25 /* FSTHelpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTHelpers.mm; sourceTree = ""; }; 5492E045202154AA00B64F25 /* FIRCollectionReferenceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRCollectionReferenceTests.mm; sourceTree = ""; }; @@ -874,7 +872,6 @@ DE51B1851F0D48AC0013853F /* Util */ = { isa = PBXGroup; children = ( - 5492E0382021401E00B64F25 /* FSTAssertTests.mm */, 7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */, 54E9281C1F33950B00C1953E /* FSTEventAccumulator.h */, 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */, @@ -1471,7 +1468,6 @@ B65D34A9203C995B0076A5E1 /* FIRTimestampTest.m in Sources */, 5492E058202154AB00B64F25 /* FSTAPIHelpers.mm in Sources */, DE2EF0851F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m in Sources */, - 5492E03D2021401F00B64F25 /* FSTAssertTests.mm in Sources */, 5492E0C82021557E00B64F25 /* FSTDatastoreTests.mm in Sources */, 7346E61D20325C6900FD6CEF /* FSTDispatchQueueTests.mm in Sources */, 5492E0B92021555100B64F25 /* FSTDocumentKeyTests.mm in Sources */, diff --git a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm index 920e3c5..e6e1a19 100644 --- a/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm +++ b/Firestore/Example/Tests/Integration/FSTDatastoreTests.mm @@ -33,7 +33,6 @@ #import "Firestore/Source/Remote/FSTDatastore.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Source/Remote/FSTRemoteStore.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" @@ -42,6 +41,7 @@ #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/precondition.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; @@ -118,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)rejectFailedWriteWithBatchID:(FSTBatchID)batchID error:(NSError *)error { - FSTFail(@"Not implemented"); + HARD_FAIL("Not implemented"); } - (void)applyRemoteEvent:(FSTRemoteEvent *)remoteEvent { @@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)rejectListenWithTargetID:(const TargetId)targetID error:(NSError *)error { - FSTFail(@"Not implemented"); + HARD_FAIL("Not implemented"); } @end diff --git a/Firestore/Example/Tests/Integration/FSTStreamTests.mm b/Firestore/Example/Tests/Integration/FSTStreamTests.mm index 2e5c9b6..b944a93 100644 --- a/Firestore/Example/Tests/Integration/FSTStreamTests.mm +++ b/Firestore/Example/Tests/Integration/FSTStreamTests.mm @@ -24,12 +24,12 @@ #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" #import "Firestore/Source/Remote/FSTDatastore.h" #import "Firestore/Source/Remote/FSTStream.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/auth/empty_credentials_provider.h" #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; @@ -121,7 +121,7 @@ using firebase::firestore::model::SnapshotVersion; * to be called. */ - (void)awaitNotificationFromBlock:(void (^)(void))block { - FSTAssert(_expectation == nil, @"Previous expectation still active"); + HARD_ASSERT(_expectation == nil, "Previous expectation still active"); XCTestExpectation *expectation = [self.testCase expectationWithDescription:@"awaitCallbackInBlock"]; _expectation = expectation; diff --git a/Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm b/Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm index 3c7f46a..63c3d72 100644 --- a/Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm +++ b/Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm @@ -21,7 +21,6 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" #import "Firestore/Source/Remote/FSTStream.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Example/Tests/Remote/FSTWatchChange+Testing.h" @@ -80,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN credentials:credentials serializer:serializer]; if (self) { - FSTAssert(datastore, @"Datastore must not be nil"); + HARD_ASSERT(datastore, "Datastore must not be nil"); _datastore = datastore; _activeTargets = [NSMutableDictionary dictionary]; } @@ -90,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Overridden FSTWatchStream methods. - (void)startWithDelegate:(id)delegate { - FSTAssert(!self.open, @"Trying to start already started watch stream"); + HARD_ASSERT(!self.open, "Trying to start already started watch stream"); self.open = YES; self.delegate = delegate; [self notifyStreamOpen]; @@ -148,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN // Technically removing an unknown target is valid (e.g. it could race with a // server-side removal), but we want to pay extra careful attention in tests // that we only remove targets we listened too. - FSTFail(@"Removing a non-active target"); + HARD_FAIL("Removing a non-active target"); } [self.activeTargets removeObjectForKey:targetID]; } @@ -204,7 +203,7 @@ NS_ASSUME_NONNULL_BEGIN credentials:credentials serializer:serializer]; if (self) { - FSTAssert(datastore, @"Datastore must not be nil"); + HARD_ASSERT(datastore, "Datastore must not be nil"); _datastore = datastore; _sentMutations = [NSMutableArray array]; } @@ -214,7 +213,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Overridden FSTWriteStream methods. - (void)startWithDelegate:(id)delegate { - FSTAssert(!self.open, @"Trying to start already started write stream"); + HARD_ASSERT(!self.open, "Trying to start already started write stream"); self.open = YES; [self.sentMutations removeAllObjects]; self.delegate = delegate; @@ -258,8 +257,8 @@ NS_ASSUME_NONNULL_BEGIN * Returns the next write that was "sent to the backend", failing if there are no queued sent */ - (NSArray *)nextSentWrite { - FSTAssert(self.sentMutations.count > 0, - @"Writes need to happen before you can call nextSentWrite."); + HARD_ASSERT(self.sentMutations.count > 0, + "Writes need to happen before you can call nextSentWrite."); NSArray *result = [self.sentMutations objectAtIndex:0]; [self.sentMutations removeObjectAtIndex:0]; return result; @@ -292,7 +291,6 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Overridden FSTDatastore methods. - (FSTWatchStream *)createWatchStream { - // FSTAssert(self.databaseInfo, @"DatabaseInfo must not be nil"); self.watchStream = [[FSTMockWatchStream alloc] initWithDatastore:self workerDispatchQueue:self.workerDispatchQueue @@ -303,7 +301,6 @@ NS_ASSUME_NONNULL_BEGIN } - (FSTWriteStream *)createWriteStream { - // FSTAssert(self.databaseInfo, @"DatabaseInfo must not be nil"); self.writeStream = [[FSTMockWriteStream alloc] initWithDatastore:self workerDispatchQueue:self.workerDispatchQueue @@ -314,7 +311,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)authorizeAndStartRPC:(GRPCProtoCall *)rpc completion:(FSTVoidErrorBlock)completion { - FSTFail(@"FSTMockDatastore shouldn't be starting any RPCs."); + HARD_FAIL("FSTMockDatastore shouldn't be starting any RPCs."); } #pragma mark - Method exposed for tests to call. diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm index 7b10bd4..77010e5 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm @@ -34,7 +34,6 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTExistenceFilter.h" #import "Firestore/Source/Remote/FSTWatchChange.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTClasses.h" #import "Firestore/Source/Util/FSTDispatchQueue.h" @@ -45,6 +44,7 @@ #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" @@ -233,7 +233,7 @@ static NSString *const kNoIOSTag = @"no-ios"; - (void)doWatchEntity:(NSDictionary *)watchEntity snapshot:(NSNumber *_Nullable)watchSnapshot { if (watchEntity[@"docs"]) { - FSTAssert(!watchEntity[@"doc"], @"Exactly one of |doc| or |docs| needs to be set."); + HARD_ASSERT(!watchEntity[@"doc"], "Exactly one of |doc| or |docs| needs to be set."); int count = 0; NSArray *docs = watchEntity[@"docs"]; for (NSDictionary *doc in docs) { @@ -277,13 +277,13 @@ static NSString *const kNoIOSTag = @"no-ios"; document:nil]; [self.driver receiveWatchChange:change snapshotVersion:[self parseVersion:watchSnapshot]]; } else { - FSTFail(@"Either key, doc or docs must be set."); + HARD_FAIL("Either key, doc or docs must be set."); } } - (void)doWatchFilter:(NSArray *)watchFilter snapshot:(NSNumber *_Nullable)watchSnapshot { NSArray *targets = watchFilter[0]; - FSTAssert(targets.count == 1, @"ExistenceFilters currently support exactly one target only."); + HARD_ASSERT(targets.count == 1, "ExistenceFilters currently support exactly one target only."); int keyCount = watchFilter.count == 0 ? 0 : (int)watchFilter.count - 1; @@ -308,7 +308,7 @@ static NSString *const kNoIOSTag = @"no-ios"; NSNumber *runBackoffTimer = closeSpec[@"runBackoffTimer"]; // TODO(b/72313632): Incorporate backoff in iOS Spec Tests. - FSTAssert(runBackoffTimer.boolValue, @"iOS Spec Tests don't support backoff."); + HARD_ASSERT(runBackoffTimer.boolValue, "iOS Spec Tests don't support backoff."); [self.driver receiveWatchStreamError:code userInfo:errorSpec]; } @@ -323,8 +323,8 @@ static NSString *const kNoIOSTag = @"no-ios"; [self.driver receiveWriteAckWithVersion:version mutationResults:@[ mutationResult ]]; if (expectUserCallback.boolValue) { - FSTAssert(write.done, @"Write should be done"); - FSTAssert(!write.error, @"Ack should not fail"); + HARD_ASSERT(write.done, "Write should be done"); + HARD_ASSERT(!write.error, "Ack should not fail"); } } @@ -336,7 +336,7 @@ static NSString *const kNoIOSTag = @"no-ios"; FSTOutstandingWrite *write = [self.driver receiveWriteError:code userInfo:errorSpec]; if (expectUserCallback.boolValue) { - FSTAssert(write.done, @"Write should be done"); + HARD_ASSERT(write.done, "Write should be done"); XCTAssertNotNil(write.error, @"Write should have failed"); XCTAssertEqualObjects(write.error.domain, FIRFirestoreErrorDomain); XCTAssertEqual(write.error.code, code); @@ -358,7 +358,7 @@ static NSString *const kNoIOSTag = @"no-ios"; } else if ([timer isEqualToString:@"online_state_timeout"]) { timerID = FSTTimerIDOnlineStateTimeout; } else { - FSTFail(@"runTimer spec step specified unknown timer: %@", timer); + HARD_FAIL("runTimer spec step specified unknown timer: %s", timer); } [self.driver runTimer:timerID]; @@ -427,7 +427,7 @@ static NSString *const kNoIOSTag = @"no-ios"; [self doWatchStreamClose:step[@"watchStreamClose"]]; } else if (step[@"watchProto"]) { // watchProto isn't yet used, and it's unclear how to create arbitrary protos from JSON. - FSTFail(@"watchProto is not yet supported."); + HARD_FAIL("watchProto is not yet supported."); } else if (step[@"writeAck"]) { [self doWriteAck:step[@"writeAck"]]; } else if (step[@"failWrite"]) { diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm index 40ebfb9..d346197 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm @@ -30,7 +30,6 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTDatastore.h" #import "Firestore/Source/Remote/FSTWatchChange.h" -#import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h" #import "Firestore/Example/Tests/SpecTests/FSTMockDatastore.h" @@ -40,6 +39,7 @@ #include "Firestore/core/src/firebase/firestore/core/database_info.h" #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/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/log.h" using firebase::firestore::auth::EmptyCredentialsProvider; @@ -183,9 +183,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)validateUsage { // We could relax this if we found a reason to. - FSTAssert(self.events.count == 0, - @"You must clear all pending events by calling" - " capturedEventsSinceLastCall before calling shutdown."); + HARD_ASSERT(self.events.count == 0, + "You must clear all pending events by calling" + " capturedEventsSinceLastCall before calling shutdown."); } - (void)shutdown { @@ -197,11 +197,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)validateNextWriteSent:(FSTMutation *)expectedWrite { NSArray *request = [self.datastore nextSentWrite]; // Make sure the write went through the pipe like we expected it to. - FSTAssert(request.count == 1, @"Only single mutation requests are supported at the moment"); + HARD_ASSERT(request.count == 1, "Only single mutation requests are supported at the moment"); FSTMutation *actualWrite = request[0]; - FSTAssert([actualWrite isEqual:expectedWrite], - @"Mock datastore received write %@ but first outstanding mutation was %@", actualWrite, - expectedWrite); + HARD_ASSERT([actualWrite isEqual:expectedWrite], + "Mock datastore received write %s but first outstanding mutation was %s", actualWrite, + expectedWrite); LOG_DEBUG("A write was sent: %s", actualWrite); } @@ -347,7 +347,7 @@ NS_ASSUME_NONNULL_BEGIN [self.datastore failWatchStreamWithError:error]; // Unlike web, stream should re-open synchronously (if we have any listeners) if (self.queryListeners.count > 0) { - FSTAssert(self.datastore.isWatchStreamOpen, @"Watch stream is open"); + HARD_ASSERT(self.datastore.isWatchStreamOpen, "Watch stream is open"); } }]; } diff --git a/Firestore/Example/Tests/Util/FSTAssertTests.mm b/Firestore/Example/Tests/Util/FSTAssertTests.mm deleted file mode 100644 index 0cba03f..0000000 --- a/Firestore/Example/Tests/Util/FSTAssertTests.mm +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2017 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. - */ - -#import "Firestore/Source/Util/FSTAssert.h" - -#import - -@interface FSTAssertTests : XCTestCase -@end - -@implementation FSTAssertTests - -- (void)testFail { - @try { - [self failingMethod]; - XCTFail("Should not have succeeded"); - } @catch (NSException *ex) { - XCTAssertEqualObjects(ex.name, NSInternalInconsistencyException); - XCTAssertEqualObjects(ex.reason, @"FIRESTORE INTERNAL ASSERTION FAILED: 0:foo:bar"); - } -} - -// A method guaranteed to fail. Note that the return type is intentionally something that is -// not actually returned in the body to ensure that the function attribute declarations in the -// macro properly mark this macro invocation as never returning. -- (int)failingMethod { - FSTFail(@"%d:%s:%@", 0, "foo", @"bar"); -} - -- (void)testCFail { - @try { - failingFunction(); - XCTFail("Should not have succeeded"); - } @catch (NSException *ex) { - XCTAssertEqualObjects(ex.name, NSInternalInconsistencyException); - XCTAssertEqualObjects(ex.reason, @"FIRESTORE INTERNAL ASSERTION FAILED: 0:foo:bar"); - } -} - -// A function guaranteed to fail. Note that the return type is intentionally something that is -// not actually returned in the body to ensure that the function attribute declarations in the -// macro properly mark this macro invocation as never returning. -int failingFunction() { - FSTCFail(@"%d:%s:%@", 0, "foo", @"bar"); -} - -- (void)testAssertNonFailing { - @try { - FSTAssert(YES, @"shouldn't fail"); - } @catch (NSException *ex) { - XCTFail("Should not have failed, but got %@", ex); - } -} - -- (void)testAssertFailing { - @try { - FSTAssert(NO, @"should fail"); - XCTFail("Should not have succeeded"); - } @catch (NSException *ex) { - XCTAssertEqualObjects(ex.name, NSInternalInconsistencyException); - XCTAssertEqualObjects(ex.reason, @"FIRESTORE INTERNAL ASSERTION FAILED: should fail"); - } -} - -- (void)testCAssertNonFailing { - @try { - nonAssertingFunction(); - } @catch (NSException *ex) { - XCTFail("Should not have failed, but got %@", ex); - } -} - -int nonAssertingFunction() { - FSTCAssert(YES, @"shouldn't fail"); - return 0; -} - -- (void)testCAssertFailing { - @try { - assertingFunction(); - XCTFail("Should not have succeeded"); - } @catch (NSException *ex) { - XCTAssertEqualObjects(ex.name, NSInternalInconsistencyException); - XCTAssertEqualObjects(ex.reason, @"FIRESTORE INTERNAL ASSERTION FAILED: should fail"); - } -} - -int assertingFunction() { - FSTCAssert(NO, @"should fail"); -} - -@end diff --git a/Firestore/Example/Tests/Util/FSTEventAccumulator.mm b/Firestore/Example/Tests/Util/FSTEventAccumulator.mm index 3ab6035..835dc68 100644 --- a/Firestore/Example/Tests/Util/FSTEventAccumulator.mm +++ b/Firestore/Example/Tests/Util/FSTEventAccumulator.mm @@ -18,12 +18,12 @@ #import +#import "Firestore/Example/Tests/Util/XCTestCase+Await.h" #import "Firestore/Source/Public/FIRDocumentSnapshot.h" #import "Firestore/Source/Public/FIRQuerySnapshot.h" #import "Firestore/Source/Public/FIRSnapshotMetadata.h" -#import "Firestore/Source/Util/FSTAssert.h" -#import "Firestore/Example/Tests/Util/XCTestCase+Await.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" NS_ASSUME_NONNULL_BEGIN @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)awaitEvents:(NSUInteger)events name:(NSString *)name { @synchronized(self) { - FSTAssert(!self.expectation, @"Existing expectation still pending?"); + HARD_ASSERT(!self.expectation, "Existing expectation still pending?"); self.expectation = [self.testCase expectationWithDescription:name]; self.maxEvents = self.maxEvents + events; [self checkFulfilled]; @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN if ([event isKindOfClass:[FIRDocumentSnapshot class]]) { return ((FIRDocumentSnapshot *)event).metadata.hasPendingWrites; } else { - FSTAssert([event isKindOfClass:[FIRQuerySnapshot class]], @"Unexpected event: %@", event); + HARD_ASSERT([event isKindOfClass:[FIRQuerySnapshot class]], "Unexpected event: %s", event); return ((FIRQuerySnapshot *)event).metadata.hasPendingWrites; } } diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index bc2f005..5ed4fd5 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -40,7 +40,6 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Source/Remote/FSTWatchChange.h" -#import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" @@ -140,7 +139,7 @@ FSTFieldValue *FSTTestFieldValue(id _Nullable value) { FSTObjectValue *FSTTestObjectValue(NSDictionary *data) { FSTFieldValue *wrapped = FSTTestFieldValue(data); - FSTCAssert([wrapped isKindOfClass:[FSTObjectValue class]], @"Unsupported value: %@", data); + HARD_ASSERT([wrapped isKindOfClass:[FSTObjectValue class]], "Unsupported value: %s", data); return (FSTObjectValue *)wrapped; } @@ -195,15 +194,15 @@ id FSTTestFilter(const absl::string_view field, NSString *opString, i } else if ([opString isEqualToString:@"array_contains"]) { op = FSTRelationFilterOperatorArrayContains; } else { - FSTCFail(@"Unsupported operator type: %@", opString); + HARD_FAIL("Unsupported operator type: %s", opString); } FSTFieldValue *data = FSTTestFieldValue(value); if ([data isEqual:[FSTDoubleValue nanValue]]) { - FSTCAssert(op == FSTRelationFilterOperatorEqual, @"Must use == with NAN."); + HARD_ASSERT(op == FSTRelationFilterOperatorEqual, "Must use == with NAN."); return [[FSTNanFilter alloc] initWithField:path]; } else if ([data isEqual:[FSTNullValue nullValue]]) { - FSTCAssert(op == FSTRelationFilterOperatorEqual, @"Must use == with Null."); + HARD_ASSERT(op == FSTRelationFilterOperatorEqual, "Must use == with Null."); return [[FSTNullFilter alloc] initWithField:path]; } else { return [FSTRelationFilter filterWithField:path filterOperator:op value:data]; @@ -218,7 +217,7 @@ FSTSortOrder *FSTTestOrderBy(const absl::string_view field, NSString *direction) } else if ([direction isEqualToString:@"desc"]) { ascending = NO; } else { - FSTCFail(@"Unsupported direction: %@", direction); + HARD_FAIL("Unsupported direction: %s", direction); } return [FSTSortOrder sortOrderWithFieldPath:path ascending:ascending]; } @@ -272,8 +271,8 @@ FSTTransformMutation *FSTTestTransformMutation(NSString *path, NSDictionary