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

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

Issue 295383012: Mojo: Require our public options structs to be aligned like int64_t's. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win 2 Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/c/system/macros.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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): 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
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 #if defined(_MSC_VER)
59 #pragma warning(push)
60 // Disable the warning "structure was padded due to __declspec(align())".
61 #pragma warning(disable:4324)
62 #endif
63 struct MOJO_ALIGNAS(1) StructAlignas1 { char x; };
64 struct MOJO_ALIGNAS(4) StructAlignas4 { char x; };
65 struct MOJO_ALIGNAS(8) StructAlignas8 { char x; };
66 #if defined(_MSC_VER)
67 #pragma warning(pop)
68 #endif
69
70 TEST(MacrosTest, Alignas) {
71 EXPECT_EQ(1u, MOJO_ALIGNOF(StructAlignas1));
72 EXPECT_EQ(4u, MOJO_ALIGNOF(StructAlignas4));
73 EXPECT_EQ(8u, MOJO_ALIGNOF(StructAlignas8));
74 }
75
47 } // namespace 76 } // namespace
48 } // namespace mojo 77 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/c/system/macros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698