e15cfd8969266346eebf34b4e829ea8fb6be8360
[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 extern payload_info_t *payload_infos[];
34
35 extern logger_manager_t *global_logger_manager;
36
37
38 /*
39 * Described in Header
40 */
41 void test_parser_with_header_payload(tester_t *tester)
42 {
43 parser_t *parser;
44 parser_context_t *parser_context;
45 ike_header_t *header_data;
46 status_t status;
47 chunk_t test_chunk;
48
49 logger_t *logger;
50
51 logger = global_logger_manager->create_logger(global_logger_manager,TESTER, "header payload");
52
53 u_int8_t test_bytes[] = {
54 0x00,0x00,0x00,0x00,
55 0x00,0x00,0x00,0x01,
56 0x00,0x00,0x00,0x00,
57 0x00,0x00,0x00,0x02,
58 0x03,0x45,0x06,0x28,
59 0x00,0x00,0x00,0x07,
60 0x00,0x00,0x00,0x08,
61 };
62 test_chunk.ptr = test_bytes;
63 test_chunk.len = sizeof(test_bytes);
64
65
66 parser = parser_create(payload_infos);
67 tester->assert_true(tester,(parser != NULL), "parser create check");
68
69 parser_context = parser->create_context(parser, test_chunk);
70 tester->assert_true(tester,(parser_context != NULL), "parser_context create check");
71
72 status = parser->parse_payload(parser, HEADER, (void**)&header_data, parser_context);
73 tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
74
75 tester->assert_true(tester,(header_data->initiator_spi == 1),"parsed initiator_spi value");
76 tester->assert_true(tester,(header_data->responder_spi == 2),"parsed responder_spi value");
77 tester->assert_true(tester,(header_data->next_payload == 3),"parsed next_payload value");
78 tester->assert_true(tester,(header_data->maj_version == 4),"parsed maj_version value");
79 tester->assert_true(tester,(header_data->min_version == 5),"parsed min_version value");
80 tester->assert_true(tester,(header_data->exchange_type == 6),"parsed exchange_type value");
81 tester->assert_true(tester,(header_data->flags.initiator == TRUE),"parsed flags.initiator value");
82 tester->assert_true(tester,(header_data->flags.version == FALSE),"parsed flags.version value");
83 tester->assert_true(tester,(header_data->flags.response == TRUE),"parsed flags.response value");
84 tester->assert_true(tester,(header_data->message_id == 7),"parsed message_id value");
85 tester->assert_true(tester,(header_data->length == 8),"parsed length value");
86
87
88 parser_context->destroy(parser_context);
89 tester->assert_true(tester,(parser->destroy(parser) == SUCCESS), "parser destroy call check");
90
91 logger->log_bytes(logger, RAW, "Header", (void*)header_data, sizeof(ike_header_t));
92
93 allocator_free(header_data);
94 }