- wrote clone function for packed
[strongswan.git] / Source / charon / tests / packet_test.c
1 /**
2 * @file packet_test.c
3 *
4 * @brief Tests to test the class type packet_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 <string.h>
24 #include "packet_test.h"
25 #include "../allocator.h"
26 #include "../packet.h"
27
28
29 /*
30 * Described in Header
31 */
32 void test_packet(tester_t *tester)
33 {
34 packet_t *packet = packet_create(AF_INET);
35 packet_t *packet2;
36 char * string_to_copy = "aha, soso";
37
38 packet->data.ptr = allocator_alloc_thing(string_to_copy);
39 packet->data.len = sizeof(string_to_copy);
40 memcpy(packet->data.ptr,string_to_copy,packet->data.len);
41
42 tester->assert_true(tester,(packet != NULL),"NULL pointer check");
43
44 tester->assert_true(tester,(packet->clone(packet,&packet2) == SUCCESS),"clone call check");
45
46 tester->assert_false(tester,(packet->data.ptr == packet2->data.ptr),"value pointer check");
47
48 tester->assert_true(tester,(memcmp(packet->data.ptr,packet2->data.ptr,packet->data.len) == 0),"cloned value check");
49
50 tester->assert_true(tester,(packet->family == packet2->family),"cloned value check");
51 tester->assert_true(tester,(packet->sockaddr_len == packet2->sockaddr_len),"cloned value check");
52 tester->assert_true(tester,(memcmp(&(packet->source),&(packet2->source), sizeof(struct sockaddr)) == 0),"cloned value check");
53 tester->assert_true(tester,(memcmp(&(packet->destination),&(packet2->destination), sizeof(struct sockaddr)) == 0),"cloned value check");
54
55
56 packet2->destroy(packet2);
57 packet->destroy(packet);
58
59
60
61 }