- LEAK_DETECTIVE activated
[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 "../globals.h"
27 #include "../sender.h"
28 #include "../packet.h"
29 #include "../socket.h"
30 #include "../send_queue.h"
31 #include "../job_queue.h"
32
33 /**
34 * Number of packets to send by sender-thread
35 */
36 #define NUMBER_OF_PACKETS_TO_SEND 50
37
38 /**
39 * Port to send the packets to
40 */
41 #define PORT_TO_SEND 4600
42
43 /**
44 * Destination IP Address
45 */
46 #define DESTINATION_IP "127.0.0.1"
47
48 void test_sender(tester_t *tester)
49 {
50 int i;
51 sender_t *sender;
52 packet_t *packet;
53 packet_t *received_packet;
54 sender = sender_create();
55
56 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
57 {
58 packet = packet_create(AF_INET);
59 packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
60 packet->data.ptr = alloc_thing(int, "packet data");
61 packet->data.len = ( sizeof(int));
62 *((int *) (packet->data.ptr)) = i;
63 global_send_queue->add(global_send_queue,packet);
64 }
65
66 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
67 {
68 global_socket->receive(global_socket,&received_packet);
69 tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
70 tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
71 received_packet->destroy(received_packet);
72 }
73
74 tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
75 }