1 | /* $Id: tstUuid.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime Testcase - UUID.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #include <iprt/uuid.h>
|
---|
32 | #include <iprt/stream.h>
|
---|
33 | #include <iprt/err.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <iprt/initterm.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | int main(int argc, char **argv)
|
---|
39 | {
|
---|
40 | int rc;
|
---|
41 | int cErrors = 0;
|
---|
42 |
|
---|
43 | rc = RTR3Init();
|
---|
44 | if (rc)
|
---|
45 | {
|
---|
46 | RTPrintf("RTR3Init failed: %Vrc\n", rc);
|
---|
47 | return 1;
|
---|
48 | }
|
---|
49 |
|
---|
50 | #define CHECK_RC() \
|
---|
51 | do { if (RT_FAILURE(rc)) { RTPrintf("tstUuid(%d): rc=%Vrc!\n", __LINE__, rc); cErrors++; } } while (0)
|
---|
52 | #define CHECK_EXPR(expr) \
|
---|
53 | do { const bool f = !!(expr); if (!f) { RTPrintf("tstUuid(%d): %s!\n", __LINE__, #expr); cErrors++; } } while (0)
|
---|
54 |
|
---|
55 | RTUUID UuidNull;
|
---|
56 | rc = RTUuidClear(&UuidNull); CHECK_RC();
|
---|
57 | CHECK_EXPR(RTUuidIsNull(&UuidNull));
|
---|
58 | CHECK_EXPR(RTUuidCompare(&UuidNull, &UuidNull) == 0);
|
---|
59 |
|
---|
60 | RTUUID Uuid;
|
---|
61 | rc = RTUuidCreate(&Uuid); CHECK_RC();
|
---|
62 | CHECK_EXPR(!RTUuidIsNull(&Uuid));
|
---|
63 | CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid) == 0);
|
---|
64 | CHECK_EXPR(RTUuidCompare(&Uuid, &UuidNull) > 0);
|
---|
65 | CHECK_EXPR(RTUuidCompare(&UuidNull, &Uuid) < 0);
|
---|
66 |
|
---|
67 | char sz[RTUUID_STR_LENGTH];
|
---|
68 | rc = RTUuidToStr(&Uuid, sz, sizeof(sz)); CHECK_RC();
|
---|
69 | RTUUID Uuid2;
|
---|
70 | rc = RTUuidFromStr(&Uuid2, sz); CHECK_RC();
|
---|
71 | CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid2) == 0);
|
---|
72 |
|
---|
73 | RTPrintf("tstUuid: Created {%s}\n", sz);
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Check the binary representation.
|
---|
77 | */
|
---|
78 | RTUUID Uuid3;
|
---|
79 | Uuid3.au8[0] = 0x01;
|
---|
80 | Uuid3.au8[1] = 0x23;
|
---|
81 | Uuid3.au8[2] = 0x45;
|
---|
82 | Uuid3.au8[3] = 0x67;
|
---|
83 | Uuid3.au8[4] = 0x89;
|
---|
84 | Uuid3.au8[5] = 0xab;
|
---|
85 | Uuid3.au8[6] = 0xcd;
|
---|
86 | Uuid3.au8[7] = 0x4f;
|
---|
87 | Uuid3.au8[8] = 0x10;
|
---|
88 | Uuid3.au8[9] = 0xb2;
|
---|
89 | Uuid3.au8[10] = 0x54;
|
---|
90 | Uuid3.au8[11] = 0x76;
|
---|
91 | Uuid3.au8[12] = 0x98;
|
---|
92 | Uuid3.au8[13] = 0xba;
|
---|
93 | Uuid3.au8[14] = 0xdc;
|
---|
94 | Uuid3.au8[15] = 0xfe;
|
---|
95 | Uuid3.Gen.u16ClockSeq = (Uuid3.Gen.u16ClockSeq & 0x3fff) | 0x8000;
|
---|
96 | Uuid3.Gen.u16TimeHiAndVersion = (Uuid3.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
|
---|
97 | const char *pszUuid3 = "67452301-ab89-4fcd-10b2-547698badcfe";
|
---|
98 | rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC();
|
---|
99 | CHECK_EXPR(strcmp(sz, pszUuid3) == 0);
|
---|
100 | rc = RTUuidFromStr(&Uuid, pszUuid3); CHECK_RC();
|
---|
101 | CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid3) == 0);
|
---|
102 | CHECK_EXPR(memcmp(&Uuid3, &Uuid, sizeof(Uuid)) == 0);
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Summary.
|
---|
106 | */
|
---|
107 | if (!cErrors)
|
---|
108 | RTPrintf("tstUuid: SUCCESS {%s}\n", sz);
|
---|
109 | else
|
---|
110 | RTPrintf("tstUuid: FAILED - %d errors\n", cErrors);
|
---|
111 | return !!cErrors;
|
---|
112 | }
|
---|
113 |
|
---|