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

Side by Side Diff: mojo/public/cpp/system/tests/macros_unittest.cc

Issue 828373008: Allow constructing {Interface,Struct}Ptr from nullptr (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 // This file tests the C++ Mojo system macros and consists of "positive" tests, 5 // This file tests the C++ Mojo system macros and consists of "positive" tests,
6 // i.e., those verifying that things work (without compile errors, or even 6 // i.e., those verifying that things work (without compile errors, or even
7 // warnings if warnings are treated as errors). 7 // warnings if warnings are treated as errors).
8 // TODO(vtl): Maybe rename "MacrosCppTest" -> "MacrosTest" if/when this gets 8 // TODO(vtl): Maybe rename "MacrosCppTest" -> "MacrosTest" if/when this gets
9 // compiled into a different binary from the C API tests. 9 // compiled into a different binary from the C API tests.
10 // TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388) 10 // TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 double local_array[4] = {6.7, 7.8, 8.9, 9.0}; 69 double local_array[4] = {6.7, 7.8, 8.9, 9.0};
70 // MSVS considers this local variable unused since MOJO_ARRAYSIZE only takes 70 // MSVS considers this local variable unused since MOJO_ARRAYSIZE only takes
71 // the size of the type of the local and not the values itself. 71 // the size of the type of the local and not the values itself.
72 MOJO_ALLOW_UNUSED_LOCAL(local_array); 72 MOJO_ALLOW_UNUSED_LOCAL(local_array);
73 EXPECT_EQ(4u, MOJO_ARRAYSIZE(local_array)); 73 EXPECT_EQ(4u, MOJO_ARRAYSIZE(local_array));
74 } 74 }
75 75
76 // Note: MSVS is very strict (and arguably buggy) about warnings for classes 76 // Note: MSVS is very strict (and arguably buggy) about warnings for classes
77 // defined in a local scope, so define these globally. 77 // defined in a local scope, so define these globally.
78 class MoveOnlyInt { 78 class MoveOnlyInt {
79 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(MoveOnlyInt, RValue) 79 MOJO_MOVE_ONLY_TYPE(MoveOnlyInt)
80 80
81 public: 81 public:
82 MoveOnlyInt() : is_set_(false), value_() {} 82 MoveOnlyInt() : is_set_(false), value_() {}
83 explicit MoveOnlyInt(int value) : is_set_(true), value_(value) {} 83 explicit MoveOnlyInt(int value) : is_set_(true), value_(value) {}
84 ~MoveOnlyInt() {} 84 ~MoveOnlyInt() {}
85 85
86 // Move-only constructor and operator=. 86 // Move-only constructor and operator=.
87 MoveOnlyInt(RValue other) { *this = other; } 87 MoveOnlyInt(MoveOnlyInt&& other) { *this = other.Pass(); }
88 MoveOnlyInt& operator=(RValue other) { 88 MoveOnlyInt& operator=(MoveOnlyInt&& other) {
89 if (other.object != this) { 89 if (&other != this) {
90 is_set_ = other.object->is_set_; 90 is_set_ = other.is_set_;
91 value_ = other.object->value_; 91 value_ = other.value_;
92 other.object->is_set_ = false; 92 other.is_set_ = false;
93 } 93 }
94 return *this; 94 return *this;
95 } 95 }
96 96
97 int value() const { 97 int value() const {
98 assert(is_set()); 98 assert(is_set());
99 return value_; 99 return value_;
100 } 100 }
101 bool is_set() const { return is_set_; } 101 bool is_set() const { return is_set_; }
102 102
(...skipping 16 matching lines...) Expand all
119 EXPECT_FALSE(y.is_set()); 119 EXPECT_FALSE(y.is_set());
120 EXPECT_TRUE(z.is_set()); 120 EXPECT_TRUE(z.is_set());
121 EXPECT_EQ(123, z.value()); 121 EXPECT_EQ(123, z.value());
122 z = z.Pass(); 122 z = z.Pass();
123 EXPECT_TRUE(z.is_set()); 123 EXPECT_TRUE(z.is_set());
124 EXPECT_EQ(123, z.value()); 124 EXPECT_EQ(123, z.value());
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 } // namespace mojo 128 } // namespace mojo
OLDNEW
« mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc ('K') | « mojo/public/cpp/system/macros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698