4 * @brief Tests to test the Sender (type sender_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
25 #include "sender_test.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>
36 * Number of packets to send by sender-thread
38 #define NUMBER_OF_PACKETS_TO_SEND 50
41 * Port to send the packets to
43 #define PORT_TO_SEND 4600
46 * Destination IP Address
48 #define DESTINATION_IP "127.0.0.1"
50 void test_sender(tester_t
*tester
)
55 packet_t
*received_packet
;
56 sender
= sender_create();
58 for (i
= 0; i
< NUMBER_OF_PACKETS_TO_SEND
; i
++)
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 global_send_queue
->add(global_send_queue
,packet
);
68 for (i
= 0; i
< NUMBER_OF_PACKETS_TO_SEND
; i
++)
70 global_socket
->receive(global_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
);
76 tester
->assert_true(tester
, (sender
->destroy(sender
) == SUCCESS
), "destroy call check");