1 | /* $Id: tstGuid.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * API Glue Testcase - Guid.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #include <VBox/com/Guid.h>
|
---|
33 |
|
---|
34 | #include <iprt/errcore.h>
|
---|
35 | #include <iprt/mem.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 | #include <iprt/test.h>
|
---|
38 | #include <iprt/uni.h>
|
---|
39 |
|
---|
40 |
|
---|
41 | static void test1(RTTEST hTest)
|
---|
42 | {
|
---|
43 | RTTestSub(hTest, "Basics");
|
---|
44 |
|
---|
45 | #define CHECK(expr) RTTESTI_CHECK(expr)
|
---|
46 | #define CHECK_DUMP(expr, value) \
|
---|
47 | do { \
|
---|
48 | if (!(expr)) \
|
---|
49 | RTTestFailed(hTest, "%d: FAILED %s, got \"%s\"", __LINE__, #expr, value); \
|
---|
50 | } while (0)
|
---|
51 |
|
---|
52 | #define CHECK_DUMP_I(expr) \
|
---|
53 | do { \
|
---|
54 | if (!(expr)) \
|
---|
55 | RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \
|
---|
56 | } while (0)
|
---|
57 | #define CHECK_EQUAL(Str, szExpect) \
|
---|
58 | do { \
|
---|
59 | if (!(Str).equals(szExpect)) \
|
---|
60 | RTTestIFailed("line %u: expected \"%s\" got \"%s\"", __LINE__, szExpect, (Str).c_str()); \
|
---|
61 | } while (0)
|
---|
62 | #define CHECK_EQUAL_I(iRes, iExpect) \
|
---|
63 | do { \
|
---|
64 | if (iRes != iExpect) \
|
---|
65 | RTTestIFailed("line %u: expected \"%zd\" got \"%zd\"", __LINE__, iExpect, iRes); \
|
---|
66 | } while (0)
|
---|
67 |
|
---|
68 | com::Guid zero;
|
---|
69 | CHECK(zero.isZero());
|
---|
70 |
|
---|
71 | com::Guid copyZero(zero);
|
---|
72 | CHECK(copyZero.isZero());
|
---|
73 |
|
---|
74 | com::Guid assignZero(zero);
|
---|
75 | CHECK(assignZero.isZero());
|
---|
76 |
|
---|
77 | com::Guid random;
|
---|
78 | random.create();
|
---|
79 | CHECK(!random.isZero());
|
---|
80 |
|
---|
81 | com::Guid copyRandom(random);
|
---|
82 | CHECK(!copyRandom.isZero());
|
---|
83 |
|
---|
84 | com::Guid assignRandom(random);
|
---|
85 | CHECK(!assignRandom.isZero());
|
---|
86 |
|
---|
87 | /** @todo extend this a lot, it needs to cover many more cases */
|
---|
88 |
|
---|
89 | #undef CHECK
|
---|
90 | #undef CHECK_DUMP
|
---|
91 | #undef CHECK_DUMP_I
|
---|
92 | #undef CHECK_EQUAL
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | int main()
|
---|
97 | {
|
---|
98 | RTTEST hTest;
|
---|
99 | RTEXITCODE rcExit = RTTestInitAndCreate("tstGuid", &hTest);
|
---|
100 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
101 | {
|
---|
102 | RTTestBanner(hTest);
|
---|
103 |
|
---|
104 | test1(hTest);
|
---|
105 |
|
---|
106 | rcExit = RTTestSummaryAndDestroy(hTest);
|
---|
107 | }
|
---|
108 | return rcExit;
|
---|
109 | }
|
---|
110 |
|
---|