Skip to content

Commit

Permalink
Remove duplicated functionality from test_config
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Oct 31, 2023
1 parent e21d910 commit 0dc9fdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 78 deletions.
25 changes: 4 additions & 21 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,10 @@
#include "gz/transport/Publisher.hh"
#include "gz/transport/TransportTypes.hh"
#include "gz/transport/Uuid.hh"
#include "test_config.hh"

// Temporarily introduce a "DISABLED_ON_LINUX" macro.
// It currently does not exist upstream.
// This can be removed when it is in upstream gz-utils
// or the discovery WrongGzIp test passes on linux
#include <gz/utils/detail/ExtraTestMacros.hh>
#if defined __linux__
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
DETAIL_GZ_UTILS_ADD_DISABLED_PREFIX(TestName)
#else
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
TestName
#endif // defined __linux__
#include "gz/utils/ExtraTestMacros.hh"

#include "test_config.hh"

using namespace gz;
using namespace transport;
Expand Down Expand Up @@ -540,16 +530,9 @@ TEST(DiscoveryTest, TestActivity)
discovery1.TestActivity(proc2Uuid, false);
}

/// Logic to disable the following test via Linux
#if defined __linux__
#define TEST_NAME DISABLED_WrongIgnIp
#else
#define TEST_NAME WrongIgnIp
#endif // defined __linux__

//////////////////////////////////////////////////
/// \brief Check that a wrong GZ_IP value makes HostAddr() to return 127.0.0.1
TEST(DiscoveryTest, TEST_NAME)
TEST(DiscoveryTest, GZ_UTILS_TEST_DISABLED_ON_LINUX(WrongIgnIp))
{
// Save the current value of GZ_IP environment variable.
std::string gzIp;
Expand Down
60 changes: 3 additions & 57 deletions test/test_config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,8 @@
DETAIL_GZ_TRANSPORT_TEST_DIR
#endif

#ifndef __APPLE__
#if (!(defined(__clang__) || __unix__) || \
(defined(__clang__) && __cplusplus >= 201703L) || \
(__unix__ && __GNUC__ >= 8))
#define GZ_HAVE_FILESYSTEM
#endif

#ifdef GZ_HAVE_FILESYSTEM
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#endif

#include <climits>
#include <filesystem>
#include <iostream>
#include <random>
#include <string>
Expand All @@ -60,37 +47,6 @@

#include "gz/transport/Helpers.hh"

#if (_MSC_VER >= 1400) // Visual Studio 2005
#include <sstream>

/// \brief setenv/unstenv are not present in Windows. Define them to make
/// the code portable.
/// \param[in] _name Variable name.
/// \param[in] _value Value.
/// \param[in] _rewrite If 'name' does exist in the environment, then its
/// value is changed to 'value' if 'rewrite' is nonzero. If overwrite is
/// zero, then the value of 'name' is not changed.
/// /return 0 on success or -1 on error.
int setenv(const char *_name, const char *_value, int /*_rewrite*/)
{
std::stringstream sstr;
std::string name = _name;
std::string value = _value;
sstr << name << '=' << value;
return _putenv(sstr.str().c_str());
}

/// \brief Deletes an environment variable.
/// \param[in] _name Variable name.
void unsetenv(const char *_name)
{
std::stringstream sstr;
std::string name = _name;
sstr << name << '=';
_putenv(sstr.str().c_str());
}
#endif

namespace testing
{
/// \brief Join _str1 and _str2 considering both as storing system paths.
Expand All @@ -100,17 +56,7 @@ namespace testing
std::string portablePathUnion(const std::string &_str1,
const std::string &_str2)
{
#ifdef __APPLE__
// Ugly as hell but trying to avoid boost::filesystem
return _str1 + "/" + _str2;
#else
#ifdef GZ_HAVE_FILESYSTEM
using namespace std::filesystem;
#else
using namespace std::experimental::filesystem;
#endif
return (path(_str1) / path(_str2)).string();
#endif
return (std::filesystem::path(_str1) / std::filesystem::path(_str2)).string();
}

#ifdef _WIN32
Expand Down Expand Up @@ -248,6 +194,6 @@ namespace testing

return std::to_string(d(randGenerator));
}
}
} // namespace testing

#endif // header guard

0 comments on commit 0dc9fdc

Please sign in to comment.