diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..aa3447b4d --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,131 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) +load( + "@gz//bazel/lint:lint.bzl", + "add_lint_tests", +) + +package( + default_visibility = GZ_VISIBILITY, + features = GZ_FEATURES, +) + +licenses(["notice"]) # Apache-2.0 + +exports_files(["LICENSE"]) + +gz_configure_header( + name = "transport_config_hh", + src = "include/gz/transport/config.hh.in", + cmakelists = ["CMakeLists.txt"], + package = "transport", +) + +gz_export_header( + name = "include/gz/transport/Export.hh", + export_base = "GZ_TRANSPORT", + lib_name = "gz-transport", + visibility = ["//visibility:private"], +) + +public_headers_no_gen = glob([ + "include/gz/transport/*.h", + "include/gz/transport/*.hh", + "include/gz/transport/detail/*.hh", +]) + +private_headers = glob(["src/*.hh"]) + +sources = glob( + ["src/*.cc"], + exclude = [ + "src/*_TEST.cc", + ], +) + +gz_include_header( + name = "transport_hh_genrule", + out = "include/gz/transport.hh", + hdrs = public_headers_no_gen + [ + "include/gz/transport/config.hh", + "include/gz/transport/Export.hh", + ], +) + +public_headers = public_headers_no_gen + [ + "include/gz/transport/config.hh", + "include/gz/transport/Export.hh", + "include/gz/transport.hh", +] + +cc_library( + name = "transport", + srcs = sources + private_headers, + hdrs = public_headers, + copts = [ + "-Wno-deprecated-declarations", + ], + includes = ["include"], + deps = [ + GZ_ROOT + "msgs", + "@uuid", + "@zmq", + ], +) + +cc_binary( + name = "topic", + srcs = [ + "src/cmd/gz.cc", + "src/cmd/gz.hh", + "src/cmd/topic_main.cc", + ], + includes = ["src/cmd"], + deps = [ + ":transport", + GZ_ROOT + "utils/cli", + ], +) + +cc_binary( + name = "service", + srcs = [ + "src/cmd/gz.cc", + "src/cmd/gz.hh", + "src/cmd/service_main.cc", + ], + includes = ["src/cmd"], + deps = [ + ":transport", + GZ_ROOT + "utils/cli", + ], +) + +test_sources = glob( + include = ["src/*_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [src], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "transport", + }, + deps = [ + ":transport", + GZ_ROOT + "common/testing", + GZ_ROOT + "transport/test:utils", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in test_sources] + +add_lint_tests() diff --git a/log/BUILD.bazel b/log/BUILD.bazel new file mode 100644 index 000000000..2dd8b6109 --- /dev/null +++ b/log/BUILD.bazel @@ -0,0 +1,91 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "cmake_configure_file", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) +load( + "@gz//bazel/lint:lint.bzl", + "add_lint_tests", +) + +cmake_configure_file( + name = "build_config", + src = "src/build_config.hh.in", + out = "include/build_config.hh", + cmakelists = ["src/CMakeLists.txt"], + defines = [ + "SCHEMA_INSTALL_PATH=transport/log/sql", + ], +) + +gz_export_header( + name = "include/gz/transport/log/Export.hh", + export_base = "GZ_TRANSPORT_LOG", + lib_name = "gz-transport-log", + visibility = ["//visibility:private"], +) + +public_headers_no_gen = glob([ + "include/gz/transport/log/*.hh", + "include/gz/transport/log/detail/*.hh", +]) + +private_headers = glob(["src/*.hh"]) + +sources = glob( + ["src/*.cc"], + exclude = [ + "src/*_TEST.cc", + ], +) + +public_headers = public_headers_no_gen + [ + "include/gz/transport/log/Export.hh", +] + +cc_library( + name = "log", + srcs = sources + private_headers + ["include/build_config.hh"], + hdrs = public_headers, + data = ["sql/0.1.0.sql"], + includes = ["include"], + deps = [ + GZ_ROOT + "transport", + "@sqlite3", + ], +) + +test_sources = glob( + include = ["src/*_TEST.cc"], + exclude = ["src/LogCommandAPI_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [src], + data = [ + "test/data/state.tlog", + ], + defines = [ + 'GZ_TRANSPORT_LOG_TEST_PATH=\\"transport/log/test\\"', + 'CORRUPT_DB_TEST_PATH=\\"transport/log/test/data/state.tlog\\"', + ], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "transport", + }, + deps = [ + ":log", + GZ_ROOT + "common/testing", + GZ_ROOT + "transport/test:utils", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in test_sources] + +add_lint_tests() diff --git a/log/src/CMakeLists.txt b/log/src/CMakeLists.txt index c285c0efb..aab305fbd 100644 --- a/log/src/CMakeLists.txt +++ b/log/src/CMakeLists.txt @@ -19,7 +19,7 @@ endif() gz_build_tests( TYPE "UNIT" SOURCES ${gtest_sources} - LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS} + LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS} test_config TEST_LIST logging_tests ) diff --git a/log/src/Log_TEST.cc b/log/src/Log_TEST.cc index 4ac008344..1faadb310 100644 --- a/log/src/Log_TEST.cc +++ b/log/src/Log_TEST.cc @@ -14,6 +14,7 @@ * limitations under the License. * */ +#include "gtest/gtest.h" #include #include @@ -21,8 +22,8 @@ #include #include "gz/transport/log/Log.hh" -#include "test_config.hh" -#include "gtest/gtest.h" + +#include "test_utils.hh" using namespace gz; using namespace gz::transport; diff --git a/log/test/integration/CMakeLists.txt b/log/test/integration/CMakeLists.txt index 5537f4511..900575125 100644 --- a/log/test/integration/CMakeLists.txt +++ b/log/test/integration/CMakeLists.txt @@ -20,6 +20,7 @@ gz_build_tests( ChirpParams ${PROJECT_LIBRARY_TARGET_NAME}-log ${EXTRA_TEST_LIB_DEPS} + test_config INCLUDE_DIRS ${CMAKE_BINARY_DIR}/test/ ) diff --git a/parameters/BUILD.bazel b/parameters/BUILD.bazel new file mode 100644 index 000000000..8a1842d0c --- /dev/null +++ b/parameters/BUILD.bazel @@ -0,0 +1,72 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "cmake_configure_file", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) +load( + "@gz//bazel/lint:lint.bzl", + "add_lint_tests", +) + +gz_export_header( + name = "include/gz/transport/parameters/Export.hh", + export_base = "GZ_TRANSPORT_PARAMETERS", + lib_name = "gz-transport-parameters", + visibility = ["//visibility:private"], +) + +public_headers_no_gen = glob([ + "include/gz/transport/parameters/*.hh", + "include/gz/transport/parameters/detail/*.hh", +]) + +private_headers = glob(["src/*.hh"]) + +sources = glob( + ["src/*.cc"], + exclude = [ + "src/*_TEST.cc", + ], +) + +public_headers = public_headers_no_gen + [ + "include/gz/transport/parameters/Export.hh", +] + +cc_library( + name = "parameters", + srcs = sources + private_headers, + hdrs = public_headers, + includes = ["include"], + visibility = GZ_VISIBILITY, + deps = [ + GZ_ROOT + "transport", + "@sqlite3", + ], +) + +test_sources = glob( + include = ["src/*_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [src], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "transport", + }, + deps = [ + ":parameters", + GZ_ROOT + "transport/test:utils", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in test_sources] + +add_lint_tests() diff --git a/src/CIface_TEST.cc b/src/CIface_TEST.cc index 1f1b70c57..b67f3c979 100644 --- a/src/CIface_TEST.cc +++ b/src/CIface_TEST.cc @@ -14,15 +14,15 @@ * limitations under the License. * */ +#include "gtest/gtest.h" + #include #include "gz/transport/CIface.h" +#include "test_utils.hh" #include -#include "gtest/gtest.h" -#include "test_config.hh" - static int count; ////////////////////////////////////////////////// diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bed76c64d..863e676d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ endif() # Build the unit tests. gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} TEST_LIST test_list - LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) + LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config) foreach(test ${test_list}) diff --git a/src/Clock_TEST.cc b/src/Clock_TEST.cc index 0c80cc487..22547b2cd 100644 --- a/src/Clock_TEST.cc +++ b/src/Clock_TEST.cc @@ -24,7 +24,6 @@ #include "gz/transport/Clock.hh" #include "gz/transport/Node.hh" #include "gz/transport/TransportTypes.hh" -#include "test_config.hh" #include "gtest/gtest.h" using namespace gz; diff --git a/src/Discovery_TEST.cc b/src/Discovery_TEST.cc index 24d1882ff..26f1b6a26 100644 --- a/src/Discovery_TEST.cc +++ b/src/Discovery_TEST.cc @@ -14,6 +14,7 @@ * limitations under the License. * */ +#include "gtest/gtest.h" #include #include @@ -21,17 +22,16 @@ #include #include -#include "gtest/gtest.h" #include "gz/transport/AdvertiseOptions.hh" #include "gz/transport/Discovery.hh" #include "gz/transport/Publisher.hh" #include "gz/transport/TransportTypes.hh" #include "gz/transport/Uuid.hh" +#include "test_utils.hh" #include "gz/utils/Environment.hh" #include "gz/utils/ExtraTestMacros.hh" -#include "test_config.hh" using namespace gz; using namespace transport; diff --git a/src/Helpers_TEST.cc b/src/Helpers_TEST.cc index 518090e11..c5674f325 100644 --- a/src/Helpers_TEST.cc +++ b/src/Helpers_TEST.cc @@ -14,14 +14,13 @@ * limitations under the License. * */ +#include "gtest/gtest.h" #include "gz/transport/Helpers.hh" +#include "test_utils.hh" #include -#include "test_config.hh" -#include "gtest/gtest.h" - using namespace gz; ////////////////////////////////////////////////// diff --git a/src/NodeOptions_TEST.cc b/src/NodeOptions_TEST.cc index d28a40e5a..96a870e60 100644 --- a/src/NodeOptions_TEST.cc +++ b/src/NodeOptions_TEST.cc @@ -15,6 +15,8 @@ * */ +#include "gtest/gtest.h" + #include #include "gz/transport/NetUtils.hh" @@ -22,9 +24,6 @@ #include -#include "test_config.hh" -#include "gtest/gtest.h" - using namespace gz; ////////////////////////////////////////////////// diff --git a/src/Node_TEST.cc b/src/Node_TEST.cc index 80427368e..cb0d31772 100644 --- a/src/Node_TEST.cc +++ b/src/Node_TEST.cc @@ -14,6 +14,8 @@ * limitations under the License. * */ +#include "gtest/gtest.h" + #include #include #include @@ -26,18 +28,13 @@ #include #include -#include "gz/transport/AdvertiseOptions.hh" #include "gz/transport/MessageInfo.hh" #include "gz/transport/Node.hh" -#include "gz/transport/NodeOptions.hh" -#include "gz/transport/TopicStatistics.hh" -#include "gz/transport/TopicUtils.hh" #include "gz/transport/TransportTypes.hh" #include -#include "gtest/gtest.h" -#include "test_config.hh" +#include "test_utils.hh" using namespace gz; diff --git a/src/SubscribeOptions_TEST.cc b/src/SubscribeOptions_TEST.cc index 8e7ccb780..d6bb9666f 100644 --- a/src/SubscribeOptions_TEST.cc +++ b/src/SubscribeOptions_TEST.cc @@ -17,7 +17,6 @@ #include "gz/transport/Helpers.hh" #include "gz/transport/SubscribeOptions.hh" -#include "test_config.hh" #include "gtest/gtest.h" using namespace gz; diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 9a559f1d7..ed165dbd8 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -41,11 +41,12 @@ install(TARGETS ${service_executable} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/gz # Build the unit tests. gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} TEST_LIST test_list - LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) + LIB_DEPS + gz + gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER} + ${EXTRA_TEST_LIB_DEPS} test_config) foreach(test ${test_list}) - target_link_libraries(${test} gz gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}) - # Inform each test of its output directory so it knows where to call the # auxiliary files from. Using a generator expression here is useful for # multi-configuration generators, like Visual Studio. diff --git a/src/cmd/gz_TEST.cc b/src/cmd/gz_TEST.cc index 5a6158e72..5dd861177 100644 --- a/src/cmd/gz_TEST.cc +++ b/src/cmd/gz_TEST.cc @@ -29,6 +29,7 @@ #include "gtest/gtest.h" #include "gz/transport/Node.hh" + #include "test_config.hh" using namespace gz; diff --git a/src/cmd/gz_src_TEST.cc b/src/cmd/gz_src_TEST.cc index 9e6deed45..04be10d0d 100644 --- a/src/cmd/gz_src_TEST.cc +++ b/src/cmd/gz_src_TEST.cc @@ -14,27 +14,21 @@ * limitations under the License. * */ +#include "gtest/gtest.h" + +#include #include #include #include #include -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4251) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif #include "gz.hh" #include "gz/transport/Node.hh" #include -#include "test_config.hh" -#include "gtest/gtest.h" +#include "test_utils.hh" using namespace gz; diff --git a/test/BUILD.bazel b/test/BUILD.bazel new file mode 100644 index 000000000..8700063d5 --- /dev/null +++ b/test/BUILD.bazel @@ -0,0 +1,15 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_ROOT", + "GZ_VISIBILITY", +) + +cc_library( + name = "utils", + hdrs = ["test_utils.hh"], + includes = ["."], + visibility = GZ_VISIBILITY, + deps = [ + GZ_ROOT + "utils", + ], +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4166255fa..a260fe231 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,11 @@ -configure_file (test_config.hh.in ${PROJECT_BINARY_DIR}/include/test_config.hh) -include_directories ( - ${PROJECT_BINARY_DIR}/include -) - add_subdirectory(gtest_vendor) add_subdirectory(integration) add_subdirectory(performance) add_subdirectory(regression) + +configure_file (test_config.hh.in ${PROJECT_BINARY_DIR}/include/test_config.hh) +add_library(test_config INTERFACE) +target_include_directories(test_config INTERFACE + ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/test +) diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index a60793e91..3fcbf15ce 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -26,7 +26,7 @@ endif() gz_build_tests(TYPE INTEGRATION SOURCES ${tests} TEST_LIST test_list - LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) + LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config) set(auxiliary_files authPubSubSubscriberInvalid_aux @@ -54,6 +54,7 @@ foreach(AUX_EXECUTABLE ${auxiliary_files}) ${PROJECT_LIBRARY_TARGET_NAME} gtest ${EXTRA_TEST_LIB_DEPS} + test_config ) endforeach(AUX_EXECUTABLE) diff --git a/test/test_config.hh.in b/test/test_config.hh.in index e71841b68..48e0dab43 100644 --- a/test/test_config.hh.in +++ b/test/test_config.hh.in @@ -22,27 +22,6 @@ #define GZ_CONFIG_PATH "@CMAKE_BINARY_DIR@/test/conf" #define GZ_VERSION_FULL "@PROJECT_VERSION_FULL@" -#include -#include -#include -#include -#include +#include "test_utils.hh" -namespace testing -{ - /// \brief Get a random number based on an integer converted to string. - /// \return A random integer converted to string. - std::string getRandomNumber() - { - // Initialize random number generator. - uint32_t seed = std::random_device {}(); - std::mt19937 randGenerator(seed); - - // Create a random number based on an integer converted to string. - std::uniform_int_distribution d(0, INT_MAX); - - return std::to_string(d(randGenerator)); - } -} // namespace testing - -#endif // header guard +#endif // GZ_TRANSPORT_TEST_CONFIG_HH_ diff --git a/test/test_utils.hh b/test/test_utils.hh new file mode 100644 index 000000000..2199a1a4c --- /dev/null +++ b/test/test_utils.hh @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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. + * +*/ + +#ifndef GZ_TRANSPORT_TEST_UTILS_HH_ +#define GZ_TRANSPORT_TEST_UTILS_HH_ + +#include +#include +#include + +namespace testing +{ + /// \brief Get a random number based on an integer converted to string. + /// \return A random integer converted to string. + inline std::string getRandomNumber() + { + // Initialize random number generator. + uint32_t seed = std::random_device {}(); + std::mt19937 randGenerator(seed); + + // Create a random number based on an integer converted to string. + std::uniform_int_distribution d(0, INT_MAX); + + return std::to_string(d(randGenerator)); + } +} // namespace testing + +#endif // GZ_TRANSPORT_TEST_UTILS_HH_ +