• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "mojo/public/cpp/bindings/wtf_array.h"
6 
7 #include "mojo/public/cpp/bindings/lib/serialization.h"
8 #include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
9 #include "mojo/public/cpp/bindings/tests/array_common_test.h"
10 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace mojo {
14 namespace test {
15 namespace {
16 
17 using WTFArrayTest = testing::Test;
18 
ARRAY_COMMON_TEST(WTFArray,NullAndEmpty)19 ARRAY_COMMON_TEST(WTFArray, NullAndEmpty)
20 ARRAY_COMMON_TEST(WTFArray, Basic)
21 ARRAY_COMMON_TEST(WTFArray, Bool)
22 ARRAY_COMMON_TEST(WTFArray, Handle)
23 ARRAY_COMMON_TEST(WTFArray, HandlesAreClosed)
24 ARRAY_COMMON_TEST(WTFArray, Clone)
25 ARRAY_COMMON_TEST(WTFArray, Serialization_ArrayOfPOD)
26 ARRAY_COMMON_TEST(WTFArray, Serialization_EmptyArrayOfPOD)
27 ARRAY_COMMON_TEST(WTFArray, Serialization_ArrayOfArrayOfPOD)
28 ARRAY_COMMON_TEST(WTFArray, Serialization_ArrayOfBool)
29 ARRAY_COMMON_TEST(WTFArray, Serialization_ArrayOfString)
30 ARRAY_COMMON_TEST(WTFArray, Resize_Copyable)
31 ARRAY_COMMON_TEST(WTFArray, Resize_MoveOnly)
32 
33 TEST_F(WTFArrayTest, MoveFromAndToWTFVector_Copyable) {
34   WTF::Vector<CopyableType> vec1(1);
35   WTFArray<CopyableType> arr(std::move(vec1));
36   ASSERT_EQ(1u, arr.size());
37   ASSERT_FALSE(arr[0].copied());
38 
39   WTF::Vector<CopyableType> vec2(arr.PassStorage());
40   ASSERT_EQ(1u, vec2.size());
41   ASSERT_FALSE(vec2[0].copied());
42 
43   ASSERT_EQ(0u, arr.size());
44   ASSERT_TRUE(arr.is_null());
45 }
46 
TEST_F(WTFArrayTest,MoveFromAndToWTFVector_MoveOnly)47 TEST_F(WTFArrayTest, MoveFromAndToWTFVector_MoveOnly) {
48   WTF::Vector<MoveOnlyType> vec1(1);
49   WTFArray<MoveOnlyType> arr(std::move(vec1));
50 
51   ASSERT_EQ(1u, arr.size());
52 
53   WTF::Vector<MoveOnlyType> vec2(arr.PassStorage());
54   ASSERT_EQ(1u, vec2.size());
55 
56   ASSERT_EQ(0u, arr.size());
57   ASSERT_TRUE(arr.is_null());
58 }
59 
60 }  // namespace
61 }  // namespace test
62 }  // namespace mojo
63