VirtualBox

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

Last change on this file since 918 was 892, checked in by vboxsync, 18 years ago

Test binary representation.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: tstUuid.cpp 892 2007-02-14 09:35:48Z 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
31
32int main(int argc, char **argv)
33{
34 int rc;
35 int cErrors = 0;
36
37#define CHECK_RC() \
38 do { if (RT_FAILURE(rc)) { RTPrintf("tstUuid(%d): rc=%Vrc!\n", __LINE__, rc); cErrors++; } } while (0)
39#define CHECK_EXPR(expr) \
40 do { const bool f = !!(expr); if (!f) { RTPrintf("tstUuid(%d): %s!\n", __LINE__, #expr); cErrors++; } } while (0)
41
42 RTUUID UuidNull;
43 rc = RTUuidClear(&UuidNull); CHECK_RC();
44 CHECK_EXPR(RTUuidIsNull(&UuidNull));
45 CHECK_EXPR(RTUuidCompare(&UuidNull, &UuidNull) == 0);
46
47 RTUUID Uuid;
48 rc = RTUuidCreate(&Uuid); CHECK_RC();
49 CHECK_EXPR(!RTUuidIsNull(&Uuid));
50 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid) == 0);
51 CHECK_EXPR(RTUuidCompare(&Uuid, &UuidNull) > 0);
52 CHECK_EXPR(RTUuidCompare(&UuidNull, &Uuid) < 0);
53
54 char sz[RTUUID_STR_LENGTH];
55 rc = RTUuidToStr(&Uuid, sz, sizeof(sz)); CHECK_RC();
56 RTUUID Uuid2;
57 rc = RTUuidFromStr(&Uuid2, sz); CHECK_RC();
58 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid2) == 0);
59
60 /*
61 * Check the binary representation.
62 */
63 RTUUID Uuid3;
64 Uuid3.au8[0] = 0x01;
65 Uuid3.au8[1] = 0x23;
66 Uuid3.au8[2] = 0x45;
67 Uuid3.au8[3] = 0x67;
68 Uuid3.au8[4] = 0x89;
69 Uuid3.au8[5] = 0xab;
70 Uuid3.au8[6] = 0xcd;
71 Uuid3.au8[7] = 0x4f;
72 Uuid3.au8[8] = 0x10;
73 Uuid3.au8[9] = 0xb2;
74 Uuid3.au8[10] = 0x54;
75 Uuid3.au8[11] = 0x76;
76 Uuid3.au8[12] = 0x98;
77 Uuid3.au8[13] = 0xba;
78 Uuid3.au8[14] = 0xdc;
79 Uuid3.au8[15] = 0xfe;
80 Uuid3.Gen.u16ClockSeq = (Uuid3.Gen.u16ClockSeq & 0x3fff) | 0x8000;
81 Uuid3.Gen.u16TimeHiAndVersion = (Uuid3.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
82 const char *pszUuid3 = "67452301-ab89-4fcd-10b2-547698badcfe";
83 rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC();
84 CHECK_EXPR(strcmp(sz, pszUuid3) == 0);
85 rc = RTUuidFromStr(&Uuid, pszUuid3); CHECK_RC();
86 CHECK_EXPR(RTUuidCompare(&Uuid, &Uuid3) == 0);
87 CHECK_EXPR(memcmp(&Uuid3, &Uuid, sizeof(Uuid)) == 0);
88
89 /*
90 * Summary.
91 */
92 if (!cErrors)
93 RTPrintf("tstUuid: SUCCESS {%s}\n", sz);
94 else
95 RTPrintf("tstUuid: FAILED - %d errors\n", cErrors);
96 return !!cErrors;
97}
98
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