13eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski/******************************************************************************
23eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *
33eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  Copyright (C) 2016 Google, Inc.
43eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *
53eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  Licensed under the Apache License, Version 2.0 (the "License");
63eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  you may not use this file except in compliance with the License.
73eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  You may obtain a copy of the License at:
83eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *
93eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  http://www.apache.org/licenses/LICENSE-2.0
103eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *
113eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  Unless required by applicable law or agreed to in writing, software
123eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  distributed under the License is distributed on an "AS IS" BASIS,
133eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  See the License for the specific language governing permissions and
153eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *  limitations under the License.
163eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski *
173eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski ******************************************************************************/
183eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
193eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski#include <gtest/gtest.h>
203eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
213eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski#include "AllocationTestHarness.h"
223eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
233eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski#include "osi/include/properties.h"
243eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
253eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowskiclass PropertiesTest : public AllocationTestHarness {};
263eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
273eb4a4827c9436ddd8333457be3474b6fadfb38fJakub PawlowskiTEST_F(PropertiesTest, test_default_value) {
283eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  char value[PROPERTY_VALUE_MAX] = {0};
293eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  osi_property_get("very.useful.test", value, "very_useful_value");
303eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  ASSERT_STREQ(value, "very_useful_value");
313eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski}
323eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
333eb4a4827c9436ddd8333457be3474b6fadfb38fJakub PawlowskiTEST_F(PropertiesTest, test_successfull_set_and_get_value) {
343eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  char value[PROPERTY_VALUE_MAX] = "nothing_interesting";
353eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  int ret = osi_property_set("very.useful.set.test", value);
363eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  ASSERT_EQ(0, ret);
373eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski
383eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  char received[PROPERTY_VALUE_MAX];
393eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  osi_property_get("very.useful.set.test", received, NULL);
403eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski  ASSERT_STREQ(received, "nothing_interesting");
413eb4a4827c9436ddd8333457be3474b6fadfb38fJakub Pawlowski}
422b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He
432b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack HeTEST_F(PropertiesTest, test_default_value_int32) {
442b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  int32_t value = 42;
452b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  int32_t rvalue = osi_property_get_int32("very.useful.test", value);
462b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  ASSERT_EQ(rvalue, value);
472b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He}
482b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He
492b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack HeTEST_F(PropertiesTest, test_successfull_set_and_get_value_int32) {
502b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  char value[PROPERTY_VALUE_MAX] = "42";
512b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  int ret = osi_property_set("very.useful.set.test", value);
522b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  ASSERT_EQ(0, ret);
532b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He
542b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  int32_t received = osi_property_get_int32("very.useful.set.test", 84);
552b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He  ASSERT_EQ(received, 42);
562b59c4a0843c9f2782cf4163f921eddb31dd6ff9Jack He}
57