4 * @brief Tests to test the class type packet_t
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
24 #include "packet_test.h"
25 #include "../allocator.h"
26 #include "../packet.h"
32 void test_packet(tester_t
*tester
)
34 packet_t
*packet
= packet_create(AF_INET
);
36 char * string_to_copy
= "aha, soso";
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
);
42 tester
->assert_true(tester
,(packet
!= NULL
),"NULL pointer check");
44 tester
->assert_true(tester
,(packet
->clone(packet
,&packet2
) == SUCCESS
),"clone call check");
46 tester
->assert_false(tester
,(packet
->data
.ptr
== packet2
->data
.ptr
),"value pointer check");
48 tester
->assert_true(tester
,(memcmp(packet
->data
.ptr
,packet2
->data
.ptr
,packet
->data
.len
) == 0),"cloned value check");
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");
56 packet2
->destroy(packet2
);
57 packet
->destroy(packet
);