- fixed parser to use new payload mechanisms
[strongswan.git] / Source / charon / testcases / 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 "parser_test.h"
25
26 #include "../generator.h"
27 #include "../parser.h"
28 #include "../utils/allocator.h"
29 #include "../utils/logger_manager.h"
30 #include "../payloads/encodings.h"
31 #include "../payloads/ike_header.h"
32
33
34 extern logger_manager_t *global_logger_manager;
35
36
37 /*
38 * Described in Header
39 */
40 void test_parser_with_header_payload(tester_t *tester)
41 {
42 parser_t *parser;
43 ike_header_t *ike_header;
44 status_t status;
45 chunk_t header_chunk;
46
47 u_int8_t header_bytes[] = {
48 0x00,0x00,0x00,0x00,
49 0x00,0x00,0x00,0x01,
50 0x00,0x00,0x00,0x00,
51 0x00,0x00,0x00,0x02,
52 0x03,0x45,0x06,0x28,
53 0x00,0x00,0x00,0x07,
54 0x00,0x00,0x00,0x08,
55 };
56 header_chunk.ptr = header_bytes;
57 header_chunk.len = sizeof(header_bytes);
58
59
60 parser = parser_create(header_chunk);
61 tester->assert_true(tester,(parser != NULL), "parser create check");
62
63 status = parser->parse_payload(parser, HEADER, (payload_t**)&ike_header);
64 tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
65
66 tester->assert_true(tester,(ike_header->initiator_spi == 1),"parsed initiator_spi value");
67 tester->assert_true(tester,(ike_header->responder_spi == 2),"parsed responder_spi value");
68 tester->assert_true(tester,(ike_header->next_payload == 3),"parsed next_payload value");
69 tester->assert_true(tester,(ike_header->maj_version == 4),"parsed maj_version value");
70 tester->assert_true(tester,(ike_header->min_version == 5),"parsed min_version value");
71 tester->assert_true(tester,(ike_header->exchange_type == 6),"parsed exchange_type value");
72 tester->assert_true(tester,(ike_header->flags.initiator == TRUE),"parsed flags.initiator value");
73 tester->assert_true(tester,(ike_header->flags.version == FALSE),"parsed flags.version value");
74 tester->assert_true(tester,(ike_header->flags.response == TRUE),"parsed flags.response value");
75 tester->assert_true(tester,(ike_header->message_id == 7),"parsed message_id value");
76 tester->assert_true(tester,(ike_header->length == 8),"parsed length value");
77
78 tester->assert_true(tester,(parser->destroy(parser) == SUCCESS), "parser destroy call check");
79
80 ike_header->destroy(ike_header);
81 }