Skip to content

Commit

Permalink
Use gz::utils::Environment functions
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 0dc9fdc commit 4895260
Show file tree
Hide file tree
Showing 35 changed files with 170 additions and 71 deletions.
16 changes: 9 additions & 7 deletions log/test/integration/playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <gz/transport/log/Playback.hh>
#include <gz/transport/log/Recorder.hh>
#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "ChirpParams.hh"
Expand Down Expand Up @@ -800,17 +802,17 @@ 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);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("IGN_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();
Expand Down
16 changes: 9 additions & 7 deletions log/test/integration/recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <gz/transport/log/Log.hh>
#include <gz/transport/log/Recorder.hh>
#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "ChirpParams.hh"
Expand Down Expand Up @@ -538,17 +540,17 @@ 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);

// TODO(CH3): Deprecated. Remove this on tick-tock.
setenv("IGN_TRANSPORT_LOG_SQL_PATH",
GZ_TRANSPORT_LOG_SQL_PATH, 1);
gz::utils::setenv("IGN_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();
Expand Down
4 changes: 3 additions & 1 deletion log/test/integration/topicChirp_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <gz/transport/Node.hh>

#include <gz/utils/Environment.hh>

#include "ChirpParams.hh"

//////////////////////////////////////////////////
Expand Down Expand Up @@ -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]);

Expand Down
9 changes: 6 additions & 3 deletions src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/
#include <gz/msgs/stringmsg.pb.h>

#include "gtest/gtest.h"
#include "gz/transport/CIface.h"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

static int count;
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gz/transport/TransportTypes.hh"
#include "gz/transport/Uuid.hh"

#include "gz/utils/Environment.hh"
#include "gz/utils/ExtraTestMacros.hh"

#include "test_config.hh"
Expand Down Expand Up @@ -536,18 +537,18 @@ TEST(DiscoveryTest, GZ_UTILS_TEST_DISABLED_ON_LINUX(WrongIgnIp))
{
// 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<MessagePublisher> 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);
}
5 changes: 4 additions & 1 deletion src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "gz/transport/Helpers.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

Expand All @@ -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));
Expand Down
7 changes: 5 additions & 2 deletions src/NodeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include "gz/transport/NetUtils.hh"
#include "gz/transport/NodeOptions.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

Expand All @@ -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);
Expand All @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
#include <string>
#include <thread>

#include "gtest/gtest.h"
#include "gz/transport/AdvertiseOptions.hh"
#include "gz/transport/MessageInfo.hh"
#include "gz/transport/Node.hh"
#include "gz/transport/NodeOptions.hh"
#include "gz/transport/TopicStatistics.hh"
#include "gz/transport/TopicUtils.hh"
#include "gz/transport/TransportTypes.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <fstream>
#include <iostream>
#include <string>

#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "gtest/gtest.h"
Expand Down Expand Up @@ -536,7 +538,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.
Expand All @@ -545,7 +547,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();
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/gz_src_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
#pragma warning(pop)
#endif

#include "gtest/gtest.h"
#include "gz.hh"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;

Expand Down Expand Up @@ -296,7 +299,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();
Expand Down
9 changes: 6 additions & 3 deletions test/integration/authPubSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
#include "gz/transport/TransportTypes.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand All @@ -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<msgs::Int32>(g_topic);
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions test/integration/authPubSubSubscriberInvalid_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion test/integration/fastPub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -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();
}
5 changes: 4 additions & 1 deletion test/integration/pub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -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();
}
7 changes: 5 additions & 2 deletions test/integration/pub_aux_throttled.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
#include <string>
#include <thread>

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;
Expand Down Expand Up @@ -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();
}
Loading

0 comments on commit 4895260

Please sign in to comment.