From c83a018d05d4fb3e7054e79d5450ee692cb79522 Mon Sep 17 00:00:00 2001 From: Cliff Frey Date: Tue, 6 Jul 2010 11:08:37 -0700 Subject: [PATCH] test: always try and break every testcase up into two submessages This is just another way that would have caught the bug introduced in 076fa15132ca3a7570392e3684af6fcb452bb0dd and fixed by 03b8eaa5f8d312f44893cdb61de550993ce3e0c0. --- test.c | 61 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/test.c b/test.c index 404b2a8..6d501d6 100644 --- a/test.c +++ b/test.c @@ -1129,38 +1129,57 @@ print_error (const char *raw, size_t error_location) void test_message (const struct message *message) { - parser_init(message->type); + size_t raw_len = strlen(message->raw); + size_t msg1len; + for (msg1len = 0; msg1len < raw_len; msg1len++) { + parser_init(message->type); - size_t read; + size_t read; + const char *msg1 = message->raw; + const char *msg2 = msg1 + msg1len; + size_t msg2len = raw_len - msg1len; - read = parse(message->raw, strlen(message->raw)); + if (msg1len) { + read = parse(msg1, msg1len); - if (message->upgrade && parser->upgrade) goto test; + if (message->upgrade && parser->upgrade) goto test; - if (read != strlen(message->raw)) { - print_error(message->raw, read); - exit(1); - } + if (read != msg1len) { + print_error(msg1, read); + exit(1); + } + } - read = parse(NULL, 0); - if (message->upgrade && parser->upgrade) goto test; + read = parse(msg2, msg2len); - if (read != 0) { - print_error(message->raw, read); - exit(1); - } + if (message->upgrade && parser->upgrade) goto test; -test: + if (read != msg2len) { + print_error(msg2, read); + exit(1); + } - if (num_messages != 1) { - printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name); - exit(1); - } + read = parse(NULL, 0); - if(!message_eq(0, message)) exit(1); + if (message->upgrade && parser->upgrade) goto test; - parser_free(); + if (read != 0) { + print_error(message->raw, read); + exit(1); + } + + test: + + if (num_messages != 1) { + printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name); + exit(1); + } + + if(!message_eq(0, message)) exit(1); + + parser_free(); + } } void