2 * tst_uuid.c --- test program from the UUID library
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
23 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
36 #define _WIN32_WINNT 0x0500
44 #include <uuid/uuid.h>
46 static int test_uuid(const char * uuid, int isValid)
48 static const char * validStr[2] = {"invalid", "valid"};
52 parsedOk = uuid_parse(uuid, uuidBits) == 0;
54 printf("%s is %s", uuid, validStr[isValid]);
55 if (parsedOk != isValid) {
56 printf(" but uuid_parse says %s\n", validStr[parsedOk]);
64 #define ATTR(x) __attribute__(x)
70 main(int argc ATTR((unused)) , char **argv ATTR((unused)))
82 uuid_unparse(buf, str);
83 printf("UUID generate = %s\n", str);
85 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
86 printf("%02x", *cp++);
89 type = uuid_type(buf); variant = uuid_variant(buf);
90 printf("UUID type = %d, UUID variant = %d\n", type, variant);
91 if (variant != UUID_VARIANT_DCE) {
92 printf("Incorrect UUID Variant; was expecting DCE!\n");
97 uuid_generate_random(buf);
98 uuid_unparse(buf, str);
99 printf("UUID random string = %s\n", str);
101 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
102 printf("%02x", *cp++);
105 type = uuid_type(buf); variant = uuid_variant(buf);
106 printf("UUID type = %d, UUID variant = %d\n", type, variant);
107 if (variant != UUID_VARIANT_DCE) {
108 printf("Incorrect UUID Variant; was expecting DCE!\n");
112 printf("Incorrect UUID type; was expecting "
113 "4 (random type)!\n");
118 uuid_generate_time(buf);
119 uuid_unparse(buf, str);
120 printf("UUID string = %s\n", str);
121 printf("UUID time: ");
122 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
123 printf("%02x", *cp++);
126 type = uuid_type(buf); variant = uuid_variant(buf);
127 printf("UUID type = %d, UUID variant = %d\n", type, variant);
128 if (variant != UUID_VARIANT_DCE) {
129 printf("Incorrect UUID Variant; was expecting DCE!\n");
133 printf("Incorrect UUID type; was expecting "
134 "1 (time-based type)!\\n");
139 time_reg = uuid_time(buf, &tv);
140 printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
142 uuid_parse(str, tst);
143 if (!uuid_compare(buf, tst))
144 printf("UUID parse and compare succeeded.\n");
146 printf("UUID parse and compare failed!\n");
150 if (uuid_is_null(tst))
151 printf("UUID clear and is null succeeded.\n");
153 printf("UUID clear and is null failed!\n");
157 if (!uuid_compare(buf, tst))
158 printf("UUID copy and compare succeeded.\n");
160 printf("UUID copy and compare failed!\n");
163 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981b", 1);
164 failed += test_uuid("84949CC5-4701-4A84-895B-354C584A981B", 1);
165 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981bc", 0);
166 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981", 0);
167 failed += test_uuid("84949cc5x4701-4a84-895b-354c584a981b", 0);
168 failed += test_uuid("84949cc504701-4a84-895b-354c584a981b", 0);
169 failed += test_uuid("84949cc5-470104a84-895b-354c584a981b", 0);
170 failed += test_uuid("84949cc5-4701-4a840895b-354c584a981b", 0);
171 failed += test_uuid("84949cc5-4701-4a84-895b0354c584a981b", 0);
172 failed += test_uuid("g4949cc5-4701-4a84-895b-354c584a981b", 0);
173 failed += test_uuid("84949cc5-4701-4a84-895b-354c584a981g", 0);
176 printf("%d failures.\n", failed);