1 /*
2 * Copyright 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 <string>
18
19 #include <gtest/gtest.h>
20
21 #include <cutils/properties.h>
22
23 #include "os/system_properties.h"
24
25 namespace testing {
26
27 using bluetooth::os::GetSystemProperty;
28 using bluetooth::os::SetSystemProperty;
29
TEST(SystemPropertiesTest,set_and_get_test)30 TEST(SystemPropertiesTest, set_and_get_test) {
31 ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "true"));
32 auto ret = GetSystemProperty("persist.bluetooth.factoryreset");
33 ASSERT_TRUE(ret);
34 ASSERT_EQ(ret, "true");
35 ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false"));
36 ret = GetSystemProperty("persist.bluetooth.factoryreset");
37 ASSERT_TRUE(ret);
38 ASSERT_EQ(ret, "false");
39 ret = GetSystemProperty("persist.bluetooth.factoryreset_do_not_exist");
40 ASSERT_FALSE(ret);
41 }
42
43 // From Android O and above, there is no limit on property key sizesss
TEST(SystemPropertiesTest,max_length_test)44 TEST(SystemPropertiesTest, max_length_test) {
45 std::string property(PROP_NAME_MAX, 'a');
46 std::string value(PROP_VALUE_MAX, '1');
47 ASSERT_TRUE(SetSystemProperty("persist.bluetooth.factoryreset", "false"));
48 ASSERT_TRUE(SetSystemProperty(property, "true"));
49 ASSERT_FALSE(SetSystemProperty("persist.bluetooth.factoryreset", value));
50 ASSERT_FALSE(SetSystemProperty(property, value));
51 ASSERT_TRUE(GetSystemProperty(property));
52 // make sure no actual operations on system property happened
53 auto ret = GetSystemProperty("persist.bluetooth.factoryreset");
54 ASSERT_TRUE(ret);
55 ASSERT_EQ(ret, "false");
56 }
57
58 } // namespace testing