guacamole-spice-protocol/tests/protocol/instruction_parse.c

77 lines
2.3 KiB
C
Raw Normal View History

/*
2016-03-25 19:59:40 +00:00
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
2013-10-02 01:12:15 +00:00
*
2016-03-25 19:59:40 +00:00
* http://www.apache.org/licenses/LICENSE-2.0
2013-10-02 01:12:15 +00:00
*
2016-03-25 19:59:40 +00:00
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
2014-01-01 22:44:28 +00:00
#include "config.h"
#include "suite.h"
2013-10-02 01:12:15 +00:00
#include <stdio.h>
#include <stdlib.h>
2014-01-01 22:44:28 +00:00
#include <unistd.h>
2013-10-02 01:12:15 +00:00
2014-01-01 22:44:28 +00:00
#include <CUnit/Basic.h>
#include <guacamole/parser.h>
2013-10-02 01:12:15 +00:00
void test_instruction_parse() {
2013-10-02 01:33:50 +00:00
/* Allocate parser */
guac_parser* parser = guac_parser_alloc();
CU_ASSERT_PTR_NOT_NULL_FATAL(parser);
2013-10-02 01:33:50 +00:00
/* Instruction input */
char buffer[] = "4.test,8.testdata,5.zxcvb,13.guacamoletest;XXXXXXXXXXXXXXXXXX";
char* current = buffer;
/* While data remains */
int remaining = sizeof(buffer)-1;
while (remaining > 18) {
/* Parse more data */
int parsed = guac_parser_append(parser, current, remaining);
if (parsed == 0)
break;
current += parsed;
remaining -= parsed;
}
CU_ASSERT_EQUAL(remaining, 18);
CU_ASSERT_EQUAL(parser->state, GUAC_PARSE_COMPLETE);
2013-10-02 01:33:50 +00:00
/* Parse is complete - no more data should be read */
CU_ASSERT_EQUAL(guac_parser_append(parser, current, 18), 0);
CU_ASSERT_EQUAL(parser->state, GUAC_PARSE_COMPLETE);
2013-10-02 01:33:50 +00:00
/* Validate resulting structure */
CU_ASSERT_EQUAL(parser->argc, 3);
CU_ASSERT_PTR_NOT_NULL_FATAL(parser->opcode);
CU_ASSERT_PTR_NOT_NULL_FATAL(parser->argv[0]);
CU_ASSERT_PTR_NOT_NULL_FATAL(parser->argv[1]);
CU_ASSERT_PTR_NOT_NULL_FATAL(parser->argv[2]);
2013-10-02 01:33:50 +00:00
/* Validate resulting content */
CU_ASSERT_STRING_EQUAL(parser->opcode, "test");
CU_ASSERT_STRING_EQUAL(parser->argv[0], "testdata");
CU_ASSERT_STRING_EQUAL(parser->argv[1], "zxcvb");
CU_ASSERT_STRING_EQUAL(parser->argv[2], "guacamoletest");
2013-10-02 01:33:50 +00:00
2013-10-02 01:12:15 +00:00
}