- moved packet and socket in new network-package
[strongswan.git] / Source / charon / testcases / 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
25 #include "packet_test.h"
26
27 #include <globals.h>
28 #include <network/packet.h>
29 #include <utils/allocator.h>
30 #include <utils/logger_manager.h>
31
32
33 /*
34 * Described in Header
35 */
36 void test_packet(tester_t *tester)
37 {
38 packet_t *packet = packet_create();
39 packet_t *packet2;
40 char * string_to_copy = "aha, soso";
41
42 packet->data.ptr = allocator_alloc(strlen(string_to_copy) + 1);
43 tester->assert_true(tester,(packet->data.ptr != NULL),"NULL pointer check");
44
45 packet->data.len = strlen(string_to_copy) + 1;
46 strcpy(packet->data.ptr,string_to_copy);
47
48 tester->assert_true(tester,(packet != NULL),"NULL pointer check");
49 tester->assert_true(tester,(packet->clone(packet,&packet2) == SUCCESS),"clone call check");
50
51 tester->assert_false(tester,(packet->data.ptr == packet2->data.ptr),"value pointer check");
52
53 tester->assert_true(tester,(packet->data.len == (strlen(string_to_copy) + 1)),"value length check");
54
55 tester->assert_true(tester,(memcmp(packet->data.ptr,packet2->data.ptr,packet->data.len) == 0),"cloned value check");
56
57 packet2->destroy(packet2);
58 packet->destroy(packet);
59 }