From: Jennifer Richards Date: Wed, 11 Apr 2018 16:01:14 +0000 (-0400) Subject: Add req encode/decode tests to make system, move from test/ to tests/ X-Git-Tag: 3.4.0~1^2~50^2~2 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=29bc5ee03fec338eb4056c9a641a45ea722b84ef Add req encode/decode tests to make system, move from test/ to tests/ --- diff --git a/CMakeLists.txt b/CMakeLists.txt index edd742c..c97e39c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,8 +96,8 @@ set(SOURCE_FILES add_executable(trust_router ${SOURCE_FILES}) # Test build targets - for debugging -add_executable(test_mon_req_encode mon/tr_mon_req.c mon/tr_mon_req.h mon/test/test_mon_req_encode.c mon/tr_mon_req_encode.c) +add_executable(test_mon_req_encode mon/tr_mon_req.c mon/tr_mon_req.h mon/tests/test_mon_req_encode.c mon/tr_mon_req_encode.c) target_link_libraries(test_mon_req_encode jansson talloc glib-2.0) -add_executable(test_mon_req_decode mon/tr_mon_req.c mon/tr_mon_req.h mon/test/test_mon_req_decode.c mon/tr_mon_req_decode.c) +add_executable(test_mon_req_decode mon/tr_mon_req.c mon/tr_mon_req.h mon/tests/test_mon_req_decode.c mon/tr_mon_req_decode.c) target_link_libraries(test_mon_req_decode jansson talloc glib-2.0) diff --git a/Makefile.am b/Makefile.am index ae745ef..2e27e3f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,8 @@ DISTCHECK_CONFIGURE_FLAGS = \ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) bin_PROGRAMS= tr/trust_router tr/trpc tid/example/tidc tid/example/tids common/tests/tr_dh_test common/tests/mq_test \ common/tests/thread_test trp/msgtst trp/test/rtbl_test trp/test/ptbl_test common/tests/cfg_test \ - common/tests/commtest common/tests/name_test common/tests/filt_test + common/tests/commtest common/tests/name_test common/tests/filt_test mon/tests/test_mon_req_encode \ + mon/tests/test_mon_req_decode AM_CPPFLAGS=-I$(srcdir)/include $(GLIB_CFLAGS) AM_CFLAGS = -Wall -Werror=missing-prototypes -Werror -Wno-parentheses $(GLIB_CFLAGS) SUBDIRS = gsscon @@ -35,6 +36,11 @@ trp/trp_upd.c \ common/tr_config.c \ common/tr_mq.c +mon_srcs = \ + mon/tr_mon_req.c \ + mon/tr_mon_req_encode.c \ + mon/tr_mon_req_decode.c + check_PROGRAMS = common/t_constraint TESTS = common/t_constraint TEST_CFLAGS = -Wno-missing-prototypes @@ -164,6 +170,16 @@ common_tests_filt_test_LDADD = gsscon/libgsscon.la $(GLIB_LIBS) common_tests_filt_test_LDFLAGS = $(AM_LDFLAGS) -ltalloc -pthread common_tests_filt_test_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) +mon_tests_test_mon_req_encode_SOURCES = mon/tests/test_mon_req_encode.c \ + $(mon_srcs) +mon_tests_test_mon_req_encode_LDADD = $(GLIB_LIBS) +mon_tests_test_mon_req_encode_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) + +mon_tests_test_mon_req_decode_SOURCES = mon/tests/test_mon_req_decode.c \ + $(mon_srcs) +mon_tests_test_mon_req_decode_LDADD = $(GLIB_LIBS) +mon_tests_test_mon_req_decode_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) + pkginclude_HEADERS = include/trust_router/tid.h include/trust_router/tr_name.h \ include/tr_debug.h include/trust_router/trp.h \ include/trust_router/tr_dh.h \ diff --git a/mon/test/req_reconfigure.test b/mon/tests/req_reconfigure.test similarity index 100% rename from mon/test/req_reconfigure.test rename to mon/tests/req_reconfigure.test diff --git a/mon/test/req_show_all_options.test b/mon/tests/req_show_all_options.test similarity index 100% rename from mon/test/req_show_all_options.test rename to mon/tests/req_show_all_options.test diff --git a/mon/test/req_show_no_options.test b/mon/tests/req_show_no_options.test similarity index 100% rename from mon/test/req_show_no_options.test rename to mon/tests/req_show_no_options.test diff --git a/mon/test/test_mon_req_decode.c b/mon/tests/test_mon_req_decode.c similarity index 87% rename from mon/test/test_mon_req_decode.c rename to mon/tests/test_mon_req_decode.c index 83ccd43..5c1c279 100644 --- a/mon/test/test_mon_req_decode.c +++ b/mon/tests/test_mon_req_decode.c @@ -13,7 +13,7 @@ /** * @return reconfigure command */ -TR_MON_REQ *reconfigure() +static TR_MON_REQ *reconfigure() { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_RECONFIGURE); assert(req); @@ -23,7 +23,7 @@ TR_MON_REQ *reconfigure() /** * @return show command with no options */ -TR_MON_REQ *show_plain() +static TR_MON_REQ *show_plain() { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_SHOW); assert(req); @@ -34,7 +34,7 @@ TR_MON_REQ *show_plain() * @param opts array of option types, terminated with OPT_TYPE_UNKNOWN * @return show command with the requested options, excluding the terminator */ -TR_MON_REQ *show_options(const TR_MON_OPT_TYPE *opts) +static TR_MON_REQ *show_options(const TR_MON_OPT_TYPE *opts) { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_SHOW); assert(req); @@ -49,7 +49,7 @@ TR_MON_REQ *show_options(const TR_MON_OPT_TYPE *opts) /** * @return show command with every option */ -TR_MON_REQ *show_all_options() +static TR_MON_REQ *show_all_options() { TR_MON_OPT_TYPE opts[] = { OPT_TYPE_SHOW_SERIAL, @@ -65,7 +65,7 @@ TR_MON_REQ *show_all_options() return show_options(opts); } -char *read_file(const char *filename) +static char *read_file(const char *filename) { FILE *f = fopen(filename, "r"); char *s = NULL; @@ -80,7 +80,7 @@ char *read_file(const char *filename) return s; } -int equal(TR_MON_REQ *r1, TR_MON_REQ *r2) +static int equal(TR_MON_REQ *r1, TR_MON_REQ *r2) { size_t ii; @@ -98,7 +98,7 @@ int equal(TR_MON_REQ *r1, TR_MON_REQ *r2) return 1; } -int run_test(const char *filename, TR_MON_REQ *(generator)()) +static int run_test(const char *filename, TR_MON_REQ *(generator)()) { TR_MON_REQ *req = NULL; TR_MON_REQ *expected = NULL; diff --git a/mon/test/test_mon_req_encode.c b/mon/tests/test_mon_req_encode.c similarity index 94% rename from mon/test/test_mon_req_encode.c rename to mon/tests/test_mon_req_encode.c index 4a6214a..c797cc0 100644 --- a/mon/test/test_mon_req_encode.c +++ b/mon/tests/test_mon_req_encode.c @@ -12,7 +12,7 @@ #define JSON_DUMP_OPTS 0 -char *reconfigure() +static char *reconfigure() { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_RECONFIGURE); json_t *req_json = tr_mon_req_encode(req); @@ -25,7 +25,7 @@ char *reconfigure() return result; } -char *show_plain() +static char *show_plain() { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_SHOW); json_t *req_json = tr_mon_req_encode(req); @@ -38,7 +38,7 @@ char *show_plain() return result; } -char *show_options(const TR_MON_OPT_TYPE *opts) +static char *show_options(const TR_MON_OPT_TYPE *opts) { TR_MON_REQ *req = tr_mon_req_new(NULL, MON_CMD_SHOW); json_t *req_json = NULL; @@ -62,7 +62,7 @@ char *show_options(const TR_MON_OPT_TYPE *opts) return result; } -char *read_file(const char *filename) +static char *read_file(const char *filename) { FILE *f = fopen(filename, "r"); char *s = NULL; diff --git a/mon/tr_mon_req.c b/mon/tr_mon_req.c index ec058f3..3adb2a3 100644 --- a/mon/tr_mon_req.c +++ b/mon/tr_mon_req.c @@ -129,6 +129,7 @@ const char *cmd_to_string(TR_MON_CMD cmd) case MON_CMD_SHOW: return "show"; } + return NULL; } // Helper macro for the cmd_from_string method @@ -176,6 +177,7 @@ const char *opt_type_to_string(TR_MON_OPT_TYPE opt_type) case OPT_TYPE_SHOW_COMMUNITIES: return "communities"; } + return NULL; } // Helper macro for the opt_type_from_string method