Skip to content

Commit

Permalink
add test case to test whether CrossPlatform::getenv_safe can find a k…
Browse files Browse the repository at this point in the history
…nown existing env var
  • Loading branch information
nam20485 committed May 8, 2024
1 parent 35cf9c5 commit f7c6d01
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion OdbDesignTests/CrossPlatformTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Fixtures/TestDataFixture.h"
#include <string>
#include <filesystem>
#include <gmock/gmock-matchers.h>
#include <cstdlib>

using namespace std::filesystem;
using namespace Odb::Test::Fixtures;
Expand All @@ -14,15 +16,34 @@ namespace Odb::Test
{
TEST_F(TestDataFixture, Test_CrossPlatform_GetEnvSafe_VariableExists)
{
auto szTestEnvValue = std::getenv(ODB_TEST_ENV_NAME);
EXPECT_THAT(szTestEnvValue, NotNull());

std::string value;
ASSERT_EQ(value.size(), 0U);
ASSERT_TRUE(CrossPlatform::getenv_safe(ODB_TEST_ENV_NAME, value));
auto bResult = CrossPlatform::getenv_safe(ODB_TEST_ENV_NAME, value);
ASSERT_STRNE(value.c_str(), "");
ASSERT_STREQ(value.c_str(), ODB_TEST_ENV_VALUE);
ASSERT_TRUE(bResult);
}

TEST_F(TestDataFixture, Test_CrossPlatform_GetEnvSafe_KnownVariableExists)
{
auto szTestEnvValue = std::getenv(ODB_TEST_DATA_DIR_ENV_NAME);
EXPECT_THAT(szTestEnvValue, NotNull());

std::string value;
ASSERT_EQ(value.size(), 0U);
auto bResult = CrossPlatform::getenv_safe(ODB_TEST_DATA_DIR_ENV_NAME, value);
ASSERT_STRNE(value.c_str(), "");
ASSERT_TRUE(bResult);
}

TEST_F(TestDataFixture, Test_CrossPlatform_GetEnvSafe_VariableDoesntExist)
{
auto szDoesntExistVal = std::getenv(ODB_TEST_NONEXISTENT_ENV_NAME);
EXPECT_THAT(szDoesntExistVal, IsNull());

std::string value;
ASSERT_EQ(value.size(), 0U);
ASSERT_FALSE(CrossPlatform::getenv_safe(ODB_TEST_NONEXISTENT_ENV_NAME, value));
Expand Down

0 comments on commit f7c6d01

Please sign in to comment.