aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@persephoneslair.org>2012-06-20 18:38:07 -0700
committerNick Mathewson <nickm@torproject.org>2012-06-22 22:21:20 -0400
commit770374a6b3e6a60b65cf9616755b018f93a17d26 (patch)
treef9d72ee1c37b5637e2d9c25a483a186689eecbae /src/test
parentc21af69f29ca5a55385a926fdac4a8e6c8fb6d37 (diff)
downloadtor-770374a6b3e6a60b65cf9616755b018f93a17d26.tar
tor-770374a6b3e6a60b65cf9616755b018f93a17d26.tar.gz
Add unit test for format_hex_number_for_helper_exit_status()
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_util.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index a3a545047..d71d280fa 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2465,6 +2465,44 @@ test_util_spawn_background_partial_read(void *ptr)
}
/**
+ * Test for format_hex_number_for_helper_exit_status()
+ */
+
+static void
+test_util_format_hex_number(void *ptr)
+{
+ int i, len;
+ char buf[HEX_ERRNO_SIZE + 1];
+ const struct {
+ const char *str;
+ unsigned int x;
+ } test_data[] = {
+ {"0", 0},
+ {"1", 1},
+ {"273A", 0x273a},
+ {"FFFF", 0xffff},
+#if UINT_MAX >= 0xffffffff
+ {"31BC421D", 0x31bc421d},
+ {"FFFFFFFF", 0xffffffff},
+#endif
+ {NULL, 0}
+ };
+
+ (void)ptr;
+
+ for (i = 0; test_data[i].str != NULL; ++i) {
+ len = format_hex_number_for_helper_exit_status(test_data[i].x,
+ buf, HEX_ERRNO_SIZE);
+ test_neq(len, 0);
+ buf[len] = '\0';
+ test_streq(buf, test_data[i].str);
+ }
+
+ done:
+ return;
+}
+
+/**
* Test that we can properly format q Windows command line
*/
static void
@@ -3031,6 +3069,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(spawn_background_ok, 0),
UTIL_TEST(spawn_background_fail, 0),
UTIL_TEST(spawn_background_partial_read, 0),
+ UTIL_TEST(format_hex_number, 0),
UTIL_TEST(join_win_cmdline, 0),
UTIL_TEST(split_lines, 0),
UTIL_TEST(n_bits_set, 0),