3 * Copyright 2019 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "src/core/lib/gprpp/global_config.h"
24 #include <gtest/gtest.h>
26 #include <grpc/support/alloc.h>
27 #include <grpc/support/log.h>
29 #include "src/core/lib/gpr/env.h"
30 #include "src/core/lib/gprpp/memory.h"
32 GPR_GLOBAL_CONFIG_DECLARE_BOOL(bool_var);
34 GPR_GLOBAL_CONFIG_DEFINE_BOOL(bool_var, false, "");
35 GPR_GLOBAL_CONFIG_DEFINE_INT32(int32_var, 0, "");
36 GPR_GLOBAL_CONFIG_DEFINE_STRING(string_var, "", "");
38 TEST(GlobalConfigTest, BoolTest) {
39 EXPECT_FALSE(GPR_GLOBAL_CONFIG_GET(bool_var));
40 GPR_GLOBAL_CONFIG_SET(bool_var, true);
41 EXPECT_TRUE(GPR_GLOBAL_CONFIG_GET(bool_var));
44 TEST(GlobalConfigTest, Int32Test) {
45 EXPECT_EQ(0, GPR_GLOBAL_CONFIG_GET(int32_var));
46 GPR_GLOBAL_CONFIG_SET(int32_var, 1024);
47 EXPECT_EQ(1024, GPR_GLOBAL_CONFIG_GET(int32_var));
50 TEST(GlobalConfigTest, StringTest) {
51 grpc_core::UniquePtr<char> value;
53 value = GPR_GLOBAL_CONFIG_GET(string_var);
54 EXPECT_EQ(0, strcmp(value.get(), ""));
56 GPR_GLOBAL_CONFIG_SET(string_var, "Test");
58 value = GPR_GLOBAL_CONFIG_GET(string_var);
59 EXPECT_EQ(0, strcmp(value.get(), "Test"));
62 int main(int argc, char** argv) {
63 ::testing::InitGoogleTest(&argc, argv);
64 int ret = RUN_ALL_TESTS();