aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Antener <antener_a@gmx.ch>2015-02-04 09:33:14 +0100
committerLorenz Meier <lm@inf.ethz.ch>2015-02-10 08:39:46 +0100
commita7580a1eae5a5fe8f2a7e70a1447009fed91645e (patch)
treea7c23d2c7dcdc1bae821f5100a5964723b1bfb6d
parent28e943ca28f10cc1ea205a0e18cf814c8a2afa52 (diff)
downloadpx4-firmware-a7580a1eae5a5fe8f2a7e70a1447009fed91645e.tar.gz
px4-firmware-a7580a1eae5a5fe8f2a7e70a1447009fed91645e.tar.bz2
px4-firmware-a7580a1eae5a5fe8f2a7e70a1447009fed91645e.zip
added actual tests and fixed reset-exclude funtction
-rw-r--r--src/modules/systemlib/param/param.c15
-rw-r--r--unittests/param_test.cpp104
2 files changed, 111 insertions, 8 deletions
diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c
index 7ff71a802..926ae75a7 100644
--- a/src/modules/systemlib/param/param.c
+++ b/src/modules/systemlib/param/param.c
@@ -504,15 +504,22 @@ param_reset_excludes(const char* excludes[], int num_excludes)
for (param = 0; handle_in_range(param); param++) {
const char* name = param_name(param);
+ bool exclude = false;
+
+ for (int index = 0; index < num_excludes; index ++) {
+ int len = strlen(excludes[index]);
- for (int index = 0, len = strlen(excludes[index]); index < num_excludes; index ++) {
if((excludes[index][len - 1] == '*'
- && strncmp(name, excludes[index], len - 1)) == 0
+ && strncmp(name, excludes[index], len - 1) == 0)
|| strcmp(name, excludes[index]) == 0) {
-
- param_reset(param);
+ exclude = true;
+ break;
}
}
+
+ if(!exclude) {
+ param_reset(param);
+ }
}
param_unlock();
diff --git a/unittests/param_test.cpp b/unittests/param_test.cpp
index bd2a9a45d..5ea6bcc60 100644
--- a/unittests/param_test.cpp
+++ b/unittests/param_test.cpp
@@ -3,7 +3,9 @@
#include "gtest/gtest.h"
-
+/*
+ * These will be used in param.c if compiling for unit tests
+ */
struct param_info_s param_array[256];
struct param_info_s *param_info_base;
struct param_info_s *param_info_limit;
@@ -24,16 +26,48 @@ void _add_parameters() {
};
test_2.val.i = 4;
+ 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;
+
param_array[0] = test_1;
param_array[1] = test_2;
+ param_array[2] = rc_x;
+ param_array[3] = rc2_x;
param_info_base = (struct param_info_s *) &param_array[0];
- param_info_limit = (struct param_info_s *) &param_array[2];
+ param_info_limit = (struct param_info_s *) &param_array[4]; // needs to point at the end of the data,
+ // therefore number of params + 1
+}
+
+void _assert_parameter_int_value(param_t param, int32_t expected) {
+ int32_t value;
+ int result = param_get(param, &value);
+ ASSERT_EQ(0, result) << printf("param_get (%i) did not return parameter\n", param);
+ ASSERT_EQ(expected, value) << printf("value for param (%i) doesn't match default value\n", param);
+}
+
+void _set_all_int_parameters_to(int32_t value) {
+ 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);
}
TEST(ParamTest, SimpleFind) {
_add_parameters();
-
- printf("diff: %i\n", (unsigned)(param_info_limit - param_info_base));
param_t param = param_find("TEST_2");
ASSERT_NE(PARAM_INVALID, param) << "param_find did not find parameter";
@@ -44,4 +78,66 @@ TEST(ParamTest, SimpleFind) {
ASSERT_EQ(4, value) << "value of returned parameter does not match";
}
+TEST(ParamTest, ResetAll) {
+ _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);
+}
+
+TEST(ParamTest, ResetAllExcludesOne) {
+ _add_parameters();
+ _set_all_int_parameters_to(50);
+
+ const char* excludes[] = {"RC_X"};
+ 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);
+}
+
+TEST(ParamTest, ResetAllExcludesTwo) {
+ _add_parameters();
+ _set_all_int_parameters_to(50);
+
+ const char* excludes[] = {"RC_X", "TEST_1"};
+ 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);
+}
+
+TEST(ParamTest, ResetAllExcludesBoundaryCheck) {
+ _add_parameters();
+ _set_all_int_parameters_to(50);
+
+ const char* excludes[] = {"RC_X", "TEST_1"};
+ 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);
+}
+
+TEST(ParamTest, ResetAllExcludesWildcard) {
+ _add_parameters();
+ _set_all_int_parameters_to(50);
+
+ const char* excludes[] = {"RC*"};
+ 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, 50);
+} \ No newline at end of file