VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstUuid.cpp@ 1532

Last change on this file since 1532 was 1203, checked in by vboxsync, 18 years ago

RTR3Init.

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/* $Id: tstUuid.cpp 1203 2007-03-04 23:48:05Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime Testcase - UUID.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/uuid.h>
27#include <iprt/stream.h>
28#include <iprt/err.h>
29#include <iprt/string.h>
30#include <iprt/initterm.h>
31
32
33int main(int argc, char **argv)
34{
35 int rc;
36 int cErrors = 0;
37
38 rc = RTR3Init();
39 if (rc)
40 {
41 RTPrintf("RTR3Init failed: %Vrc\n", rc);
42 return 1;
43 }
44
45#define CHECK_RC() \
46 do { if (RT_FAILURE(rc)) { RTPrintf("tstUuid(%d): rc=%Vrc!\n", __LINE__, rc); cErrors++; } } while (0)
47#define CHECK_EXPR(expr) \
48 do { const bool f = !!(expr); if (!f) { RTPrintf("tstUuid(%d): %s!\n", __LINE__, #expr); cErrors++; } } while (0)
49
50 RTUUID UuidNull;
51 rc = RTUuidClear(&UuidNull); CHECK_RC();
52 CHECK_EXPR(RTUuidIsNull(&UuidNull));
53 CHECK_EXPR(RTUuidCompare(&UuidNull, &UuidNull) == 0);
54
55 RTUUID Uuid;
56 rc = RTUuidCreate(&Uuid); CHECK_RC();
57 CHECK_EXPR(!RTUuidIsNull(&Uuid));
58 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid) == 0);
59 CHECK_EXPR(RTUuidCompare(&Uuid, &UuidNull) > 0);
60 CHECK_EXPR(RTUuidCompare(&UuidNull, &Uuid) < 0);
61
62 char sz[RTUUID_STR_LENGTH];
63 rc = RTUuidToStr(&Uuid, sz, sizeof(sz)); CHECK_RC();
64 RTUUID Uuid2;
65 rc = RTUuidFromStr(&Uuid2, sz); CHECK_RC();
66 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid2) == 0);
67
68 RTPrintf("tstUuid: Created {%s}\n", sz);
69
70 /*
71 * Check the binary representation.
72 */
73 RTUUID Uuid3;
74 Uuid3.au8[0] = 0x01;
75 Uuid3.au8[1] = 0x23;
76 Uuid3.au8[2] = 0x45;
77 Uuid3.au8[3] = 0x67;
78 Uuid3.au8[4] = 0x89;
79 Uuid3.au8[5] = 0xab;
80 Uuid3.au8[6] = 0xcd;
81 Uuid3.au8[7] = 0x4f;
82 Uuid3.au8[8] = 0x10;
83 Uuid3.au8[9] = 0xb2;
84 Uuid3.au8[10] = 0x54;
85 Uuid3.au8[11] = 0x76;
86 Uuid3.au8[12] = 0x98;
87 Uuid3.au8[13] = 0xba;
88 Uuid3.au8[14] = 0xdc;
89 Uuid3.au8[15] = 0xfe;
90 Uuid3.Gen.u16ClockSeq = (Uuid3.Gen.u16ClockSeq & 0x3fff) | 0x8000;
91 Uuid3.Gen.u16TimeHiAndVersion = (Uuid3.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
92 const char *pszUuid3 = "67452301-ab89-4fcd-10b2-547698badcfe";
93 rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC();
94 CHECK_EXPR(strcmp(sz, pszUuid3) == 0);
95 rc = RTUuidFromStr(&Uuid, pszUuid3); CHECK_RC();
96 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid3) == 0);
97 CHECK_EXPR(memcmp(&Uuid3, &Uuid, sizeof(Uuid)) == 0);
98
99 /*
100 * Summary.
101 */
102 if (!cErrors)
103 RTPrintf("tstUuid: SUCCESS {%s}\n", sz);
104 else
105 RTPrintf("tstUuid: FAILED - %d errors\n", cErrors);
106 return !!cErrors;
107}
108
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette