blob: b9fc5f69a062853ed8cd72a482899072af49fcf0 [file] [log] [blame]
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00001/*
2 * tst_uuid.c --- test program from the UUID library
3 *
Theodore Ts'o1e0a2211998-12-04 08:13:52 +00004 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00005 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
10 */
11
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000012#include <stdio.h>
13#include <linux/ext2_fs.h>
14
15#include "uuid.h"
16
17int
Theodore Ts'o818180c1998-06-27 05:11:14 +000018main(int argc, char **argv)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000019{
20 uuid_t buf, tst;
21 char str[100];
Theodore Ts'o1e0a2211998-12-04 08:13:52 +000022 struct timeval tv;
23 time_t time_reg;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000024 unsigned char *cp;
25 int i;
26 int failed = 0;
Theodore Ts'ob19d1a91999-06-18 00:32:03 +000027 int type, variant;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000028
29 uuid_generate(buf);
30 uuid_unparse(buf, str);
Theodore Ts'ob19d1a91999-06-18 00:32:03 +000031 printf("UUID generate = %s\n", str);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000032 printf("UUID: ");
33 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
34 printf("%02x", *cp++);
35 }
36 printf("\n");
Theodore Ts'ob19d1a91999-06-18 00:32:03 +000037 type = uuid_type(buf); variant = uuid_variant(buf);
38 printf("UUID type = %d, UUID variant = %d\n", type, variant);
39 if (variant != UUID_VARIANT_DCE) {
40 printf("Incorrect UUID Variant; was expecting DCE!\n");
41 failed++;
42 }
43 printf("\n");
44
45 uuid_generate_random(buf);
46 uuid_unparse(buf, str);
47 printf("UUID random string = %s\n", str);
48 printf("UUID: ");
49 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
50 printf("%02x", *cp++);
51 }
52 printf("\n");
53 type = uuid_type(buf); variant = uuid_variant(buf);
54 printf("UUID type = %d, UUID variant = %d\n", type, variant);
55 if (variant != UUID_VARIANT_DCE) {
56 printf("Incorrect UUID Variant; was expecting DCE!\n");
57 failed++;
58 }
59 if (type != 4) {
60 printf("Incorrect UUID type; was expecting "
61 "4 (random type)!\n");
62 failed++;
63 }
64 printf("\n");
65
66 uuid_generate_time(buf);
67 uuid_unparse(buf, str);
68 printf("UUID string = %s\n", str);
69 printf("UUID time: ");
70 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) {
71 printf("%02x", *cp++);
72 }
73 printf("\n");
74 type = uuid_type(buf); variant = uuid_variant(buf);
75 printf("UUID type = %d, UUID variant = %d\n", type, variant);
76 if (variant != UUID_VARIANT_DCE) {
77 printf("Incorrect UUID Variant; was expecting DCE!\n");
78 failed++;
79 }
80 if (type != 1) {
81 printf("Incorrect UUID type; was expecting "
82 "1 (time-based type)!\\n");
83 failed++;
84 }
Theodore Ts'o1e0a2211998-12-04 08:13:52 +000085 tv.tv_sec = 0;
86 tv.tv_usec = 0;
87 time_reg = uuid_time(buf, &tv);
88 printf("UUID time is: (%d, %d): %s\n", tv.tv_sec, tv.tv_usec,
89 ctime(&time_reg));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000090 uuid_parse(str, tst);
Theodore Ts'ob19d1a91999-06-18 00:32:03 +000091 if (!uuid_compare(buf, tst))
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000092 printf("UUID parse and compare succeeded.\n");
93 else {
94 printf("UUID parse and compare failed!\n");
95 failed++;
96 }
97 uuid_clear(tst);
98 if (uuid_is_null(tst))
99 printf("UUID clear and is null succeeded.\n");
100 else {
101 printf("UUID clear and is null failed!\n");
102 failed++;
103 }
104 uuid_copy(buf, tst);
Theodore Ts'ob19d1a91999-06-18 00:32:03 +0000105 if (!uuid_compare(buf, tst))
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000106 printf("UUID copy and compare succeeded.\n");
107 else {
108 printf("UUID copy and compare failed!\n");
109 failed++;
110 }
111 if (failed) {
112 printf("%d failures.\n", failed);
113 exit(1);
114 }
115 return 0;
116}
117
118
119