Debian Codegraph @

test/core/gprpp/global_config_test.cc

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