diff options
author | Esteban Manchado Velázquez <emanchado@demiurgo.org> | 2012-02-05 17:53:01 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-03-08 20:49:18 -0500 |
commit | 14177f03a944da7d2a542ea8e66d040315c8fc14 (patch) | |
tree | 6f54e86f89b58f1a12253fceca5e9caa62d4e54d /src/test/test_util.c | |
parent | 314c851bc2ffacfe95d56a8d73c261b851f6a228 (diff) | |
download | tor-14177f03a944da7d2a542ea8e66d040315c8fc14.tar.gz tor-14177f03a944da7d2a542ea8e66d040315c8fc14.zip |
Improve tor_snprintf tests
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index f5f20385d0..2a315cbf54 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -591,14 +591,21 @@ test_util_strmisc(void) test_eq(-10.0, d); } - /* Test failing snprintf cases */ + /* Test tor_snprintf */ + /* Returning -1 when there's not enough room in the output buffer */ test_eq(-1, tor_snprintf(buf, 0, "Foo")); test_eq(-1, tor_snprintf(buf, 2, "Foo")); - - /* Test printf with uint64 */ + test_eq(-1, tor_snprintf(buf, 3, "Foo")); + test_neq(-1, tor_snprintf(buf, 4, "Foo")); + /* Always NUL-terminate the output */ + tor_snprintf(buf, 5, "abcdef"); + test_eq(0, buf[4]); + tor_snprintf(buf, 10, "abcdef"); + test_eq(0, buf[6]); + /* uint64 */ tor_snprintf(buf, sizeof(buf), "x!"U64_FORMAT"!x", U64_PRINTF_ARG(U64_LITERAL(12345678901))); - test_streq(buf, "x!12345678901!x"); + test_streq("x!12345678901!x", buf); /* Test str{,case}cmpstart */ test_assert(strcmpstart("abcdef", "abcdef")==0); |