]> git.ipfire.org Git - thirdparty/strongswan.git/blame - Source/charon/testcases/receiver_test.c
- changed allocation behavior
[thirdparty/strongswan.git] / Source / charon / testcases / receiver_test.c
CommitLineData
73c0902a
JH
1/**
2 * @file receiver_test.c
79538669 3 *
ed37dee6 4 * @brief Tests for the receiver_t class.
79538669 5 *
73c0902a
JH
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 */
79538669 22
73c0902a
JH
23#include <string.h>
24#include <unistd.h>
25
88878242
MW
26#include "receiver_test.h"
27
94852e75 28#include <globals.h>
867952ad 29#include <threads/receiver.h>
716abc9f
MW
30#include <network/packet.h>
31#include <network/socket.h>
94852e75
JH
32#include <queues/send_queue.h>
33#include <queues/job_queue.h>
716abc9f 34#include <queues/jobs/incoming_packet_job.h>
4a962238 35#include <encoding/payloads/encodings.h>
94852e75 36#include <utils/allocator.h>
73c0902a
JH
37
38/**
39 * Number of packets to send by sender-thread
40 */
41#define NUMBER_OF_PACKETS_TO_SEND 100
42
43/**
44 * Port to send the packets to
45 */
46#define PORT_TO_SEND 4600
47
48/**
49 * Destination IP Address
50 */
51#define DESTINATION_IP "127.0.0.1"
79538669 52
73c0902a
JH
53void test_receiver(tester_t *tester)
54{
55 int i;
56 receiver_t *receiver;
57 packet_t *packet;
58 job_t *job;
59 packet_t *received_packet;
60 receiver = receiver_create();
79538669 61
73c0902a
JH
62 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
63 {
66e379a2
MW
64 packet = packet_create();
65 packet->destination = host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND);
6c4b815f 66 packet->data.ptr = allocator_alloc_thing(int);
73c0902a
JH
67 packet->data.len = ( sizeof(int));
68 *((int *) (packet->data.ptr)) = i;
69 global_socket->send(global_socket,packet);
70 packet->destroy(packet);
71 }
79538669 72
73c0902a
JH
73 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
74 {
d0cc48e5 75 job = global_job_queue->get(global_job_queue);
d5fc0f73
JH
76 tester->assert_true(tester, (job->get_type(job) == INCOMING_PACKET), "job type check");
77
df3c59d0 78 received_packet = ((incoming_packet_job_t *)(job))->get_packet((incoming_packet_job_t *)(job));
73c0902a
JH
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);
82
83 job->destroy(job);
79538669
JH
84 }
85
d048df5c 86 receiver->destroy(receiver);
73c0902a 87}