From abc676ef13b56601dba3369e2f662d6e75f9de22 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 1 Oct 2013 20:58:15 -0700 Subject: [PATCH] Fix test's assumptions regarding contract of parser. --- tests/protocol/instruction_parse.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/protocol/instruction_parse.c b/tests/protocol/instruction_parse.c index 10637bbb..d7814524 100644 --- a/tests/protocol/instruction_parse.c +++ b/tests/protocol/instruction_parse.c @@ -55,20 +55,22 @@ void test_instruction_parse() { char buffer[] = "4.test,8.testdata,5.zxcvb,13.guacamoletest;XXXXXXXXXXXXXXXXXX"; char* current = buffer; - /* First element */ - CU_ASSERT_EQUAL(guac_instruction_append(instruction, current, 7), 7); - CU_ASSERT_EQUAL(instruction->state, GUAC_INSTRUCTION_PARSE_LENGTH); - current += 7; + /* While data remains */ + int remaining = sizeof(buffer)-1; + while (remaining > 18) { - /* Part of second */ - CU_ASSERT_EQUAL(guac_instruction_append(instruction, current, 9), 9); - CU_ASSERT_EQUAL(instruction->state, GUAC_INSTRUCTION_PARSE_CONTENT); - current += 9; + /* Parse more data */ + int parsed = guac_instruction_append(instruction, current, remaining); + if (parsed == 0) + break; - /* Rest of instruction */ - CU_ASSERT_EQUAL(guac_instruction_append(instruction, current, 45), 27); + current += parsed; + remaining -= parsed; + + } + + CU_ASSERT_EQUAL(remaining, 18); CU_ASSERT_EQUAL(instruction->state, GUAC_INSTRUCTION_PARSE_COMPLETE); - current += 27; /* Parse is complete - no more data should be read */ CU_ASSERT_EQUAL(guac_instruction_append(instruction, current, 18), 0);