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

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

Issue 2034273002: Mojo C++ bindings: introduce mojo::WTFMap for blink bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed the code of adding enum key support to WTF::HashMap; which turned out to be non-trivial; wi… Created 4 years, 6 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/wtf_map_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a70c134ac254f51a80aca51082ee2fe2b49450a5
--- /dev/null
+++ b/mojo/public/cpp/bindings/tests/wtf_map_unittest.cc
@@ -0,0 +1,67 @@
+// 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/wtf_map.h"
+
+#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
+#include "mojo/public/cpp/bindings/tests/container_test_util.h"
+#include "mojo/public/cpp/bindings/tests/map_common_test.h"
+#include "mojo/public/cpp/bindings/wtf_array.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/wtf/text/WTFString.h"
+
+namespace mojo {
+namespace test {
+
+namespace {
+
+using WTFMapTest = testing::Test;
+
+MAP_COMMON_TEST(WTFMap, NullAndEmpty)
+MAP_COMMON_TEST(WTFMap, InsertWorks)
+MAP_COMMON_TEST(WTFMap, TestIndexOperator)
+MAP_COMMON_TEST(WTFMap, TestIndexOperatorAsRValue)
+MAP_COMMON_TEST(WTFMap, TestIndexOperatorMoveOnly)
+MAP_COMMON_TEST(WTFMap, MapArrayClone)
+MAP_COMMON_TEST(WTFMap, ArrayOfMap)
+
+TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_Copyable) {
+ WTF::HashMap<int32_t, CopyableType> map1;
+ map1.add(123, CopyableType());
+ map1.find(123)->value.ResetCopied();
+ ASSERT_FALSE(map1.find(123)->value.copied());
+
+ WTFMap<int32_t, CopyableType> mojo_map(std::move(map1));
+ ASSERT_EQ(1u, mojo_map.size());
+ ASSERT_NE(mojo_map.end(), mojo_map.find(123));
+ ASSERT_FALSE(mojo_map[123].copied());
+
+ WTF::HashMap<int32_t, CopyableType> map2(mojo_map.PassStorage());
+ ASSERT_EQ(1u, map2.size());
+ ASSERT_NE(map2.end(), map2.find(123));
+ ASSERT_FALSE(map2.find(123)->value.copied());
+
+ ASSERT_EQ(0u, mojo_map.size());
+ ASSERT_TRUE(mojo_map.is_null());
+}
+
+TEST_F(WTFMapTest, MoveFromAndToWTFHashMap_MoveOnly) {
+ WTF::HashMap<int32_t, MoveOnlyType> map1;
+ map1.add(123, MoveOnlyType());
+
+ WTFMap<int32_t, MoveOnlyType> mojo_map(std::move(map1));
+ ASSERT_EQ(1u, mojo_map.size());
+ ASSERT_NE(mojo_map.end(), mojo_map.find(123));
+
+ WTF::HashMap<int32_t, MoveOnlyType> map2(mojo_map.PassStorage());
+ ASSERT_EQ(1u, map2.size());
+ ASSERT_NE(map2.end(), map2.find(123));
+
+ ASSERT_EQ(0u, mojo_map.size());
+ ASSERT_TRUE(mojo_map.is_null());
+}
+
+} // namespace
+} // namespace test
+} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/tests/map_unittest.cc ('k') | mojo/public/cpp/bindings/tests/wtf_types_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698