380bbaaf1784d862ee0601c33b0d5e16d41dadd5
[strongswan.git] / Source / charon / tests / event_queue_test.c
1 /**
2 * @file event_queue_test.h
3 *
4 * @brief Tests to test the Event-Queue type event_queue_t
5 *
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
24
25 #include "../tester.h"
26 #include "../event_queue.h"
27
28 void test_event_queue(tester_t *tester)
29 {
30 event_queue_t * event_queue = event_queue_create();
31 timeval_t current_time;
32 timeval_t time1, time2, time3;
33 job_t * current_job;
34 int count;
35 job_t * job1 = job_create(INCOMING_PACKET,"incoming packet");
36 job_t * job2 = job_create(RETRANSMIT_REQUEST,"retransmit request");
37 job_t * job3 = job_create(ESTABLISH_IKE_SA,"establish ike sa");
38
39 gettimeofday(&current_time,NULL);
40 time1.tv_usec = 0;
41 time1.tv_sec = current_time.tv_sec + 3;
42 time2.tv_usec = 0;
43 time2.tv_sec = current_time.tv_sec + 12;
44 time3.tv_usec = 0;
45 time3.tv_sec = current_time.tv_sec + 12;
46
47 tester->assert_true(tester,(event_queue->add(event_queue,job1,time1) == SUCCESS), "add call check");
48 tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
49 tester->assert_true(tester,(count == 1), "count value check");
50
51 tester->assert_true(tester,(event_queue->add(event_queue,job2,time2) == SUCCESS), "add call check");
52 tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
53 tester->assert_true(tester,(count == 2), "count value check");
54
55 tester->assert_true(tester,(event_queue->add(event_queue,job3,time3) == SUCCESS), "add call check");
56 tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
57 tester->assert_true(tester,(count == 3), "count value check");
58
59 tester->assert_true(tester,(event_queue->get(event_queue,&current_job) == SUCCESS), "get call check");
60 fprintf(stderr,"%s\n",(char *) current_job->assigned_data);
61 tester->assert_true(tester,(event_queue->get(event_queue,&current_job) == SUCCESS), "get call check");
62 fprintf(stderr,"%s\n",(char *) current_job->assigned_data);
63 tester->assert_true(tester,(event_queue->get(event_queue,&current_job) == SUCCESS), "get call check");
64 fprintf(stderr,"%s\n",(char *) current_job->assigned_data);
65
66 tester->assert_true(tester,(event_queue->destroy(event_queue) == SUCCESS), "destroy call check");
67 }