1 | /* $Id: tstGuestCtrlContextID.cpp 42215 2012-07-18 18:05:25Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * Context ID makeup/extraction test cases.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2012 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #define LOG_ENABLED
|
---|
21 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
22 | #define LOG_INSTANCE NULL
|
---|
23 | #include <VBox/log.h>
|
---|
24 |
|
---|
25 | #include "../include/GuestCtrlImplPrivate.h"
|
---|
26 |
|
---|
27 | using namespace com;
|
---|
28 |
|
---|
29 | #include <iprt/env.h>
|
---|
30 | #include <iprt/rand.h>
|
---|
31 | #include <iprt/stream.h>
|
---|
32 | #include <iprt/test.h>
|
---|
33 |
|
---|
34 | int main()
|
---|
35 | {
|
---|
36 | RTTEST hTest;
|
---|
37 | int rc = RTTestInitAndCreate("tstMakeup", &hTest);
|
---|
38 | if (rc)
|
---|
39 | return rc;
|
---|
40 | RTTestBanner(hTest);
|
---|
41 |
|
---|
42 | RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
|
---|
43 | HRESULT hrc = com::Initialize();
|
---|
44 | if (FAILED(hrc))
|
---|
45 | {
|
---|
46 | RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
|
---|
47 | return RTEXITCODE_FAILURE;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /* Don't let the assertions trigger here
|
---|
51 | * -- we rely on the return values in the test(s) below. */
|
---|
52 | RTAssertSetQuiet(true);
|
---|
53 |
|
---|
54 | uint32_t uContextMax = UINT32_MAX;
|
---|
55 | RTTestIPrintf(RTTESTLVL_DEBUG, "Max context is: %RU32\n", uContextMax);
|
---|
56 |
|
---|
57 | /* Do 64 tests total. */
|
---|
58 | for (int t = 0; t < 64 && !RTTestErrorCount(hTest); t++)
|
---|
59 | {
|
---|
60 | uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS);
|
---|
61 | uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_PROCESSES);
|
---|
62 | uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS);
|
---|
63 |
|
---|
64 | uint64_t uContextID = VBOX_GUESTCTRL_CONTEXTID_MAKE(s, p, c);
|
---|
65 | RTTestIPrintf(RTTESTLVL_DEBUG, "ContextID (%d,%d,%d) = %RU32\n", s, p, c, uContextID);
|
---|
66 | if (s != VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID))
|
---|
67 | {
|
---|
68 | RTTestFailed(hTest, "%d,%d,%d: Session is %d, expected %d -> %RU64\n",
|
---|
69 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
|
---|
70 | }
|
---|
71 | else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID))
|
---|
72 | {
|
---|
73 | RTTestFailed(hTest, "%d,%d,%d: Process is %d, expected %d -> %RU64\n",
|
---|
74 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID), p, uContextID);
|
---|
75 | }
|
---|
76 | if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
|
---|
77 | {
|
---|
78 | RTTestFailed(hTest, "%d,%d,%d: Count is %d, expected %d -> %RU64\n",
|
---|
79 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID), c, uContextID);
|
---|
80 | }
|
---|
81 | if (uContextID > UINT32_MAX)
|
---|
82 | {
|
---|
83 | RTTestFailed(hTest, "%d,%d,%d: Value overflow; does not fit anymore: %RU64\n",
|
---|
84 | s, p, c, uContextID);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
|
---|
89 | com::Shutdown();
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * Summary.
|
---|
93 | */
|
---|
94 | return RTTestSummaryAndDestroy(hTest);
|
---|
95 | }
|
---|
96 |
|
---|