- fixed bad SVN issues, should all work again now
[strongswan.git] / Source / charon / testcases / receiver_test.c
1 /**
2 * @file receiver_test.c
3 *
4 * @brief Tests to test the Receiver (type receiver_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 #include <unistd.h>
25
26 #include "receiver_test.h"
27
28 #include "../globals.h"
29 #include "../receiver.h"
30 #include "../packet.h"
31 #include "../socket.h"
32 #include "../queues/send_queue.h"
33 #include "../queues/job_queue.h"
34 #include "../payloads/encodings.h"
35 #include "../utils/allocator.h"
36
37 /**
38 * Number of packets to send by sender-thread
39 */
40 #define NUMBER_OF_PACKETS_TO_SEND 100
41
42 /**
43 * Port to send the packets to
44 */
45 #define PORT_TO_SEND 4600
46
47 /**
48 * Destination IP Address
49 */
50 #define DESTINATION_IP "127.0.0.1"
51
52 void test_receiver(tester_t *tester)
53 {
54 int i;
55 receiver_t *receiver;
56 packet_t *packet;
57 job_t *job;
58 packet_t *received_packet;
59 receiver = receiver_create();
60
61 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
62 {
63 packet = packet_create(AF_INET);
64 packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
65 packet->data.ptr = allocator_alloc_thing(int);
66 packet->data.len = ( sizeof(int));
67 *((int *) (packet->data.ptr)) = i;
68 global_socket->send(global_socket,packet);
69 packet->destroy(packet);
70 }
71
72 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
73 {
74 global_job_queue->get(global_job_queue,&job);
75 tester->assert_true(tester, (job->type == INCOMING_PACKET), "job type check");
76 received_packet = (packet_t *) job->assigned_data;
77 tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
78 tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
79 received_packet->destroy(received_packet);
80
81 job->destroy(job);
82 }
83
84 tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check");
85 }