diff options
author | Gil <mcg@google.com> | 2018-07-11 15:27:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 15:27:50 -0700 |
commit | e1ace703fbf4458d9e887ebf30050b1a0482a2d2 (patch) | |
tree | 63537e388b8d16a5625eedce0937cb50bf69d4c7 /Firestore/core/test/firebase | |
parent | 79f663d5eaaa4b7f9fe46d176c82660d38e4be8a (diff) |
Fix Firestore source errors under VS2017 (#1515)
* Project file updates from sync_project.rb
* Fix misc compile errors under VS2017
* Fix util/hashing under VS2017
std::hash<int> is not just a pass through in Microsoft's STL.
* Disable unsafe code warnings in VS2017
... where comparing against a reference implementation that has no easy
safe equivalent.
* Handle drive letters in paths on Windows
Diffstat (limited to 'Firestore/core/test/firebase')
3 files changed, 50 insertions, 16 deletions
diff --git a/Firestore/core/test/firebase/firestore/immutable/sorted_map_test.cc b/Firestore/core/test/firebase/firestore/immutable/sorted_map_test.cc index 75353d9..acd0642 100644 --- a/Firestore/core/test/firebase/firestore/immutable/sorted_map_test.cc +++ b/Firestore/core/test/firebase/firestore/immutable/sorted_map_test.cc @@ -14,6 +14,13 @@ * limitations under the License. */ +// Disable warnings in the MSVC standard library about the use of std::mismatch. +// There's no guaranteed safe way to use it in C++11 but the test verifies that +// our implementation matches the standard so we need to call it. +#if defined(_MSC_VER) +#define _SCL_SECURE_NO_WARNINGS 1 +#endif + #include "Firestore/core/src/firebase/firestore/immutable/sorted_map.h" #include <numeric> diff --git a/Firestore/core/test/firebase/firestore/util/hashing_test.cc b/Firestore/core/test/firebase/firestore/util/hashing_test.cc index 2c5c2f7..d762bbe 100644 --- a/Firestore/core/test/firebase/firestore/util/hashing_test.cc +++ b/Firestore/core/test/firebase/firestore/util/hashing_test.cc @@ -28,7 +28,7 @@ namespace util { struct HasHashMember { size_t Hash() const { - return 42; + return 42u; } }; @@ -66,22 +66,23 @@ TEST(HashingTest, StringView) { // that, but that requires an explicit specialization. Since we're only // defining this for compatibility with Objective-C and not really sensitive // to performance or hash quality here, this is good enough. - size_t expected = 'a'; - expected = 31u * expected + 1; + size_t expected = std::hash<unsigned char>{}('a'); + expected = 31u * expected + std::hash<size_t>{}(1); ASSERT_EQ(expected, Hash(absl::string_view{"a"})); } TEST(HashingTest, SizeT) { - ASSERT_EQ(42u, Hash(size_t{42u})); + size_t expected = std::hash<size_t>{}(42u); + ASSERT_EQ(expected, Hash(size_t{42u})); } TEST(HashingTest, Array) { int values[] = {0, 1, 2}; - size_t expected = 0; - expected = 31 * expected + 1; - expected = 31 * expected + 2; - expected = 31 * expected + 3; // length of array + size_t expected = std::hash<int>{}(0); + expected = 31u * expected + std::hash<int>{}(1); + expected = 31u * expected + std::hash<int>{}(2); + expected = 31u * expected + std::hash<size_t>{}(3); // length of array ASSERT_EQ(expected, Hash(values)); } @@ -91,7 +92,10 @@ TEST(HashingTest, HasHashMember) { TEST(HashingTest, RangeOfStdHashable) { std::vector<int> values{42}; - ASSERT_EQ(31u * 42u + 1, Hash(values)); + + size_t expected = std::hash<int>{}(42); + expected = 31u * expected + std::hash<size_t>{}(1); // length of array + ASSERT_EQ(expected, Hash(values)); std::vector<int> values_leading_zero{0, 42}; std::vector<int> values_trailing_zero{42, 0}; @@ -103,18 +107,30 @@ TEST(HashingTest, RangeOfStdHashable) { TEST(HashingTest, RangeOfHashMember) { std::vector<HasHashMember> values{HasHashMember{}}; - ASSERT_EQ(31u * 42u + 1, Hash(values)); + + // We trust the underlying Hash() member to do its thing, so unlike the other + // examples, the 42u here is not run through std::hash<size_t>{}(). + size_t expected = 42u; + expected = 31u * expected + std::hash<size_t>{}(1); // length of array + ASSERT_EQ(expected, Hash(values)); } TEST(HashingTest, Composite) { // Verify the result ends up as if hand-rolled - EXPECT_EQ(1u, Hash(1)); - EXPECT_EQ(31u, Hash(1, 0)); - EXPECT_EQ(31u * 31u, Hash(1, 0, 0)); + EXPECT_EQ(std::hash<int>{}(1), Hash(1)); + + size_t expected = std::hash<int>{}(1); + expected = 31 * expected + std::hash<int>{}(0); + EXPECT_EQ(expected, Hash(1, 0)); + + expected = std::hash<int>{}(1); + expected = 31 * expected + std::hash<int>{}(0); + expected = 31 * expected + std::hash<int>{}(0); + EXPECT_EQ(expected, Hash(1, 0, 0)); - size_t expected = Hash(1); - expected = 31 * expected + Hash(2); - expected = 31 * expected + Hash(3); + expected = Hash(1); + expected = 31u * expected + Hash(2); + expected = 31u * expected + Hash(3); EXPECT_EQ(expected, Hash(1, 2, 3)); } diff --git a/Firestore/core/test/firebase/firestore/util/strerror_test.cc b/Firestore/core/test/firebase/firestore/util/strerror_test.cc index 854cb08..e6e64a4 100644 --- a/Firestore/core/test/firebase/firestore/util/strerror_test.cc +++ b/Firestore/core/test/firebase/firestore/util/strerror_test.cc @@ -23,9 +23,20 @@ namespace firestore { namespace util { TEST(StrErrorTest, ValidErrorCode) { +#if defined(_MSC_VER) +#pragma warning(push) + // strerror is unsafe generally, but it's used here as the simplest possible + // reference implementation. +#pragma warning(disable : 4996) +#endif + errno = EAGAIN; EXPECT_EQ(StrError(EINTR), strerror(EINTR)); EXPECT_EQ(errno, EAGAIN); + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif } TEST(StrErrorTest, InvalidErrorCode) { |