1 | /* $Id: tstGuid.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * API Glue Testcase - Guid.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2022 Oracle Corporation
|
---|
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 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <VBox/com/Guid.h>
|
---|
23 |
|
---|
24 | #include <iprt/errcore.h>
|
---|
25 | #include <iprt/mem.h>
|
---|
26 | #include <iprt/string.h>
|
---|
27 | #include <iprt/test.h>
|
---|
28 | #include <iprt/uni.h>
|
---|
29 |
|
---|
30 |
|
---|
31 | static void test1(RTTEST hTest)
|
---|
32 | {
|
---|
33 | RTTestSub(hTest, "Basics");
|
---|
34 |
|
---|
35 | #define CHECK(expr) RTTESTI_CHECK(expr)
|
---|
36 | #define CHECK_DUMP(expr, value) \
|
---|
37 | do { \
|
---|
38 | if (!(expr)) \
|
---|
39 | RTTestFailed(hTest, "%d: FAILED %s, got \"%s\"", __LINE__, #expr, value); \
|
---|
40 | } while (0)
|
---|
41 |
|
---|
42 | #define CHECK_DUMP_I(expr) \
|
---|
43 | do { \
|
---|
44 | if (!(expr)) \
|
---|
45 | RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \
|
---|
46 | } while (0)
|
---|
47 | #define CHECK_EQUAL(Str, szExpect) \
|
---|
48 | do { \
|
---|
49 | if (!(Str).equals(szExpect)) \
|
---|
50 | RTTestIFailed("line %u: expected \"%s\" got \"%s\"", __LINE__, szExpect, (Str).c_str()); \
|
---|
51 | } while (0)
|
---|
52 | #define CHECK_EQUAL_I(iRes, iExpect) \
|
---|
53 | do { \
|
---|
54 | if (iRes != iExpect) \
|
---|
55 | RTTestIFailed("line %u: expected \"%zd\" got \"%zd\"", __LINE__, iExpect, iRes); \
|
---|
56 | } while (0)
|
---|
57 |
|
---|
58 | com::Guid zero;
|
---|
59 | CHECK(zero.isZero());
|
---|
60 |
|
---|
61 | com::Guid copyZero(zero);
|
---|
62 | CHECK(copyZero.isZero());
|
---|
63 |
|
---|
64 | com::Guid assignZero(zero);
|
---|
65 | CHECK(assignZero.isZero());
|
---|
66 |
|
---|
67 | com::Guid random;
|
---|
68 | random.create();
|
---|
69 | CHECK(!random.isZero());
|
---|
70 |
|
---|
71 | com::Guid copyRandom(random);
|
---|
72 | CHECK(!copyRandom.isZero());
|
---|
73 |
|
---|
74 | com::Guid assignRandom(random);
|
---|
75 | CHECK(!assignRandom.isZero());
|
---|
76 |
|
---|
77 | /** @todo extend this a lot, it needs to cover many more cases */
|
---|
78 |
|
---|
79 | #undef CHECK
|
---|
80 | #undef CHECK_DUMP
|
---|
81 | #undef CHECK_DUMP_I
|
---|
82 | #undef CHECK_EQUAL
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | int main()
|
---|
87 | {
|
---|
88 | RTTEST hTest;
|
---|
89 | RTEXITCODE rcExit = RTTestInitAndCreate("tstGuid", &hTest);
|
---|
90 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
91 | {
|
---|
92 | RTTestBanner(hTest);
|
---|
93 |
|
---|
94 | test1(hTest);
|
---|
95 |
|
---|
96 | rcExit = RTTestSummaryAndDestroy(hTest);
|
---|
97 | }
|
---|
98 | return rcExit;
|
---|
99 | }
|
---|
100 |
|
---|