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

Side by Side Diff: mojo/public/cpp/bindings/tests/array_unittest.cc

Issue 611633002: mojom: Add associative arrays to the mojom language. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved test classes to their own shared file. Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/bindings/array.h" 5 #include "mojo/public/cpp/bindings/array.h"
6 #include "mojo/public/cpp/bindings/lib/array_internal.h" 6 #include "mojo/public/cpp/bindings/lib/array_internal.h"
7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
9 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
9 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" 11 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 namespace test { 15 namespace test {
15 namespace { 16 namespace {
16 17
17 using mojo::internal::Array_Data; 18 using mojo::internal::Array_Data;
18 using mojo::internal::ArrayValidateParams; 19 using mojo::internal::ArrayValidateParams;
19 using mojo::internal::FixedBuffer; 20 using mojo::internal::FixedBuffer;
20 using mojo::internal::NoValidateParams; 21 using mojo::internal::NoValidateParams;
21 using mojo::internal::String_Data; 22 using mojo::internal::String_Data;
22 23
23 class CopyableType {
24 public:
25 CopyableType() : copied_(false), ptr_(this) { num_instances_++; }
26 CopyableType(const CopyableType& other) : copied_(true), ptr_(other.ptr()) {
27 num_instances_++;
28 }
29 CopyableType& operator=(const CopyableType& other) {
30 copied_ = true;
31 ptr_ = other.ptr();
32 return *this;
33 }
34 ~CopyableType() { num_instances_--; }
35
36 bool copied() const { return copied_; }
37 static size_t num_instances() { return num_instances_; }
38 CopyableType* ptr() const { return ptr_; }
39 void ResetCopied() { copied_ = false; }
40
41 private:
42 bool copied_;
43 static size_t num_instances_;
44 CopyableType* ptr_;
45 };
46
47 size_t CopyableType::num_instances_ = 0;
48
49 class MoveOnlyType {
50 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(MoveOnlyType, RValue)
51 public:
52 typedef MoveOnlyType Data_;
53 MoveOnlyType() : moved_(false), ptr_(this) { num_instances_++; }
54 MoveOnlyType(RValue other) : moved_(true), ptr_(other.object->ptr()) {
55 num_instances_++;
56 }
57 MoveOnlyType& operator=(RValue other) {
58 moved_ = true;
59 ptr_ = other.object->ptr();
60 return *this;
61 }
62 ~MoveOnlyType() { num_instances_--; }
63
64 bool moved() const { return moved_; }
65 static size_t num_instances() { return num_instances_; }
66 MoveOnlyType* ptr() const { return ptr_; }
67 void ResetMoved() { moved_ = false; }
68
69 private:
70 bool moved_;
71 static size_t num_instances_;
72 MoveOnlyType* ptr_;
73 };
74
75 size_t MoveOnlyType::num_instances_ = 0;
76
77 class ArrayTest : public testing::Test { 24 class ArrayTest : public testing::Test {
78 public: 25 public:
79 virtual ~ArrayTest() {} 26 virtual ~ArrayTest() {}
80 27
81 private: 28 private:
82 Environment env_; 29 Environment env_;
83 }; 30 };
84 31
85 // Tests that basic Array operations work. 32 // Tests that basic Array operations work.
86 TEST_F(ArrayTest, Basic) { 33 TEST_F(ArrayTest, Basic) {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 EXPECT_TRUE(array[i].moved()); 426 EXPECT_TRUE(array[i].moved());
480 EXPECT_EQ(value_ptrs[i], array[i].ptr()); 427 EXPECT_EQ(value_ptrs[i], array[i].ptr());
481 } 428 }
482 array.reset(); 429 array.reset();
483 EXPECT_EQ(0u, MoveOnlyType::num_instances()); 430 EXPECT_EQ(0u, MoveOnlyType::num_instances());
484 } 431 }
485 432
486 } // namespace 433 } // namespace
487 } // namespace test 434 } // namespace test
488 } // namespace mojo 435 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/cpp/bindings/tests/container_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698