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): Fix no-compile tests (which are all disabled; crbug.com/105388) | 8 // TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388) |
9 // and write some "negative" tests. | 9 // and write some "negative" tests. |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 // First test |MOJO_COMPILE_ASSERT()| in a global scope. | 37 // First test |MOJO_COMPILE_ASSERT()| in a global scope. |
38 MOJO_COMPILE_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), | 38 MOJO_COMPILE_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), |
39 bad_compile_assert_failure_in_global_scope); | 39 bad_compile_assert_failure_in_global_scope); |
40 | 40 |
41 TEST(MacrosTest, CompileAssert) { | 41 TEST(MacrosTest, CompileAssert) { |
42 // Then in a local scope. | 42 // Then in a local scope. |
43 MOJO_COMPILE_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t), | 43 MOJO_COMPILE_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t), |
44 bad_compile_assert_failure); | 44 bad_compile_assert_failure); |
45 } | 45 } |
46 | 46 |
| 47 TEST(MacrosTest, Alignof) { |
| 48 // Strictly speaking, this isn't a portable test, but I think it'll pass on |
| 49 // all the platforms we currently support. |
| 50 EXPECT_EQ(1u, MOJO_ALIGNOF(char)); |
| 51 EXPECT_EQ(4u, MOJO_ALIGNOF(int32_t)); |
| 52 EXPECT_EQ(8u, MOJO_ALIGNOF(int64_t)); |
| 53 EXPECT_EQ(8u, MOJO_ALIGNOF(double)); |
| 54 } |
| 55 |
| 56 // These structs are used in the Alignas test. Define them globally to avoid |
| 57 // MSVS warnings/errors. |
| 58 struct MOJO_ALIGNAS(1) StructAlignas1 { char x; }; |
| 59 struct MOJO_ALIGNAS(4) StructAlignas4 { char x; }; |
| 60 struct MOJO_ALIGNAS(8) StructAlignas8 { char x; }; |
| 61 struct MOJO_ALIGNAS(MOJO_ALIGNOF(int64_t)) StructAlignasInt64 { char x; }; |
| 62 |
| 63 TEST(MacrosTest, Alignas) { |
| 64 EXPECT_EQ(1u, MOJO_ALIGNOF(StructAlignas1)); |
| 65 EXPECT_EQ(4u, MOJO_ALIGNOF(StructAlignas4)); |
| 66 EXPECT_EQ(8u, MOJO_ALIGNOF(StructAlignas8)); |
| 67 EXPECT_EQ(MOJO_ALIGNOF(int64_t), MOJO_ALIGNOF(StructAlignasInt64)); |
| 68 } |
| 69 |
47 } // namespace | 70 } // namespace |
48 } // namespace mojo | 71 } // namespace mojo |
OLD | NEW |