VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstGuestCtrlContextID.cpp@ 42214

Last change on this file since 42214 was 42214, checked in by vboxsync, 12 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: tstGuestCtrlContextID.cpp 42214 2012-07-18 18:02:58Z 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
27using namespace com;
28
29#include <iprt/env.h>
30#include <iprt/rand.h>
31#include <iprt/stream.h>
32#include <iprt/test.h>
33
34int 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#if 0
89 #define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uProcess, uCount) \
90 ( (uint32_t)((uSession) & 0xff) << 24 \
91 | (uint32_t)((uProcess) & 0xff) << 16 \
92 | (uint32_t)((uCount) & 0xffff) \
93 )
94/** Gets the session ID out of a context ID. */
95#define VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID) \
96 (uContextID) >> 24)
97/** Gets the process ID out of a context ID. */
98#define VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID) \
99 (uContextID) >> 16)
100/** Gets the conext count of a process out of a context ID. */
101#define VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID) \
102 ((uContextID) && 0xffff)
103#endif
104
105 RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
106 com::Shutdown();
107
108 /*
109 * Summary.
110 */
111 return RTTestSummaryAndDestroy(hTest);
112}
113
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