xref: /aosp_15_r20/external/grpc-grpc/test/core/gpr/env_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include "src/core/lib/gprpp/env.h"
20 
21 #include "gtest/gtest.h"
22 
23 #include <grpc/support/log.h>
24 
25 #include "test/core/util/test_config.h"
26 
27 #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x)
28 
TEST(EnvTest,SetenvGetenv)29 TEST(EnvTest, SetenvGetenv) {
30   const char* name = "FOO";
31   const char* value = "BAR";
32 
33   LOG_TEST_NAME("test_setenv_getenv");
34 
35   grpc_core::SetEnv(name, value);
36   auto retrieved_value = grpc_core::GetEnv(name);
37   ASSERT_EQ(value, retrieved_value);
38 }
39 
TEST(EnvTest,Unsetenv)40 TEST(EnvTest, Unsetenv) {
41   const char* name = "FOO";
42   const char* value = "BAR";
43 
44   LOG_TEST_NAME("test_unsetenv");
45 
46   grpc_core::SetEnv(name, value);
47   grpc_core::UnsetEnv(name);
48   auto retrieved_value = grpc_core::GetEnv(name);
49   ASSERT_FALSE(retrieved_value.has_value());
50 }
51 
main(int argc,char ** argv)52 int main(int argc, char** argv) {
53   grpc::testing::TestEnvironment env(&argc, argv);
54   ::testing::InitGoogleTest(&argc, argv);
55   return RUN_ALL_TESTS();
56 }
57