blob: 073b4cee7403e51a026387a638b07d6ac15c63a1 [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;
Michael Spangce7b9452020-06-11 21:43:00 -040034 uint64_t array[7];
Alexei Frolovc10c8122019-11-01 16:31:19 -070035 };
Michael Spangce7b9452020-06-11 21:43:00 -040036 Object objects[9];
Alexei Frolovc10c8122019-11-01 16:31:19 -070037
Michael Spangce7b9452020-06-11 21:43:00 -040038 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);
Alexei Frolovc10c8122019-11-01 16:31:19 -070041}
42
Alexei Frolovc10c8122019-11-01 16:31:19 -070043#define HELLO hello
44#define WORLD WORLD_IMPL()
45#define WORLD_IMPL() WORLD !
46
47TEST(Macros, Stringify) {
48 EXPECT_STREQ("", PW_STRINGIFY());
49 EXPECT_STREQ("> _ <", PW_STRINGIFY(> _ <));
50 EXPECT_STREQ("hello WORLD !", PW_STRINGIFY(HELLO WORLD));
51 EXPECT_STREQ("hello, WORLD !", PW_STRINGIFY(HELLO, WORLD));
52 EXPECT_STREQ("a, b, c, hello, WORLD ! 2",
53 PW_STRINGIFY(a, b, c, HELLO, WORLD 2));
54}
55
56} // namespace
57} // namespace pw