diff --git a/log/test/integration/playback.cc b/log/test/integration/playback.cc index 48171ff54..39bf07498 100644 --- a/log/test/integration/playback.cc +++ b/log/test/integration/playback.cc @@ -21,6 +21,8 @@ #include #include #include + +#include #include #include "ChirpParams.hh" @@ -800,13 +802,13 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); - setenv("GZ_TRANSPORT_LOG_SQL_PATH", - GZ_TRANSPORT_LOG_SQL_PATH, 1); + gz::utils::setenv("GZ_TRANSPORT_LOG_SQL_PATH", + GZ_TRANSPORT_LOG_SQL_PATH); - setenv(gz::transport::log::SchemaLocationEnvVar.c_str(), - GZ_TRANSPORT_LOG_SQL_PATH, 1); + gz::utils::setenv(gz::transport::log::SchemaLocationEnvVar, + GZ_TRANSPORT_LOG_SQL_PATH); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/log/test/integration/recorder.cc b/log/test/integration/recorder.cc index 7402f1fea..e23265e33 100644 --- a/log/test/integration/recorder.cc +++ b/log/test/integration/recorder.cc @@ -24,6 +24,8 @@ #include #include #include + +#include #include #include "ChirpParams.hh" @@ -538,13 +540,13 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); - setenv("GZ_TRANSPORT_LOG_SQL_PATH", - GZ_TRANSPORT_LOG_SQL_PATH, 1); + gz::utils::setenv("GZ_TRANSPORT_LOG_SQL_PATH", + GZ_TRANSPORT_LOG_SQL_PATH); - setenv(gz::transport::log::SchemaLocationEnvVar.c_str(), - GZ_TRANSPORT_LOG_SQL_PATH, 1); + gz::utils::setenv(gz::transport::log::SchemaLocationEnvVar, + GZ_TRANSPORT_LOG_SQL_PATH); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/log/test/integration/topicChirp_aux.cc b/log/test/integration/topicChirp_aux.cc index ae67e26ec..94f2942b3 100644 --- a/log/test/integration/topicChirp_aux.cc +++ b/log/test/integration/topicChirp_aux.cc @@ -22,6 +22,8 @@ #include +#include + #include "ChirpParams.hh" ////////////////////////////////////////////////// @@ -90,7 +92,7 @@ int main(int argc, char **argv) return -2; } - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); const int chirps = atoi(argv[2]); diff --git a/src/CIface_TEST.cc b/src/CIface_TEST.cc index a3dc0e765..1f1b70c57 100644 --- a/src/CIface_TEST.cc +++ b/src/CIface_TEST.cc @@ -16,8 +16,11 @@ */ #include -#include "gtest/gtest.h" #include "gz/transport/CIface.h" + +#include + +#include "gtest/gtest.h" #include "test_config.hh" static int count; @@ -180,10 +183,10 @@ int main(int argc, char **argv) std::string partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); // Enable verbose mode. - // setenv("GZ_VERBOSE", "1", 1); + // gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/Discovery_TEST.cc b/src/Discovery_TEST.cc index b113ccbff..24d1882ff 100644 --- a/src/Discovery_TEST.cc +++ b/src/Discovery_TEST.cc @@ -27,20 +27,11 @@ #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 -#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/Environment.hh" +#include "gz/utils/ExtraTestMacros.hh" + +#include "test_config.hh" using namespace gz; using namespace transport; @@ -540,31 +531,24 @@ 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(WrongGzIp)) { // Save the current value of GZ_IP environment variable. std::string gzIp; - env("GZ_IP", gzIp); + gz::utils::env("GZ_IP", gzIp); // Incorrect value for GZ_IP - setenv("GZ_IP", "127.0.0.0", 1); + ASSERT_TRUE(gz::utils::setenv("GZ_IP", "127.0.0.0")); transport::Discovery discovery1(pUuid1, g_ip, g_msgPort); EXPECT_EQ(discovery1.HostAddr(), "127.0.0.1"); // Unset GZ_IP. - unsetenv("GZ_IP"); + ASSERT_TRUE(gz::utils::unsetenv("GZ_IP")); // Restore GZ_IP. if (!gzIp.empty()) - setenv("GZ_IP", gzIp.c_str(), 1); + gz::utils::setenv("GZ_IP", gzIp); } diff --git a/src/Helpers_TEST.cc b/src/Helpers_TEST.cc index c7f79c167..518090e11 100644 --- a/src/Helpers_TEST.cc +++ b/src/Helpers_TEST.cc @@ -16,6 +16,9 @@ */ #include "gz/transport/Helpers.hh" + +#include + #include "test_config.hh" #include "gtest/gtest.h" @@ -33,7 +36,7 @@ TEST(HelpersTest, env) EXPECT_FALSE(transport::env(name, value)); // Create a random environment variable and give it its name as value. - setenv(name.c_str(), name.c_str(), 1); + ASSERT_TRUE(gz::utils::setenv(name, name)); // Check that we find the environment variable and the value is correct. EXPECT_TRUE(transport::env(name, value)); diff --git a/src/NodeOptions_TEST.cc b/src/NodeOptions_TEST.cc index b8a78c2fc..d28a40e5a 100644 --- a/src/NodeOptions_TEST.cc +++ b/src/NodeOptions_TEST.cc @@ -19,6 +19,9 @@ #include "gz/transport/NetUtils.hh" #include "gz/transport/NodeOptions.hh" + +#include + #include "test_config.hh" #include "gtest/gtest.h" @@ -30,7 +33,7 @@ TEST(NodeOptionsTest, ignPartition) { // Set GZ_PARTITION std::string aPartition = "customPartition"; - setenv("GZ_PARTITION", aPartition.c_str(), 1); + ASSERT_TRUE(gz::utils::setenv("GZ_PARTITION", aPartition)); transport::NodeOptions opts; EXPECT_EQ(opts.Partition(), aPartition); @@ -53,7 +56,7 @@ TEST(NodeOptionsTest, ignPartition) TEST(NodeOptionsTest, accessors) { // Check the default values. - unsetenv("GZ_PARTITION"); + gz::utils::unsetenv("GZ_PARTITION"); transport::NodeOptions opts; EXPECT_TRUE(opts.NameSpace().empty()); auto defaultPartition = transport::hostname() + ":" + transport::username(); diff --git a/src/Node_TEST.cc b/src/Node_TEST.cc index 4e2b69716..80427368e 100644 --- a/src/Node_TEST.cc +++ b/src/Node_TEST.cc @@ -26,7 +26,6 @@ #include #include -#include "gtest/gtest.h" #include "gz/transport/AdvertiseOptions.hh" #include "gz/transport/MessageInfo.hh" #include "gz/transport/Node.hh" @@ -34,6 +33,10 @@ #include "gz/transport/TopicStatistics.hh" #include "gz/transport/TopicUtils.hh" #include "gz/transport/TransportTypes.hh" + +#include + +#include "gtest/gtest.h" #include "test_config.hh" using namespace gz; @@ -2324,10 +2327,10 @@ int main(int argc, char **argv) g_FQNPartition = std::string("/") + partition; // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); // Enable verbose mode. - setenv("GZ_VERBOSE", "1", 1); + gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/cmd/gz_TEST.cc b/src/cmd/gz_TEST.cc index 1968de211..9a4bae4a4 100644 --- a/src/cmd/gz_TEST.cc +++ b/src/cmd/gz_TEST.cc @@ -22,6 +22,8 @@ #include #include #include + +#include #include #include "gtest/gtest.h" @@ -615,7 +617,7 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); // Make sure that we load the library recently built and not the one installed // in your system. @@ -624,7 +626,7 @@ int main(int argc, char **argv) transport::env("LD_LIBRARY_PATH", value); // Add the directory where Gazebo Transport has been built. value = std::string(GZ_TEST_LIBRARY_PATH) + ":" + value; - setenv("LD_LIBRARY_PATH", value.c_str(), 1); + gz::utils::setenv("LD_LIBRARY_PATH", value); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/cmd/gz_src_TEST.cc b/src/cmd/gz_src_TEST.cc index 80c60240e..8caf0c59d 100644 --- a/src/cmd/gz_src_TEST.cc +++ b/src/cmd/gz_src_TEST.cc @@ -28,10 +28,13 @@ #pragma warning(pop) #endif -#include "gtest/gtest.h" #include "gz.hh" #include "gz/transport/Node.hh" + +#include + #include "test_config.hh" +#include "gtest/gtest.h" using namespace gz; @@ -299,7 +302,7 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/authPubSub.cc b/test/integration/authPubSub.cc index f0fd6eaf5..9da50e44b 100644 --- a/test/integration/authPubSub.cc +++ b/test/integration/authPubSub.cc @@ -29,6 +29,9 @@ #include "gtest/gtest.h" #include "gz/transport/Node.hh" #include "gz/transport/TransportTypes.hh" + +#include + #include "test_config.hh" using namespace gz; @@ -40,8 +43,8 @@ static std::string g_topic = "/foo"; // NOLINT(*) TEST(authPubSub, InvalidAuth) { // Setup the username and password for this test - setenv("GZ_TRANSPORT_USERNAME", "admin", 1); - setenv("GZ_TRANSPORT_PASSWORD", "test", 1); + ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_USERNAME", "admin")); + ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_PASSWORD", "test")); transport::Node node; auto pub = node.Advertise(g_topic); @@ -86,7 +89,7 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/authPubSubSubscriberInvalid_aux.cc b/test/integration/authPubSubSubscriberInvalid_aux.cc index 9b8d2d4dd..39035728e 100644 --- a/test/integration/authPubSubSubscriberInvalid_aux.cc +++ b/test/integration/authPubSubSubscriberInvalid_aux.cc @@ -30,6 +30,9 @@ #endif #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -81,13 +84,13 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); // Set the username for this test. - setenv("GZ_TRANSPORT_USERNAME", argv[2], 1); + gz::utils::setenv("GZ_TRANSPORT_USERNAME", argv[2]); // Set the password for this test. - setenv("GZ_TRANSPORT_PASSWORD", argv[3], 1); + gz::utils::setenv("GZ_TRANSPORT_PASSWORD", argv[3]); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/fastPub_aux.cc b/test/integration/fastPub_aux.cc index bd04c41e7..d0df10cf0 100644 --- a/test/integration/fastPub_aux.cc +++ b/test/integration/fastPub_aux.cc @@ -26,6 +26,9 @@ #endif #include "gz/transport/Node.hh" + +#include + #include "test_config.hh" using namespace gz; @@ -58,7 +61,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); advertiseAndPublish(); } diff --git a/test/integration/pub_aux.cc b/test/integration/pub_aux.cc index c9ebebfb9..2737a3b84 100644 --- a/test/integration/pub_aux.cc +++ b/test/integration/pub_aux.cc @@ -22,6 +22,9 @@ #include "gtest/gtest.h" #include "gz/transport/Node.hh" + +#include + #include "test_config.hh" using namespace gz; @@ -59,7 +62,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); advertiseAndPublish(); } diff --git a/test/integration/pub_aux_throttled.cc b/test/integration/pub_aux_throttled.cc index e2040c4f2..0416523ca 100644 --- a/test/integration/pub_aux_throttled.cc +++ b/test/integration/pub_aux_throttled.cc @@ -20,8 +20,11 @@ #include #include -#include "gtest/gtest.h" #include "gz/transport/Node.hh" + +#include + +#include "gtest/gtest.h" #include "test_config.hh" using namespace gz; @@ -61,7 +64,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); advertiseAndPublish(); } diff --git a/test/integration/scopedTopic.cc b/test/integration/scopedTopic.cc index 9c36a935f..9be96a64c 100644 --- a/test/integration/scopedTopic.cc +++ b/test/integration/scopedTopic.cc @@ -21,6 +21,9 @@ #include "gz/transport/AdvertiseOptions.hh" #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -67,7 +70,7 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/scopedTopicSubscriber_aux.cc b/test/integration/scopedTopicSubscriber_aux.cc index 76c17d508..3bb44f16a 100644 --- a/test/integration/scopedTopicSubscriber_aux.cc +++ b/test/integration/scopedTopicSubscriber_aux.cc @@ -20,6 +20,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -73,7 +76,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/statistics.cc b/test/integration/statistics.cc index 771d054a3..628d248bf 100644 --- a/test/integration/statistics.cc +++ b/test/integration/statistics.cc @@ -23,6 +23,9 @@ #include "gtest/gtest.h" #include "gz/transport/Node.hh" #include "gz/transport/TransportTypes.hh" + +#include + #include "test_config.hh" using namespace gz; @@ -78,8 +81,8 @@ int main(int argc, char **argv) std::string partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); - setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1", 1); + gz::utils::setenv("GZ_PARTITION", partition); + gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsPubSub.cc b/test/integration/twoProcsPubSub.cc index 7b5550301..46987404f 100644 --- a/test/integration/twoProcsPubSub.cc +++ b/test/integration/twoProcsPubSub.cc @@ -20,9 +20,12 @@ #include #include -#include "gtest/gtest.h" #include "gz/transport/Node.hh" #include "gz/transport/TransportTypes.hh" + +#include + +#include "gtest/gtest.h" #include "test_config.hh" using namespace gz; @@ -542,8 +545,8 @@ int main(int argc, char **argv) g_FQNPartition = std::string("/") + partition; // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); - setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1", 1); + gz::utils::setenv("GZ_PARTITION", partition); + gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsPubSubSubscriber_aux.cc b/test/integration/twoProcsPubSubSubscriber_aux.cc index ccd0f4ccd..49a360a02 100644 --- a/test/integration/twoProcsPubSubSubscriber_aux.cc +++ b/test/integration/twoProcsPubSubSubscriber_aux.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -157,8 +160,8 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); - setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1", 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); + gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsPublisher_aux.cc b/test/integration/twoProcsPublisher_aux.cc index ee49964bd..ccb49c83f 100644 --- a/test/integration/twoProcsPublisher_aux.cc +++ b/test/integration/twoProcsPublisher_aux.cc @@ -20,6 +20,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "test_config.hh" using namespace gz; @@ -55,7 +58,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); advertiseAndPublish(); } diff --git a/test/integration/twoProcsSrvCall.cc b/test/integration/twoProcsSrvCall.cc index 059d3ab00..9ccd9abdc 100644 --- a/test/integration/twoProcsSrvCall.cc +++ b/test/integration/twoProcsSrvCall.cc @@ -23,6 +23,9 @@ #include "gz/transport/Node.hh" #include "gz/transport/TopicUtils.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -339,10 +342,10 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); // Enable verbose mode. - // setenv("GZ_VERBOSE", "1", 1); + // gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallReplierInc_aux.cc b/test/integration/twoProcsSrvCallReplierInc_aux.cc index 8ef1c4b49..1f27e84fb 100644 --- a/test/integration/twoProcsSrvCallReplierInc_aux.cc +++ b/test/integration/twoProcsSrvCallReplierInc_aux.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -63,7 +66,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallReplier_aux.cc b/test/integration/twoProcsSrvCallReplier_aux.cc index 6dacc1cb9..5b8523590 100644 --- a/test/integration/twoProcsSrvCallReplier_aux.cc +++ b/test/integration/twoProcsSrvCallReplier_aux.cc @@ -20,6 +20,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -53,7 +56,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); runReplier(); } diff --git a/test/integration/twoProcsSrvCallStress.cc b/test/integration/twoProcsSrvCallStress.cc index 2f9d71265..f08357928 100644 --- a/test/integration/twoProcsSrvCallStress.cc +++ b/test/integration/twoProcsSrvCallStress.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -68,7 +71,7 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallSync1.cc b/test/integration/twoProcsSrvCallSync1.cc index ef93771da..27087049e 100644 --- a/test/integration/twoProcsSrvCallSync1.cc +++ b/test/integration/twoProcsSrvCallSync1.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -83,10 +86,10 @@ int main(int argc, char **argv) partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", partition); // Enable verbose mode. - setenv("GZ_VERBOSE", "1", 1); + gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutInput.cc b/test/integration/twoProcsSrvCallWithoutInput.cc index d98c112a0..cefa1ef7b 100644 --- a/test/integration/twoProcsSrvCallWithoutInput.cc +++ b/test/integration/twoProcsSrvCallWithoutInput.cc @@ -23,6 +23,9 @@ #include "gz/transport/Node.hh" #include "gz/transport/TopicUtils.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -289,10 +292,10 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); // Enable verbose mode. - // setenv("GZ_VERBOSE", "1", 1); + // gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutInputReplierInc_aux.cc b/test/integration/twoProcsSrvCallWithoutInputReplierInc_aux.cc index 195de0791..1cc15a893 100644 --- a/test/integration/twoProcsSrvCallWithoutInputReplierInc_aux.cc +++ b/test/integration/twoProcsSrvCallWithoutInputReplierInc_aux.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -64,7 +67,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutInputReplier_aux.cc b/test/integration/twoProcsSrvCallWithoutInputReplier_aux.cc index 31eb1c13c..6ab90212d 100644 --- a/test/integration/twoProcsSrvCallWithoutInputReplier_aux.cc +++ b/test/integration/twoProcsSrvCallWithoutInputReplier_aux.cc @@ -20,6 +20,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -54,7 +57,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); runReplier(); } diff --git a/test/integration/twoProcsSrvCallWithoutInputStress.cc b/test/integration/twoProcsSrvCallWithoutInputStress.cc index 972cce3a5..7d2fc7c4b 100644 --- a/test/integration/twoProcsSrvCallWithoutInputStress.cc +++ b/test/integration/twoProcsSrvCallWithoutInputStress.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -65,7 +68,7 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutInputSync1.cc b/test/integration/twoProcsSrvCallWithoutInputSync1.cc index d2177b375..230a96f88 100644 --- a/test/integration/twoProcsSrvCallWithoutInputSync1.cc +++ b/test/integration/twoProcsSrvCallWithoutInputSync1.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -78,10 +81,10 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); // Enable verbose mode. - setenv("GZ_VERBOSE", "1", 1); + gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutOutput.cc b/test/integration/twoProcsSrvCallWithoutOutput.cc index 526e2283e..1d365a0be 100644 --- a/test/integration/twoProcsSrvCallWithoutOutput.cc +++ b/test/integration/twoProcsSrvCallWithoutOutput.cc @@ -22,6 +22,9 @@ #include "gz/transport/Node.hh" #include "gz/transport/TopicUtils.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -171,10 +174,10 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); // Enable verbose mode. - // setenv("GZ_VERBOSE", "1", 1); + // gz::utils::setenv("GZ_VERBOSE", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutOutputReplierInc_aux.cc b/test/integration/twoProcsSrvCallWithoutOutputReplierInc_aux.cc index 25dd7216e..8354ddb48 100644 --- a/test/integration/twoProcsSrvCallWithoutOutputReplierInc_aux.cc +++ b/test/integration/twoProcsSrvCallWithoutOutputReplierInc_aux.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -62,7 +65,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/integration/twoProcsSrvCallWithoutOutputReplier_aux.cc b/test/integration/twoProcsSrvCallWithoutOutputReplier_aux.cc index 8eff1867f..285b06a60 100644 --- a/test/integration/twoProcsSrvCallWithoutOutputReplier_aux.cc +++ b/test/integration/twoProcsSrvCallWithoutOutputReplier_aux.cc @@ -20,6 +20,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -53,7 +56,7 @@ int main(int argc, char **argv) } // Set the partition name for this test. - setenv("GZ_PARTITION", argv[1], 1); + gz::utils::setenv("GZ_PARTITION", argv[1]); runReplier(); } diff --git a/test/integration/twoProcsSrvCallWithoutOutputStress.cc b/test/integration/twoProcsSrvCallWithoutOutputStress.cc index 3d76b95ec..c32a7e636 100644 --- a/test/integration/twoProcsSrvCallWithoutOutputStress.cc +++ b/test/integration/twoProcsSrvCallWithoutOutputStress.cc @@ -21,6 +21,9 @@ #include #include "gz/transport/Node.hh" + +#include + #include "gtest/gtest.h" #include "test_config.hh" @@ -61,7 +64,7 @@ int main(int argc, char **argv) g_partition = testing::getRandomNumber(); // Set the partition name for this process. - setenv("GZ_PARTITION", g_partition.c_str(), 1); + gz::utils::setenv("GZ_PARTITION", g_partition); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/test_config.hh.in b/test/test_config.hh.in index bc7ea350a..481d35a18 100644 --- a/test/test_config.hh.in +++ b/test/test_config.hh.in @@ -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 - #else - #include - #endif -#endif - #include +#include #include #include #include @@ -60,37 +47,6 @@ #include "gz/transport/Helpers.hh" -#if (_MSC_VER >= 1400) // Visual Studio 2005 - #include - - /// \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. @@ -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 @@ -248,6 +194,6 @@ namespace testing return std::to_string(d(randGenerator)); } -} +} // namespace testing #endif // header guard