blob: 50b5cf1d6ee8eaba70da401a6840d018e6861199 [file] [log] [blame]
Alexei Frolovc10c8122019-11-01 16:31:19 -07001// Copyright 2019 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -08004// use this file except in compliance with the License. You may obtain a copy of
5// the License at
Alexei Frolovc10c8122019-11-01 16:31:19 -07006//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
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
Wyatt Hepler1a960942019-11-26 14:13:38 -080012// License for the specific language governing permissions and limitations under
13// the License.
Alexei Frolovc10c8122019-11-01 16:31:19 -070014
15#include "pw_preprocessor/util.h"
16
17#include <cstdint>
18
19#include "pw_unit_test/framework.h"
20
21namespace pw {
22namespace {
23
24TEST(Macros, ArraySize) {
25 uint32_t hello_there[123];
26 static_assert(PW_ARRAY_SIZE(hello_there) == 123);
27
28 char characters[500];
29 static_assert(PW_ARRAY_SIZE(characters) == 500);
30 static_assert(PW_ARRAY_SIZE("2345") == 5);
31
32 struct Object {
33 int a;
34 uint64_t array[2048];
35 };
36 Object objects[404];
37
38 static_assert(PW_ARRAY_SIZE(objects) == 404);
39 static_assert(PW_ARRAY_SIZE(Object::array) == 2048);
40 static_assert(PW_ARRAY_SIZE(objects[1].array) == 2048);
41}
42
43TEST(Macros, UnusedVariable) {
44 int this_is_not_used = 12;
45 PW_UNUSED(this_is_not_used);
46
47 volatile void* volatile wow;
48 wow = nullptr;
49 PW_UNUSED(wow);
50}
51
52#define HELLO hello
53#define WORLD WORLD_IMPL()
54#define WORLD_IMPL() WORLD !
55
56TEST(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));
63}
64
65} // namespace
66} // namespace pw