1 /******************************************************************************
2 *
3 * Copyright 2016 Google, Inc.
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 "osi/include/properties.h"
20
21 #include <gtest/gtest.h>
22
23 class PropertiesTest : public ::testing::Test {};
24
TEST_F(PropertiesTest,test_default_value)25 TEST_F(PropertiesTest, test_default_value) {
26 char value[PROPERTY_VALUE_MAX] = {0};
27 osi_property_get("very.useful.test", value, "very_useful_value");
28 ASSERT_STREQ(value, "very_useful_value");
29 }
30
TEST_F(PropertiesTest,test_successfull_set_and_get_value)31 TEST_F(PropertiesTest, test_successfull_set_and_get_value) {
32 #ifdef __ANDROID__
33 char value[PROPERTY_VALUE_MAX] = "nothing_interesting";
34 int ret = osi_property_set("very.useful.set.test", value);
35 ASSERT_EQ(0, ret);
36
37 char received[PROPERTY_VALUE_MAX];
38 osi_property_get("very.useful.set.test", received, NULL);
39 ASSERT_STREQ(received, "nothing_interesting");
40 #endif
41 }
42
TEST_F(PropertiesTest,test_default_value_int32)43 TEST_F(PropertiesTest, test_default_value_int32) {
44 int32_t value = 42;
45 int32_t rvalue = osi_property_get_int32("very.useful.test", value);
46 ASSERT_EQ(rvalue, value);
47 }
48
TEST_F(PropertiesTest,test_successfull_set_and_get_value_int32)49 TEST_F(PropertiesTest, test_successfull_set_and_get_value_int32) {
50 #ifdef __ANDROID__
51 char value[PROPERTY_VALUE_MAX] = "42";
52 int ret = osi_property_set("very.useful.set.test", value);
53 ASSERT_EQ(0, ret);
54
55 int32_t received = osi_property_get_int32("very.useful.set.test", 84);
56 ASSERT_EQ(received, 42);
57 #endif
58 }
59