• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <iostream>
3 #include <time.h>
4 using namespace testing::ext;
5 
6 class TimeTzsetTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: tzset_001
13  * @tc.desc: Verify the behavior of the tzset() function by setting the time zone using the "TZ" environment variable,
14  *           calling tzset() to apply the changes, obtaining local time representations, and comparing the results to
15  *           the expected timezone abbreviations.
16  * @tc.type: FUNC
17  **/
18 HWTEST_F(TimeTzsetTest, tzset_001, TestSize.Level1)
19 {
20     setenv("TZ", "Asia/Shanghai", 1);
21     tzset();
22     std::time_t t1 = std::time(nullptr);
23     std::tm* localTime1 = std::localtime(&t1);
24     EXPECT_STREQ("CST", localTime1->tm_zone);
25 
26     setenv("TZ", "America/Logs_Angeles", 1);
27     tzset();
28     std::time_t t2 = std::time(nullptr);
29     std::tm* localTime2 = std::localtime(&t2);
30     EXPECT_STREQ("Americ", localTime2->tm_zone);
31 }