Add req encode/decode tests to make system, move from test/ to tests/
authorJennifer Richards <jennifer@painless-security.com>
Wed, 11 Apr 2018 16:01:14 +0000 (12:01 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Wed, 11 Apr 2018 16:01:14 +0000 (12:01 -0400)
CMakeLists.txt
Makefile.am
mon/tests/req_reconfigure.test [moved from mon/test/req_reconfigure.test with 100% similarity]
mon/tests/req_show_all_options.test [moved from mon/test/req_show_all_options.test with 100% similarity]
mon/tests/req_show_no_options.test [moved from mon/test/req_show_no_options.test with 100% similarity]
mon/tests/test_mon_req_decode.c [moved from mon/test/test_mon_req_decode.c with 87% similarity]
mon/tests/test_mon_req_encode.c [moved from mon/test/test_mon_req_encode.c with 94% similarity]
mon/tr_mon_req.c

index edd742c..c97e39c 100644 (file)
@@ -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)
index ae745ef..2e27e3f 100644 (file)
@@ -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 \
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 (file)
@@ -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;
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 (file)
@@ -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;
index ec058f3..3adb2a3 100644 (file)
@@ -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