VirtualBox

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

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

Main/GuestCtrl: Reduce number of maximum guest sessions at once to 32 in favor of having up to 2048 objects (processes, files, ...) per session.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: tstGuestCtrlContextID.cpp 43036 2012-08-28 13:22:39Z 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 /* VBOX_GUESTCTRL_MAX_* includes 0 as an object, so subtract one. */
61 uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
62 uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1);
63 uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1);
64
65 uint64_t uContextID = VBOX_GUESTCTRL_CONTEXTID_MAKE(s, p, c);
66 RTTestIPrintf(RTTESTLVL_DEBUG, "ContextID (%d,%d,%d) = %RU32\n", s, p, c, uContextID);
67 if (s != VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID))
68 {
69 RTTestFailed(hTest, "%d,%d,%d: Session is %d, expected %d -> %RU64\n",
70 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
71 }
72 else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID))
73 {
74 RTTestFailed(hTest, "%d,%d,%d: Object is %d, expected %d -> %RU64\n",
75 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID), p, uContextID);
76 }
77 if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
78 {
79 RTTestFailed(hTest, "%d,%d,%d: Count is %d, expected %d -> %RU64\n",
80 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID), c, uContextID);
81 }
82 if (uContextID > UINT32_MAX)
83 {
84 RTTestFailed(hTest, "%d,%d,%d: Value overflow; does not fit anymore: %RU64\n",
85 s, p, c, uContextID);
86 }
87 }
88
89 RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
90 com::Shutdown();
91
92 /*
93 * Summary.
94 */
95 return RTTestSummaryAndDestroy(hTest);
96}
97
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