d9974adcf00233b28e9306b9a9b790275c70e042
[strongswan.git] / Source / charon / tests / sender_test.c
1 /**
2 * @file sender_test.h
3 *
4 * @brief Tests to test the Sender (type sender_t)
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #include <string.h>
24
25 #include "sender_test.h"
26 #include "../sender.h"
27 #include "../packet.h"
28 #include "../socket.h"
29 #include "../send_queue.h"
30 #include "../job_queue.h"
31
32 extern send_queue_t *global_send_queue;
33
34 extern socket_t *global_socket;
35
36 /**
37 * Number of packets to send by sender-thread
38 */
39 #define NUMBER_OF_PACKETS_TO_SEND 400
40
41 /**
42 * Port to send the packets to
43 */
44 #define PORT_TO_SEND 4600
45
46 /**
47 * Destination IP Address
48 */
49 #define DESTINATION_IP "127.0.0.1"
50
51 void test_sender(tester_t *tester)
52 {
53 int i;
54 sender_t *sender;
55 packet_t *packet;
56 packet_t *received_packet;
57 sender = sender_create();
58
59 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
60 {
61 packet = packet_create(AF_INET);
62 packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
63 packet->data.ptr = alloc_thing(int, "packet data");
64 packet->data.len = ( sizeof(int));
65 *((int *) (packet->data.ptr)) = i;
66 global_send_queue->add(global_send_queue,packet);
67 }
68
69 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
70 {
71 global_socket->receive(global_socket,&received_packet);
72 tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
73 tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
74 received_packet->destroy(received_packet);
75 }
76
77 tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
78 }