OLD | NEW |
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) |
11 // and write some "negative" tests. | 11 // and write some "negative" tests. |
12 | 12 |
13 #include "mojo/public/cpp/system/macros.h" | 13 #include "mojo/public/cpp/system/macros.h" |
14 | 14 |
15 #include <assert.h> | 15 #include <assert.h> |
16 #include <stdint.h> | 16 #include <stdint.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 | 18 |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 | |
23 // The test for |MOJO_STATIC_CONST_MEMBER_DEFINITION| is really a compile/link | |
24 // test. To test it fully would really require a header file and multiple .cc | |
25 // files, but we'll just cursorily verify it. | |
26 // | |
27 // This is defined outside of an anonymous namespace because | |
28 // MOJO_STATIC_CONST_MEMBER_DEFINITION may not be used on internal symbols. | |
29 struct StructWithStaticConstMember { | |
30 static const int kStaticConstMember = 123; | |
31 }; | |
32 MOJO_STATIC_CONST_MEMBER_DEFINITION | |
33 const int StructWithStaticConstMember::kStaticConstMember; | |
34 | |
35 namespace { | 22 namespace { |
36 | 23 |
37 // Note: MSVS is very strict (and arguably buggy) about warnings for classes | 24 // Note: MSVS is very strict (and arguably buggy) about warnings for classes |
38 // defined in a local scope, so define these globally. | 25 // defined in a local scope, so define these globally. |
39 struct TestOverrideBaseClass { | 26 struct TestOverrideBaseClass { |
40 virtual ~TestOverrideBaseClass() {} | 27 virtual ~TestOverrideBaseClass() {} |
41 virtual void ToBeOverridden() {} | 28 virtual void ToBeOverridden() {} |
42 virtual void AlsoToBeOverridden() = 0; | 29 virtual void AlsoToBeOverridden() = 0; |
43 }; | 30 }; |
44 | 31 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_EQ(123, y.value()); | 120 EXPECT_EQ(123, y.value()); |
134 MoveOnlyInt z(y.Pass()); | 121 MoveOnlyInt z(y.Pass()); |
135 EXPECT_FALSE(y.is_set()); | 122 EXPECT_FALSE(y.is_set()); |
136 EXPECT_TRUE(z.is_set()); | 123 EXPECT_TRUE(z.is_set()); |
137 EXPECT_EQ(123, z.value()); | 124 EXPECT_EQ(123, z.value()); |
138 z = z.Pass(); | 125 z = z.Pass(); |
139 EXPECT_TRUE(z.is_set()); | 126 EXPECT_TRUE(z.is_set()); |
140 EXPECT_EQ(123, z.value()); | 127 EXPECT_EQ(123, z.value()); |
141 } | 128 } |
142 | 129 |
143 // Use it, to make sure things get linked in and to avoid any warnings about | |
144 // unused things. | |
145 TEST(MacrosCppTest, StaticConstMemberDefinition) { | |
146 EXPECT_EQ(123, StructWithStaticConstMember::kStaticConstMember); | |
147 } | |
148 | |
149 // The test for |ignore_result()| is also just a compilation test. (Note that | 130 // The test for |ignore_result()| is also just a compilation test. (Note that |
150 // |MOJO_WARN_UNUSED_RESULT| can only be used in the prototype. | 131 // |MOJO_WARN_UNUSED_RESULT| can only be used in the prototype. |
151 int ReturnsIntYouMustUse() MOJO_WARN_UNUSED_RESULT; | 132 int ReturnsIntYouMustUse() MOJO_WARN_UNUSED_RESULT; |
152 | 133 |
153 int ReturnsIntYouMustUse() { | 134 int ReturnsIntYouMustUse() { |
154 return 123; | 135 return 123; |
155 } | 136 } |
156 | 137 |
157 TEST(MacrosCppTest, IgnoreResult) { | 138 TEST(MacrosCppTest, IgnoreResult) { |
158 ignore_result(ReturnsIntYouMustUse()); | 139 ignore_result(ReturnsIntYouMustUse()); |
159 } | 140 } |
160 | 141 |
161 } // namespace | 142 } // namespace |
162 } // namespace mojo | 143 } // namespace mojo |
OLD | NEW |