diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-10 15:38:12 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-10 15:38:12 +0000 |
commit | 3818e5c858338080c0705e233c7c66425af6cd20 (patch) | |
tree | 8fc655c9d4895323446da0f46ae9591944b728b1 /Source/charon/tests | |
parent | 1473b8f6c935e07d88b8319dd0088b573faf4ee7 (diff) | |
download | strongswan-3818e5c858338080c0705e233c7c66425af6cd20.tar.bz2 strongswan-3818e5c858338080c0705e233c7c66425af6cd20.tar.xz |
- wrote clone function for packed
- test for whole packet functionality
Diffstat (limited to 'Source/charon/tests')
-rw-r--r-- | Source/charon/tests/packet_test.c | 61 | ||||
-rw-r--r-- | Source/charon/tests/packet_test.h | 36 |
2 files changed, 97 insertions, 0 deletions
diff --git a/Source/charon/tests/packet_test.c b/Source/charon/tests/packet_test.c new file mode 100644 index 000000000..f2cb22887 --- /dev/null +++ b/Source/charon/tests/packet_test.c @@ -0,0 +1,61 @@ +/** + * @file packet_test.c + * + * @brief Tests to test the class type packet_t + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include <string.h> +#include "packet_test.h" +#include "../allocator.h" +#include "../packet.h" + + +/* + * Described in Header + */ +void test_packet(tester_t *tester) +{ + packet_t *packet = packet_create(AF_INET); + packet_t *packet2; + char * string_to_copy = "aha, soso"; + + packet->data.ptr = allocator_alloc_thing(string_to_copy); + packet->data.len = sizeof(string_to_copy); + memcpy(packet->data.ptr,string_to_copy,packet->data.len); + + tester->assert_true(tester,(packet != NULL),"NULL pointer check"); + + tester->assert_true(tester,(packet->clone(packet,&packet2) == SUCCESS),"clone call check"); + + tester->assert_false(tester,(packet->data.ptr == packet2->data.ptr),"value pointer check"); + + tester->assert_true(tester,(memcmp(packet->data.ptr,packet2->data.ptr,packet->data.len) == 0),"cloned value check"); + + tester->assert_true(tester,(packet->family == packet2->family),"cloned value check"); + tester->assert_true(tester,(packet->sockaddr_len == packet2->sockaddr_len),"cloned value check"); + tester->assert_true(tester,(memcmp(&(packet->source),&(packet2->source), sizeof(struct sockaddr)) == 0),"cloned value check"); + tester->assert_true(tester,(memcmp(&(packet->destination),&(packet2->destination), sizeof(struct sockaddr)) == 0),"cloned value check"); + + + packet2->destroy(packet2); + packet->destroy(packet); + + + +} diff --git a/Source/charon/tests/packet_test.h b/Source/charon/tests/packet_test.h new file mode 100644 index 000000000..4a4eb8ffc --- /dev/null +++ b/Source/charon/tests/packet_test.h @@ -0,0 +1,36 @@ +/** + * @file packet_test.h + * + * @brief Tests to test the class type packet_t + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef PACKET_TEST_H_ +#define PACKET_TEST_H_ + +#include "../tester.h" + +/** + * @brief Test function used to test the packet_t functionality + * + * + * @param tester associated tester_t object + */ +void test_packet(tester_t *tester); + +#endif /*PACKET_TEST_H_*/ |