Skip to content

Add a ToString function to create human-readable debug descriptions #2384

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 15 commits into from
Feb 15, 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
20 changes: 10 additions & 10 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@
B67BF449216EB43000CA9097 /* create_noop_connectivity_monitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */; };
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2AD2023DDB20028D6BE /* field_path_test.cc */; };
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2B02024FFD70028D6BE /* resource_path_test.cc */; };
B68B1E012213A765008977EF /* to_string_apple_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = B68B1E002213A764008977EF /* to_string_apple_test.mm */; };
B68FC0E521F6848700A7055C /* watch_change_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = B68FC0E421F6848700A7055C /* watch_change_test.mm */; };
B696858E2214B53900271095 /* to_string_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B696858D2214B53900271095 /* to_string_test.cc */; };
B6BBE43121262CF400C6A53E /* grpc_stream_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */; };
B6D1B68520E2AB1B00B35856 /* exponential_backoff_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */; };
B6D9649121544D4F00EB9CFB /* grpc_connection_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */; };
Expand Down Expand Up @@ -522,7 +524,9 @@
B67BF448216EB43000CA9097 /* create_noop_connectivity_monitor.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = create_noop_connectivity_monitor.cc; sourceTree = "<group>"; };
B686F2AD2023DDB20028D6BE /* field_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_path_test.cc; sourceTree = "<group>"; };
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
B68B1E002213A764008977EF /* to_string_apple_test.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = to_string_apple_test.mm; sourceTree = "<group>"; };
B68FC0E421F6848700A7055C /* watch_change_test.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = watch_change_test.mm; sourceTree = "<group>"; };
B696858D2214B53900271095 /* to_string_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = to_string_test.cc; sourceTree = "<group>"; };
B69CF05A219B9105004C434D /* FIRFirestore+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FIRFirestore+Testing.h"; sourceTree = "<group>"; };
B6BBE42F21262CF400C6A53E /* grpc_stream_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = grpc_stream_test.cc; sourceTree = "<group>"; };
B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = exponential_backoff_test.cc; sourceTree = "<group>"; };
Expand Down Expand Up @@ -701,7 +705,6 @@
546854A720A3681B004BDBD5 /* remote */ = {
isa = PBXGroup;
children = (
B68FC0E421F6848700A7055C /* watch_change_test.mm */,
546854A820A36867004BDBD5 /* datastore_test.mm */,
B6D1B68420E2AB1A00B35856 /* exponential_backoff_test.cc */,
B6D9649021544D4F00EB9CFB /* grpc_connection_test.cc */,
Expand All @@ -710,6 +713,7 @@
B6D964942163E63900EB9CFB /* grpc_unary_call_test.cc */,
61F72C5520BC48FD001A68CB /* serializer_test.cc */,
B66D8995213609EE0086DA0C /* stream_test.mm */,
B68FC0E421F6848700A7055C /* watch_change_test.mm */,
);
path = remote;
sourceTree = "<group>";
Expand Down Expand Up @@ -752,6 +756,8 @@
54131E9620ADE678001DF3FF /* string_format_test.cc */,
AB380CFC201A2EE200D97691 /* string_util_test.cc */,
79507DF8378D3C42F5B36268 /* string_win_test.cc */,
B68B1E002213A764008977EF /* to_string_apple_test.mm */,
B696858D2214B53900271095 /* to_string_test.cc */,
2A0CF41BA5AED6049B0BEB2C /* type_traits_apple_test.mm */,
);
path = util;
Expand Down Expand Up @@ -1678,8 +1684,6 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-macOS_example/Pods-macOS_example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/BoringSSL-GRPC-macOS/openssl_grpc.framework",
Expand All @@ -1692,8 +1696,6 @@
"${BUILT_PRODUCTS_DIR}/nanopb-macOS/nanopb.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl_grpc.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework",
Expand Down Expand Up @@ -1769,15 +1771,11 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-macOS_example-checkManifestLockResult.txt",
);
Expand Down Expand Up @@ -1981,7 +1979,6 @@
5492E0BA2021555100B64F25 /* FSTDocumentSetTests.mm in Sources */,
5492E0BD2021555100B64F25 /* FSTDocumentTests.mm in Sources */,
5492E03E2021401F00B64F25 /* FSTEventAccumulator.mm in Sources */,
B68FC0E521F6848700A7055C /* watch_change_test.mm in Sources */,
5492E067202154B900B64F25 /* FSTEventManagerTests.mm in Sources */,
5492E0BF2021555100B64F25 /* FSTFieldValueTests.mm in Sources */,
54764FAF1FAA21B90085E60A /* FSTGoogleTestTests.mm in Sources */,
Expand Down Expand Up @@ -2099,11 +2096,14 @@
AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */,
54A0352A20A3B3BD003E0143 /* testutil.cc in Sources */,
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */,
B68B1E012213A765008977EF /* to_string_apple_test.mm in Sources */,
B696858E2214B53900271095 /* to_string_test.cc in Sources */,
ABC1D7E12023A40C00BA84F0 /* token_test.cc in Sources */,
54A0352720A3AED0003E0143 /* transform_operations_test.mm in Sources */,
549CCA5120A36DBC00BCEB75 /* tree_sorted_map_test.cc in Sources */,
C80B10E79CDD7EF7843C321E /* type_traits_apple_test.mm in Sources */,
ABC1D7DE2023A05300BA84F0 /* user_test.cc in Sources */,
B68FC0E521F6848700A7055C /* watch_change_test.mm in Sources */,
544129DE21C2DDC800EFB9CC /* write.pb.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
11 changes: 7 additions & 4 deletions Firestore/Example/Tests/Model/FSTFieldValueTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
} else if ([value isKindOfClass:[FSTDocumentKeyReference class]]) {
// We directly convert these here so that the databaseIDs can be different.
FSTDocumentKeyReference *reference = (FSTDocumentKeyReference *)value;
wrappedValue = [FSTReferenceValue referenceValue:reference.key
databaseID:reference.databaseID];
wrappedValue =
[FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:reference.key]
databaseID:reference.databaseID];
} else {
wrappedValue = FSTTestFieldValue(value);
}
Expand Down Expand Up @@ -258,7 +259,7 @@ - (void)testWrapResourceNames {
for (FSTDocumentKeyReference *value in values) {
FSTFieldValue *wrapped = FSTTestFieldValue(value);
XCTAssertEqualObjects([wrapped class], [FSTReferenceValue class]);
XCTAssertEqualObjects([wrapped value], value.key);
XCTAssertEqualObjects([wrapped value], [FSTDocumentKey keyWithDocumentKey:value.key]);
XCTAssertTrue(*((FSTReferenceValue *)wrapped).databaseID ==
*(const DatabaseId *)(value.databaseID));
}
Expand Down Expand Up @@ -459,7 +460,9 @@ - (void)testValueEquality {
],
@[ FSTTestFieldValue(FSTTestGeoPoint(1, 0)) ],
@[
[FSTReferenceValue referenceValue:FSTTestDocKey(@"coll/doc1") databaseID:&database_id],
[FSTReferenceValue
referenceValue:[FSTDocumentKey keyWithDocumentKey:FSTTestDocKey(@"coll/doc1")]
databaseID:&database_id],
FSTTestFieldValue(FSTTestRef("project", DatabaseId::kDefault, @"coll/doc1"))
],
@[ FSTTestRef("project", "(default)", @"coll/doc2") ],
Expand Down
18 changes: 11 additions & 7 deletions Firestore/Source/API/FIRQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,13 @@ - (FIRQuery *)queryWithFilterOperator:(FSTRelationFilterOperator)filterOperator
"a valid document ID, but it was an empty string.");
}
ResourcePath path = self.query.path.Append([documentKey UTF8String]);
fieldValue = [FSTReferenceValue referenceValue:DocumentKey{path}
databaseID:self.firestore.databaseID];
fieldValue =
[FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:DocumentKey{path}]
databaseID:self.firestore.databaseID];
} else if ([value isKindOfClass:[FIRDocumentReference class]]) {
FIRDocumentReference *ref = (FIRDocumentReference *)value;
fieldValue = [FSTReferenceValue referenceValue:ref.key databaseID:self.firestore.databaseID];
fieldValue = [FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:ref.key]
databaseID:self.firestore.databaseID];
} else {
FSTThrowInvalidArgument(@"Invalid query. When querying by document ID you must provide a "
"valid string or DocumentReference, but it was of type: %@",
Expand Down Expand Up @@ -568,8 +570,9 @@ - (FSTBound *)boundFromSnapshot:(FIRDocumentSnapshot *)snapshot isBefore:(BOOL)i
// orders), multiple documents could match the position, yielding duplicate results.
for (FSTSortOrder *sortOrder in self.query.sortOrders) {
if (sortOrder.field == FieldPath::KeyFieldPath()) {
[components addObject:[FSTReferenceValue referenceValue:document.key
databaseID:self.firestore.databaseID]];
[components addObject:[FSTReferenceValue
referenceValue:[FSTDocumentKey keyWithDocumentKey:document.key]
databaseID:self.firestore.databaseID]];
} else {
FSTFieldValue *value = [document fieldForPath:sortOrder.field];
if (value != nil) {
Expand Down Expand Up @@ -610,8 +613,9 @@ - (FSTBound *)boundFromFieldValues:(NSArray<id> *)fieldValues isBefore:(BOOL)isB
@"Invalid query. Document ID '%@' contains a slash.", documentID);
}
const DocumentKey key{self.query.path.Append([documentID UTF8String])};
[components addObject:[FSTReferenceValue referenceValue:key
databaseID:self.firestore.databaseID]];
[components
addObject:[FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:key]
databaseID:self.firestore.databaseID]];
} else {
FSTFieldValue *fieldValue = [self.firestore.dataConverter parsedQueryValue:rawValue];
[components addObject:fieldValue];
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Source/API/FSTUserDataConverter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ - (nullable FSTFieldValue *)parseScalarValue:(nullable id)input context:(ParseCo
self.databaseID->project_id().c_str(), self.databaseID->database_id().c_str(),
context.FieldDescription().c_str());
}
return [FSTReferenceValue referenceValue:reference.key databaseID:self.databaseID];
return [FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:reference.key]
databaseID:self.databaseID];

} else {
FSTThrowInvalidArgument(@"Unsupported type: %@%s", NSStringFromClass([input class]),
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Source/Core/FSTView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (BOOL)isEqual:(id)other {

- (NSUInteger)hash {
NSUInteger hash = self.type;
hash = hash * 31u + [self.key hash];
hash = hash * 31u + self.key.Hash();
return hash;
}

Expand Down Expand Up @@ -241,8 +241,8 @@ - (FSTViewDocumentChanges *)computeChangesWithDocuments:(const MaybeDocumentMap
newDoc = (FSTDocument *)maybeNewDoc;
}
if (newDoc) {
HARD_ASSERT(key == newDoc.key, "Mismatching key in document changes: %s != %s", key,
newDoc.key.ToString());
HARD_ASSERT(key == newDoc.key, "Mismatching key in document changes: %s != %s",
key.ToString(), newDoc.key.ToString());
if (![self.query matchesDocument:newDoc]) {
newDoc = nil;
}
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Source/Core/FSTViewSnapshot.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (NSString *)description {
std::string result = absl::StrJoin(
_changeMap, ",",
[](std::string *out, const std::pair<DocumentKey, FSTDocumentViewChange *> &kv) {
out->append(StringFormat("%s: %s", kv.first, kv.second));
out->append(StringFormat("%s: %s", kv.first.ToString(), kv.second));
});
return WrapNSString(std::string{"{"} + result + "}");
}
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Source/Model/FSTDocument.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (BOOL)isEqual:(id)other {
}

- (NSUInteger)hash {
NSUInteger result = [self.key hash];
NSUInteger result = self.key.Hash();
result = result * 31 + self.version.Hash();
result = result * 31 + [self.data hash];
result = result * 31 + _documentState;
Expand Down Expand Up @@ -212,7 +212,7 @@ - (BOOL)isEqual:(id)other {
}

- (NSUInteger)hash {
NSUInteger result = [self.key hash];
NSUInteger result = self.key.Hash();
result = result * 31 + self.version.Hash();
result = result * 31 + (_hasCommittedMutations ? 1 : 0);
return result;
Expand Down Expand Up @@ -250,7 +250,7 @@ - (BOOL)isEqual:(id)other {
}

- (NSUInteger)hash {
NSUInteger result = [self.key hash];
NSUInteger result = self.key.Hash();
result = result * 31 + self.version.Hash();
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Source/Remote/FSTSerializerBeta.mm
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ - (FSTReferenceValue *)decodedReferenceValue:(NSString *)resourceName {
HARD_ASSERT(database_id == *self.databaseID, "Database %s:%s cannot encode reference from %s:%s",
self.databaseID->project_id(), self.databaseID->database_id(),
database_id.project_id(), database_id.database_id());
return [FSTReferenceValue referenceValue:key databaseID:self.databaseID];
return [FSTReferenceValue referenceValue:[FSTDocumentKey keyWithDocumentKey:key]
databaseID:self.databaseID];
}

- (GCFSArrayValue *)encodedArrayValue:(FSTArrayValue *)arrayValue {
Expand Down
2 changes: 2 additions & 0 deletions Firestore/core/src/firebase/firestore/immutable/sorted_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace immutable {
template <typename K, typename V, typename C = util::Comparator<K>>
class SortedMap : public impl::SortedMapBase {
public:
using key_type = K;
using mapped_type = V;
/** The type of the entries stored in the map. */
using value_type = std::pair<K, V>;
using array_type = impl::ArraySortedMap<K, V, C>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Firestore/core/src/firebase/firestore/model/mutation_batch.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
#include "Firestore/core/src/firebase/firestore/util/string_util.h"
#include "Firestore/core/src/firebase/firestore/util/to_string.h"
#include "absl/strings/match.h"

NS_ASSUME_NONNULL_BEGIN
Expand Down
4 changes: 0 additions & 4 deletions Firestore/core/src/firebase/firestore/model/document_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ class DocumentKey {
explicit DocumentKey(ResourcePath&& path);

#if defined(__OBJC__)
operator FSTDocumentKey*() const {
return [FSTDocumentKey keyWithDocumentKey:*this];
}

NSUInteger Hash() const {
return util::Hash(ToString());
}
Expand Down
1 change: 1 addition & 0 deletions Firestore/core/src/firebase/firestore/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ cc_library(
range.h
string_util.cc
string_util.h
to_string.h
type_traits.h
DEPENDS
absl_base
Expand Down
2 changes: 1 addition & 1 deletion Firestore/core/src/firebase/firestore/util/string_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct FormatChoice<5> {};
*
* Chooses a conversion to a text form in this order:
* * If the value is exactly of `bool` type (without implicit conversions)
* the text will the "true" or "false".
* the text will be "true" or "false".
* * If the value is of type `const char*`, the text will be the value
* interpreted as a C string. To show the address of a single char or to
* show the `const char*` as an address, cast to `void*`.
Expand Down
17 changes: 0 additions & 17 deletions Firestore/core/src/firebase/firestore/util/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ std::string PrefixSuccessor(absl::string_view prefix);
*/
std::string ImmediateSuccessor(absl::string_view s);

/**
* Returns a string description of the contents of the given collection.
*/
template <typename Container>
std::string ToString(const Container& container) {
std::string result;
result.append("[");
const char* sep = "";
for (auto&& item : container) {
result.append(sep);
result.append(item);
sep = ", ";
}
result.append("]");
return result;
}

} // namespace util
} // namespace firestore
} // namespace firebase
Expand Down
Loading