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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
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
7 // warnings if warnings are treated as errors).
8 // TODO(vtl): Fix no-compile tests (which are all disabled; crbug.com/105388)
9 // and write some "negative" tests.
10
11 #include <mojo/macros.h>
12
13 #include <assert.h>
14 #include <stdint.h>
15 #include <stdlib.h>
16
17 #include "gtest/gtest.h"
18
19 namespace mojo {
20 namespace {
21
22 TEST(MacrosTest, AllowUnused) {
23 // Test that no warning/error is issued even though |x| is unused.
24 int x = 123;
25 MOJO_ALLOW_UNUSED_LOCAL(x);
26 }
27
28 int MustUseReturnedResult() MOJO_WARN_UNUSED_RESULT;
29 int MustUseReturnedResult() {
30 return 456;
31 }
32
33 TEST(MacrosTest, WarnUnusedResult) {
34 if (!MustUseReturnedResult())
35 abort();
36 }
37
38 // First test |MOJO_STATIC_ASSERT()| in a global scope.
39 MOJO_STATIC_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t),
40 "Bad static_assert() failure in global scope");
41
42 TEST(MacrosTest, CompileAssert) {
43 // Then in a local scope.
44 MOJO_STATIC_ASSERT(sizeof(int32_t) == 2 * sizeof(int16_t),
45 "Bad static_assert() failure");
46 }
47
48 TEST(MacrosTest, Alignof) {
49 // Strictly speaking, this isn't a portable test, but I think it'll pass on
50 // all the platforms we currently support.
51 EXPECT_EQ(1u, MOJO_ALIGNOF(char));
52 EXPECT_EQ(4u, MOJO_ALIGNOF(int32_t));
53 EXPECT_EQ(8u, MOJO_ALIGNOF(int64_t));
54 EXPECT_EQ(8u, MOJO_ALIGNOF(double));
55 }
56
57 // These structs are used in the Alignas test. Define them globally to avoid
58 // MSVS warnings/errors.
59 #if defined(_MSC_VER)
60 #pragma warning(push)
61 // Disable the warning "structure was padded due to __declspec(align())".
62 #pragma warning(disable : 4324)
63 #endif
64 struct MOJO_ALIGNAS(1) StructAlignas1 {
65 char x;
66 };
67 struct MOJO_ALIGNAS(4) StructAlignas4 {
68 char x;
69 };
70 struct MOJO_ALIGNAS(8) StructAlignas8 {
71 char x;
72 };
73 #if defined(_MSC_VER)
74 #pragma warning(pop)
75 #endif
76
77 TEST(MacrosTest, Alignas) {
78 EXPECT_EQ(1u, MOJO_ALIGNOF(StructAlignas1));
79 EXPECT_EQ(4u, MOJO_ALIGNOF(StructAlignas4));
80 EXPECT_EQ(8u, MOJO_ALIGNOF(StructAlignas8));
81 }
82
83 } // namespace
84 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/c/tests/environment/async_waiter_perftest_helpers.cc ('k') | mojo/public/c/tests/result_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698