1 // Copyright 2018 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 #include "base/component_export.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace base {
9 namespace {
10
11 using ComponentExportTest = testing::Test;
12
13 #define IS_TEST_COMPONENT_A_IMPL 1
14 #define IS_TEST_COMPONENT_B_IMPL
15 #define IS_TEST_COMPONENT_C_IMPL 0
16 #define IS_TEST_COMPONENT_D_IMPL 2
17 #define IS_TEST_COMPONENT_E_IMPL xyz
18
TEST(ComponentExportTest,ImportExport)19 TEST(ComponentExportTest, ImportExport) {
20 // Defined as 1. Treat as export.
21 EXPECT_EQ(1, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_A));
22
23 // Defined, but empty. Treat as import.
24 EXPECT_EQ(0, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_B));
25
26 // Defined, but 0. Treat as import.
27 EXPECT_EQ(0, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_C));
28
29 // Defined, but some other arbitrary thing that isn't 1. Treat as import.
30 EXPECT_EQ(0, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_D));
31 EXPECT_EQ(0, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_E));
32
33 // Undefined. Treat as import.
34 EXPECT_EQ(0, INSIDE_COMPONENT_IMPL(TEST_COMPONENT_F));
35
36 // And just for good measure, ensure that the macros evaluate properly in the
37 // context of preprocessor #if blocks.
38 #if INSIDE_COMPONENT_IMPL(TEST_COMPONENT_A)
39 EXPECT_TRUE(true);
40 #else
41 EXPECT_TRUE(false);
42 #endif
43
44 #if !INSIDE_COMPONENT_IMPL(TEST_COMPONENT_B)
45 EXPECT_TRUE(true);
46 #else
47 EXPECT_TRUE(false);
48 #endif
49
50 #if !INSIDE_COMPONENT_IMPL(TEST_COMPONENT_C)
51 EXPECT_TRUE(true);
52 #else
53 EXPECT_TRUE(false);
54 #endif
55
56 #if !INSIDE_COMPONENT_IMPL(TEST_COMPONENT_D)
57 EXPECT_TRUE(true);
58 #else
59 EXPECT_TRUE(false);
60 #endif
61
62 #if !INSIDE_COMPONENT_IMPL(TEST_COMPONENT_E)
63 EXPECT_TRUE(true);
64 #else
65 EXPECT_TRUE(false);
66 #endif
67
68 #if !INSIDE_COMPONENT_IMPL(TEST_COMPONENT_F)
69 EXPECT_TRUE(true);
70 #else
71 EXPECT_TRUE(false);
72 #endif
73 }
74
75 #undef IS_TEST_COMPONENT_A_IMPL
76 #undef IS_TEST_COMPONENT_B_IMPL
77 #undef IS_TEST_COMPONENT_C_IMPL
78 #undef IS_TEST_COMPONENT_D_IMPL
79 #undef IS_TEST_COMPONENT_E_IMPL
80
81 } // namespace
82 } // namespace base
83