diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-07 14:05:28 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-07 14:05:28 +0000 |
commit | 73c0902a0e8933c22f832db2f5ac0acf39155c62 (patch) | |
tree | 276d060b2a9337ea683d18aa67ed4abbb88bf64f /Source/charon/tests | |
parent | 50fffcc4f02cceb8e5d8a06a84e2da3a7ba35441 (diff) | |
download | strongswan-73c0902a0e8933c22f832db2f5ac0acf39155c62.tar.bz2 strongswan-73c0902a0e8933c22f832db2f5ac0acf39155c62.tar.xz |
- receiver-test written
Diffstat (limited to 'Source/charon/tests')
-rw-r--r-- | Source/charon/tests/receiver_test.c | 82 | ||||
-rw-r--r-- | Source/charon/tests/receiver_test.h | 35 |
2 files changed, 117 insertions, 0 deletions
diff --git a/Source/charon/tests/receiver_test.c b/Source/charon/tests/receiver_test.c new file mode 100644 index 000000000..58074bc2a --- /dev/null +++ b/Source/charon/tests/receiver_test.c @@ -0,0 +1,82 @@ +/** + * @file receiver_test.c + * + * @brief Tests to test the Receiver (type receiver_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 <unistd.h> + +#include "sender_test.h" +#include "../globals.h" +#include "../receiver.h" +#include "../packet.h" +#include "../socket.h" +#include "../send_queue.h" +#include "../job_queue.h" + +/** + * Number of packets to send by sender-thread + */ +#define NUMBER_OF_PACKETS_TO_SEND 100 + +/** + * Port to send the packets to + */ +#define PORT_TO_SEND 4600 + +/** + * Destination IP Address + */ +#define DESTINATION_IP "127.0.0.1" + +void test_receiver(tester_t *tester) +{ + int i; + receiver_t *receiver; + packet_t *packet; + job_t *job; + packet_t *received_packet; + receiver = receiver_create(); + + for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++) + { + packet = packet_create(AF_INET); + packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND); + packet->data.ptr = alloc_thing(int, "packet data"); + packet->data.len = ( sizeof(int)); + *((int *) (packet->data.ptr)) = i; + global_socket->send(global_socket,packet); + packet->destroy(packet); + } + + for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++) + { + global_job_queue->get(global_job_queue,&job); + tester->assert_true(tester, (job->type == INCOMING_PACKET), "job type check"); + received_packet = (packet_t *) job->assigned_data; + tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check"); + tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check"); + received_packet->destroy(received_packet); + + job->destroy(job); + } + + tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check"); +} diff --git a/Source/charon/tests/receiver_test.h b/Source/charon/tests/receiver_test.h new file mode 100644 index 000000000..a4f0ea4c5 --- /dev/null +++ b/Source/charon/tests/receiver_test.h @@ -0,0 +1,35 @@ +/** + * @file receiver_test.h + * + * @brief Tests to test the Receiver (type receiver_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 RECEIVER_TEST_H_ +#define RECEIVER_TEST_H_ + +#include "../tester.h" + +/** + * @brief Test function for the type receiver_t + * + * @param tester tester object + */ +void test_receiver(tester_t *tester); + +#endif /*RECEIVER_TEST_H_*/ |