| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/environment.h> |
| 7 |
|
| 8 |
#include <aws/common/string.h> |
| 9 |
|
| 10 |
#include <aws/testing/aws_test_harness.h> |
| 11 |
|
| 12 |
AWS_STATIC_STRING_FROM_LITERAL(s_test_variable, "AWS_TEST_VAR"); |
| 13 |
|
| 14 |
AWS_STATIC_STRING_FROM_LITERAL(s_test_value, "SOME_VALUE"); |
| 15 |
|
| 16 |
static int s_test_environment_functions_fn(struct aws_allocator *allocator, void *ctx) { |
| 17 |
(void)ctx; |
| 18 |
|
| 19 |
struct aws_string *value; |
| 20 |
|
| 21 |
int result = aws_get_environment_value(allocator, s_test_variable, &value); |
| 22 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 23 |
ASSERT_TRUE(value == NULL); |
| 24 |
|
| 25 |
result = aws_set_environment_value(s_test_variable, (struct aws_string *)s_test_value); |
| 26 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 27 |
|
| 28 |
result = aws_get_environment_value(allocator, s_test_variable, &value); |
| 29 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 30 |
ASSERT_TRUE(aws_string_compare(value, s_test_value) == 0); |
| 31 |
|
| 32 |
aws_string_destroy(value); |
| 33 |
|
| 34 |
result = aws_unset_environment_value(s_test_variable); |
| 35 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 36 |
|
| 37 |
result = aws_get_environment_value(allocator, s_test_variable, &value); |
| 38 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 39 |
ASSERT_TRUE(value == NULL); |
| 40 |
|
| 41 |
return AWS_OP_SUCCESS; |
| 42 |
} |
| 43 |
|
| 44 |
AWS_TEST_CASE(test_environment_functions, s_test_environment_functions_fn) |
| 45 |
|
| 46 |
static int s_test_env_functions_fn(struct aws_allocator *allocator, void *ctx) { |
| 47 |
(void)ctx; |
| 48 |
|
| 49 |
const char *env_name = aws_string_c_str(s_test_variable); |
| 50 |
struct aws_string *value = aws_get_env(allocator, env_name); |
| 51 |
ASSERT_TRUE(value == NULL); |
| 52 |
|
| 53 |
value = aws_get_env_nonempty(allocator, env_name); |
| 54 |
ASSERT_TRUE(value == NULL); |
| 55 |
|
| 56 |
int result = aws_set_environment_value(s_test_variable, (struct aws_string *)s_test_value); |
| 57 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 58 |
|
| 59 |
value = aws_get_env(allocator, env_name); |
| 60 |
ASSERT_TRUE(aws_string_compare(value, s_test_value) == 0); |
| 61 |
aws_string_destroy(value); |
| 62 |
|
| 63 |
value = aws_get_env_nonempty(allocator, env_name); |
| 64 |
ASSERT_TRUE(aws_string_compare(value, s_test_value) == 0); |
| 65 |
aws_string_destroy(value); |
| 66 |
|
| 67 |
struct aws_string *empty_str = aws_string_new_from_c_str(allocator, ""); |
| 68 |
result = aws_set_environment_value(s_test_variable, empty_str); |
| 69 |
ASSERT_TRUE(result == AWS_OP_SUCCESS); |
| 70 |
|
| 71 |
value = aws_get_env(allocator, env_name); |
| 72 |
#ifndef AWS_OS_WINDOWS |
| 73 |
ASSERT_TRUE(aws_string_compare(value, empty_str) == 0); |
| 74 |
#endif |
| 75 |
aws_string_destroy(value); |
| 76 |
|
| 77 |
value = aws_get_env_nonempty(allocator, env_name); |
| 78 |
ASSERT_TRUE(value == NULL); |
| 79 |
|
| 80 |
aws_string_destroy(empty_str); |
| 81 |
return AWS_OP_SUCCESS; |
| 82 |
} |
| 83 |
|
| 84 |
AWS_TEST_CASE(test_env_functions, s_test_env_functions_fn) |