]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
tinytest tt_{mem,str}_op now handle NULLs better
authorNick Mathewson <nickm@torproject.org>
Thu, 6 Mar 2014 17:12:13 +0000 (12:12 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 6 Mar 2014 17:12:13 +0000 (12:12 -0500)
Now a NULL argument to either makes it fail, not crash.

Fies bug 9004; bugfix on 0.2.2.4-alpha.

changes/bug9004 [new file with mode: 0644]
src/ext/tinytest_macros.h
src/test/test.h

diff --git a/changes/bug9004 b/changes/bug9004
new file mode 100644 (file)
index 0000000..5bab7ea
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor bugfixes (testing):
+    - Improve the tinytest implementation of string operation tests
+      so that comparisons NULL strings no longer crash the tests;
+      they now just fail, normally. Fixes bug 9004; bugfix on
+      0.2.2.4-alpha.
+
index 9ff69b1d506dab1f8d1ecc92517f8a4734754bd3..5bb8f8ec6929a57e7d788d2101803543630bc7db 100644 (file)
        tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt,        \
            {print_=value_;},{},die_on_fail)
 
+#define tt_assert_test_type_opt(a,b,str_test,type,test,fmt,die_on_fail)        \
+       tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt,        \
+            {print_=value_?value_:"<NULL>";},{},die_on_fail)
+
 /* Helper: assert that a op b, when cast to type.  Format the values with
  * printf format fmt on failure. */
 #define tt_assert_op_type(a,op,b,type,fmt)                             \
            (val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION)
 
 #define tt_str_op(a,op,b)                                              \
-       tt_assert_test_type(a,b,#a" "#op" "#b,const char *,             \
-           (strcmp(val1_,val2_) op 0),"<%s>",TT_EXIT_TEST_FUNCTION)
+       tt_assert_test_type_opt(a,b,#a" "#op" "#b,const char *,         \
+           (val1_ && val2_ && strcmp(val1_,val2_) op 0),"<%s>",        \
+           TT_EXIT_TEST_FUNCTION)
 
 #define tt_want_int_op(a,op,b)                                         \
        tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0)
index a89b558e5ac8e2e0201708714abbb931279ac25b..b902c6e47880a543b07ca972292e2bab1765b16f 100644 (file)
 #define test_mem_op(expr1, op, expr2, len)                              \
   tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2,            \
                           const char *,                                 \
-                          (memcmp(val1_, val2_, len) op 0),             \
+                          (val1_ && val2_ && memcmp(val1_, val2_, len) op 0), \
                           char *, "%s",                                 \
                           { size_t printlen = (len)*2+1;                \
-                            print_ = tor_malloc(printlen);              \
-                            base16_encode(print_, printlen, value_,     \
-                                          (len)); },                    \
+                            if (value_) {                               \
+                              print_ = tor_malloc(printlen);            \
+                              base16_encode(print_, printlen, value_,   \
+                                            (len));                     \
+                            } else {                                    \
+                              print_ = tor_strdup("null");              \
+                            }                                           \
+                          },                                            \
                           { tor_free(print_); },                        \
                           TT_EXIT_TEST_FUNCTION                         \
                           );