aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/plugins/unit_tester/tests/test_id.c
blob: 56dab24212ef33139e271df14a91e05d387451cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2009 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 <daemon.h>

/*******************************************************************************
 * identification part enumeration test
 ******************************************************************************/
bool test_id_parts()
{
	identification_t *id;
	enumerator_t *enumerator;
	id_part_t part;
	chunk_t data;
	int i = 0;
	
	id = identification_create_from_string("C=CH, O=strongSwan, CN=tester");
	
	enumerator = id->create_part_enumerator(id);
	while (enumerator->enumerate(enumerator, &part, &data))
	{
		switch (i++)
		{
			case 0:
				if (part != ID_PART_RDN_C ||
					!chunk_equals(data, chunk_create("CH", 2)))
				{
					return FALSE;
				}
				break;
			case 1:
				if (part != ID_PART_RDN_O ||
					!chunk_equals(data, chunk_create("strongSwan", 10)))
				{
					return FALSE;
				}
				break;
			case 2:
				if (part != ID_PART_RDN_CN ||
					!chunk_equals(data, chunk_create("tester", 6)))
				{
					return FALSE;
				}
				break;
			default:
				return FALSE;
		}
	}
	if (i < 3)
	{
		return FALSE;
	}
	enumerator->destroy(enumerator);
	id->destroy(id);
	return TRUE;
}