- globals packed in a daemon
[strongswan.git] / Source / charon / testcases / sender_test.c
1 /**
2 * @file sender_test.h
3 *
4 * @brief Tests for the sender_t class.
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
27 #include <daemon.h>
28 #include <threads/sender.h>
29 #include <network/packet.h>
30 #include <network/socket.h>
31 #include <queues/send_queue.h>
32 #include <queues/job_queue.h>
33 #include <utils/allocator.h>
34
35 /**
36 * Number of packets to send by sender-thread
37 */
38 #define NUMBER_OF_PACKETS_TO_SEND 50
39
40 /**
41 * Port to send the packets to
42 */
43 #define PORT_TO_SEND 4600
44
45 /**
46 * Destination IP Address
47 */
48 #define DESTINATION_IP "127.0.0.1"
49
50 void test_sender(tester_t *tester)
51 {
52 int i;
53 sender_t *sender;
54 packet_t *packet;
55 packet_t *received_packet;
56 sender = sender_create();
57
58 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
59 {
60 packet = packet_create(AF_INET);
61 packet->destination = host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND);
62 packet->data.ptr = allocator_alloc_thing(int);
63 packet->data.len = ( sizeof(int));
64 *((int *) (packet->data.ptr)) = i;
65 charon->send_queue->add(charon->send_queue,packet);
66 }
67
68 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
69 {
70 charon->socket->receive(charon->socket,&received_packet);
71 tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
72 tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
73 received_packet->destroy(received_packet);
74 }
75
76 sender->destroy(sender);
77 }