diff --git a/BUILD.bazel b/BUILD.bazel index 25c091f..15284b7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -46,6 +46,29 @@ cc_library( ], ) +cc_library( + name = "ExtraTestMacros", + hdrs = [ + "include/gz/utils/ExtraTestMacros.hh", + "include/gz/utils/detail/ExtraTestMacros.hh", + ], + includes = ["include"], + visibility = ["//visibility:public"], + deps = [ + ":SuppressWarning", + ], +) + +cc_test( + name = "ExtraTestMacros_TEST", + srcs = ["src/ExtraTestMacros_TEST.cc"], + deps = [ + ":ExtraTestMacros", + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) + cc_library( name = "ImplPtr", hdrs = [ diff --git a/include/gz/utils/ExtraTestMacros.hh b/include/gz/utils/ExtraTestMacros.hh index 45ae3cc..e0ab39e 100644 --- a/include/gz/utils/ExtraTestMacros.hh +++ b/include/gz/utils/ExtraTestMacros.hh @@ -25,8 +25,17 @@ /// as part of the test suite execution. /// The macro uses the Disabled_ prefix provided by googletest. See /// https://chromium.googlesource.com/external/github.com/google/googletest/+/HEAD/googletest/docs/advanced.md +/// TODO(gz-utils4): remove the windows alias #define GZ_UTILS_TEST_ENABLED_ONLY_ON_WINDOWS(TestName) \ - DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WINDOWS(TestName) + DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName) + +/// \brief Restrict the execution of the test to just the Windows platform +/// Other platforms will get the test compiled but it won't be run +/// as part of the test suite execution. +/// The macro uses the Disabled_ prefix provided by googletest. See +/// https://chromium.googlesource.com/external/github.com/google/googletest/+/HEAD/googletest/docs/advanced.md +#define GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName) \ + DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName) /// \brief Restrict the execution of the test for the Windows platform. /// The test will be compiled on Windows too but will never be run as diff --git a/src/ExtraTestMacros_TEST.cc b/src/ExtraTestMacros_TEST.cc new file mode 100644 index 0000000..97d26f3 --- /dev/null +++ b/src/ExtraTestMacros_TEST.cc @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2024 Open Source Robotics Foundation + * + * 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 + * + * http://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 + +#include + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(OnlyWindowsOn)) +{ +#if defined __APPLE__ + ADD_FAILURE() << "Windows only test on Apple platform"; +#elif defined __linux__ + ADD_FAILURE() << "Windows only test on Linux platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_WIN32(OnlyWindowsOff)) +{ +#if defined __WIN32 + ADD_FAILURE() << "Ran on Windows platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_MAC(OnlyMacOn)) +{ +#if defined _WIN32 + ADD_FAILURE() << "Apple only test on Windows platform"; +#elif defined __linux__ + ADD_FAILURE() << "Apple only test on Linux platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_MAC(OnlyMacOff)) +{ +#if defined __APPLE__ + ADD_FAILURE() << "Ran on Apple platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(OnlyLinuxOn)) +{ +#if defined _WIN32 + ADD_FAILURE() << "Linux only test on Windows platform"; +#elif defined __APPLE__ + ADD_FAILURE() << "Linux only test on Apple platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_LINUX(OnlyLinuxOff)) +{ +#if defined __linux__ + ADD_FAILURE() << "Ran on Linux platform"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_ARM32(OnlyArm32On)) +{ +#if defined __aarch64__ || defined _M_ARM64 + ADD_FAILURE() << "Ran on Arm64 arch"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_ARM32(OnlyArm32Off)) +{ +#if defined __arm__ || defined _M_ARM + ADD_FAILURE() << "Ran on Arm32 arch"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_ARM64(OnlyArm64On)) +{ +#if defined __arm__ || defined _M_ARM + ADD_FAILURE() << "Ran on Arm32 arch"; +#endif +} + +GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_ARM64(OnlyArm64Off)) +{ +#if defined __aarch64__ || defined _M_ARM64 + ADD_FAILURE() << "Ran on Arm64 arch"; +#endif +}