From 766a773215cfd632d9573e26d74cf15e05201504 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 22 Feb 2022 15:01:17 -0600 Subject: [PATCH] Test updates Signed-off-by: Michael Carroll --- CMakeLists.txt | 3 +- av/src/AudioDecoder.cc | 2 +- av/src/AudioDecoder_TEST.cc | 5 +- av/src/CMakeLists.txt | 6 +- av/src/VideoEncoder_TEST.cc | 8 +- events/src/CMakeLists.txt | 9 +- events/src/Event_TEST.cc | 2 +- events/src/MouseEvent_TEST.cc | 2 +- graphics/src/Animation_TEST.cc | 4 +- graphics/src/CMakeLists.txt | 9 +- graphics/src/ColladaExporter_TEST.cc | 6 +- graphics/src/ColladaLoader_TEST.cc | 4 +- graphics/src/Dem_TEST.cc | 3 +- graphics/src/GTSMeshUtils_TEST.cc | 3 +- graphics/src/ImageHeightmap_TEST.cc | 4 +- graphics/src/Image_TEST.cc | 4 +- graphics/src/Material_TEST.cc | 4 +- graphics/src/MeshManager_TEST.cc | 3 +- graphics/src/Mesh_TEST.cc | 3 +- graphics/src/OBJLoader_TEST.cc | 4 +- graphics/src/SVGLoader_TEST.cc | 9 +- graphics/src/SubMesh_TEST.cc | 3 +- include/ignition/common/TempDirectory.hh | 15 ++ profiler/src/CMakeLists.txt | 8 +- src/Base64_TEST.cc | 2 +- src/Battery_TEST.cc | 5 +- src/CMakeLists.txt | 3 +- src/Console_TEST.cc | 3 +- src/EnumIface_TEST.cc | 3 +- src/Filesystem_TEST.cc | 2 +- src/MaterialDensity_TEST.cc | 4 +- src/PluginLoader_TEST.cc | 56 +++++-- src/TempDirectory.cc | 11 +- src/TempDirectory_TEST.cc | 2 +- src/Util_TEST.cc | 4 +- src/WorkerPool_TEST.cc | 2 +- test/CMakeLists.txt | 2 - test/integration/CMakeLists.txt | 1 + test/integration/encoder_timing.cc | 1 - test/integration/plugin.cc | 1 - test/integration/video_encoder.cc | 3 +- test/performance/plugin_specialization.cc | 1 - test/test_config.h.in | 184 ---------------------- 43 files changed, 165 insertions(+), 248 deletions(-) delete mode 100644 test/test_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index da71892bb..f3acb5d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) # Initialize the project #============================================================================ project(ignition-common5 VERSION 5.0.0) +set(IGN_COMMON_VER ${PROJECT_VERSION_MAJOR}) #============================================================================ # Find ignition-cmake @@ -125,7 +126,7 @@ configure_file("${PROJECT_SOURCE_DIR}/cppcheck.suppress.in" ${PROJECT_BINARY_DIR}/cppcheck.suppress) ign_configure_build(QUIT_IF_BUILD_ERRORS - COMPONENTS av events graphics profiler) + COMPONENTS av events graphics profiler testing) #============================================================================ # Create package information diff --git a/av/src/AudioDecoder.cc b/av/src/AudioDecoder.cc index b639317c5..cf62e6d8c 100644 --- a/av/src/AudioDecoder.cc +++ b/av/src/AudioDecoder.cc @@ -269,7 +269,7 @@ bool AudioDecoder::SetFile(const std::string &_filename) #endif // Open codec - if (avcodec_open2(this->dataPtr->codecCtx, + if (avcodec_open2(this->dataPtr->codecCtx, this->dataPtr->codec, nullptr) < 0) { ignerr << "Couldn't open audio codec.\n"; diff --git a/av/src/AudioDecoder_TEST.cc b/av/src/AudioDecoder_TEST.cc index 687741e56..003b54b5a 100644 --- a/av/src/AudioDecoder_TEST.cc +++ b/av/src/AudioDecoder_TEST.cc @@ -17,9 +17,8 @@ #include #include -#include - -#include "test_config.h" +#include +#include using namespace ignition; diff --git a/av/src/CMakeLists.txt b/av/src/CMakeLists.txt index ff959e31a..294c37993 100644 --- a/av/src/CMakeLists.txt +++ b/av/src/CMakeLists.txt @@ -21,9 +21,11 @@ if(IGN_COMMON_BUILD_HW_VIDEO) target_compile_definitions(${av_target} PRIVATE IGN_COMMON_BUILD_HW_VIDEO) endif() -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} +ign_build_tests( + TYPE UNIT + SOURCES ${gtest_sources} LIB_DEPS ${av_target} - ignition-cmake${IGN_CMAKE_VER}::utilities + ignition-common${IGN_COMMON_VER}-testing ) diff --git a/av/src/VideoEncoder_TEST.cc b/av/src/VideoEncoder_TEST.cc index 495b11a7d..8f376edef 100644 --- a/av/src/VideoEncoder_TEST.cc +++ b/av/src/VideoEncoder_TEST.cc @@ -17,7 +17,9 @@ #include "ignition/common/Console.hh" #include "ignition/common/VideoEncoder.hh" -#include "test_config.h" + +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" using namespace ignition; using namespace common; @@ -28,7 +30,11 @@ class VideoEncoderTest : public common::testing::AutoLogFixture protected: void SetUp() override { Console::SetVerbosity(4); + tempDir = common::testing::MakeTestTempDirectory(); + ASSERT_TRUE(tempDir->Valid()) << tempDir->Path(); } + + public: std::shared_ptr tempDir; }; ///////////////////////////////////////////////// diff --git a/events/src/CMakeLists.txt b/events/src/CMakeLists.txt index 3947ce68c..350d010e0 100644 --- a/events/src/CMakeLists.txt +++ b/events/src/CMakeLists.txt @@ -7,5 +7,10 @@ target_link_libraries(${events_target} PUBLIC ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER}) -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} - LIB_DEPS ${events_target}) +ign_build_tests( + TYPE UNIT + SOURCES ${gtest_sources} + LIB_DEPS + ${events_target} + ignition-common${IGN_COMMON_VER}-testing +) diff --git a/events/src/Event_TEST.cc b/events/src/Event_TEST.cc index 388bd6b0d..5a56f18e1 100644 --- a/events/src/Event_TEST.cc +++ b/events/src/Event_TEST.cc @@ -17,7 +17,7 @@ #include -#include "test_config.h" +#include "ignition/common/testing/AutoLogFixture.hh" #include #include diff --git a/events/src/MouseEvent_TEST.cc b/events/src/MouseEvent_TEST.cc index e954a6eec..771bab3c4 100644 --- a/events/src/MouseEvent_TEST.cc +++ b/events/src/MouseEvent_TEST.cc @@ -17,7 +17,7 @@ #include -#include "test_config.h" +#include "ignition/common/testing/AutoLogFixture.hh" #include "ignition/common/MouseEvent.hh" #include "ignition/common/config.hh" diff --git a/graphics/src/Animation_TEST.cc b/graphics/src/Animation_TEST.cc index 3ad3c5496..84458c364 100644 --- a/graphics/src/Animation_TEST.cc +++ b/graphics/src/Animation_TEST.cc @@ -17,13 +17,13 @@ #include -#include "test_config.h" - #include #include #include #include +#include "ignition/common/testing/AutoLogFixture.hh" + using namespace ignition; class AnimationTest : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/CMakeLists.txt b/graphics/src/CMakeLists.txt index 461c993a2..85e5b19a5 100644 --- a/graphics/src/CMakeLists.txt +++ b/graphics/src/CMakeLists.txt @@ -20,8 +20,13 @@ target_link_libraries(${graphics_target} GTS::GTS FreeImage::FreeImage) -ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} - LIB_DEPS ${graphics_target}) +ign_build_tests( + TYPE UNIT + SOURCES ${gtest_sources} + LIB_DEPS + ${graphics_target} + ignition-common${IGN_COMMON_VER}-testing +) if(USE_EXTERNAL_TINYXML2) diff --git a/graphics/src/ColladaExporter_TEST.cc b/graphics/src/ColladaExporter_TEST.cc index 5d1af1b8c..db4bdd203 100644 --- a/graphics/src/ColladaExporter_TEST.cc +++ b/graphics/src/ColladaExporter_TEST.cc @@ -17,13 +17,15 @@ #include #include "tinyxml2.h" -#include "test_config.h" #include "ignition/common/ColladaLoader.hh" #include "ignition/common/ColladaExporter.hh" #include "ignition/common/Filesystem.hh" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" + #ifdef _WIN32 #define snprintf _snprintf #endif @@ -36,7 +38,7 @@ class ColladaExporter : public common::testing::AutoLogFixture { { // Call superclass to make sure that logging is initialized this->common::testing::AutoLogFixture::SetUp(); - ASSERT_TRUE(common::testing::TestTmpPath(this->pathOut)); + this->pathOut = common::testing::TempPath(); common::createDirectories(this->pathOut); } diff --git a/graphics/src/ColladaLoader_TEST.cc b/graphics/src/ColladaLoader_TEST.cc index 0936e9ed4..ea62b4a76 100644 --- a/graphics/src/ColladaLoader_TEST.cc +++ b/graphics/src/ColladaLoader_TEST.cc @@ -16,7 +16,6 @@ */ #include -#include "test_config.h" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" #include "ignition/common/Material.hh" @@ -24,6 +23,9 @@ #include "ignition/common/Skeleton.hh" #include "ignition/common/SkeletonAnimation.hh" +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" + using namespace ignition; class ColladaLoader : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/Dem_TEST.cc b/graphics/src/Dem_TEST.cc index bc39e7248..2105b6cf9 100644 --- a/graphics/src/Dem_TEST.cc +++ b/graphics/src/Dem_TEST.cc @@ -20,7 +20,8 @@ #include #include "ignition/common/Dem.hh" -#include "test_config.h" + +#include "ignition/common/testing/AutoLogFixture.hh" using namespace ignition; diff --git a/graphics/src/GTSMeshUtils_TEST.cc b/graphics/src/GTSMeshUtils_TEST.cc index b9d8a0f96..568a69ae0 100644 --- a/graphics/src/GTSMeshUtils_TEST.cc +++ b/graphics/src/GTSMeshUtils_TEST.cc @@ -18,11 +18,12 @@ #include #include -#include "test_config.h" #include "ignition/common/GTSMeshUtils.hh" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" +#include "ignition/common/testing/AutoLogFixture.hh" + using namespace ignition; class GTSMeshUtils : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/ImageHeightmap_TEST.cc b/graphics/src/ImageHeightmap_TEST.cc index b40880879..8f7d1005b 100644 --- a/graphics/src/ImageHeightmap_TEST.cc +++ b/graphics/src/ImageHeightmap_TEST.cc @@ -17,7 +17,9 @@ #include #include "ignition/common/ImageHeightmap.hh" -#include "test_config.h" + +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" #define ELEVATION_TOL 1e-8 diff --git a/graphics/src/Image_TEST.cc b/graphics/src/Image_TEST.cc index 7b9837c2e..99c91d22f 100644 --- a/graphics/src/Image_TEST.cc +++ b/graphics/src/Image_TEST.cc @@ -18,7 +18,9 @@ #include #include -#include "test_config.h" + +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" using namespace ignition; diff --git a/graphics/src/Material_TEST.cc b/graphics/src/Material_TEST.cc index add9e417f..1553de7ba 100644 --- a/graphics/src/Material_TEST.cc +++ b/graphics/src/Material_TEST.cc @@ -16,10 +16,12 @@ #include -#include "test_config.h" #include "ignition/common/Material.hh" #include "ignition/common/Pbr.hh" +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" + using namespace ignition; class MaterialTest : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/MeshManager_TEST.cc b/graphics/src/MeshManager_TEST.cc index 76b198d3d..998e5258b 100644 --- a/graphics/src/MeshManager_TEST.cc +++ b/graphics/src/MeshManager_TEST.cc @@ -17,12 +17,13 @@ #include -#include "test_config.h" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" #include "ignition/common/MeshManager.hh" #include "ignition/common/config.hh" +#include "ignition/common/testing/AutoLogFixture.hh" + using namespace ignition; #ifndef _WIN32 diff --git a/graphics/src/Mesh_TEST.cc b/graphics/src/Mesh_TEST.cc index e714c317a..e3eb7d6ab 100644 --- a/graphics/src/Mesh_TEST.cc +++ b/graphics/src/Mesh_TEST.cc @@ -17,13 +17,14 @@ #include -#include "test_config.h" #include "ignition/common/Material.hh" #include "ignition/common/Mesh.hh" #include "ignition/common/Skeleton.hh" #include "ignition/common/SubMesh.hh" #include "ignition/math/Vector3.hh" +#include "ignition/common/testing/AutoLogFixture.hh" + using namespace ignition; class MeshTest : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/OBJLoader_TEST.cc b/graphics/src/OBJLoader_TEST.cc index 26625c51b..b1ae472aa 100644 --- a/graphics/src/OBJLoader_TEST.cc +++ b/graphics/src/OBJLoader_TEST.cc @@ -16,12 +16,14 @@ */ #include -#include "test_config.h" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" #include "ignition/common/Material.hh" #include "ignition/common/OBJLoader.hh" +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" + using namespace ignition; class OBJLoaderTest : public common::testing::AutoLogFixture { }; diff --git a/graphics/src/SVGLoader_TEST.cc b/graphics/src/SVGLoader_TEST.cc index 37d79ba0b..3570ff7f6 100644 --- a/graphics/src/SVGLoader_TEST.cc +++ b/graphics/src/SVGLoader_TEST.cc @@ -17,10 +17,11 @@ #include -#include "test_config.h" - #include "ignition/common/SVGLoader.hh" +#include "ignition/common/testing/AutoLogFixture.hh" +#include "ignition/common/testing/TestPaths.hh" + using namespace ignition; using namespace common; @@ -36,7 +37,9 @@ double tol = 0.05; /// \brief return path to svg file in test/data/svg std::string testSvg(const std::string &_filename) { - return common::testing::TestFile("data", "svg", _filename); + std::string file = common::testing::TestFile("data", "svg", _filename); + EXPECT_TRUE(exists(file)); + return file; } ///////////////////////////////////////////////// diff --git a/graphics/src/SubMesh_TEST.cc b/graphics/src/SubMesh_TEST.cc index 69992a749..dbfd2225f 100644 --- a/graphics/src/SubMesh_TEST.cc +++ b/graphics/src/SubMesh_TEST.cc @@ -17,12 +17,13 @@ #include -#include "test_config.h" #include "ignition/math/Vector3.hh" #include "ignition/common/Mesh.hh" #include "ignition/common/SubMesh.hh" #include "ignition/common/MeshManager.hh" +#include "ignition/common/testing/AutoLogFixture.hh" + using namespace ignition; class SubMeshTest : public common::testing::AutoLogFixture { }; diff --git a/include/ignition/common/TempDirectory.hh b/include/ignition/common/TempDirectory.hh index a23c3eab3..b00b6f83a 100644 --- a/include/ignition/common/TempDirectory.hh +++ b/include/ignition/common/TempDirectory.hh @@ -74,6 +74,21 @@ namespace ignition const std::string &_subDir = "ignition", bool _cleanup = true); + /// \brief Create a directory in the tempDirectoryPath by expanding + /// a name template. This directory can also be automatically cleaned + /// up when the object goes out of scope. + /// + /// The TempDirectory will have the form _root/_subdir/_prefixXXXXX/ + /// + /// \param[in] _prefix String to be expanded for the template + /// \param[in] _subDir Subdirectory in OS _root, if desired + /// \param[in] _cleanup True to indicate that the filesystem should + /// be cleaned as part of the destructor + public: TempDirectory(const std::string &_root, + const std::string &_prefix = "temp_dir", + const std::string &_subDir = "ignition", + bool _cleanup = true); + /// \brief Destroy the temporary directory, removing from filesystem /// if cleanup is true. public: ~TempDirectory(); diff --git a/profiler/src/CMakeLists.txt b/profiler/src/CMakeLists.txt index 239611b6d..3874cb0fb 100644 --- a/profiler/src/CMakeLists.txt +++ b/profiler/src/CMakeLists.txt @@ -79,8 +79,12 @@ if(IGN_PROFILER_REMOTERY) endif() endif() -ign_build_tests(TYPE UNIT SOURCES ${PROFILER_TESTS} - LIB_DEPS ${profiler_target} +ign_build_tests( + TYPE UNIT + SOURCES ${PROFILER_TESTS} + LIB_DEPS + ${profiler_target} + ignition-common${IGN_COMMON_VER}-testing TEST_LIST profiler_tests) if(TARGET UNIT_Profiler_Remotery_TEST) diff --git a/src/Base64_TEST.cc b/src/Base64_TEST.cc index 4aed870d0..4917c21cf 100644 --- a/src/Base64_TEST.cc +++ b/src/Base64_TEST.cc @@ -18,7 +18,7 @@ #include #include -#include "test_config.h" +#include "ignition/common/testing/AutoLogFixture.hh" using namespace ignition; diff --git a/src/Battery_TEST.cc b/src/Battery_TEST.cc index 6584fc5e2..cdc3e3b39 100644 --- a/src/Battery_TEST.cc +++ b/src/Battery_TEST.cc @@ -14,9 +14,12 @@ * limitations under the License. * */ +#include + #include + #include "ignition/common/Battery.hh" -#include "test_config.h" +#include "ignition/common/testing/AutoLogFixture.hh" using namespace ignition; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 62cc2ef15..9be6984a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,7 +49,8 @@ ign_build_tests( TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS - ignition-cmake${IGN_CMAKE_VER}::utilities + ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER} + ignition-common${IGN_COMMON_VER}-testing INCLUDE_DIRS # Used to make internal source file headers visible to the unit tests ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/Console_TEST.cc b/src/Console_TEST.cc index e946ffce7..737d56de1 100644 --- a/src/Console_TEST.cc +++ b/src/Console_TEST.cc @@ -20,10 +20,9 @@ #include "ignition/common/Console.hh" #include "ignition/common/Filesystem.hh" +#include "ignition/common/TempDirectory.hh" #include "ignition/common/Util.hh" -#include "test_config.h" - using namespace ignition; using namespace ignition::common; diff --git a/src/EnumIface_TEST.cc b/src/EnumIface_TEST.cc index 90e68d5f7..b5287736d 100644 --- a/src/EnumIface_TEST.cc +++ b/src/EnumIface_TEST.cc @@ -18,7 +18,8 @@ #include #include "ignition/common/EnumIface.hh" -#include "test_config.h" + +#include "ignition/common/testing/AutoLogFixture.hh" using namespace ignition; diff --git a/src/Filesystem_TEST.cc b/src/Filesystem_TEST.cc index ebe39d698..762b75667 100644 --- a/src/Filesystem_TEST.cc +++ b/src/Filesystem_TEST.cc @@ -17,7 +17,7 @@ #include -#include +#include #include #include diff --git a/src/MaterialDensity_TEST.cc b/src/MaterialDensity_TEST.cc index 184c7b9fc..19176ffc4 100644 --- a/src/MaterialDensity_TEST.cc +++ b/src/MaterialDensity_TEST.cc @@ -14,10 +14,10 @@ * limitations under the License. * */ - #include + #include "ignition/common/MaterialDensity.hh" -#include "test_config.h" +#include "ignition/common/testing/AutoLogFixture.hh" using namespace ignition; using namespace common; diff --git a/src/PluginLoader_TEST.cc b/src/PluginLoader_TEST.cc index 12e4d2994..6dc3ec3bb 100644 --- a/src/PluginLoader_TEST.cc +++ b/src/PluginLoader_TEST.cc @@ -18,15 +18,36 @@ #include #include +#include + +#include "ignition/common/config.hh" #include "ignition/common/PluginLoader.hh" #include "ignition/common/SystemPaths.hh" +#include "ignition/common/TempDirectory.hh" -#include "ignition/common/config.hh" -#include "test_config.h" +///////////////////////////////////////////////// +class TestTempDirectory : public ignition::common::TempDirectory +{ + public: TestTempDirectory(): + ignition::common::TempDirectory("plugin_loader", "ign_common", true) + { + } +}; + +///////////////////////////////////////////////// +bool create_new_empty_file(const std::string &_filename) +{ + try + { + std::fstream fs(_filename, std::ios::out); + } + catch(...) + { + return false; + } + return true; +} -#ifndef IGN_COMMON_LIB_PATH -#define IGN_COMMON_LIB_PATH "./ign_common" -#endif ///////////////////////////////////////////////// TEST(PluginLoader, InitialNoInterfacesImplemented) @@ -45,20 +66,33 @@ TEST(PluginLoader, LoadNonexistantLibrary) ///////////////////////////////////////////////// TEST(PluginLoader, LoadNonLibrary) { - std::string projectPath(IGN_COMMON_LIB_PATH); + TestTempDirectory tempDir; + create_new_empty_file("not_a_library.txt"); + ignition::common::PluginLoader pm; - EXPECT_TRUE(pm.LoadLibrary(projectPath + "/test_config.h").empty()); + EXPECT_TRUE(pm.LoadLibrary("not_a_library.txt").empty()); } ///////////////////////////////////////////////// TEST(PluginLoader, LoadNonPluginLibrary) { - std::string libraryName("ignition-common"); - libraryName += std::to_string(IGNITION_COMMON_MAJOR_VERSION); + std::string libDir = "lib_dir"; + std::string libName = "foobar"; + + TestTempDirectory tempDir; + ignition::common::createDirectory(libDir); + create_new_empty_file( + ignition::common::joinPaths(libDir, "lib" + libName + ".so")); ignition::common::SystemPaths sp; - sp.AddPluginPaths(IGN_COMMON_LIB_PATH); - std::string path = sp.FindSharedLibrary(libraryName); + + // Fails without plugin dirs setup + std::string path = sp.FindSharedLibrary("foo"); + ASSERT_TRUE(path.empty()); + + sp.AddPluginPaths( + ignition::common::joinPaths(ignition::common::cwd(), libDir)); + path = sp.FindSharedLibrary(libName); ASSERT_FALSE(path.empty()); ignition::common::PluginLoader pm; diff --git a/src/TempDirectory.cc b/src/TempDirectory.cc index cf65b3a64..a8a04494f 100644 --- a/src/TempDirectory.cc +++ b/src/TempDirectory.cc @@ -161,13 +161,22 @@ class ignition::common::TempDirectory::Implementation TempDirectory::TempDirectory(const std::string &_prefix, const std::string &_subDir, bool _cleanup): + TempDirectory(common::tempDirectoryPath(), _prefix, _subDir, _cleanup) +{ +} + +///////////////////////////////////////////////// +TempDirectory::TempDirectory(const std::string &_root, + const std::string &_prefix, + const std::string &_subDir, + bool _cleanup): dataPtr(ignition::utils::MakeUniqueImpl()) { this->dataPtr->oldPath = common::cwd(); this->dataPtr->doCleanup = _cleanup; - auto tempPath = common::tempDirectoryPath(); + auto tempPath = _root; if (!_subDir.empty()) { tempPath = common::joinPaths(tempPath, _subDir); diff --git a/src/TempDirectory_TEST.cc b/src/TempDirectory_TEST.cc index a0c3ad7bb..1814682f6 100644 --- a/src/TempDirectory_TEST.cc +++ b/src/TempDirectory_TEST.cc @@ -18,7 +18,7 @@ #include #include -#include +#include ///////////////////////////////////////////////// TEST(TempDirectory, tempDirectoryPath) diff --git a/src/Util_TEST.cc b/src/Util_TEST.cc index f01c9e41e..39fe1f60c 100644 --- a/src/Util_TEST.cc +++ b/src/Util_TEST.cc @@ -14,13 +14,13 @@ * limitations under the License. * */ +#include +#include #include -#include #include #include -#include "test_config.h" using namespace ignition; diff --git a/src/WorkerPool_TEST.cc b/src/WorkerPool_TEST.cc index 5dbec7989..5bd90136d 100644 --- a/src/WorkerPool_TEST.cc +++ b/src/WorkerPool_TEST.cc @@ -21,7 +21,7 @@ #include "ignition/common/Console.hh" #include "ignition/common/WorkerPool.hh" -#include "ignition/utilities/ExtraTestMacros.hh" +#include "ignition/utils/ExtraTestMacros.hh" namespace igncmn = ignition::common; using namespace igncmn; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ff32b05f3..307dcf48f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,5 +17,3 @@ add_subdirectory(performance) add_subdirectory(regression) add_subdirectory(plugins) add_subdirectory(static_assertions) - -configure_file(test_config.h.in ${PROJECT_BINARY_DIR}/test_config.h) diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 1aa52c366..6f24e78ac 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -14,6 +14,7 @@ endif() ign_build_tests( TYPE INTEGRATION SOURCES ${tests} + LIB_DEPS ignition-common${IGN_COMMON_VER}-testing ) if(TARGET INTEGRATION_plugin) diff --git a/test/integration/encoder_timing.cc b/test/integration/encoder_timing.cc index dfef1147f..13cc11461 100644 --- a/test/integration/encoder_timing.cc +++ b/test/integration/encoder_timing.cc @@ -17,7 +17,6 @@ #include #include "ignition/common/VideoEncoder.hh" #include "ignition/common/Video.hh" -#include "test_config.h" using namespace ignition; using namespace common; diff --git a/test/integration/plugin.cc b/test/integration/plugin.cc index 74e0b850a..bcbb79151 100644 --- a/test/integration/plugin.cc +++ b/test/integration/plugin.cc @@ -32,7 +32,6 @@ #include "ignition/common/PluginPtr.hh" #include "ignition/common/SpecializedPluginPtr.hh" -#include "test_config.h" #include "DummyPluginsPath.h" #include "plugins/DummyPlugins.hh" diff --git a/test/integration/video_encoder.cc b/test/integration/video_encoder.cc index 7368abb6c..8ac6adde1 100644 --- a/test/integration/video_encoder.cc +++ b/test/integration/video_encoder.cc @@ -22,7 +22,8 @@ #include "ignition/common/Video.hh" #include "ignition/common/ffmpeg_inc.hh" -#include "test_config.h" +#include +#include using namespace ignition; using namespace common; diff --git a/test/performance/plugin_specialization.cc b/test/performance/plugin_specialization.cc index aca48c858..c5ccbd11f 100644 --- a/test/performance/plugin_specialization.cc +++ b/test/performance/plugin_specialization.cc @@ -25,7 +25,6 @@ #include "ignition/common/SpecializedPluginPtr.hh" #include "ignition/common/Console.hh" -#include "test_config.h" #include "DummyPluginsPath.h" #include "plugins/DummyPlugins.hh" diff --git a/test/test_config.h.in b/test/test_config.h.in deleted file mode 100644 index aea2bf931..000000000 --- a/test/test_config.h.in +++ /dev/null @@ -1,184 +0,0 @@ -/* THIS HEADER WAS AUTOMATICALLY GENERATED - * AND SHOULD NOT BE DIRECTLY MODIFIED. - * - * See test/test_config.h.in in the ignition-common - * repo for the original source of this header. -*/ - -#ifndef IGNITION_TESTING__TEST_CONFIG_H_ -#define IGNITION_TESTING__TEST_CONFIG_H_ - -#include - -#include -#include "ignition/common/Console.hh" -#include "ignition/common/Filesystem.hh" -#include "ignition/common/TempDirectory.hh" -#include "ignition/common/Util.hh" - -#define PROJECT_BINARY_PATH "${PROJECT_BINARY_DIR}" -#define PROJECT_SOURCE_PATH "${PROJECT_SOURCE_DIR}" - -namespace ignition -{ - namespace common - { - namespace testing - { - /// \brief Method to retrieve root directory of project source - /// - /// This is used to get various test files - /// \param[inout] _sourceDir Full path to the source directory - /// \return True if directory is set correctly, false otherwise - bool ProjectSourcePath(std::string &_sourceDir) - { - // Bazel builds set TEST_SRCDIR - if (common::env("TEST_SRCDIR", _sourceDir)) - { - _sourceDir = common::joinPaths( - _sourceDir, "__main__", "ign_common"); - return true; - } - else - { - // CMake builds set PROJECT_SOURCE_DIR - _sourceDir = "${PROJECT_SOURCE_DIR}"; - return true; - } - } - - /// \brief Method to retrieve temporary directory for test outputs - /// - /// \param[inout] _tmpDir Full path to the temp directory - /// \return True if directory is set correctly, false otherwise - bool TestTmpPath(std::string &_tmpDir) - { - // Bazel builds set TEST_UNDECLARED_OUTPUTS_DIR - if (common::env("TEST_UNDECLARED_OUTPUTS_DIR", _tmpDir)) - { - return true; - } - else - { - _tmpDir = common::createTempDirectory("ignition", - common::tempDirectoryPath()); - return !_tmpDir.empty(); - } - } - - /// \brief Retrieve a file from the project source directory - /// \param[in] variable length of arguments relative to the - /// repository source directory - /// \return Full path to requested file - template - std::string SourceFile(Args const &... args) - { - std::string dataDir; - ProjectSourcePath(dataDir); - return common::joinPaths(dataDir, args...); - } - - /// \brief Retrieve a file from the test directory - /// \param[in] variable length of arguments relative to the - /// repository test directory - /// \return Full path to requested test file - template - std::string TestFile(Args const &... args) - { - return SourceFile("test", args...); - } - - /// \brief Retrieve a file from the project temporary directory - /// \param[in] variable length of arguments relative to the - /// temporary test directory - /// \return Full path to requested file - template - std::string TempPath(Args const &... args) - { - std::string dataDir; - TestTmpPath(dataDir); - return common::joinPaths(dataDir, args...); - } - - /// \brief A utility class that stores test logs in ~/.ignition/test_logs. - /// This functionality is needed to keep all the log information reported - /// by ignition during continuous integration. Without this, debugging - /// failing tests is significantly more difficult. - class AutoLogFixture : public ::testing::Test - { - /// \brief Setup the test fixture. This gets called by gtest. - protected: virtual void SetUp() - { - const ::testing::TestInfo *const testInfo = - ::testing::UnitTest::GetInstance()->current_test_info(); - - std::string testName = testInfo->name(); - std::string testCaseName = testInfo->test_case_name(); - this->logFilename = testCaseName + "_" + testName + ".log"; - - this->temp = std::make_unique( - "test", "ign_common", true); - ASSERT_TRUE(this->temp->Valid()); - common::setenv(IGN_HOMEDIR, this->temp->Path()); - - // Initialize Console - ignLogInit(common::joinPaths(this->temp->Path(), "test_logs"), - this->logFilename); - - ignition::common::Console::SetVerbosity(4); - - // Read the full path to the log directory. - this->logDirectory = ignLogDirectory(); - } - - /// \brief Get a string with the full log file path. - /// \return The full log file path as a string. - protected: std::string FullLogPath() const - { - return ignition::common::joinPaths( - this->logDirectory, this->logFilename); - } - - /// \brief Get a string with all the log content loaded from the disk. - /// \return A string with all the log content. - protected: std::string LogContent() const - { - std::string loggedString; - // Open the log file, and read back the string - std::ifstream ifs(this->FullLogPath().c_str(), std::ios::in); - - while (!ifs.eof()) - { - std::string line; - std::getline(ifs, line); - loggedString += line; - } - return loggedString; - } - - /// \brief Default destructor. - public: virtual ~AutoLogFixture() - { - ignLogClose(); - EXPECT_TRUE(ignition::common::unsetenv(IGN_HOMEDIR)); - } - - /// \brief String with the full path of the logfile - private: std::string logFilename; - - /// \brief String with the full path to log directory - private: std::string logDirectory; - - /// \brief String with the base path to log directory - private: std::string logBasePath; - - /// \brief Temporary directory to run test in - private: std::unique_ptr temp; - }; - } // namespace testing - } // namespace common -} // namespace ignition - - - -#endif // IGNITION_TESTING__TEST_CONFIG_H_