1 /*
2 *
3 * Copyright 2019 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 <stdio.h>
20 #include <string.h>
21
22 #include <gtest/gtest.h>
23
24 #include <grpc/support/alloc.h>
25 #include <grpc/support/log.h>
26
27 #include "src/core/lib/gpr/env.h"
28 #include "src/core/lib/gprpp/global_config.h"
29 #include "src/core/lib/gprpp/memory.h"
30
31 GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var);
32
33 GPR_GLOBAL_CONFIG_DEFINE_BOOL(bool_var, false, "");
34 GPR_GLOBAL_CONFIG_DEFINE_INT32(int32_var, 0, "");
35 GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "", "");
36
TEST(GlobalConfigTest,BoolTest)37 TEST(GlobalConfigTest, BoolTest) {
38 EXPECT_FALSE(GPR_GLOBAL_CONFIG_GET(bool_var));
39 GPR_GLOBAL_CONFIG_SET(bool_var, true);
40 EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var));
41 }
42
TEST(GlobalConfigTest,Int32Test)43 TEST(GlobalConfigTest, Int32Test) {
44 EXPECT_EQ(0, GPR_GLOBAL_CONFIG_GET(int32_var));
45 GPR_GLOBAL_CONFIG_SET(int32_var, 1024);
46 EXPECT_EQ(1024, GPR_GLOBAL_CONFIG_GET(int32_var));
47 }
48
TEST(GlobalConfigTest,StringTest)49 TEST(GlobalConfigTest, StringTest) {
50 grpc_core::UniquePtr<char> value;
51
52 value = GPR_GLOBAL_CONFIG_GET(string_var);
53 EXPECT_EQ(0, strcmp(value.get(), ""));
54
55 GPR_GLOBAL_CONFIG_SET(string_var, "Test");
56
57 value = GPR_GLOBAL_CONFIG_GET(string_var);
58 EXPECT_EQ(0, strcmp(value.get(), "Test"));
59 }
60
main(int argc,char ** argv)61 int main(int argc, char** argv) {
62 ::testing::InitGoogleTest(&argc, argv);
63 int ret = RUN_ALL_TESTS();
64 return ret;
65 }
66