diff --git a/.github/ci/packages.apt b/.github/ci/packages.apt index b104efe1..e4a55939 100644 --- a/.github/ci/packages.apt +++ b/.github/ci/packages.apt @@ -3,7 +3,6 @@ libcurl4-openssl-dev libgflags-dev libignition-cmake2-dev libignition-common3-dev -libignition-math4-dev libignition-tools-dev libjsoncpp-dev libtinyxml2-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index a006d0b1..c31e3986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,8 @@ project(ignition-fuel_tools3 VERSION 3.4.0) # Find ignition-cmake #============================================================================ # If you get an error at this line, you need to install ignition-cmake -find_package(ignition-cmake2 REQUIRED) +find_package(ignition-cmake2 2.3 REQUIRED) +set(IGN_CMAKE_VER ${ignition-cmake2_VERSION_MAJOR}) #============================================================================ # Configure the project diff --git a/configure.bat b/configure.bat index 5103da8a..90dccdf5 100644 --- a/configure.bat +++ b/configure.bat @@ -8,7 +8,8 @@ call %win_lib% :download_unzip_install curl-7.57.0-vc15-x64-dll-MD.zip call %win_lib% :download_unzip_install jsoncpp-1.8.4-vc15-x64-dll-MD.zip call %win_lib% :download_unzip_install libyaml-0.1.7-vc15-x64-md.zip call %win_lib% :download_unzip_install libzip-1.4.0_zlip-1.2.11_vc15-x64-dll-MD.zip -call %win_lib% :install_ign_project ign-common gz11 +call %win_lib% :install_ign_project ign-cmake ign-cmake2 +call %win_lib% :install_ign_project ign-common ign-common3 :: Set configuration variables @set build_type=Release diff --git a/include/ignition/fuel_tools/ClientConfig.hh b/include/ignition/fuel_tools/ClientConfig.hh index e78e6e7c..8f088385 100644 --- a/include/ignition/fuel_tools/ClientConfig.hh +++ b/include/ignition/fuel_tools/ClientConfig.hh @@ -26,6 +26,13 @@ #include "ignition/fuel_tools/Export.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -167,4 +174,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/CollectionIdentifier.hh b/include/ignition/fuel_tools/CollectionIdentifier.hh index e6ef01c2..3917b9c7 100644 --- a/include/ignition/fuel_tools/CollectionIdentifier.hh +++ b/include/ignition/fuel_tools/CollectionIdentifier.hh @@ -23,6 +23,13 @@ #include "ignition/fuel_tools/Helpers.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -105,4 +112,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/FuelClient.hh b/include/ignition/fuel_tools/FuelClient.hh index 6b318e6c..6a7751fd 100644 --- a/include/ignition/fuel_tools/FuelClient.hh +++ b/include/ignition/fuel_tools/FuelClient.hh @@ -29,6 +29,13 @@ #include "ignition/fuel_tools/Result.hh" #include "ignition/fuel_tools/WorldIter.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -309,4 +316,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/LocalCache.hh b/include/ignition/fuel_tools/LocalCache.hh index e415a9ce..9bc1dd8b 100644 --- a/include/ignition/fuel_tools/LocalCache.hh +++ b/include/ignition/fuel_tools/LocalCache.hh @@ -26,6 +26,13 @@ #include "ignition/fuel_tools/ModelIter.hh" #include "ignition/fuel_tools/WorldIter.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::shared_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -103,4 +110,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/Model.hh b/include/ignition/fuel_tools/Model.hh index 71ca60ce..46648db0 100644 --- a/include/ignition/fuel_tools/Model.hh +++ b/include/ignition/fuel_tools/Model.hh @@ -25,6 +25,12 @@ #include "ignition/fuel_tools/Result.hh" #include "ignition/fuel_tools/ModelIdentifier.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::shared_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif namespace ignition { @@ -107,4 +113,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/ModelIdentifier.hh b/include/ignition/fuel_tools/ModelIdentifier.hh index 451d6173..f55cbd58 100644 --- a/include/ignition/fuel_tools/ModelIdentifier.hh +++ b/include/ignition/fuel_tools/ModelIdentifier.hh @@ -18,7 +18,6 @@ #ifndef IGNITION_FUEL_TOOLS_MODELIDENTIFIER_HH_ #define IGNITION_FUEL_TOOLS_MODELIDENTIFIER_HH_ -// #include #include #include #include @@ -27,6 +26,13 @@ #include "ignition/fuel_tools/Helpers.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -236,4 +242,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/ModelIter.hh b/include/ignition/fuel_tools/ModelIter.hh index b5744d20..834f5f5b 100644 --- a/include/ignition/fuel_tools/ModelIter.hh +++ b/include/ignition/fuel_tools/ModelIter.hh @@ -23,6 +23,13 @@ #include "ignition/fuel_tools/Helpers.hh" #include "ignition/fuel_tools/Model.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -74,4 +81,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/ModelIterPrivate.hh b/include/ignition/fuel_tools/ModelIterPrivate.hh index 5a39b510..497e1821 100644 --- a/include/ignition/fuel_tools/ModelIterPrivate.hh +++ b/include/ignition/fuel_tools/ModelIterPrivate.hh @@ -26,6 +26,13 @@ #include "ignition/fuel_tools/ModelIdentifier.hh" #include "ignition/fuel_tools/RestClient.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::vector +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -155,4 +162,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/ModelPrivate.hh b/include/ignition/fuel_tools/ModelPrivate.hh index 62e77b3f..9fa064e5 100644 --- a/include/ignition/fuel_tools/ModelPrivate.hh +++ b/include/ignition/fuel_tools/ModelPrivate.hh @@ -23,6 +23,13 @@ #include "ignition/fuel_tools/Helpers.hh" #include "ignition/fuel_tools/ModelIdentifier.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::string +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -39,4 +46,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/RestClient.hh b/include/ignition/fuel_tools/RestClient.hh index b83609ae..07056d00 100644 --- a/include/ignition/fuel_tools/RestClient.hh +++ b/include/ignition/fuel_tools/RestClient.hh @@ -24,6 +24,13 @@ #include "ignition/fuel_tools/Export.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::string +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -112,4 +119,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/Result.hh b/include/ignition/fuel_tools/Result.hh index e5d712a3..64fb89f7 100644 --- a/include/ignition/fuel_tools/Result.hh +++ b/include/ignition/fuel_tools/Result.hh @@ -23,6 +23,13 @@ #include "ignition/fuel_tools/Export.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -119,4 +126,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/WorldIdentifier.hh b/include/ignition/fuel_tools/WorldIdentifier.hh index a9406c37..d05c1397 100644 --- a/include/ignition/fuel_tools/WorldIdentifier.hh +++ b/include/ignition/fuel_tools/WorldIdentifier.hh @@ -23,6 +23,13 @@ #include "ignition/fuel_tools/Helpers.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -149,4 +156,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/WorldIter.hh b/include/ignition/fuel_tools/WorldIter.hh index c55194ec..d13e317d 100644 --- a/include/ignition/fuel_tools/WorldIter.hh +++ b/include/ignition/fuel_tools/WorldIter.hh @@ -22,6 +22,13 @@ #include "ignition/fuel_tools/Helpers.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::unique_ptr +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -69,4 +76,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/include/ignition/fuel_tools/WorldIterPrivate.hh b/include/ignition/fuel_tools/WorldIterPrivate.hh index f0897bef..1813078c 100644 --- a/include/ignition/fuel_tools/WorldIterPrivate.hh +++ b/include/ignition/fuel_tools/WorldIterPrivate.hh @@ -25,6 +25,13 @@ #include "ignition/fuel_tools/WorldIdentifier.hh" #include "ignition/fuel_tools/RestClient.hh" +#ifdef _WIN32 +// Disable warning C4251 which is triggered by +// std::vector +#pragma warning(push) +#pragma warning(disable: 4251) +#endif + namespace ignition { namespace fuel_tools @@ -129,4 +136,8 @@ namespace ignition } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2c1f80b..0c5e2d3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ ign_target_interface_include_directories(${PROJECT_LIBRARY_TARGET_NAME} ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS + ignition-cmake${IGN_CMAKE_VER}::utilities ignition-common${IGN_COMMON_MAJOR_VER}::ignition-common${IGN_COMMON_MAJOR_VER} TINYXML2::TINYXML2 ) diff --git a/src/ClientConfig_TEST.cc b/src/ClientConfig_TEST.cc index 06c269a7..18a1c581 100644 --- a/src/ClientConfig_TEST.cc +++ b/src/ClientConfig_TEST.cc @@ -27,6 +27,21 @@ using namespace ignition; using namespace fuel_tools; +///////////////////////////////////////////////// +/// \brief Helper to remove file according to OS, while Windows +/// has this issue: +/// https://github.com/ignitionrobotics/ign-common/issues/51 +/// \todo(anyone) Remove this once Windows issue is solved. +/// \param[in] _path Path to file to be removed. +void removeFileTemp(const std::string &_path) +{ +#ifndef _WIN32 + EXPECT_TRUE(ignition::common::removeFile(_path)); +#else + ignition::common::removeFile(_path); +#endif +} + ///////////////////////////////////////////////// /// \brief Get home directory. /// \return Home directory or empty string if home wasn't found. @@ -116,7 +131,7 @@ TEST(ClientConfig, CustomConfiguration) EXPECT_EQ("/tmp/ignition/fuel", config.CacheLocation()); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -147,7 +162,7 @@ TEST(ClientConfig, RepeatedServerConfiguration) EXPECT_FALSE(config.LoadConfig(testPath)); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -171,7 +186,7 @@ TEST(ClientConfig, NoServerUrlConfiguration) EXPECT_FALSE(config.LoadConfig(testPath)); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -195,7 +210,7 @@ TEST(ClientConfig, EmptyServerUrlConfiguration) EXPECT_FALSE(config.LoadConfig(testPath)); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -216,7 +231,7 @@ TEST(ClientConfig, NoCachePathConfiguration) EXPECT_FALSE(config.LoadConfig(testPath)); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -238,7 +253,7 @@ TEST(ClientConfig, EmptyCachePathConfiguration) EXPECT_FALSE(config.LoadConfig(testPath)); // Remove the configuration file. - EXPECT_TRUE(ignition::common::removeFile(testPath)); + removeFileTemp(testPath); } ///////////////////////////////////////////////// @@ -275,7 +290,11 @@ TEST(ClientConfig, AsString) std::string str = client.AsString(); igndbg << str << std::endl; +#ifndef _WIN32 EXPECT_NE(str.find(".ignition/fuel"), std::string::npos); +#else + EXPECT_NE(str.find(".ignition\\fuel"), std::string::npos); +#endif EXPECT_NE(str.find("https://fuel.ignitionrobotics.org"), std::string::npos); } diff --git a/src/CollectionIdentifier_TEST.cc b/src/CollectionIdentifier_TEST.cc index 8ed7dcbf..9ce08ce9 100644 --- a/src/CollectionIdentifier_TEST.cc +++ b/src/CollectionIdentifier_TEST.cc @@ -57,6 +57,7 @@ TEST(CollectionIdentifier, UniqueName) CollectionIdentifier id; id.SetName("hello"); id.SetOwner("alice"); +#ifndef _WIN32 id.SetServer(srv1); EXPECT_EQ("https://localhost:8001/alice/collections/hello", id.UniqueName()); @@ -65,6 +66,19 @@ TEST(CollectionIdentifier, UniqueName) id.SetServer(srv3); EXPECT_EQ("https://localhost:8003/alice/collections/hello", id.UniqueName()); +#else + id.SetServer(srv1); + EXPECT_EQ("https://localhost:8001\\alice\\collections\\hello", + id.UniqueName()); + + id.SetServer(srv2); + EXPECT_EQ("https://localhost:8002\\alice\\collections\\hello", + id.UniqueName()); + + id.SetServer(srv3); + EXPECT_EQ("https://localhost:8003\\alice\\collections\\hello", + id.UniqueName()); +#endif } ///////////////////////////////////////////////// @@ -118,6 +132,7 @@ TEST(CollectionIdentifier, AsString) common::Console::SetVerbosity(4); { CollectionIdentifier id; +#ifndef _WIN32 std::string str = "Name: \n"\ "Owner: \n"\ @@ -126,6 +141,16 @@ TEST(CollectionIdentifier, AsString) " URL: https://fuel.ignitionrobotics.org\n" " Version: 1.0\n" " API key: \n"; +#else + std::string str = + "Name: \n"\ + "Owner: \n"\ + "Unique name: https://fuel.ignitionrobotics.org\\\\collections\\\n" + "Server:\n" + " URL: https://fuel.ignitionrobotics.org\n" + " Version: 1.0\n" + " API key: \n"; +#endif EXPECT_EQ(str, id.AsString()); } diff --git a/src/FuelClient.cc b/src/FuelClient.cc index 3af37d9d..c73ef41c 100644 --- a/src/FuelClient.cc +++ b/src/FuelClient.cc @@ -400,9 +400,8 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id, } // Route - std::string route = ignition::common::joinPaths(_id.Owner(), - "models", _id.Name(), _id.VersionStr(), - _id.Name() + ".zip"); + std::string route = _id.Owner() + "/models/" + _id.Name() + "/" + + _id.VersionStr() + "/" + _id.Name() + ".zip"; ignmsg << "Downloading model [" << _id.UniqueName() << "]" << std::endl; diff --git a/src/FuelClient_TEST.cc b/src/FuelClient_TEST.cc index 9151a59b..b7ec6230 100644 --- a/src/FuelClient_TEST.cc +++ b/src/FuelClient_TEST.cc @@ -19,6 +19,8 @@ #include #include #include +#include + #include "ignition/fuel_tools/FuelClient.hh" #include "ignition/fuel_tools/ClientConfig.hh" #include "ignition/fuel_tools/Result.hh" @@ -43,48 +45,45 @@ using namespace ignition::fuel_tools; /// Taken from LocalCache_TEST void createLocalModel(ClientConfig &_conf) { - common::createDirectories( - "test_cache/localhost:8007/alice/models/My Model/2/meshes"); - common::createDirectories( - "test_cache/localhost:8007/alice/models/My Model/3/meshes"); + igndbg << "Creating local model in [" << common::cwd() << "]" << std::endl; + + auto modelPath = common::joinPaths( + "test_cache", "localhost:8007", "alice", "models", "My Model"); + + common::createDirectories(common::joinPaths(modelPath, "2", "meshes")); + common::createDirectories(common::joinPaths(modelPath, "3", "meshes")); { - std::ofstream fout( - "test_cache/localhost:8007/alice/models/My Model/2/model.config", + std::ofstream fout(common::joinPaths(modelPath, "2", "model.config"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/alice/models/My Model/2/model.config", - "test_cache/localhost:8007/alice/models/My Model/3/model.config"); + common::copyFile(common::joinPaths(modelPath, "2", "model.config"), + common::joinPaths(modelPath, "3", "model.config")); } { - std::ofstream fout( - "test_cache/localhost:8007/alice/models/My Model/2/model.sdf", + std::ofstream fout(common::joinPaths(modelPath, "2", "model.sdf"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/alice/models/My Model/2/model.sdf", - "test_cache/localhost:8007/alice/models/My Model/3/model.sdf"); + common::copyFile(common::joinPaths(modelPath, "2", "model.sdf"), + common::joinPaths(modelPath, "3", "model.sdf")); } { - std::ofstream fout( - "test_cache/localhost:8007/alice/models/My Model/2/meshes/model.dae", + std::ofstream fout(common::joinPaths(modelPath, "2", "meshes", "model.dae"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/alice/models/My Model/2/meshes/model.dae", - "test_cache/localhost:8007/alice/models/My Model/3/meshes/model.dae"); + common::copyFile(common::joinPaths(modelPath, "2", "meshes", "model.dae"), + common::joinPaths(modelPath, "3", "meshes", "model.dae")); } ignition::fuel_tools::ServerConfig srv; @@ -98,23 +97,23 @@ void createLocalModel(ClientConfig &_conf) /// Taken from LocalCache_TEST void createLocalWorld(ClientConfig &_conf) { - common::createDirectories( - "test_cache/localhost:8007/banana/worlds/My World/2"); - common::createDirectories( - "test_cache/localhost:8007/banana/worlds/My World/3"); + igndbg << "Creating local world in [" << common::cwd() << "]" << std::endl; + + auto worldPath = common::joinPaths( + "test_cache", "localhost:8007", "banana", "worlds", "My World"); + common::createDirectories(common::joinPaths(worldPath, "2")); + common::createDirectories(common::joinPaths(worldPath, "3")); { - std::ofstream fout( - "test_cache/localhost:8007/banana/worlds/My World/2/strawberry.world", + std::ofstream fout(common::joinPaths(worldPath, "2", "strawberry.world"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/banana/worlds/My World/2/strawberry.world", - "test_cache/localhost:8007/banana/worlds/My World/3/strawberry.world"); + common::copyFile(common::joinPaths(worldPath, "2", "strawberry.world"), + common::joinPaths(worldPath, "3", "strawberry.world")); } ignition::fuel_tools::ServerConfig srv; @@ -393,14 +392,16 @@ TEST_F(FuelClientTest, ParseModelFileURL) } ///////////////////////////////////////////////// -TEST_F(FuelClientTest, DownloadModel) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadModel)) { // Configure to use binary path as cache ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); // Create client FuelClient client(config); @@ -425,29 +426,23 @@ TEST_F(FuelClientTest, DownloadModel) EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res2); // Check it was downloaded to `2` - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2"); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2")); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2/" - "model.sdf")); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2/" - "model.config")); + auto modelPath = common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "chapulina", "models", "Test box"); + + EXPECT_EQ(path, common::joinPaths(modelPath, "2")); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2"))); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2", "model.sdf"))); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2", + "model.config"))); // Check it wasn't downloaded to model root directory - EXPECT_FALSE(common::exists( - "test_cache/fuel.ignitionrobotics.org/chapulina/models/" - "Test box/model.config")); + EXPECT_FALSE(common::exists(common::joinPaths(modelPath, "model.config"))); // Check it is cached Result res3 = client.CachedModel(url, cachedPath); EXPECT_TRUE(res3); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res3); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2", - cachedPath); + EXPECT_EQ(common::joinPaths(modelPath, "2"), cachedPath); } // Download model with pbr paths from URL and check that paths are fixed @@ -469,33 +464,26 @@ TEST_F(FuelClientTest, DownloadModel) EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res2); // Check it was downloaded to `2` - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/iche033/models/Rescue Randy/2"); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/iche033/models/Rescue Randy/2")); - const std::string modelSdfPath = - "test_cache/fuel.ignitionrobotics.org/iche033/models/Rescue Randy/2/" - "model.sdf"; - EXPECT_TRUE(common::exists(modelSdfPath)); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/iche033/models/Rescue Randy/2/" - "model.config")); + auto modelPath = common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "iche033", "models", "Rescue Randy"); + + EXPECT_EQ(path, common::joinPaths(modelPath, "2")); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2"))); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2", "model.sdf"))); + EXPECT_TRUE(common::exists(common::joinPaths(modelPath, "2", + "model.config"))); // Check it wasn't downloaded to model root directory - EXPECT_FALSE(common::exists( - "test_cache/fuel.ignitionrobotics.org/iche033/models/" - "Rescue Randy/model.config")); + EXPECT_FALSE(common::exists(common::joinPaths(modelPath, "model.config"))); // Check it is cached Result res3 = client.CachedModel(url, cachedPath); EXPECT_TRUE(res3); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res3); - EXPECT_EQ(common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/iche033/models/Rescue Randy/2", - cachedPath); + EXPECT_EQ(common::joinPaths(modelPath, "2"), cachedPath); // Check that URIs have been updated. - std::ifstream ifs(modelSdfPath); + std::ifstream ifs(common::joinPaths(modelPath, "2", "model.sdf")); std::string modelSdf((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_EQ(std::string::npos, modelSdf.find("model://")); @@ -533,14 +521,16 @@ TEST_F(FuelClientTest, DownloadModel) } ///////////////////////////////////////////////// -TEST_F(FuelClientTest, CachedModel) +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedModel)) { // Configure to use binary path as cache and populate it ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocalModel(config); // Create client @@ -554,8 +544,8 @@ TEST_F(FuelClientTest, CachedModel) auto result = client.CachedModel(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/alice/models/My Model/3", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", "localhost:8007", + "alice", "models", "My Model", "3"), path); } // Cached model (tip) @@ -565,8 +555,8 @@ TEST_F(FuelClientTest, CachedModel) auto result = client.CachedModel(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/alice/models/My Model/3", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", "localhost:8007", + "alice", "models", "My Model", "3"), path); } // Cached model (version number) @@ -576,8 +566,8 @@ TEST_F(FuelClientTest, CachedModel) auto result = client.CachedModel(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/alice/models/My Model/2", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", "localhost:8007", + "alice", "models", "My Model", "2"), path); } // Cached model file (tip) @@ -588,8 +578,8 @@ TEST_F(FuelClientTest, CachedModel) auto result = client.CachedModelFile(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/alice/models/My Model/3/model.sdf", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", "localhost:8007", + "alice", "models", "My Model", "3", "model.sdf"), path); } // Deeper cached model file @@ -600,9 +590,8 @@ TEST_F(FuelClientTest, CachedModel) auto result = client.CachedModelFile(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/alice/models/My Model/2/meshes/model.dae", - path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", "localhost:8007", + "alice", "models", "My Model", "2", "meshes", "model.dae"), path); } // Non-cached model @@ -922,7 +911,9 @@ TEST_F(FuelClientTest, ParseWorldFileUrl) } ////////////////////////////////////////////////// -TEST_F(FuelClientTest, DownloadWorld) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadWorld)) { // Configure to use binary path as cache ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); @@ -935,7 +926,7 @@ TEST_F(FuelClientTest, DownloadWorld) ClientConfig config; config.AddServer(server); - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); // Create client FuelClient client(config); @@ -960,27 +951,21 @@ TEST_F(FuelClientTest, DownloadWorld) EXPECT_EQ(Result(ResultType::FETCH), res2); // Check it was downloaded to `1` - EXPECT_EQ(path, common::cwd() + - "/test_cache/fuel.ignitionrobotics.org/OpenRobotics/worlds/" - "Test world/2"); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/OpenRobotics/worlds/" - "Test world/2")); - EXPECT_TRUE(common::exists( - "test_cache/fuel.ignitionrobotics.org/OpenRobotics/worlds/" - "Test world/2/test.world")); + auto worldPath = common::joinPaths(common::cwd(), "test_cache", + "fuel.ignitionrobotics.org", "OpenRobotics", "worlds", "Test world"); + + EXPECT_EQ(path, common::joinPaths(worldPath, "2")); + EXPECT_TRUE(common::exists(common::joinPaths(worldPath, "2"))); + EXPECT_TRUE(common::exists(common::joinPaths(worldPath, "2", "test.sdf"))); // Check it wasn't downloaded to world root directory - EXPECT_FALSE(common::exists( - "test_cache/fuel.ignitionrobotics.org/" + - std::string("OpenRobotics/worlds/Test world/test.world"))); + EXPECT_FALSE(common::exists(common::joinPaths(worldPath, "test.sdf"))); // Check it is cached auto res3 = client.CachedWorld(url, cachedPath); EXPECT_TRUE(res3); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), res3); - EXPECT_EQ(common::cwd() + "/test_cache/fuel.ignitionrobotics.org" - "/OpenRobotics/worlds/Test world/2", cachedPath); + EXPECT_EQ(common::joinPaths(worldPath, "2"), cachedPath); } // Try using nonexistent URL @@ -1004,14 +989,16 @@ TEST_F(FuelClientTest, DownloadWorld) } ///////////////////////////////////////////////// -TEST_F(FuelClientTest, CachedWorld) +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedWorld)) { // Configure to use binary path as cache and populate it ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocalWorld(config); // Create client @@ -1025,8 +1012,8 @@ TEST_F(FuelClientTest, CachedWorld) auto result = client.CachedWorld(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/banana/worlds/My World/3", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "localhost:8007", "banana", "worlds", "My World", "3"), path); } // Cached world (tip) @@ -1036,8 +1023,8 @@ TEST_F(FuelClientTest, CachedWorld) auto result = client.CachedWorld(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/banana/worlds/My World/3", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "localhost:8007", "banana", "worlds", "My World", "3"), path); } // Cached world (version number) @@ -1047,8 +1034,8 @@ TEST_F(FuelClientTest, CachedWorld) auto result = client.CachedWorld(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/banana/worlds/My World/2", path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "localhost:8007", "banana", "worlds", "My World", "2"), path); } // Cached world file (tip) @@ -1059,9 +1046,9 @@ TEST_F(FuelClientTest, CachedWorld) auto result = client.CachedWorldFile(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/banana/worlds/My World/3/strawberry.world", - path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "localhost:8007", "banana", "worlds", "My World", "3", + "strawberry.world"), path); } // Deeper cached world file @@ -1072,9 +1059,9 @@ TEST_F(FuelClientTest, CachedWorld) auto result = client.CachedWorldFile(url, path); EXPECT_TRUE(result); EXPECT_EQ(Result(ResultType::FETCH_ALREADY_EXISTS), result); - EXPECT_EQ(common::cwd() + - "/test_cache/localhost:8007/banana/worlds/My World/2/strawberry.world", - path); + EXPECT_EQ(common::joinPaths(common::cwd(), "test_cache", + "localhost:8007", "banana", "worlds", "My World", "2", + "strawberry.world"), path); } // Non-cached world @@ -1191,10 +1178,12 @@ TEST_F(FuelClientTest, WorldDetails) } ///////////////////////////////////////////////// -TEST_F(FuelClientTest, Models) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) { ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); FuelClient client(config); ServerConfig serverConfig; ModelIdentifier modelId; @@ -1223,10 +1212,12 @@ TEST_F(FuelClientTest, Models) } ///////////////////////////////////////////////// -TEST_F(FuelClientTest, Worlds) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_F(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Worlds)) { ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); FuelClient client(config); ServerConfig serverConfig; WorldIdentifier worldId; diff --git a/src/Interface_TEST.cc b/src/Interface_TEST.cc index 39f77baa..1d781ac0 100644 --- a/src/Interface_TEST.cc +++ b/src/Interface_TEST.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "ignition/fuel_tools/ClientConfig.hh" #include "ignition/fuel_tools/FuelClient.hh" #include "ignition/fuel_tools/Interface.hh" @@ -36,7 +37,9 @@ using namespace ignition; using namespace ignition::fuel_tools; ///////////////////////////////////////////////// -TEST(Interface, FetchResources) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(Interface, IGN_UTILS_TEST_DISABLED_ON_WIN32(FetchResources)) { common::Console::SetVerbosity(4); @@ -45,7 +48,7 @@ TEST(Interface, FetchResources) common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig config; - config.SetCacheLocation(common::cwd() + "/test_cache"); + config.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); // Create client FuelClient client(config); diff --git a/src/LocalCache_TEST.cc b/src/LocalCache_TEST.cc index 9fdeb13c..7317023d 100644 --- a/src/LocalCache_TEST.cc +++ b/src/LocalCache_TEST.cc @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include "ignition/fuel_tools/ClientConfig.hh" #include "ignition/fuel_tools/LocalCache.hh" @@ -42,35 +44,49 @@ using namespace fuel_tools; /// \brief Creates a directory structure in the build directory with 6 models void createLocal6Models(ClientConfig &_conf) { - common::createDirectories("test_cache/localhost:8001/alice/models/am1/2"); - common::createDirectories("test_cache/localhost:8001/alice/models/am2/1"); - common::createDirectories("test_cache/localhost:8001/bob/models/bm1/1"); - common::createDirectories("test_cache/localhost:8001/bob/models/bm2/2"); - common::createDirectories("test_cache/localhost:8001/trudy/models/tm1/3"); - common::createDirectories("test_cache/localhost:8001/trudy/models/tm2/2"); - - std::ofstream fout( - "test_cache/localhost:8001/alice/models/am1/2/model.config", + igndbg << "Creating 6 local models in [" << common::cwd() << "]" << std::endl; + + auto serverPath = common::joinPaths("test_cache", "localhost:8001"); + common::createDirectories(common::joinPaths(serverPath, + "alice", "models", "am1", "2")); + common::createDirectories(common::joinPaths(serverPath, + "alice", "models", "am2", "1")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "models", "bm1", "1")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "models", "bm2", "2")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "models", "tm1", "3")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "models", "tm2", "2")); + + std::ofstream fout(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8001/alice/models/am1/2/model.config", - "test_cache/localhost:8001/alice/models/am2/1/model.config"); - common::copyFile( - "test_cache/localhost:8001/alice/models/am1/2/model.config", - "test_cache/localhost:8001/bob/models/bm1/1/model.config"); - common::copyFile( - "test_cache/localhost:8001/alice/models/am1/2/model.config", - "test_cache/localhost:8001/bob/models/bm2/2/model.config"); - common::copyFile( - "test_cache/localhost:8001/alice/models/am1/2/model.config", - "test_cache/localhost:8001/trudy/models/tm1/3/model.config"); - common::copyFile( - "test_cache/localhost:8001/alice/models/am1/2/model.config", - "test_cache/localhost:8001/trudy/models/tm2/2/model.config"); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "alice", "models", "am2", "1", "model.config")); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "bob", "models", "bm1", "1", "model.config")); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "bob", "models", "bm2", "2", "model.config")); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "trudy", "models", "tm1", "3", "model.config")); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "trudy", "models", "tm2", "2", "model.config")); ignition::fuel_tools::ServerConfig srv; srv.SetUrl(common::URI("http://localhost:8001/")); @@ -80,23 +96,31 @@ void createLocal6Models(ClientConfig &_conf) /// \brief Creates a directory structure in the build directory with 3 models void createLocal3Models(ClientConfig &_conf) { - common::createDirectories("test_cache/localhost:8007/alice/models/am1/2"); - common::createDirectories("test_cache/localhost:8007/bob/models/bm1/1"); - common::createDirectories("test_cache/localhost:8007/trudy/models/tm1/3"); - - std::ofstream fout( - "test_cache/localhost:8007/alice/models/am1/2/model.config", + igndbg << "Creating 3 local models in [" << common::cwd() << "]" << std::endl; + + auto serverPath = common::joinPaths("test_cache", "localhost:8007"); + common::createDirectories(common::joinPaths(serverPath, + "alice", "models", "am1", "2")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "models", "bm1", "1")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "models", "tm1", "3")); + + std::ofstream fout(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/alice/models/am1/2/model.config", - "test_cache/localhost:8007/bob/models/bm1/1/model.config"); - common::copyFile( - "test_cache/localhost:8007/alice/models/am1/2/model.config", - "test_cache/localhost:8007/trudy/models/tm1/3/model.config"); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "bob", "models", "bm1", "1", "model.config")); + common::copyFile(common::joinPaths(serverPath, + "alice", "models", "am1", "2", "model.config"), + common::joinPaths(serverPath, + "trudy", "models", "tm1", "3", "model.config")); ignition::fuel_tools::ServerConfig srv; srv.SetUrl(ignition::common::URI("http://localhost:8007/")); @@ -106,35 +130,49 @@ void createLocal3Models(ClientConfig &_conf) /// \brief Creates a directory structure in the build directory with 6 worlds void createLocal6Worlds(ClientConfig &_conf) { - common::createDirectories("test_cache/localhost:8001/alice/worlds/am1/2"); - common::createDirectories("test_cache/localhost:8001/alice/worlds/am2/1"); - common::createDirectories("test_cache/localhost:8001/bob/worlds/bm1/1"); - common::createDirectories("test_cache/localhost:8001/bob/worlds/bm2/2"); - common::createDirectories("test_cache/localhost:8001/trudy/worlds/tm1/3"); - common::createDirectories("test_cache/localhost:8001/trudy/worlds/tm2/2"); - - std::ofstream fout( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", + igndbg << "Creating 6 local worlds in [" << common::cwd() << "]" << std::endl; + + auto serverPath = common::joinPaths("test_cache", "localhost:8001"); + common::createDirectories(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2")); + common::createDirectories(common::joinPaths(serverPath, + "alice", "worlds", "am2", "1")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "worlds", "bm1", "1")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "worlds", "bm2", "2")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "worlds", "tm1", "3")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "worlds", "tm2", "2")); + + std::ofstream fout(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", - "test_cache/localhost:8001/alice/worlds/am2/1/world.world"); - common::copyFile( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", - "test_cache/localhost:8001/bob/worlds/bm1/1/world.world"); - common::copyFile( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", - "test_cache/localhost:8001/bob/worlds/bm2/2/world.world"); - common::copyFile( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", - "test_cache/localhost:8001/trudy/worlds/tm1/3/world.world"); - common::copyFile( - "test_cache/localhost:8001/alice/worlds/am1/2/world.world", - "test_cache/localhost:8001/trudy/worlds/tm2/2/world.world"); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "alice", "worlds", "am2", "1", "world.world")); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "bob", "worlds", "bm1", "1", "world.world")); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "bob", "worlds", "bm2", "2", "world.world")); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "trudy", "worlds", "tm1", "3", "world.world")); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "trudy", "worlds", "tm2", "2", "world.world")); ignition::fuel_tools::ServerConfig srv; srv.SetUrl(ignition::common::URI("http://localhost:8001/")); @@ -144,38 +182,57 @@ void createLocal6Worlds(ClientConfig &_conf) /// \brief Creates a directory structure in the build directory with 3 worlds void createLocal3Worlds(ClientConfig &_conf) { - common::createDirectories("test_cache/localhost:8007/alice/worlds/am1/2"); - common::createDirectories("test_cache/localhost:8007/bob/worlds/bm1/1"); - common::createDirectories("test_cache/localhost:8007/trudy/worlds/tm1/3"); - - std::ofstream fout( - "test_cache/localhost:8007/alice/worlds/am1/2/world.world", + igndbg << "Creating 3 local worlds in [" << common::cwd() << "]" << std::endl; + + auto serverPath = common::joinPaths("test_cache", "localhost:8007"); + common::createDirectories(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2")); + common::createDirectories(common::joinPaths(serverPath, + "bob", "worlds", "bm1", "1")); + common::createDirectories(common::joinPaths(serverPath, + "trudy", "worlds", "tm1", "3")); + + std::ofstream fout(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), std::ofstream::trunc); fout << ""; fout.flush(); fout.close(); - common::copyFile( - "test_cache/localhost:8007/alice/worlds/am1/2/world.world", - "test_cache/localhost:8007/bob/worlds/bm1/1/world.world"); - common::copyFile( - "test_cache/localhost:8007/alice/worlds/am1/2/world.world", - "test_cache/localhost:8007/trudy/worlds/tm1/3/world.world"); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "bob", "worlds", "bm1", "1", "world.world")); + common::copyFile(common::joinPaths(serverPath, + "alice", "worlds", "am1", "2", "world.world"), + common::joinPaths(serverPath, + "trudy", "worlds", "tm1", "3", "world.world")); ignition::fuel_tools::ServerConfig srv; srv.SetUrl(common::URI("http://localhost:8007/")); _conf.AddServer(srv); } +///////////////////////////////////////////////// +class LocalCacheTest : public ::testing::Test +{ + public: void SetUp() override + { + ignition::common::Console::SetVerbosity(4); + } +}; + ///////////////////////////////////////////////// /// \brief Iterate through all models in cache -TEST(LocalCache, AllModels) +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllModels)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Models(conf); createLocal3Models(conf); @@ -196,14 +253,17 @@ TEST(LocalCache, AllModels) ///////////////////////////////////////////////// /// \brief Get all models that match some fields -TEST(LocalCache, MatchingModels) +/// \brief Iterate through all models in cache +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModels)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; conf.Clear(); - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Models(conf); createLocal3Models(conf); @@ -241,13 +301,16 @@ TEST(LocalCache, MatchingModels) ///////////////////////////////////////////////// /// \brief Get a specific model from cache -TEST(LocalCache, MatchingModel) +/// \brief Iterate through all models in cache +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingModel)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Models(conf); ignition::fuel_tools::LocalCache cache(&conf); @@ -296,13 +359,16 @@ TEST(LocalCache, MatchingModel) ///////////////////////////////////////////////// /// \brief Iterate through all worlds in cache -TEST(LocalCache, AllWorlds) +/// \brief Iterate through all models in cache +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllWorlds)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Worlds(conf); createLocal3Worlds(conf); @@ -323,14 +389,17 @@ TEST(LocalCache, AllWorlds) ///////////////////////////////////////////////// /// \brief Get all worlds that match some fields -TEST(LocalCache, MatchingWorlds) +/// \brief Iterate through all models in cache +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingWorlds)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; conf.Clear(); - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Worlds(conf); createLocal3Worlds(conf); @@ -356,13 +425,16 @@ TEST(LocalCache, MatchingWorlds) ///////////////////////////////////////////////// /// \brief Get a specific world from cache -TEST(LocalCache, MatchingWorld) +/// \brief Iterate through all models in cache +// Windows doesn't support colons in filenames +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/106 +TEST_F(LocalCacheTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(MatchingWorld)) { ASSERT_EQ(0, ChangeDirectory(PROJECT_BINARY_PATH)); common::removeAll("test_cache"); common::createDirectories("test_cache"); ClientConfig conf; - conf.SetCacheLocation(common::cwd() + "/test_cache"); + conf.SetCacheLocation(common::joinPaths(common::cwd(), "test_cache")); createLocal6Worlds(conf); ignition::fuel_tools::LocalCache cache(&conf); diff --git a/src/ModelIdentifier_TEST.cc b/src/ModelIdentifier_TEST.cc index 896e59cb..3be41597 100644 --- a/src/ModelIdentifier_TEST.cc +++ b/src/ModelIdentifier_TEST.cc @@ -66,13 +66,16 @@ TEST(ModelIdentifier, UniqueName) id.SetName("hello"); id.SetOwner("alice"); id.SetServer(srv1); - EXPECT_EQ("https://localhost:8001/alice/models/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("https://localhost:8001", "alice", "models", + "hello"), id.UniqueName()); id.SetServer(srv2); - EXPECT_EQ("https://localhost:8002/alice/models/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("https://localhost:8002", "alice", "models", + "hello"), id.UniqueName()); id.SetServer(srv3); - EXPECT_EQ("https://localhost:8003/alice/models/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("https://localhost:8003", "alice", "models", + "hello"), id.UniqueName()); } ///////////////////////////////////////////////// @@ -141,6 +144,7 @@ TEST(ModelIdentifier, AsString) common::Console::SetVerbosity(4); { ModelIdentifier id; +#ifndef _WIN32 std::string str = "Name: \n"\ "Owner: \n"\ @@ -159,6 +163,26 @@ TEST(ModelIdentifier, AsString) " URL: https://fuel.ignitionrobotics.org\n" " Version: 1.0\n" " API key: \n"; +#else + std::string str = + "Name: \n"\ + "Owner: \n"\ + "Version: tip\n"\ + "Unique name: https://fuel.ignitionrobotics.org\\\\models\\\n" + "Description: \n" + "File size: 0\n" + "Upload date: 0\n" + "Likes: 0\n" + "Downloads: 0\n" + "License name: \n" + "License URL: \n" + "License image URL: \n" + "Tags: \n" + "Server:\n" + " URL: https://fuel.ignitionrobotics.org\n" + " Version: 1.0\n" + " API key: \n"; +#endif EXPECT_EQ(str, id.AsString()); } diff --git a/src/WorldIdentifier_TEST.cc b/src/WorldIdentifier_TEST.cc index c9310144..caac57be 100644 --- a/src/WorldIdentifier_TEST.cc +++ b/src/WorldIdentifier_TEST.cc @@ -57,13 +57,16 @@ TEST(WorldIdentifier, UniqueName) id.SetName("hello"); id.SetOwner("alice"); id.SetServer(srv1); - EXPECT_EQ("localhost:8001/alice/worlds/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("localhost:8001", "alice", "worlds", "hello"), + id.UniqueName()); id.SetServer(srv2); - EXPECT_EQ("localhost:8002/alice/worlds/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("localhost:8002", "alice", "worlds", "hello"), + id.UniqueName()); id.SetServer(srv3); - EXPECT_EQ("localhost:8003/alice/worlds/hello", id.UniqueName()); + EXPECT_EQ(common::joinPaths("localhost:8003", "alice", "worlds", "hello"), + id.UniqueName()); } ///////////////////////////////////////////////// @@ -112,6 +115,7 @@ TEST(WorldIdentifier, AsString) common::Console::SetVerbosity(4); { WorldIdentifier id; +#ifndef _WIN32 std::string str = "Name: \n"\ "Owner: \n"\ @@ -122,6 +126,18 @@ TEST(WorldIdentifier, AsString) " URL: https://fuel.ignitionrobotics.org\n" " Version: 1.0\n" " API key: \n"; +#else + std::string str = + "Name: \n"\ + "Owner: \n"\ + "Version: tip\n"\ + "Unique name: fuel.ignitionrobotics.org\\\\worlds\\\n" + "Local path: \n" + "Server:\n" + " URL: https://fuel.ignitionrobotics.org\n" + " Version: 1.0\n" + " API key: \n"; +#endif EXPECT_EQ(str, id.AsString()); } diff --git a/src/Zip.cc b/src/Zip.cc index 90469f0f..4ac51e79 100644 --- a/src/Zip.cc +++ b/src/Zip.cc @@ -136,8 +136,9 @@ bool Zip::Extract(const std::string &_src, continue; } - // check if it's a directory - std::string dst = ignition::common::joinPaths(_dst, sb.name); + auto entryname = std::string(sb.name); + common::changeFromUnixPath(entryname); + std::string dst = ignition::common::joinPaths(_dst, entryname); // Create intermediate directories if needed. std::string dirname = dst; @@ -171,6 +172,8 @@ bool Zip::Extract(const std::string &_src, else file.write(buf, len); + igndbg << "Created file [" << dst << "]" << std::endl; + delete[] buf; file.close(); zip_fclose(zf); diff --git a/src/Zip_TEST.cc b/src/Zip_TEST.cc index d21cedd4..7adea596 100644 --- a/src/Zip_TEST.cc +++ b/src/Zip_TEST.cc @@ -138,15 +138,25 @@ bool createNewEmptyFile(const std::string &_filename) #endif #include +#include #include #include "ignition/fuel_tools/Zip.hh" using namespace ignition; using namespace fuel_tools; +///////////////////////////////////////////////// +class ZipTest : public ::testing::Test +{ + public: void SetUp() override + { + ignition::common::Console::SetVerbosity(4); + } +}; + ///////////////////////////////////////////////// /// \brief Test basic API -TEST(Zip, API) +TEST_F(ZipTest, API) { // Extract invalid paths EXPECT_FALSE(Zip::Extract("", "")); @@ -159,7 +169,7 @@ TEST(Zip, API) ///////////////////////////////////////////////// /// \brief Test compress and extract -TEST(Zip, CompressAndExtract) +TEST_F(ZipTest, CompressAndExtract) { std::string newTempDir; ASSERT_TRUE(createAndSwitchToTempDir(newTempDir)); diff --git a/src/ign_src_TEST.cc b/src/ign_src_TEST.cc index 7151e6ae..4f2ae116 100644 --- a/src/ign_src_TEST.cc +++ b/src/ign_src_TEST.cc @@ -21,10 +21,13 @@ #include #include +#include #include "ign.hh" #include "test/test_config.h" // NOLINT(build/include) +using namespace ignition; + // Std streams static std::streambuf *g_stdOutFile; static std::streambuf *g_stdErrFile; @@ -75,7 +78,9 @@ TEST(CmdLine, ModelListFail) } ///////////////////////////////////////////////// -TEST(CmdLine, ModelListConfigServerUgly) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerUgly)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -93,7 +98,9 @@ TEST(CmdLine, ModelListConfigServerUgly) } ///////////////////////////////////////////////// -TEST(CmdLine, ModelListCustomServerPretty) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelListConfigServerPretty)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -120,7 +127,10 @@ TEST(CmdLine, ModelListCustomServerPretty) } ///////////////////////////////////////////////// -TEST(CmdLine, ModelListCustomServerPrettyOwner) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32( + ModelListConfigServerPrettyOwner)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -187,7 +197,9 @@ TEST(CmdLine, ModelDownloadWrongUrl) } ///////////////////////////////////////////////// -TEST(CmdLine, ModelDownloadUnversioned) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(ModelDownloadUnversioned)) { cmdVerbosity("4"); @@ -222,7 +234,9 @@ TEST(CmdLine, ModelDownloadUnversioned) } ///////////////////////////////////////////////// -TEST(CmdLine, DownloadConfigCache) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(DownloadConfigCache)) { cmdVerbosity("4"); @@ -232,8 +246,8 @@ TEST(CmdLine, DownloadConfigCache) // Test config std::ofstream ofs; - std::string testPath = - std::string(PROJECT_BINARY_PATH) + "/test_cache/test_conf.yaml"; + std::string testPath = common::joinPaths( + std::string(PROJECT_BINARY_PATH), "test_cache", "test_conf.yaml"); ofs.open(testPath, std::ofstream::out | std::ofstream::app); ofs << "---" << std::endl @@ -261,13 +275,13 @@ TEST(CmdLine, DownloadConfigCache) EXPECT_TRUE(stdErrBuffer.str().empty()) << stdErrBuffer.str(); // Check files - EXPECT_TRUE(ignition::common::isDirectory(std::string(PROJECT_BINARY_PATH) + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box")); - EXPECT_TRUE(ignition::common::isDirectory(std::string(PROJECT_BINARY_PATH) + - "/test_cache/fuel.ignitionrobotics.org/chapulina/models/Test box/2")); - EXPECT_TRUE(ignition::common::isFile(std::string(PROJECT_BINARY_PATH) + - std::string("/test_cache/fuel.ignitionrobotics.org/chapulina/models") + - "/Test box/2/model.sdf")); + auto modelPath = common::joinPaths(std::string(PROJECT_BINARY_PATH), + "test_cache", "fuel.ignitionrobotics.org", "chapulina", "models", + "Test box"); + EXPECT_TRUE(ignition::common::isDirectory(modelPath)); + EXPECT_TRUE(ignition::common::isDirectory(common::joinPaths(modelPath, "2"))); + EXPECT_TRUE(ignition::common::isFile(common::joinPaths(modelPath, "2", + "model.sdf"))); clearIOStreams(stdOutBuffer, stdErrBuffer); restoreIO(); @@ -291,7 +305,10 @@ TEST(CmdLine, WorldListFail) } ///////////////////////////////////////////////// -TEST(CmdLine, WorldListConfigServerUgly) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( + WorldListConfigServerUgly)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -311,7 +328,10 @@ TEST(CmdLine, WorldListConfigServerUgly) } ///////////////////////////////////////////////// -TEST(CmdLine, WorldListCustomServerPretty) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( + WorldListConfigServerPretty)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -368,7 +388,10 @@ TEST(CmdLine, WorldListCustomServerPrettyOwner) } ///////////////////////////////////////////////// -TEST(CmdLine, WorldDownloadBadUrl) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( + WorldDownloadBadUrl)) { std::stringstream stdOutBuffer; std::stringstream stdErrBuffer; @@ -403,7 +426,10 @@ TEST(CmdLine, WorldDownloadWrongUrl) } ///////////////////////////////////////////////// -TEST(CmdLine, WorldDownloadUnversioned) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST(FuelClientTest, IGN_UTILS_TEST_DISABLED_ON_WIN32( + WorldDownloadUnversioned)) { cmdVerbosity("4"); @@ -446,7 +472,9 @@ INSTANTIATE_TEST_CASE_P(CollectionTest, DownloadCollectionTest, ::testing::Values(1, 2, 16),); // NOLINT ///////////////////////////////////////////////// -TEST_P(DownloadCollectionTest, AllItems) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(AllItems)) { cmdVerbosity("4"); @@ -483,10 +511,10 @@ TEST_P(DownloadCollectionTest, AllItems) EXPECT_TRUE(ignition::common::isDirectory( "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE")); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE/1")); + "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE/2")); EXPECT_TRUE(ignition::common::isFile( std::string("test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/") + - "TEAMBASE/1/model.sdf")); + "TEAMBASE/2/model.sdf")); // World: Test World EXPECT_TRUE(ignition::common::isDirectory( @@ -512,7 +540,9 @@ TEST_P(DownloadCollectionTest, AllItems) ///////////////////////////////////////////////// /// Download only models -TEST_P(DownloadCollectionTest, Models) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Models)) { cmdVerbosity("4"); @@ -549,10 +579,10 @@ TEST_P(DownloadCollectionTest, Models) EXPECT_TRUE(ignition::common::isDirectory( "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE")); EXPECT_TRUE(ignition::common::isDirectory( - "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE/1")); + "test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/TEAMBASE/2")); EXPECT_TRUE(ignition::common::isFile( std::string("test_cache/fuel.ignitionrobotics.org/OpenRobotics/models/") + - "TEAMBASE/1/model.sdf")); + "TEAMBASE/2/model.sdf")); // World: Test World EXPECT_FALSE(ignition::common::isDirectory( @@ -567,7 +597,9 @@ TEST_P(DownloadCollectionTest, Models) ///////////////////////////////////////////////// /// Download only worlds -TEST_P(DownloadCollectionTest, Worlds) +// Protocol "https" not supported or disabled in libcurl for Windows +// https://github.com/ignitionrobotics/ign-fuel-tools/issues/105 +TEST_P(DownloadCollectionTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Worlds)) { cmdVerbosity("4"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e3cc9333..a6179166 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,7 +10,10 @@ configure_file (test_config.h.in ${PROJECT_BINARY_DIR}/test/test_config.h) # Build gtest add_library(gtest STATIC gtest/src/gtest-all.cc) add_library(gtest_main STATIC gtest/src/gtest_main.cc) -target_link_libraries(gtest_main gtest) +target_link_libraries( + gtest_main gtest + ignition-cmake${IGN_CMAKE_VER}::utilities +) set(GTEST_LIBRARY "${PROJECT_BINARY_DIR}/test/libgtest.a") set(GTEST_MAIN_LIBRARY "${PROJECT_BINARY_DIR}/test/libgtest_main.a") diff --git a/test/integration/zip.cc b/test/integration/zip.cc index e7318199..6691426c 100644 --- a/test/integration/zip.cc +++ b/test/integration/zip.cc @@ -17,6 +17,7 @@ #include +#include #include #include "ignition/fuel_tools/Zip.hh" @@ -25,30 +26,41 @@ using namespace ignition; using namespace fuel_tools; +///////////////////////////////////////////////// +class ZipIntegrationTest : public ::testing::Test +{ + public: void SetUp() override + { + ignition::common::Console::SetVerbosity(4); + } +}; + ///////////////////////////////////////////////// // Test compressing files in a directory into a zip archive -TEST(Zip, Extract) +TEST_F(ZipIntegrationTest, Extract) { // extract a compressed archive std::string dst = std::string(PROJECT_BINARY_PATH); - std::string archivePath = std::string(TEST_PATH) + "/media/box.zip"; + common::changeFromUnixPath(dst); + std::string archivePath = common::joinPaths(std::string(TEST_PATH), "media", + "box.zip"); EXPECT_TRUE(Zip::Extract(archivePath, dst)); // check extracted contents - std::string boxPath = dst + "/box"; - EXPECT_TRUE(ignition::common::exists(boxPath)); - EXPECT_TRUE(ignition::common::isDirectory(boxPath)); + std::string boxPath = common::joinPaths(dst, "box"); + EXPECT_TRUE(ignition::common::exists(boxPath)) << boxPath; + EXPECT_TRUE(ignition::common::isDirectory(boxPath)) << boxPath; - std::string boxFilePath = boxPath +"/file"; - EXPECT_TRUE(ignition::common::exists(boxFilePath)); - EXPECT_TRUE(ignition::common::isFile(boxFilePath)); + std::string boxFilePath = common::joinPaths(boxPath, "file"); + EXPECT_TRUE(ignition::common::exists(boxFilePath)) << boxFilePath; + EXPECT_TRUE(ignition::common::isFile(boxFilePath)) << boxFilePath; - std::string boxDirPath = boxPath +"/dir"; - EXPECT_TRUE(ignition::common::exists(boxDirPath)); - EXPECT_TRUE(ignition::common::isDirectory(boxDirPath)); + std::string boxDirPath = common::joinPaths(boxPath, "dir"); + EXPECT_TRUE(ignition::common::exists(boxDirPath)) << boxDirPath; + EXPECT_TRUE(ignition::common::isDirectory(boxDirPath)) << boxDirPath; - std::string boxFile2Path = boxDirPath +"/file2"; - EXPECT_TRUE(ignition::common::exists(boxFile2Path)); + std::string boxFile2Path = common::joinPaths(boxDirPath, "file2"); + EXPECT_TRUE(ignition::common::exists(boxFile2Path)) << boxFile2Path; EXPECT_TRUE(ignition::common::isFile(boxFile2Path)); // cleanup @@ -58,11 +70,12 @@ TEST(Zip, Extract) ///////////////////////////////////////////////// // Test extracting a zip archive -TEST(Zip, Compress) +TEST_F(ZipIntegrationTest, Compress) { // compress a directory into a zip archive - std::string archivePath = std::string(PROJECT_BINARY_PATH) + "/box.zip"; - std::string src = std::string(TEST_PATH) + "/media/box"; + std::string archivePath = common::joinPaths( + std::string(PROJECT_BINARY_PATH), "box.zip"); + std::string src = common::joinPaths(std::string(TEST_PATH), "media", "box"); EXPECT_TRUE(Zip::Compress(src, archivePath)); EXPECT_TRUE(ignition::common::exists(archivePath)); @@ -73,19 +86,19 @@ TEST(Zip, Compress) EXPECT_TRUE(Zip::Extract(archivePath, dst)); // check extracted contents - std::string boxPath = dst + "/box"; + std::string boxPath = common::joinPaths(dst, "box"); EXPECT_TRUE(ignition::common::exists(boxPath)); EXPECT_TRUE(ignition::common::isDirectory(boxPath)); - std::string boxFilePath = boxPath +"/file"; + std::string boxFilePath = common::joinPaths(boxPath, "file"); EXPECT_TRUE(ignition::common::exists(boxFilePath)); EXPECT_TRUE(ignition::common::isFile(boxFilePath)); - std::string boxDirPath = boxPath +"/dir"; + std::string boxDirPath = common::joinPaths(boxPath, "dir"); EXPECT_TRUE(ignition::common::exists(boxDirPath)); EXPECT_TRUE(ignition::common::isDirectory(boxDirPath)); - std::string boxFile2Path = boxDirPath +"/file2"; + std::string boxFile2Path = common::joinPaths(boxDirPath, "file2"); EXPECT_TRUE(ignition::common::exists(boxFile2Path)); EXPECT_TRUE(ignition::common::isFile(boxFile2Path));