aboutsummaryrefslogtreecommitdiffstats
path: root/test/uuid.c
blob: a77ebcc015fa3dc5b01003968264eac0d8227cc9 (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
/*
 * The Rin Library – library "conformance" tests
 *
 * Copyright (C) 2015-2017 Gediminas Jakutis
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; version 2.1
 * of the License.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "test.h"
#include "uuid_test_private.h"

int uuid_test(char *testname)
{
	static const struct test tests[] = {
			{"formatmacro", rin_uuid_format_macro_test} };
	size_t i;

	for (i = 0; i < arrlen(tests); ++i) {
		if (!strcmp(testname, tests[i].name)) {
			return tests[i].testfunc();
		}
	}

	return EXIT_FAILURE;
}

static int rin_uuid_format_macro_test(void)
{
	int ret;
	size_t i;
	char buf[64];
	static const char in[][16] = {
			{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
			{ 0 },
			{ (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff,
			  (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff,
			  (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff,
			  (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff}};
	static const char *expected[] = { "00010203-0405-0607-0809-0a0b0c0d0e0f",
					  "00000000-0000-0000-0000-000000000000",
					  "ffffffff-ffff-ffff-ffff-ffffffffffff" };

	for (i = 0; i < arrlen(expected); ++i) {
		snprintf(buf, sizeof(buf), PRIUUID, PRIUUIDARG(in[i]));
		ret = ok(strcmp(buf, expected[i]),
				"%s: expected: %s, got: %s",
				__func__,
				expected[i],
				buf);
	}

	return ret;
}