2 * @file receiver_test.c
4 * @brief Tests to test the Receiver (type receiver_t)
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
26 #include "receiver_test.h"
29 #include <threads/receiver.h>
30 #include <network/packet.h>
31 #include <network/socket.h>
32 #include <queues/send_queue.h>
33 #include <queues/job_queue.h>
34 #include <queues/jobs/incoming_packet_job.h>
35 #include <encoding/payloads/encodings.h>
36 #include <utils/allocator.h>
39 * Number of packets to send by sender-thread
41 #define NUMBER_OF_PACKETS_TO_SEND 100
44 * Port to send the packets to
46 #define PORT_TO_SEND 4600
49 * Destination IP Address
51 #define DESTINATION_IP "127.0.0.1"
53 void test_receiver(tester_t
*tester
)
59 packet_t
*received_packet
;
60 receiver
= receiver_create();
62 for (i
= 0; i
< NUMBER_OF_PACKETS_TO_SEND
; i
++)
64 packet
= packet_create();
65 packet
->destination
= host_create(AF_INET
,DESTINATION_IP
,PORT_TO_SEND
);
66 packet
->data
.ptr
= allocator_alloc_thing(int);
67 packet
->data
.len
= ( sizeof(int));
68 *((int *) (packet
->data
.ptr
)) = i
;
69 global_socket
->send(global_socket
,packet
);
70 packet
->destroy(packet
);
73 for (i
= 0; i
< NUMBER_OF_PACKETS_TO_SEND
; i
++)
75 global_job_queue
->get(global_job_queue
,&job
);
76 tester
->assert_true(tester
, (job
->get_type(job
) == INCOMING_PACKET
), "job type check");
78 ((incoming_packet_job_t
*)(job
))->get_packet((incoming_packet_job_t
*)(job
),&received_packet
);
79 tester
->assert_true(tester
, (received_packet
->data
.len
== (sizeof(int))), "received data length check");
80 tester
->assert_true(tester
, (i
== *((int *)(received_packet
->data
.ptr
))), "received data value check");
81 received_packet
->destroy(received_packet
);
86 receiver
->destroy(receiver
);