diff options
author | Alexei Frolov <frolv@google.com> | 2019-11-01 16:31:19 -0700 |
---|---|---|
committer | Alexei Frolov <frolv@google.com> | 2019-11-04 16:07:34 -0800 |
commit | c10c81201dba4d6533b1270baec0cd24aca752b9 (patch) | |
tree | c56efe2a0bfb9ba2398868a7ec144deea6226d24 /pw_preprocessor/util_test.cc | |
parent | 1a82c146ff11c1b0486d12716082476eabad19dd (diff) | |
download | pigweed-c10c81201dba4d6533b1270baec0cd24aca752b9.tar.gz |
Add preprocessor and unit_test modules
This change adds two Pigweed modules: pw_preprocessor and pw_unit_test.
The preprocessor module contains header files providing helpful macros
for the C preprocessor. The unit test module contains a starter
implementation of a unit testing framework for Pigweed.
Change-Id: I46e1a4cae1fd8ce36d7840a2e92f8013fb489cde
Diffstat (limited to 'pw_preprocessor/util_test.cc')
-rw-r--r-- | pw_preprocessor/util_test.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/pw_preprocessor/util_test.cc b/pw_preprocessor/util_test.cc new file mode 100644 index 000000000..0ce027f53 --- /dev/null +++ b/pw_preprocessor/util_test.cc @@ -0,0 +1,66 @@ +// Copyright 2019 The Pigweed Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. + +#include "pw_preprocessor/util.h" + +#include <cstdint> + +#include "pw_unit_test/framework.h" + +namespace pw { +namespace { + +TEST(Macros, ArraySize) { + uint32_t hello_there[123]; + static_assert(PW_ARRAY_SIZE(hello_there) == 123); + + char characters[500]; + static_assert(PW_ARRAY_SIZE(characters) == 500); + static_assert(PW_ARRAY_SIZE("2345") == 5); + + struct Object { + int a; + uint64_t array[2048]; + }; + Object objects[404]; + + static_assert(PW_ARRAY_SIZE(objects) == 404); + static_assert(PW_ARRAY_SIZE(Object::array) == 2048); + static_assert(PW_ARRAY_SIZE(objects[1].array) == 2048); +} + +TEST(Macros, UnusedVariable) { + int this_is_not_used = 12; + PW_UNUSED(this_is_not_used); + + volatile void* volatile wow; + wow = nullptr; + PW_UNUSED(wow); +} + +#define HELLO hello +#define WORLD WORLD_IMPL() +#define WORLD_IMPL() WORLD ! + +TEST(Macros, Stringify) { + EXPECT_STREQ("", PW_STRINGIFY()); + EXPECT_STREQ("> _ <", PW_STRINGIFY(> _ <)); + EXPECT_STREQ("hello WORLD !", PW_STRINGIFY(HELLO WORLD)); + EXPECT_STREQ("hello, WORLD !", PW_STRINGIFY(HELLO, WORLD)); + EXPECT_STREQ("a, b, c, hello, WORLD ! 2", + PW_STRINGIFY(a, b, c, HELLO, WORLD 2)); +} + +} // namespace +} // namespace pw |