- wrote test for sender_t

This commit is contained in:
Jan Hutter 2005-11-07 13:04:14 +00:00
parent 7bcc866743
commit 6962f6c92f
3 changed files with 124 additions and 4 deletions

View File

@ -34,6 +34,7 @@
#include "tests/event_queue_test.h"
#include "tests/send_queue_test.h"
#include "tests/socket_test.h"
#include "tests/sender_test.h"
/* output for test messages */
@ -57,17 +58,17 @@ test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,
/**
* Test for event_queue_t
*/
test_t event_queue_test = {test_event_queue,"Event-Queue Test"};
test_t event_queue_test = {test_event_queue,"Event-Queue"};
/**
* Test 1 for job_queue_t
*/
test_t job_queue_test1 = {test_job_queue,"Job-Queue Test1"};
test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
/**
* Test 1 for linked_list_t
*/
test_t send_queue_test = {test_send_queue,"Send-Queue Test"};
test_t send_queue_test = {test_send_queue,"Send-Queue"};
/**
* Test for socket_t
@ -79,6 +80,11 @@ test_t socket_test = {test_socket,"Socket"};
*/
test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
/**
* Test for sender_t
*/
test_t sender_test = {test_sender,"Sender"};
/**
* Global job-queue
@ -113,6 +119,7 @@ socket_t *global_socket;
&event_queue_test,
&send_queue_test,
&socket_test,
&sender_test,
NULL
};
@ -125,7 +132,7 @@ socket_t *global_socket;
tester_t *tester = tester_create(test_output, FALSE);
tester->perform_tests(tester,all_tests);
// tester->perform_test(tester,&event_queue_test);
/* tester->perform_test(tester,&sender_test); */
tester->destroy(tester);

View File

@ -0,0 +1,78 @@
/**
* @file sender_test.h
*
* @brief Tests to test the Sender (type sender_t)
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <string.h>
#include "sender_test.h"
#include "../sender.h"
#include "../packet.h"
#include "../socket.h"
#include "../send_queue.h"
#include "../job_queue.h"
extern send_queue_t *global_send_queue;
extern socket_t *global_socket;
/**
* Number of packets to send by sender-thread
*/
#define NUMBER_OF_PACKETS_TO_SEND 400
/**
* Port to send the packets to
*/
#define PORT_TO_SEND 4600
/**
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_sender(tester_t *tester)
{
int i;
sender_t *sender;
packet_t *packet;
packet_t *received_packet;
sender = sender_create();
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
packet->data.ptr = alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_send_queue->add(global_send_queue,packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_socket->receive(global_socket,&received_packet);
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
received_packet->destroy(received_packet);
}
tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
}

View File

@ -0,0 +1,35 @@
/**
* @file sender_test.h
*
* @brief Tests to test the Sender (type sender_t)
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef SENDER_TEST_H_
#define SENDER_TEST_H_
#include "../tester.h"
/**
* @brief Test function for the type sender_t
*
* @param tester tester object
*/
void test_sender(tester_t *tester);
#endif /*SENDER_TEST_H_*/