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