• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 
3 using namespace testing::ext;
4 
5 class EnvGetenvTest : public testing::Test {
SetUp()6     void SetUp() override {}
TearDown()7     void TearDown() override {}
8 };
9 
10 /**
11  * @tc.name: getenv_001
12  * @tc.desc: Verify whether the getenv function can correctly obtain the value of environmental variables, and
13  *           verified it by setting and deleting environmental variables, and verified whether the obtained value meets
14  *           expectations through assertions.
15  * @tc.type: FUNC
16  */
17 HWTEST_F(EnvGetenvTest, getenv_001, TestSize.Level1)
18 {
19     EXPECT_TRUE(setenv("PATH", "/usr/bin:/usr/local/bin", 1) == 0);
20     EXPECT_TRUE(strcmp("/usr/bin:/usr/local/bin", getenv("PATH")) == 0);
21     EXPECT_TRUE(unsetenv("PATH") == 0);
22     EXPECT_EQ(getenv("PATH"), nullptr);
23 }