Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: mojo/public/cpp/bindings/tests/hash_unittest.cc

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Fix merge problem in BUILD.gn file Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/hash_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/hash_unittest.cc b/mojo/public/cpp/bindings/tests/hash_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f468196b0014527acb7162f8d9c6d7e4d80bcaee
--- /dev/null
+++ b/mojo/public/cpp/bindings/tests/hash_unittest.cc
@@ -0,0 +1,41 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/bindings/lib/hash_util.h"
+
+#include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace test {
+namespace {
+
+using HashTest = testing::Test;
+
+static ContainsOtherPtr MakeContainsOther(uint64_t other) {
+ ContainsOtherPtr ptr = ContainsOther::New();
+ ptr->other = other;
+ return ptr;
+}
+
+static SimpleNestedStructPtr MakeSimpleNestedStruct(ContainsOtherPtr nested) {
+ SimpleNestedStructPtr ptr = SimpleNestedStruct::New();
+ ptr->nested = std::move(nested);
+ return ptr;
+}
+
+TEST_F(HashTest, NestedStruct) {
+ ASSERT_EQ(2007u, ::mojo::internal::Hash(
+ ::mojo::internal::kHashSeed,
+ MakeSimpleNestedStruct(MakeContainsOther(1))));
+}
+
+TEST_F(HashTest, UnmappedNativeStruct) {
+ ASSERT_EQ(31u, ::mojo::internal::Hash(::mojo::internal::kHashSeed,
+ UnmappedNativeStruct::New()));
+}
+
+} // namespace
+} // namespace test
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698