aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/test
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-06-01 13:42:47 -0700
committerGravatar GitHub <noreply@github.com>2018-06-01 13:42:47 -0700
commitbb546e19885ae084823e0315e93564a44c0a8257 (patch)
treed755ae6087bae52da506fd7f9c5570d182ee85d5 /Firestore/core/test
parent8b703e3b04f9b3784a93fe3fa579a1d8f07e981e (diff)
Fix Firestore compilation under Xcode < 9.2 (#1367)
* Don't rely on specialization failure to determine when std::hash is unavailable. Instead manually declare the conditions under which std::hash should be defined. * Fix detection of Objective-C classes in Xcode < 9.2 std::is_base_of<NSObject, NSString>{} is false there so the overloads defined for Objective-C types weren't getting enabled. * Add explicit tests for StringFormat using Objective-C objects * Add explicit tests for HasStdHash
Diffstat (limited to 'Firestore/core/test')
-rw-r--r--Firestore/core/test/firebase/firestore/util/CMakeLists.txt9
-rw-r--r--Firestore/core/test/firebase/firestore/util/hashing_test.cc18
-rw-r--r--Firestore/core/test/firebase/firestore/util/string_format_apple_test.mm60
-rw-r--r--Firestore/core/test/firebase/firestore/util/type_traits_apple_test.mm50
4 files changed, 137 insertions, 0 deletions
diff --git a/Firestore/core/test/firebase/firestore/util/CMakeLists.txt b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt
index bcb1c84..c07a4ea 100644
--- a/Firestore/core/test/firebase/firestore/util/CMakeLists.txt
+++ b/Firestore/core/test/firebase/firestore/util/CMakeLists.txt
@@ -137,3 +137,12 @@ cc_test(
firebase_firestore_util
gmock
)
+
+if(APPLE)
+ target_sources(
+ firebase_firestore_util_test
+ PUBLIC
+ string_format_apple_test.mm
+ type_traits_apple_test.mm
+ )
+endif()
diff --git a/Firestore/core/test/firebase/firestore/util/hashing_test.cc b/Firestore/core/test/firebase/firestore/util/hashing_test.cc
index e5d9ff8..2c5c2f7 100644
--- a/Firestore/core/test/firebase/firestore/util/hashing_test.cc
+++ b/Firestore/core/test/firebase/firestore/util/hashing_test.cc
@@ -16,6 +16,9 @@
#include "Firestore/core/src/firebase/firestore/util/hashing.h"
+#include <map>
+#include <string>
+
#include "absl/strings/string_view.h"
#include "gtest/gtest.h"
@@ -29,6 +32,21 @@ struct HasHashMember {
}
};
+TEST(HashingTest, HasStdHash) {
+ EXPECT_TRUE(impl::has_std_hash<float>::value);
+ EXPECT_TRUE(impl::has_std_hash<double>::value);
+ EXPECT_TRUE(impl::has_std_hash<int>::value);
+ EXPECT_TRUE(impl::has_std_hash<int64_t>::value);
+ EXPECT_TRUE(impl::has_std_hash<std::string>::value);
+ EXPECT_TRUE(impl::has_std_hash<void*>::value);
+ EXPECT_TRUE(impl::has_std_hash<const char*>::value);
+
+ struct Foo {};
+ EXPECT_FALSE(impl::has_std_hash<Foo>::value);
+ EXPECT_FALSE(impl::has_std_hash<absl::string_view>::value);
+ EXPECT_FALSE((impl::has_std_hash<std::map<std::string, std::string>>::value));
+}
+
TEST(HashingTest, Int) {
ASSERT_EQ(std::hash<int>{}(0), Hash(0));
}
diff --git a/Firestore/core/test/firebase/firestore/util/string_format_apple_test.mm b/Firestore/core/test/firebase/firestore/util/string_format_apple_test.mm
new file mode 100644
index 0000000..f0bcd35
--- /dev/null
+++ b/Firestore/core/test/firebase/firestore/util/string_format_apple_test.mm
@@ -0,0 +1,60 @@
+/*
+ * 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/util/string_format.h"
+
+#import <Foundation/NSString.h>
+
+#include "gtest/gtest.h"
+
+@interface FSTDescribable : NSObject
+@end
+
+@implementation FSTDescribable
+
+- (NSString*)description {
+ return @"description";
+}
+
+@end
+
+namespace firebase {
+namespace firestore {
+namespace util {
+
+TEST(StringFormatTest, NSString) {
+ EXPECT_EQ("Hello World", StringFormat("Hello %s", @"World"));
+
+ NSString* hello = [NSString stringWithUTF8String:"Hello"];
+ EXPECT_EQ("Hello World", StringFormat("%s World", hello));
+
+ // NOLINTNEXTLINE false positive on "string"
+ NSMutableString* world = [NSMutableString string];
+ [world appendString:@"World"];
+ EXPECT_EQ("Hello World", StringFormat("Hello %s", world));
+}
+
+TEST(StringFormatTest, FSTDescribable) {
+ FSTDescribable* desc = [[FSTDescribable alloc] init];
+ EXPECT_EQ("Hello description", StringFormat("Hello %s", desc));
+
+ id desc_id = desc;
+ EXPECT_EQ("Hello description", StringFormat("Hello %s", desc_id));
+}
+
+} // namespace util
+} // namespace firestore
+} // namespace firebase
diff --git a/Firestore/core/test/firebase/firestore/util/type_traits_apple_test.mm b/Firestore/core/test/firebase/firestore/util/type_traits_apple_test.mm
new file mode 100644
index 0000000..dfb03bb
--- /dev/null
+++ b/Firestore/core/test/firebase/firestore/util/type_traits_apple_test.mm
@@ -0,0 +1,50 @@
+/*
+ * 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/util/type_traits.h"
+
+#import <Foundation/NSArray.h>
+#import <Foundation/NSObject.h>
+#import <Foundation/NSString.h>
+
+#include "gtest/gtest.h"
+
+namespace firebase {
+namespace firestore {
+namespace util {
+
+TEST(TypeTraitsTest, IsObjectiveCPointer) {
+ static_assert(is_objective_c_pointer<NSObject*>{}, "NSObject");
+ static_assert(is_objective_c_pointer<NSString*>{}, "NSString");
+ static_assert(is_objective_c_pointer<NSArray<NSString*>*>{},
+ "NSArray<NSString*>");
+
+ static_assert(is_objective_c_pointer<id>{}, "id");
+ static_assert(is_objective_c_pointer<id<NSCopying>>{}, "id<NSCopying>");
+
+ static_assert(!is_objective_c_pointer<int*>{}, "int*");
+ static_assert(!is_objective_c_pointer<void*>{}, "void*");
+ static_assert(!is_objective_c_pointer<int>{}, "int");
+ static_assert(!is_objective_c_pointer<void>{}, "void");
+
+ struct Foo {};
+ static_assert(!is_objective_c_pointer<Foo>{}, "Foo");
+ static_assert(!is_objective_c_pointer<Foo*>{}, "Foo");
+}
+
+} // namespace util
+} // namespace firestore
+} // namespace firebase