2015-02-02 11:53:12 -04:00
|
|
|
#include <systemlib/visibility.h>
|
|
|
|
#include <systemlib/param/param.h>
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2015-02-04 04:33:14 -04:00
|
|
|
/*
|
|
|
|
* These will be used in param.c if compiling for unit tests
|
|
|
|
*/
|
2015-02-03 05:35:20 -04:00
|
|
|
struct param_info_s param_array[256];
|
|
|
|
struct param_info_s *param_info_base;
|
|
|
|
struct param_info_s *param_info_limit;
|
2015-02-02 11:53:12 -04:00
|
|
|
|
2015-02-03 06:49:34 -04:00
|
|
|
/*
|
|
|
|
* Adds test parameters
|
|
|
|
*/
|
2015-03-02 15:32:39 -04:00
|
|
|
void _add_parameters()
|
|
|
|
{
|
2015-02-03 06:49:34 -04:00
|
|
|
struct param_info_s test_1 = {
|
|
|
|
"TEST_1",
|
|
|
|
PARAM_TYPE_INT32
|
|
|
|
};
|
|
|
|
test_1.val.i = 2;
|
|
|
|
|
|
|
|
struct param_info_s test_2 = {
|
|
|
|
"TEST_2",
|
|
|
|
PARAM_TYPE_INT32
|
|
|
|
};
|
|
|
|
test_2.val.i = 4;
|
|
|
|
|
2015-02-04 04:33:14 -04:00
|
|
|
struct param_info_s rc_x = {
|
|
|
|
"RC_X",
|
|
|
|
PARAM_TYPE_INT32
|
|
|
|
};
|
|
|
|
rc_x.val.i = 8;
|
|
|
|
|
|
|
|
struct param_info_s rc2_x = {
|
|
|
|
"RC2_X",
|
|
|
|
PARAM_TYPE_INT32
|
|
|
|
};
|
|
|
|
rc2_x.val.i = 16;
|
|
|
|
|
2015-02-03 05:35:20 -04:00
|
|
|
param_array[0] = test_1;
|
2015-02-03 06:49:34 -04:00
|
|
|
param_array[1] = test_2;
|
2015-02-04 04:33:14 -04:00
|
|
|
param_array[2] = rc_x;
|
|
|
|
param_array[3] = rc2_x;
|
2015-02-03 05:35:20 -04:00
|
|
|
param_info_base = (struct param_info_s *) ¶m_array[0];
|
2015-02-04 04:33:14 -04:00
|
|
|
param_info_limit = (struct param_info_s *) ¶m_array[4]; // needs to point at the end of the data,
|
2015-03-02 15:32:39 -04:00
|
|
|
// therefore number of params + 1
|
2015-02-04 04:33:14 -04:00
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
void _assert_parameter_int_value(param_t param, int32_t expected)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
int32_t value;
|
|
|
|
int result = param_get(param, &value);
|
2015-06-30 02:15:23 -03:00
|
|
|
ASSERT_EQ(0, result) << printf("param_get (%lu) did not return parameter\n", param);
|
|
|
|
ASSERT_EQ(expected, value) << printf("value for param (%lu) doesn't match default value\n", param);
|
2015-02-04 04:33:14 -04:00
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
void _set_all_int_parameters_to(int32_t value)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
param_set((param_t)0, &value);
|
|
|
|
param_set((param_t)1, &value);
|
|
|
|
param_set((param_t)2, &value);
|
|
|
|
param_set((param_t)3, &value);
|
|
|
|
|
|
|
|
_assert_parameter_int_value((param_t)0, value);
|
|
|
|
_assert_parameter_int_value((param_t)1, value);
|
|
|
|
_assert_parameter_int_value((param_t)2, value);
|
|
|
|
_assert_parameter_int_value((param_t)3, value);
|
2015-02-03 06:49:34 -04:00
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, SimpleFind)
|
|
|
|
{
|
2015-02-03 06:49:34 -04:00
|
|
|
_add_parameters();
|
2015-03-02 15:32:39 -04:00
|
|
|
|
2015-02-03 06:49:34 -04:00
|
|
|
param_t param = param_find("TEST_2");
|
|
|
|
ASSERT_NE(PARAM_INVALID, param) << "param_find did not find parameter";
|
2015-02-02 11:53:12 -04:00
|
|
|
|
|
|
|
int32_t value;
|
2015-02-03 06:49:34 -04:00
|
|
|
int result = param_get(param, &value);
|
|
|
|
ASSERT_EQ(0, result) << "param_get did not return parameter";
|
|
|
|
ASSERT_EQ(4, value) << "value of returned parameter does not match";
|
2015-02-02 11:53:12 -04:00
|
|
|
}
|
2015-02-03 06:49:34 -04:00
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, ResetAll)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
_add_parameters();
|
|
|
|
_set_all_int_parameters_to(50);
|
|
|
|
|
|
|
|
param_reset_all();
|
|
|
|
|
|
|
|
_assert_parameter_int_value((param_t)0, 2);
|
|
|
|
_assert_parameter_int_value((param_t)1, 4);
|
|
|
|
_assert_parameter_int_value((param_t)2, 8);
|
|
|
|
_assert_parameter_int_value((param_t)3, 16);
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, ResetAllExcludesOne)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
_add_parameters();
|
|
|
|
_set_all_int_parameters_to(50);
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
const char *excludes[] = {"RC_X"};
|
2015-02-04 04:33:14 -04:00
|
|
|
param_reset_excludes(excludes, 1);
|
|
|
|
|
|
|
|
_assert_parameter_int_value((param_t)0, 2);
|
|
|
|
_assert_parameter_int_value((param_t)1, 4);
|
|
|
|
_assert_parameter_int_value((param_t)2, 50);
|
|
|
|
_assert_parameter_int_value((param_t)3, 16);
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, ResetAllExcludesTwo)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
_add_parameters();
|
|
|
|
_set_all_int_parameters_to(50);
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
const char *excludes[] = {"RC_X", "TEST_1"};
|
2015-02-04 04:33:14 -04:00
|
|
|
param_reset_excludes(excludes, 2);
|
|
|
|
|
|
|
|
_assert_parameter_int_value((param_t)0, 50);
|
|
|
|
_assert_parameter_int_value((param_t)1, 4);
|
|
|
|
_assert_parameter_int_value((param_t)2, 50);
|
|
|
|
_assert_parameter_int_value((param_t)3, 16);
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, ResetAllExcludesBoundaryCheck)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
_add_parameters();
|
|
|
|
_set_all_int_parameters_to(50);
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
const char *excludes[] = {"RC_X", "TEST_1"};
|
2015-02-04 04:33:14 -04:00
|
|
|
param_reset_excludes(excludes, 1);
|
|
|
|
|
|
|
|
_assert_parameter_int_value((param_t)0, 2);
|
|
|
|
_assert_parameter_int_value((param_t)1, 4);
|
|
|
|
_assert_parameter_int_value((param_t)2, 50);
|
|
|
|
_assert_parameter_int_value((param_t)3, 16);
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
TEST(ParamTest, ResetAllExcludesWildcard)
|
|
|
|
{
|
2015-02-04 04:33:14 -04:00
|
|
|
_add_parameters();
|
|
|
|
_set_all_int_parameters_to(50);
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
const char *excludes[] = {"RC*"};
|
2015-02-04 04:33:14 -04:00
|
|
|
param_reset_excludes(excludes, 1);
|
2015-02-03 06:49:34 -04:00
|
|
|
|
2015-02-04 04:33:14 -04:00
|
|
|
_assert_parameter_int_value((param_t)0, 2);
|
|
|
|
_assert_parameter_int_value((param_t)1, 4);
|
|
|
|
_assert_parameter_int_value((param_t)2, 50);
|
|
|
|
_assert_parameter_int_value((param_t)3, 50);
|
|
|
|
}
|