From dbd170f752b422004835def53f84b786f32c9a08 Mon Sep 17 00:00:00 2001 From: Esteban Manchado Velázquez Date: Mon, 20 Feb 2012 22:53:08 +0100 Subject: Some more corner cases for tor_sscanf --- src/test/test_util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/test/test_util.c') diff --git a/src/test/test_util.c b/src/test/test_util.c index c63f97d7f6..e2050f8d77 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1379,10 +1379,14 @@ test_util_sscanf(void) char s1[10], s2[10], s3[10], ch; int r; - /* Simple tests (malformed patterns and literal matching) */ + /* Simple tests (malformed patterns, literal matching, ...) */ test_eq(-1, tor_sscanf("123", "%i", &r)); /* %i is not supported */ test_eq(-1, tor_sscanf("wrong", "%5c", s1)); /* %c cannot have a number. */ test_eq(-1, tor_sscanf("hello", "%s", s1)); /* %s needs a number. */ + test_eq(-1, tor_sscanf("prettylongstring", "%999999s", s1)); + test_eq(-1, tor_sscanf("prettylongstring", "%0s", s1)); + test_eq(-1, tor_sscanf("We're the 99 monkeys", "We're the 99%%")); + test_eq(0, tor_sscanf("prettylongstring", "%10s", NULL)); /* No '%'-strings: always "success" */ test_eq(0, tor_sscanf("hello world", "hello world")); test_eq(0, tor_sscanf("hello world", "good bye")); @@ -1477,6 +1481,8 @@ test_util_sscanf(void) test_eq(2, tor_sscanf("76trombones", "%6u%9s", &u1, s1)); /* %u%s */ test_eq(76, u1); test_streq(s1, "trombones"); + test_eq(1, tor_sscanf("prettylongstring", "%999s", s1)); + test_streq(s1, "prettylongstring"); /* %s doesn't eat spaces */ test_eq(2, tor_sscanf("hello world", "%9s %9s", s1, s2)); test_streq(s1, "hello"); -- cgit v1.2.3-54-g00ecf