aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/tests/sender_test.c
diff options
context:
space:
mode:
authorJan Hutter <jhutter@hsr.ch>2005-11-07 13:04:14 +0000
committerJan Hutter <jhutter@hsr.ch>2005-11-07 13:04:14 +0000
commit6962f6c92f47438773b43b784ef34dc9a096cf5e (patch)
tree787293e12b5d733d1ef2bca74123c41ca8932458 /Source/charon/tests/sender_test.c
parent7bcc8667437044bd50852dd8978682644dbe73fd (diff)
downloadstrongswan-6962f6c92f47438773b43b784ef34dc9a096cf5e.tar.bz2
strongswan-6962f6c92f47438773b43b784ef34dc9a096cf5e.tar.xz
- wrote test for sender_t
Diffstat (limited to 'Source/charon/tests/sender_test.c')
-rw-r--r--Source/charon/tests/sender_test.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/charon/tests/sender_test.c b/Source/charon/tests/sender_test.c
new file mode 100644
index 000000000..d9974adcf
--- /dev/null
+++ b/Source/charon/tests/sender_test.c
@@ -0,0 +1,78 @@
+/**
+ * @file sender_test.h
+ *
+ * @brief Tests to test the Sender (type sender_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 "sender_test.h"
+#include "../sender.h"
+#include "../packet.h"
+#include "../socket.h"
+#include "../send_queue.h"
+#include "../job_queue.h"
+
+extern send_queue_t *global_send_queue;
+
+extern socket_t *global_socket;
+
+/**
+ * Number of packets to send by sender-thread
+ */
+#define NUMBER_OF_PACKETS_TO_SEND 400
+
+/**
+ * Port to send the packets to
+ */
+#define PORT_TO_SEND 4600
+
+/**
+ * Destination IP Address
+ */
+#define DESTINATION_IP "127.0.0.1"
+
+void test_sender(tester_t *tester)
+{
+ int i;
+ sender_t *sender;
+ packet_t *packet;
+ packet_t *received_packet;
+ sender = sender_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_send_queue->add(global_send_queue,packet);
+ }
+
+ for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
+ {
+ global_socket->receive(global_socket,&received_packet);
+ 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);
+ }
+
+ tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
+}