VirtualBox

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

Last change on this file since 4968 was 4750, checked in by vboxsync, 17 years ago

eol style native

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