960e451068416050ba50caec90494a07ea2c05a4
[strongswan.git] / Source / charon / testcases / ike_sa_id_test.c
1 /**
2 * @file ike_sa_id_test.c
3 *
4 * @brief Tests to test the IKE_SA Identifier class ike_sa_id_test_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 #include "ike_sa_id_test.h"
24
25 #include <sa/ike_sa_id.h>
26
27 /*
28 * described in Header-File
29 */
30 void test_ike_sa_id(tester_t *tester)
31 {
32 ike_sa_id_t *ike_sa_id, *clone, *equal, *other1, *other2, *other3, *other4;
33 u_int64_t initiator, initiator2, responder, responder2;
34 bool is_initiator;
35 bool are_equal = FALSE;
36
37 initiator = 0;
38
39 initiator2 = 12345612;
40
41 responder = 34334;
42
43 responder2 = 987863;
44
45 is_initiator = TRUE;
46
47 ike_sa_id = ike_sa_id_create(initiator, responder, is_initiator);
48 equal = ike_sa_id_create(initiator, responder, is_initiator);
49 other1 = ike_sa_id_create(initiator, responder2, is_initiator);
50 other2 = ike_sa_id_create(initiator2, responder2, is_initiator);
51 other3 = ike_sa_id_create(initiator2, responder, is_initiator);
52 is_initiator = FALSE;
53 other4 = ike_sa_id_create(initiator, responder, is_initiator);
54
55 /* check equality */
56 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,equal,&are_equal) == SUCCESS), "equal call check");
57 tester->assert_true(tester,(are_equal == TRUE), "equal check");
58 tester->assert_true(tester,(equal->equals(equal,ike_sa_id,&are_equal) == SUCCESS), "equal call check");
59 tester->assert_true(tester,(are_equal == TRUE), "equal check");
60
61 /* check clone functionality and equality*/
62 tester->assert_true(tester,(ike_sa_id->clone(ike_sa_id,&clone) == SUCCESS), "clone call check");
63 tester->assert_false(tester,(clone == ike_sa_id), "clone pointer check");
64 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,clone,&are_equal) == SUCCESS), "equal call check");
65 tester->assert_true(tester,(are_equal == TRUE), "equal check");
66
67 /* check for non equality */
68 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other1,&are_equal) == SUCCESS), "equal call check");
69 tester->assert_false(tester,(are_equal == TRUE), "equal check");
70
71 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other2,&are_equal) == SUCCESS), "equal call check");
72 tester->assert_false(tester,(are_equal == TRUE), "equal check");
73
74 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other3,&are_equal) == SUCCESS), "equal call check");
75 tester->assert_false(tester,(are_equal == TRUE), "equal check");
76
77 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other4,&are_equal) == SUCCESS), "equal call check");
78 tester->assert_false(tester,(are_equal == TRUE), "equal check");
79
80 tester->assert_true(tester,(other4->replace_values(other4,ike_sa_id) == SUCCESS), "replace values call check");
81 tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other4,&are_equal) == SUCCESS), "equal call check");
82 tester->assert_true(tester,(are_equal == TRUE), "equal check");
83
84
85 /* check destroy functionality */
86 ike_sa_id->destroy(ike_sa_id);
87 equal->destroy(equal);
88 clone->destroy(clone);
89 other1->destroy(other1);
90 other2->destroy(other2);
91 other3->destroy(other3);
92 other4->destroy(other4);
93 }