- documented
[strongswan.git] / Source / charon / tests / parser_test.c
1 /**
2 * @file parser_test.h
3 *
4 *
5 */
6
7 /*
8 * Copyright (C) 2005 Jan Hutter, Martin Willi
9 * Hochschule fuer Technik Rapperswil
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 */
21
22 #include <string.h>
23
24 #include "../allocator.h"
25 #include "parser_test.h"
26 #include "../tester.h"
27 #include "../logger.h"
28 #include "../encodings.h"
29 #include "../generator.h"
30 #include "../parser.h"
31 #include "../encodings/ike_header.h"
32
33 extern payload_info_t *payload_infos[];
34
35 extern logger_t *global_logger;
36
37 /*
38 * Described in Header
39 */
40 void test_parser_with_header_payload(tester_t *tester)
41 {
42 parser_t *parser;
43 parser_context_t *parser_context;
44 ike_header_t *header_data;
45 status_t status;
46 chunk_t test_chunk;
47
48 u_int8_t test_bytes[] = {
49 0x00,0x00,0x00,0x00,
50 0x00,0x00,0x00,0x01,
51 0x00,0x00,0x00,0x00,
52 0x00,0x00,0x00,0x02,
53 0x03,0x45,0x06,0x28,
54 0x00,0x00,0x00,0x07,
55 0x00,0x00,0x00,0x08,
56 };
57 test_chunk.ptr = test_bytes;
58 test_chunk.len = sizeof(test_bytes);
59
60
61 parser = parser_create(payload_infos);
62 tester->assert_true(tester,(parser != NULL), "parser create check");
63
64 parser_context = parser->create_context(parser, test_chunk);
65 tester->assert_true(tester,(parser_context != NULL), "parser_context create check");
66
67 status = parser->parse_payload(parser, HEADER, (void**)&header_data, parser_context);
68 tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
69
70 tester->assert_true(tester,(header_data->initiator_spi == 1),"parsed initiator_spi value");
71 tester->assert_true(tester,(header_data->responder_spi == 2),"parsed responder_spi value");
72 tester->assert_true(tester,(header_data->next_payload == 3),"parsed next_payload value");
73 tester->assert_true(tester,(header_data->maj_version == 4),"parsed maj_version value");
74 tester->assert_true(tester,(header_data->min_version == 5),"parsed min_version value");
75 tester->assert_true(tester,(header_data->exchange_type == 6),"parsed exchange_type value");
76 tester->assert_true(tester,(header_data->flags.initiator == TRUE),"parsed flags.initiator value");
77 tester->assert_true(tester,(header_data->flags.version == FALSE),"parsed flags.version value");
78 tester->assert_true(tester,(header_data->flags.response == TRUE),"parsed flags.response value");
79 tester->assert_true(tester,(header_data->message_id == 7),"parsed message_id value");
80 tester->assert_true(tester,(header_data->length == 8),"parsed length value");
81
82
83 parser_context->destroy(parser_context);
84 tester->assert_true(tester,(parser->destroy(parser) == SUCCESS), "parser destroy call check");
85
86 global_logger->log_bytes(global_logger, RAW, "Header", (void*)header_data, sizeof(ike_header_t));
87
88 allocator_free(header_data);
89 }