aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ctrl/ctrl_test.c
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-02-24 13:59:14 +0100
committerMax <msuraev@sysmocom.de>2017-03-01 16:37:59 +0000
commit70c7d4160dfb9b710e4bf93d3d6265dce8b0392f (patch)
treec2791ce6eeb6dafa55f79d851e2f21cb0bd4358e /tests/ctrl/ctrl_test.c
parent9756c4691d576c5bfe175245a82d00b2d03ed70e (diff)
Use value_string for ctrl_type
Use value_string for enum ctrl_type instead of custom code. Add corresponding unit tests. Related: OS#1615 Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28
Diffstat (limited to 'tests/ctrl/ctrl_test.c')
-rw-r--r--tests/ctrl/ctrl_test.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
new file mode 100644
index 00000000..3bbab76a
--- /dev/null
+++ b/tests/ctrl/ctrl_test.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/ctrl/control_cmd.h>
+
+inline void check_type(enum ctrl_type c)
+{
+ const char *t = get_value_string(ctrl_type_vals, c);
+ int v = get_string_value(ctrl_type_vals, t);
+
+ printf("ctrl type %d is %s ", c, t);
+ if (v < 0)
+ printf("[PARSE FAILED]\n");
+ else
+ printf("-> %d %s\n", v, c != v ? "FAIL" : "OK");
+}
+
+int main(int argc, char **argv)
+{
+ printf("Checking ctrl types...\n");
+
+ check_type(CTRL_TYPE_UNKNOWN);
+ check_type(CTRL_TYPE_GET);
+ check_type(CTRL_TYPE_SET);
+ check_type(CTRL_TYPE_GET_REPLY);
+ check_type(CTRL_TYPE_SET_REPLY);
+ check_type(CTRL_TYPE_TRAP);
+ check_type(CTRL_TYPE_ERROR);
+ check_type(64);
+
+ return 0;
+}