tst_uuid.c revision 96394d11b01b5613b635e4c5963a19e222e57afb
1/* 2 * tst_uuid.c --- test program from the UUID library 3 * 4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o. 5 * 6 * %Begin-Header% 7 * This file may be redistributed under the terms of the GNU Public 8 * License. 9 * %End-Header% 10 */ 11 12#include <stdio.h> 13#include <linux/ext2_fs.h> 14 15#include "uuid.h" 16 17int 18main(int argc, char **argv) 19{ 20 uuid_t buf, tst; 21 char str[100]; 22 struct timeval tv; 23 time_t time_reg; 24 unsigned char *cp; 25 int i; 26 int failed = 0; 27 int type, variant; 28 29 uuid_generate(buf); 30 uuid_unparse(buf, str); 31 printf("UUID generate = %s\n", str); 32 printf("UUID: "); 33 for (i=0, cp = (unsigned char *) &buf; i < 16; i++) { 34 printf("%02x", *cp++); 35 } 36 printf("\n"); 37 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 } 85 tv.tv_sec = 0; 86 tv.tv_usec = 0; 87 time_reg = uuid_time(buf, &tv); 88 printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec, 89 ctime(&time_reg)); 90 uuid_parse(str, tst); 91 if (!uuid_compare(buf, tst)) 92 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); 105 if (!uuid_compare(buf, tst)) 106 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 120