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/gpr/env.h"
20
21 #include <stdio.h>
22 #include <string.h>
23
24 #include <grpc/support/alloc.h>
25 #include <grpc/support/log.h>
26
27 #include "src/core/lib/gpr/string.h"
28 #include "test/core/util/test_config.h"
29
30 #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x)
31
test_setenv_getenv(void)32 static void test_setenv_getenv(void) {
33 const char* name = "FOO";
34 const char* value = "BAR";
35 char* retrieved_value;
36
37 LOG_TEST_NAME("test_setenv_getenv");
38
39 gpr_setenv(name, value);
40 retrieved_value = gpr_getenv(name);
41 GPR_ASSERT(retrieved_value != nullptr);
42 GPR_ASSERT(strcmp(value, retrieved_value) == 0);
43 gpr_free(retrieved_value);
44 }
45
test_unsetenv(void)46 static void test_unsetenv(void) {
47 const char* name = "FOO";
48 const char* value = "BAR";
49 char* retrieved_value;
50
51 LOG_TEST_NAME("test_unsetenv");
52
53 gpr_setenv(name, value);
54 gpr_unsetenv(name);
55 retrieved_value = gpr_getenv(name);
56 GPR_ASSERT(retrieved_value == nullptr);
57 }
58
main(int argc,char ** argv)59 int main(int argc, char** argv) {
60 grpc::testing::TestEnvironment env(argc, argv);
61 test_setenv_getenv();
62 test_unsetenv();
63 return 0;
64 }
65