Alexei Frolov | c10c812 | 2019-11-01 16:31:19 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Pigweed Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
Wyatt Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 4 | // use this file except in compliance with the License. You may obtain a copy of |
| 5 | // the License at |
Alexei Frolov | c10c812 | 2019-11-01 16:31:19 -0700 | [diff] [blame] | 6 | // |
| 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 Hepler | 1a96094 | 2019-11-26 14:13:38 -0800 | [diff] [blame] | 12 | // License for the specific language governing permissions and limitations under |
| 13 | // the License. |
Alexei Frolov | c10c812 | 2019-11-01 16:31:19 -0700 | [diff] [blame] | 14 | |
| 15 | #include "pw_preprocessor/util.h" |
| 16 | |
| 17 | #include <cstdint> |
| 18 | |
| 19 | #include "pw_unit_test/framework.h" |
| 20 | |
| 21 | namespace pw { |
| 22 | namespace { |
| 23 | |
| 24 | TEST(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 | |
| 43 | TEST(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 | |
| 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)); |
| 63 | } |
| 64 | |
| 65 | } // namespace |
| 66 | } // namespace pw |