1 // Copyright 2019 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
15 #include "pw_preprocessor/util.h"
19 #include "pw_unit_test/framework.h"
24 TEST(Macros, ArraySize) {
25 uint32_t hello_there[123];
26 static_assert(PW_ARRAY_SIZE(hello_there) == 123);
29 static_assert(PW_ARRAY_SIZE(characters) == 500);
30 static_assert(PW_ARRAY_SIZE("2345") == 5);
38 static_assert(PW_ARRAY_SIZE(objects) == 9);
39 static_assert(PW_ARRAY_SIZE(Object::array) == 7);
40 static_assert(PW_ARRAY_SIZE(objects[1].array) == 7);
43 TEST(Macros, UnusedVariable) {
44 int this_is_not_used = 12;
45 PW_UNUSED(this_is_not_used);
47 volatile void* volatile wow;
53 #define WORLD WORLD_IMPL()
54 #define WORLD_IMPL() WORLD !
56 TEST(Macros, Stringify) {
57 EXPECT_STREQ("", PW_STRINGIFY());
58 EXPECT_STREQ("> _ <", PW_STRINGIFY(> _ <));
59 EXPECT_STREQ("hello WORLD !", PW_STRINGIFY(HELLO WORLD));
60 EXPECT_STREQ("hello, WORLD !", PW_STRINGIFY(HELLO, WORLD));
61 EXPECT_STREQ("a, b, c, hello, WORLD ! 2",
62 PW_STRINGIFY(a, b, c, HELLO, WORLD 2));