Skip to content

Add xcgmock #2595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
36FD4CE79613D18BC783C55B /* string_apple_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0EE5300F8233D14025EF0456 /* string_apple_test.mm */; };
3B843E4C1F3A182900548890 /* remote_store_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B843E4A1F3930A400548890 /* remote_store_spec_test.json */; };
4AA4ABE36065DB79CD76DD8D /* Pods_Firestore_Benchmarks_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F694C3CE4B77B3C0FA4BBA53 /* Pods_Firestore_Benchmarks_iOS.framework */; };
4D1F46B2DD91198C8867C04C /* xcgmock_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4425A513895DEC60325A139E /* xcgmock_test.mm */; };
54131E9720ADE679001DF3FF /* string_format_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54131E9620ADE678001DF3FF /* string_format_test.cc */; };
544129DA21C2DDC800EFB9CC /* common.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 544129D221C2DDC800EFB9CC /* common.pb.cc */; };
544129DB21C2DDC800EFB9CC /* firestore.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 544129D421C2DDC800EFB9CC /* firestore.pb.cc */; };
Expand Down Expand Up @@ -182,6 +183,7 @@
84DBE646DCB49305879D3500 /* nanopb_string_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 353EEE078EF3F39A9B7279F6 /* nanopb_string_test.cc */; };
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
8C82D4D3F9AB63E79CC52DC8 /* Pods_Firestore_IntegrationTests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECEBABC7E7B693BE808A1052 /* Pods_Firestore_IntegrationTests_iOS.framework */; };
9794E074439ABE5457E60F35 /* xcgmock_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4425A513895DEC60325A139E /* xcgmock_test.mm */; };
AB356EF7200EA5EB0089B766 /* field_value_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB356EF6200EA5EB0089B766 /* field_value_test.cc */; };
AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CF82019382300D97691 /* target_id_generator_test.cc */; };
AB380CFE201A2F4500D97691 /* string_util_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CFC201A2EE200D97691 /* string_util_test.cc */; };
Expand Down Expand Up @@ -326,6 +328,7 @@
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 = "<group>"; };
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 = "<group>"; };
403DBF6EFB541DFD01582AA3 /* path_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = path_test.cc; sourceTree = "<group>"; };
4425A513895DEC60325A139E /* xcgmock_test.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = xcgmock_test.mm; sourceTree = "<group>"; };
444B7AB3F5A2929070CB1363 /* hard_assert_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = hard_assert_test.cc; sourceTree = "<group>"; };
54131E9620ADE678001DF3FF /* string_format_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = string_format_test.cc; sourceTree = "<group>"; };
544129D021C2DDC800EFB9CC /* query.pb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = query.pb.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -559,6 +562,7 @@
B6FB468A208F9B9100554BA2 /* executor_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = executor_test.h; sourceTree = "<group>"; };
B79CA87A1A01FC5329031C9B /* Pods_Firestore_FuzzTests_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_FuzzTests_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B9C261C26C5D311E1E3C0CB9 /* query_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = query_test.cc; sourceTree = "<group>"; };
BA6E5B9D53CCF301F58A62D7 /* xcgmock.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = xcgmock.h; sourceTree = "<group>"; };
BB92EB03E3F92485023F64ED /* Pods_Firestore_Example_iOS_Firestore_SwiftTests_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example_iOS_Firestore_SwiftTests_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C8522DE226C467C54E6788D8 /* mutation_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = mutation_test.cc; sourceTree = "<group>"; };
D0A6E9136804A41CEC9D55D4 /* delayed_constructor_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = delayed_constructor_test.cc; sourceTree = "<group>"; };
Expand Down Expand Up @@ -715,6 +719,8 @@
5467FB07203E6A44009C9584 /* app_testing.mm */,
54A0352820A3B3BD003E0143 /* testutil.cc */,
54A0352920A3B3BD003E0143 /* testutil.h */,
BA6E5B9D53CCF301F58A62D7 /* xcgmock.h */,
4425A513895DEC60325A139E /* xcgmock_test.mm */,
);
path = testutil;
sourceTree = "<group>";
Expand Down Expand Up @@ -2138,6 +2144,7 @@
ABC1D7DE2023A05300BA84F0 /* user_test.cc in Sources */,
B68FC0E521F6848700A7055C /* watch_change_test.mm in Sources */,
544129DE21C2DDC800EFB9CC /* write.pb.cc in Sources */,
9794E074439ABE5457E60F35 /* xcgmock_test.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2185,6 +2192,7 @@
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */,
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */,
CA989C0E6020C372A62B7062 /* testutil.cc in Sources */,
4D1F46B2DD91198C8867C04C /* xcgmock_test.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2670,12 +2678,12 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/cpp\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/nanopb\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
"\"${PODS_ROOT}/GoogleTest/googlemock/include\"",
"\"${PODS_ROOT}/GoogleTest/googletest/include\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/nanopb\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/cpp\"",
"\"${PODS_ROOT}/ProtobufCpp/src\"",
);
INFOPLIST_FILE = "Tests/Tests-Info.plist";
Expand Down Expand Up @@ -2748,12 +2756,12 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/cpp\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/nanopb\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
"\"${PODS_ROOT}/GoogleTest/googlemock/include\"",
"\"${PODS_ROOT}/GoogleTest/googletest/include\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/nanopb\"",
"\"${PODS_ROOT}/../../../Firestore/Protos/cpp\"",
"\"${PODS_ROOT}/ProtobufCpp/src\"",
);
INFOPLIST_FILE = "Tests/Tests-Info.plist";
Expand Down Expand Up @@ -3044,8 +3052,9 @@
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
"\"${PODS_ROOT}/GoogleTest/googlemock/include\"",
"\"${PODS_ROOT}/GoogleTest/googletest/include\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
);
INFOPLIST_FILE = "Tests/Tests-Info.plist";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -3081,8 +3090,9 @@
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
"\"${PODS_ROOT}/GoogleTest/googlemock/include\"",
"\"${PODS_ROOT}/GoogleTest/googletest/include\"",
"\"${PODS_ROOT}/leveldb-library/include\"",
);
INFOPLIST_FILE = "Tests/Tests-Info.plist";
OTHER_LDFLAGS = (
Expand Down
97 changes: 48 additions & 49 deletions Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
#include "Firestore/core/src/firebase/firestore/util/status.h"
#include "Firestore/core/src/firebase/firestore/util/statusor.h"
#include "Firestore/core/test/firebase/firestore/testutil/xcgmock.h"

using firebase::firestore::FirestoreErrorCode;
using firebase::firestore::core::DocumentViewChange;
Expand All @@ -49,9 +50,28 @@
using firebase::firestore::util::ExecutorLibdispatch;
using firebase::firestore::util::Status;
using firebase::firestore::util::StatusOr;
using testing::ElementsAre;
using testing::IsEmpty;

NS_ASSUME_NONNULL_BEGIN

namespace {

ViewSnapshot ExcludingMetadataChanges(const ViewSnapshot &snapshot) {
return ViewSnapshot{
snapshot.query(),
snapshot.documents(),
snapshot.old_documents(),
snapshot.document_changes(),
snapshot.mutated_keys(),
snapshot.from_cache(),
snapshot.sync_state_changed(),
/*excludes_metadata_changes=*/true,
};
}

} // namespace

@interface FSTQueryListenerTests : XCTestCase
@end

Expand All @@ -67,20 +87,6 @@ - (void)setUp {
waitForSyncWhenOnline:NO];
}

- (ViewSnapshot)setExcludesMetadataChanges:(bool)excludesMetadataChanges
snapshot:(const ViewSnapshot &)snapshot {
return ViewSnapshot{
snapshot.query(),
snapshot.documents(),
snapshot.old_documents(),
snapshot.document_changes(),
snapshot.mutated_keys(),
snapshot.from_cache(),
snapshot.sync_state_changed(),
excludesMetadataChanges,
};
}

- (void)testRaisesCollectionEvents {
std::vector<ViewSnapshot> accum;
std::vector<ViewSnapshot> otherAccum;
Expand Down Expand Up @@ -109,9 +115,9 @@ - (void)testRaisesCollectionEvents {
[listener queryDidChangeViewSnapshot:snap2];
[otherListener queryDidChangeViewSnapshot:snap2];

XCTAssertTrue((accum == std::vector<ViewSnapshot>{snap1, snap2}));
XCTAssertTrue((accum[0].document_changes() == std::vector<DocumentViewChange>{change1, change2}));
XCTAssertTrue(accum[1].document_changes() == std::vector<DocumentViewChange>{change3});
XC_ASSERT_THAT(accum, ElementsAre(snap1, snap2));
XC_ASSERT_THAT(accum[0].document_changes(), ElementsAre(change1, change2));
XC_ASSERT_THAT(accum[1].document_changes(), ElementsAre(change3));

ViewSnapshot expectedSnap2{
snap2.query(),
Expand All @@ -122,7 +128,7 @@ - (void)testRaisesCollectionEvents {
snap2.from_cache(),
/*sync_state_changed=*/true,
/*excludes_metadata_changes=*/true};
XCTAssertTrue((otherAccum == std::vector<ViewSnapshot>{expectedSnap2}));
XC_ASSERT_THAT(otherAccum, ElementsAre(expectedSnap2));
}

- (void)testRaisesErrorEvent {
Expand All @@ -137,7 +143,7 @@ - (void)testRaisesErrorEvent {
Status testError{FirestoreErrorCode::Unauthenticated, "Some info"};
[listener queryDidError:testError];

XCTAssertTrue((accum == std::vector<Status>{testError}));
XC_ASSERT_THAT(accum, ElementsAre(testError));
}

- (void)testRaisesEventForEmptyCollectionAfterSync {
Expand All @@ -153,10 +159,10 @@ - (void)testRaisesEventForEmptyCollectionAfterSync {
ViewSnapshot snap2 = FSTTestApplyChanges(view, @[], FSTTestTargetChangeMarkCurrent()).value();

[listener queryDidChangeViewSnapshot:snap1];
XCTAssertTrue(accum.empty());
XC_ASSERT_THAT(accum, IsEmpty());

[listener queryDidChangeViewSnapshot:snap2];
XCTAssertTrue((accum == std::vector<ViewSnapshot>{snap2}));
XC_ASSERT_THAT(accum, ElementsAre(snap2));
}

- (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
Expand Down Expand Up @@ -193,7 +199,7 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
}];

// We should get the first snapshot but not the second.
XCTAssertTrue((accum == std::vector<ViewSnapshot>{viewSnapshot1}));
XC_ASSERT_THAT(accum, ElementsAre(viewSnapshot1));
}

- (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
Expand Down Expand Up @@ -225,10 +231,9 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
[fullListener queryDidChangeViewSnapshot:snap2]; // state change event
[fullListener queryDidChangeViewSnapshot:snap3]; // doc2 update

XCTAssertTrue((filteredAccum ==
std::vector<ViewSnapshot>{[self setExcludesMetadataChanges:true snapshot:snap1],
[self setExcludesMetadataChanges:true snapshot:snap3]}));
XCTAssertTrue((fullAccum == std::vector<ViewSnapshot>{snap1, snap2, snap3}));
XC_ASSERT_THAT(filteredAccum,
ElementsAre(ExcludingMetadataChanges(snap1), ExcludingMetadataChanges(snap3)));
XC_ASSERT_THAT(fullAccum, ElementsAre(snap1, snap2, snap3));
}

- (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
Expand Down Expand Up @@ -270,18 +275,15 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
[fullListener queryDidChangeViewSnapshot:snap2];
[fullListener queryDidChangeViewSnapshot:snap3];

XCTAssertTrue((filteredAccum ==
std::vector<ViewSnapshot>{[self setExcludesMetadataChanges:true snapshot:snap1],
[self setExcludesMetadataChanges:true snapshot:snap3]}));
XCTAssertTrue(
(filteredAccum[0].document_changes() == std::vector<DocumentViewChange>{change1, change2}));
XCTAssertTrue((filteredAccum[1].document_changes() == std::vector<DocumentViewChange>{change4}));

XCTAssertTrue((fullAccum == std::vector<ViewSnapshot>{snap1, snap2, snap3}));
XCTAssertTrue(
(fullAccum[0].document_changes() == std::vector<DocumentViewChange>{change1, change2}));
XCTAssertTrue((fullAccum[1].document_changes() == std::vector<DocumentViewChange>{change3}));
XCTAssertTrue((fullAccum[2].document_changes() == std::vector<DocumentViewChange>{change4}));
XC_ASSERT_THAT(filteredAccum,
ElementsAre(ExcludingMetadataChanges(snap1), ExcludingMetadataChanges(snap3)));
XC_ASSERT_THAT(filteredAccum[0].document_changes(), ElementsAre(change1, change2));
XC_ASSERT_THAT(filteredAccum[1].document_changes(), ElementsAre(change4));

XC_ASSERT_THAT(fullAccum, ElementsAre(snap1, snap2, snap3));
XC_ASSERT_THAT(fullAccum[0].document_changes(), ElementsAre(change1, change2));
XC_ASSERT_THAT(fullAccum[1].document_changes(), ElementsAre(change3));
XC_ASSERT_THAT(fullAccum[2].document_changes(), ElementsAre(change4));
}

- (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
Expand Down Expand Up @@ -326,10 +328,9 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
snap4.sync_state_changed(),
/*excludes_metadata_changes=*/true // This test excludes document metadata changes
};
XCTAssertTrue(
(fullAccum == std::vector<ViewSnapshot>{[self setExcludesMetadataChanges:true snapshot:snap1],
[self setExcludesMetadataChanges:true snapshot:snap3],
expectedSnap4}));

XC_ASSERT_THAT(fullAccum, ElementsAre(ExcludingMetadataChanges(snap1),
ExcludingMetadataChanges(snap3), expectedSnap4));
}

- (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadataChangesIsFalse {
Expand Down Expand Up @@ -363,9 +364,7 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
snap2.from_cache(),
snap2.sync_state_changed(),
/*excludes_metadata_changes=*/true};
XCTAssertTrue((filteredAccum == std::vector<ViewSnapshot>{[self setExcludesMetadataChanges:true
snapshot:snap1],
expectedSnap2}));
XC_ASSERT_THAT(filteredAccum, ElementsAre(ExcludingMetadataChanges(snap1), expectedSnap2));
}

- (void)testWillWaitForSyncIfOnline {
Expand Down Expand Up @@ -405,7 +404,7 @@ - (void)testWillWaitForSyncIfOnline {
/*from_cache=*/false,
/*sync_state_changed=*/true,
/*excludes_metadata_changes=*/true};
XCTAssertTrue((events == std::vector<ViewSnapshot>{expectedSnap}));
XC_ASSERT_THAT(events, ElementsAre(expectedSnap));
}

- (void)testWillRaiseInitialEventWhenGoingOffline {
Expand Down Expand Up @@ -452,7 +451,7 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
/*from_cache=*/true,
/*sync_state_changed=*/false,
/*excludes_metadata_changes=*/true};
XCTAssertTrue((events == std::vector<ViewSnapshot>{expectedSnap1, expectedSnap2}));
XC_ASSERT_THAT(events, ElementsAre(expectedSnap1, expectedSnap2));
}

- (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
Expand All @@ -479,7 +478,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
/*from_cache=*/true,
/*sync_state_changed=*/true,
/*excludes_metadata_changes=*/true};
XCTAssertTrue((events == std::vector<ViewSnapshot>{expectedSnap}));
XC_ASSERT_THAT(events, ElementsAre(expectedSnap));
}

- (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
Expand All @@ -505,7 +504,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
/*from_cache=*/true,
/*sync_state_changed=*/true,
/*excludes_metadata_changes=*/true};
XCTAssertTrue((events == std::vector<ViewSnapshot>{expectedSnap}));
XC_ASSERT_THAT(events, ElementsAre(expectedSnap));
}

- (FSTQueryListener *)listenToQuery:(FSTQuery *)query handler:(ViewSnapshotHandler &&)handler {
Expand Down
Loading