diff options
author | Max <msuraev@sysmocom.de> | 2017-02-24 13:59:14 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2017-03-01 16:37:59 +0000 |
commit | 70c7d4160dfb9b710e4bf93d3d6265dce8b0392f (patch) | |
tree | c2791ce6eeb6dafa55f79d851e2f21cb0bd4358e /tests | |
parent | 9756c4691d576c5bfe175245a82d00b2d03ed70e (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')
-rw-r--r-- | tests/Makefile.am | 7 | ||||
-rw-r--r-- | tests/ctrl/ctrl_test.c | 36 | ||||
-rw-r--r-- | tests/ctrl/ctrl_test.ok | 9 | ||||
-rw-r--r-- | tests/testsuite.at | 6 |
4 files changed, 56 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index f6d4db3e..35b91501 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,7 +11,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \ logging/logging_test fr/fr_test codec/codec_test \ loggingrb/loggingrb_test strrb/strrb_test \ vty/vty_test comp128/comp128_test utils/utils_test \ - smscb/gsm0341_test stats/stats_test \ + smscb/gsm0341_test stats/stats_test ctrl/ctrl_test \ bitvec/bitvec_test msgb/msgb_test bits/bitcomp_test \ tlv/tlv_test gsup/gsup_test oap/oap_test fsm/fsm_test \ write_queue/wqueue_test socket/socket_test @@ -42,6 +42,9 @@ comp128_comp128_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/ auth_milenage_test_SOURCES = auth/milenage_test.c auth_milenage_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la +ctrl_ctrl_test_SOURCES = ctrl/ctrl_test.c +ctrl_ctrl_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/ctrl/libosmoctrl.la + gea_gea_test_SOURCES = gea/gea_test.c gea_gea_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la @@ -164,7 +167,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ timer/timer_test.ok sms/sms_test.ok ussd/ussd_test.ok \ smscb/smscb_test.ok bits/bitrev_test.ok a5/a5_test.ok \ - conv/conv_test.ok auth/milenage_test.ok \ + conv/conv_test.ok auth/milenage_test.ok ctrl/ctrl_test.ok \ lapd/lapd_test.ok gsm0408/gsm0408_test.ok \ gsm0808/gsm0808_test.ok gb/bssgp_fc_tests.err \ gb/bssgp_fc_tests.ok gb/bssgp_fc_tests.sh \ 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; +} diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok new file mode 100644 index 00000000..c4b05e9a --- /dev/null +++ b/tests/ctrl/ctrl_test.ok @@ -0,0 +1,9 @@ +Checking ctrl types... +ctrl type 0 is unknown 0x0 [PARSE FAILED] +ctrl type 1 is GET -> 1 OK +ctrl type 2 is SET -> 2 OK +ctrl type 3 is GET_REPLY -> 3 OK +ctrl type 4 is SET_REPLY -> 4 OK +ctrl type 5 is TRAP -> 5 OK +ctrl type 6 is ERROR -> 6 OK +ctrl type 64 is unknown 0x40 [PARSE FAILED] diff --git a/tests/testsuite.at b/tests/testsuite.at index a3be0e7d..6d8c5d3e 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -9,6 +9,12 @@ cat $abs_srcdir/a5/a5_test.ok > expout AT_CHECK([$abs_top_builddir/tests/a5/a5_test], [0], [expout]) AT_CLEANUP +AT_SETUP([ctrl]) +AT_KEYWORDS([ctrl]) +cat $abs_srcdir/ctrl/ctrl_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/ctrl/ctrl_test], [0], [expout]) +AT_CLEANUP + AT_SETUP([kasumi]) AT_KEYWORDS([kasumi]) cat $abs_srcdir/kasumi/kasumi_test.ok > expout |