[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] A few more test cases and unreachable lines



commit c390efe84fa7a4c47e39ce0cc7e34550f515d5be
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Jun 19 16:21:21 2019 -0400

    A few more test cases and unreachable lines
---
 src/lib/confmgt/typedvar.c | 18 ++++++++++--------
 src/test/test_confparse.c  | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/lib/confmgt/typedvar.c b/src/lib/confmgt/typedvar.c
index fc45c4448..c2b9b4572 100644
--- a/src/lib/confmgt/typedvar.c
+++ b/src/lib/confmgt/typedvar.c
@@ -44,7 +44,7 @@ typed_var_assign_ex(void *target, const char *value, char **errmsg,
                     const var_type_def_t *def)
 {
   if (BUG(!def))
-    return -1;
+    return -1; // LCOV_EXCL_LINE
   // clear old value if needed.
   typed_var_free_ex(target, def);
 
@@ -67,7 +67,7 @@ typed_var_kvassign_ex(void *target, const config_line_t *line,
                       char **errmsg, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return -1;
+    return -1; // LCOV_EXCL_LINE
 
   if (def->fns->kv_parse) {
     // We do _not_ free the old value here, since linelist options
@@ -86,7 +86,7 @@ void
 typed_var_free_ex(void *target, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return;
+    return; // LCOV_EXCL_LINE
   if (def->fns->clear) {
     def->fns->clear(target, def->params);
   }
@@ -102,7 +102,7 @@ char *
 typed_var_encode_ex(const void *value, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return NULL;
+    return NULL; // LCOV_EXCL_LINE
   tor_assert(def->fns->encode);
   return def->fns->encode(value, def->params);
 }
@@ -121,7 +121,7 @@ typed_var_kvencode_ex(const char *key, const void *value,
                       const var_type_def_t *def)
 {
   if (BUG(!def))
-    return NULL;
+    return NULL; // LCOV_EXCL_LINE
   if (def->fns->kv_encode) {
     return def->fns->kv_encode(key, value, def->params);
   }
@@ -145,7 +145,7 @@ int
 typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return -1;
+    return -1; // LCOV_EXCL_LINE
   if (def->fns->copy) {
     // If we have been provided a copy fuction, use it.
     return def->fns->copy(dest, src, def);
@@ -160,8 +160,10 @@ typed_var_copy_ex(void *dest, const void *src, const var_type_def_t *def)
   char *err = NULL;
   int rv = typed_var_assign_ex(dest, enc, &err, def);
   if (BUG(rv < 0)) {
+    // LCOV_EXCL_START
     log_warn(LD_BUG, "Encoded value %s was not parseable as a %s: %s",
              escaped(enc), def->name, err?err:"");
+    // LCOV_EXCL_STOP
   }
   tor_free(err);
   tor_free(enc);
@@ -176,7 +178,7 @@ bool
 typed_var_eq_ex(const void *a, const void *b, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return false;
+    return false; // LCOV_EXCL_LINE
 
   if (def->fns->eq) {
     // Use a provided eq function if we got one.
@@ -200,7 +202,7 @@ bool
 typed_var_ok_ex(const void *value, const var_type_def_t *def)
 {
   if (BUG(!def))
-    return false;
+    return false; // LCOV_EXCL_LINE
 
   if (def->fns->ok)
     return def->fns->ok(value, def->params);
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index 9e626356d..d0c33841f 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -290,6 +290,8 @@ test_confparse_assign_simple(void *arg)
   tt_str_op(tst->mixed_hidden_lines->next->value, OP_EQ, "ABC");
   tt_assert(!tst->mixed_hidden_lines->next->next);
 
+  tt_assert(config_check_ok(&test_fmt, tst, LOG_ERR));
+
  done:
   config_free(&test_fmt, tst);
 }
@@ -344,6 +346,8 @@ test_confparse_assign_deprecated(void *arg)
 
   tt_int_op(tst->deprecated_int, OP_EQ, 7);
 
+  tt_assert(config_check_ok(&test_fmt, tst, LOG_ERR));
+
  done:
   teardown_capture_of_logs();
   config_free(&test_fmt, tst);
@@ -489,6 +493,8 @@ static const badval_test_t bv_badabool =
 static const badval_test_t bv_badtime = { "time lunchtime\n", "Invalid time" };
 static const badval_test_t bv_virt = { "MixedLines 7\n", "virtual option" };
 static const badval_test_t bv_rs = { "Routerset 2.2.2.2.2\n", "Invalid" };
+static const badval_test_t bv_big_interval =
+  { "interval 1000 months", "too large" };
 
 /* Try config_dump(), and make sure it behaves correctly */
 static void
@@ -885,6 +891,18 @@ test_confparse_unitparse(void *args)
   ;
 }
 
+static void
+test_confparse_check_ok_fail(void *arg)
+{
+  (void)arg;
+  test_struct_t *tst = config_new(&test_fmt);
+  tst->pos = -10;
+  tt_assert(! config_check_ok(&test_fmt, tst, LOG_INFO));
+
+ done:
+  config_free(&test_fmt, tst);
+}
+
 #define CONFPARSE_TEST(name, flags)                          \
   { #name, test_confparse_ ## name, flags, NULL, NULL }
 
@@ -912,6 +930,7 @@ struct testcase_t confparse_tests[] = {
   BADVAL_TEST(badtime),
   BADVAL_TEST(virt),
   BADVAL_TEST(rs),
+  BADVAL_TEST(big_interval),
   CONFPARSE_TEST(dump, 0),
   CONFPARSE_TEST(reset, 0),
   CONFPARSE_TEST(reassign, 0),
@@ -919,5 +938,6 @@ struct testcase_t confparse_tests[] = {
   CONFPARSE_TEST(get_assigned, 0),
   CONFPARSE_TEST(extra_lines, 0),
   CONFPARSE_TEST(unitparse, 0),
+  CONFPARSE_TEST(check_ok_fail, 0),
   END_OF_TESTCASES
 };



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits