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 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 33 TEST_F(PropertiesTest, test_successfull_set_and_get_value) { 34 char value[PROPERTY_VALUE_MAX] = "nothing_interesting"; 35 int ret = osi_property_set("very.useful.set.test", value); 36 ASSERT_EQ(0, ret); 37 38 char received[PROPERTY_VALUE_MAX]; 39 osi_property_get("very.useful.set.test", received, NULL); 40 ASSERT_STREQ(received, "nothing_interesting"); 41 } 42 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 49 TEST_F(PropertiesTest, test_successfull_set_and_get_value_int32) { 50 char value[PROPERTY_VALUE_MAX] = "42"; 51 int ret = osi_property_set("very.useful.set.test", value); 52 ASSERT_EQ(0, ret); 53 54 int32_t received = osi_property_get_int32("very.useful.set.test", 84); 55 ASSERT_EQ(received, 42); 56 }