49ffb0829975dbc5270f382ae2b3651013dcaa27
[strongswan.git] / Source / charon / tests / generator_test.c
1 /**
2 * @file generator.h
3 *
4 * @brief Tests to test the Generator class generator_t
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <freeswan.h>
24 #include <pluto/constants.h>
25 #include <pluto/defs.h>
26
27 #include "../allocator.h"
28 #include "generator_test.h"
29 #include "../tester.h"
30 #include "../encodings.h"
31 #include "../generator.h"
32 #include "../encodings/ike_header.h"
33
34 extern payload_info_t *payload_infos[];
35
36 void test_generator_with_unsupported_payload(tester_t *tester)
37 {
38 generator_t *generator;
39 void * data_struct;
40 chunk_t generated_data;
41
42 generator = generator_create(payload_infos);
43 tester->assert_true(tester,(generator != NULL), "generator create check");
44 tester->assert_true(tester,(generator->generate_payload(generator,(payload_type_t) -1,data_struct,&generated_data) == NOT_SUPPORTED),"generate_payload call check");
45
46 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
47 }
48
49 void test_generator_with_header_payload(tester_t *tester)
50 {
51 generator_t *generator;
52 ike_header_t header_data;
53 chunk_t generated_data;
54
55 header_data.initiator_spi = 1;
56 header_data.responder_spi = 2;
57 header_data.next_payload = 3;
58 header_data.maj_version = 4;
59 header_data.min_version = 5;
60 header_data.exchange_type = 6;
61 header_data.flags.initiator = TRUE;
62 header_data.flags.version = TRUE;
63 header_data.flags.response = TRUE;
64 header_data.message_id = 7;
65 header_data.length = 8;
66
67 generator = generator_create(payload_infos);
68 tester->assert_true(tester,(generator != NULL), "generator create check");
69 tester->assert_true(tester,(generator->generate_payload(generator,HEADER,&header_data,&generated_data) == SUCCESS),"generate_payload call check");
70
71 int i;
72 u_int8_t *data = generated_data.ptr;
73
74 for (i = 0; i < generated_data.len;i++)
75 {
76 fprintf(stderr,"%x\n",data[i]);
77 }
78
79
80 allocator_free_chunk(generated_data);
81
82 tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
83 }