]> git.ipfire.org Git - people/ms/strongswan.git/blame - programs/charon/testing/sender_test.c
- import of strongswan-2.7.0
[people/ms/strongswan.git] / programs / charon / testing / sender_test.c
CommitLineData
6962f6c9
JH
1/**
2 * @file sender_test.h
79538669 3 *
ed37dee6 4 * @brief Tests for the sender_t class.
79538669 5 *
6962f6c9
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 */
22
23#include <string.h>
24
25#include "sender_test.h"
88878242 26
0e96f7d8 27#include <daemon.h>
867952ad 28#include <threads/sender.h>
716abc9f
MW
29#include <network/packet.h>
30#include <network/socket.h>
94852e75
JH
31#include <queues/send_queue.h>
32#include <queues/job_queue.h>
e168ee17 33#include <queues/jobs/incoming_packet_job.h>
6962f6c9 34
6962f6c9
JH
35/**
36 * Number of packets to send by sender-thread
37 */
e168ee17 38#define NUMBER_OF_PACKETS_TO_SEND 5
79538669 39
51d56047 40void test_sender(protected_tester_t *tester)
6962f6c9
JH
41{
42 int i;
43 sender_t *sender;
e168ee17
MW
44 receiver_t *receiver;
45 job_t *job;
6962f6c9 46 packet_t *packet;
e168ee17
MW
47 packet_t *received_packet;
48 char test_data[] = {
49 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, /* spi */
50 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05, /* spi */
51 0x05, /* next payload */
52 0x20, /* IKE version */
53 0x00, /* exchange type */
54 0x00, /* flags */
55 0x00,0x00,0x00,0x01, /* message id */
56 0x00,0x00,0x00,0x24, /* length */
57 0x12,0x34,0x56,0x67, /* some data */
58 0x12,0x34,0x56,0x67,
59 };
60 chunk_t data = chunk_from_buf(test_data);
61 chunk_t received;
6962f6c9 62 sender = sender_create();
e168ee17 63 receiver = receiver_create();
79538669 64
6962f6c9
JH
65 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
66 {
67 packet = packet_create(AF_INET);
e168ee17
MW
68 packet->set_destination(packet, host_create(AF_INET, "127.0.0.1", 500));
69 packet->set_source(packet, host_create(AF_INET, "127.0.0.1", 500));
70 packet->set_data(packet, chunk_clone(data));
0e96f7d8 71 charon->send_queue->add(charon->send_queue,packet);
6962f6c9 72 }
79538669 73
6962f6c9
JH
74 for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
75 {
e168ee17
MW
76 job = charon->job_queue->get(charon->job_queue);
77 tester->assert_true(tester, (job->get_type(job) == INCOMING_PACKET), "job type check");
78 received_packet = ((incoming_packet_job_t *)(job))->get_packet((incoming_packet_job_t *)(job));
79 received = received_packet->get_data(received_packet);
80 tester->assert_true(tester, received.len == data.len, "received data length check");
81 tester->assert_true(tester, memcmp(received.ptr, data.ptr, data.len) == 0, "received data value check");
6962f6c9 82 received_packet->destroy(received_packet);
e168ee17 83 job->destroy(job);
79538669
JH
84 }
85
d048df5c 86 sender->destroy(sender);
e168ee17 87 receiver->destroy(receiver);
6962f6c9 88}