• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android-base/properties.h>
18 #include <gtest/gtest.h>
19 #include <chrono>
20 
21 #include "linkerconfig/variables.h"
22 
23 using android::linkerconfig::modules::Variables;
24 
TEST(linkerconfig_variables,load_from_map)25 TEST(linkerconfig_variables, load_from_map) {
26   Variables::AddValue("TEST_KEY", "TEST_VALUE");
27   auto value = Variables::GetValue("TEST_KEY");
28   ASSERT_TRUE(value.has_value());
29   ASSERT_EQ("TEST_VALUE", value.value());
30 }
31 
TEST(linkerconfig_variables,load_from_property)32 TEST(linkerconfig_variables, load_from_property) {
33 #if defined(__BIONIC__)
34   android::base::SetProperty("debug.linkerconfig.test_prop_key",
35                              "TEST_PROP_VALUE");
36   ASSERT_TRUE(android::base::WaitForProperty("debug.linkerconfig.test_prop_key",
37                                              "TEST_PROP_VALUE",
38                                              std::chrono::seconds(1)));
39   auto value = Variables::GetValue("debug.linkerconfig.test_prop_key");
40   ASSERT_TRUE(value.has_value());
41   ASSERT_EQ("TEST_PROP_VALUE", value.value());
42 #endif
43 }
44 
TEST(linkerconfig_variables,fallback_value)45 TEST(linkerconfig_variables, fallback_value) {
46   auto value = Variables::GetValue("INVALID_KEY");
47   ASSERT_FALSE(value.has_value());
48 }
49 
TEST(linkerconfig_variables,empty_value)50 TEST(linkerconfig_variables, empty_value) {
51   Variables::AddValue("TEST_KEY", "");
52   ASSERT_FALSE(Variables::GetValue("TEST_KEY").has_value());
53 }