From 6862128151fb78f63685a8da5575783c426d64a7 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 5 Apr 2006 12:10:50 +0000 Subject: ../svn-commit.tmp --- Source/testing/sender_test.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Source/testing/sender_test.c (limited to 'Source/testing/sender_test.c') diff --git a/Source/testing/sender_test.c b/Source/testing/sender_test.c new file mode 100644 index 000000000..003cf761e --- /dev/null +++ b/Source/testing/sender_test.c @@ -0,0 +1,80 @@ +/** + * @file sender_test.h + * + * @brief Tests for the sender_t class. + * + */ + +/* + * 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 . + * + * 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 + +#include "sender_test.h" + +#include +#include +#include +#include +#include +#include +#include + +/** + * Number of packets to send by sender-thread + */ +#define NUMBER_OF_PACKETS_TO_SEND 50 + +/** + * Port to send the packets to + */ +#define PORT_TO_SEND 4600 + +/** + * Destination IP Address + */ +#define DESTINATION_IP "127.0.0.1" + +void test_sender(protected_tester_t *tester) +{ + int i; + sender_t *sender; + packet_t *packet; + packet_t *received_packet; + chunk_t packet_data; + sender = sender_create(); + + for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++) + { + packet = packet_create(AF_INET); + packet->set_destination(packet, host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND)); + packet_data.ptr = allocator_alloc_thing(int); + packet_data.len = ( sizeof(int)); + *((int *) (packet_data.ptr)) = i; + packet->set_data(packet, packet_data); + charon->send_queue->add(charon->send_queue,packet); + } + + for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++) + { + charon->socket->receive(charon->socket,&received_packet); + packet_data = received_packet->get_data(received_packet); + tester->assert_true(tester, (packet_data.len == (sizeof(int))), "received data length check"); + tester->assert_true(tester, (i == *((int *)(packet_data.ptr))), "received data value check"); + received_packet->destroy(received_packet); + } + + sender->destroy(sender); +} -- cgit v1.2.3