VirtualBox

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

Last change on this file since 61572 was 55969, checked in by vboxsync, 10 years ago

Removed unnecessary LOG_INSTANCE definitions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: tstGuestCtrlContextID.cpp 55969 2015-05-20 14:50:23Z vboxsync $ */
2/** @file
3 * Context ID makeup/extraction test cases.
4 */
5
6/*
7 * Copyright (C) 2012 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#define LOG_ENABLED
19#define LOG_GROUP LOG_GROUP_MAIN
20#include <VBox/log.h>
21
22#include "../include/GuestCtrlImplPrivate.h"
23
24using namespace com;
25
26#include <iprt/env.h>
27#include <iprt/rand.h>
28#include <iprt/stream.h>
29#include <iprt/test.h>
30
31int main()
32{
33 RTTEST hTest;
34 int rc = RTTestInitAndCreate("tstGuestCtrlContextID", &hTest);
35 if (rc)
36 return rc;
37 RTTestBanner(hTest);
38
39 RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
40 HRESULT hrc = com::Initialize();
41 if (FAILED(hrc))
42 {
43 RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
44 return RTEXITCODE_FAILURE;
45 }
46
47 /* Don't let the assertions trigger here
48 * -- we rely on the return values in the test(s) below. */
49 RTAssertSetQuiet(true);
50
51#if 0
52 for (int t = 0; t < 4 && !RTTestErrorCount(hTest); t++)
53 {
54 uint32_t uSession = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
55 uint32_t uFilter = VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSession);
56 RTTestIPrintf(RTTESTLVL_INFO, "Session: %RU32, Filter: %x\n", uSession, uFilter);
57
58 uint32_t uSession2 = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
59 uint32_t uCID = VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession2,
60 RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1),
61 RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1));
62 RTTestIPrintf(RTTESTLVL_INFO, "CID: %x (Session: %d), Masked: %x\n",
63 uCID, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uCID), uCID & uFilter);
64 if ((uCID & uFilter) == uCID)
65 {
66 RTTestIPrintf(RTTESTLVL_INFO, "=========== Masking works: %x vs. %x\n",
67 uCID & uFilter, uFilter);
68 }
69 }
70#endif
71
72 uint32_t uContextMax = UINT32_MAX;
73 RTTestIPrintf(RTTESTLVL_DEBUG, "Max context is: %RU32\n", uContextMax);
74
75 /* Do 4048 tests total. */
76 for (int t = 0; t < 4048 && !RTTestErrorCount(hTest); t++)
77 {
78 /* VBOX_GUESTCTRL_MAX_* includes 0 as an object, so subtract one. */
79 uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
80 uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1);
81 uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1);
82
83 uint64_t uContextID = VBOX_GUESTCTRL_CONTEXTID_MAKE(s, p, c);
84 RTTestIPrintf(RTTESTLVL_DEBUG, "ContextID (%d,%d,%d) = %RU32\n", s, p, c, uContextID);
85 if (s != VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID))
86 {
87 RTTestFailed(hTest, "%d,%d,%d: Session is %d, expected %d -> %RU64\n",
88 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
89 }
90 else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID))
91 {
92 RTTestFailed(hTest, "%d,%d,%d: Object is %d, expected %d -> %RU64\n",
93 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID), p, uContextID);
94 }
95 if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
96 {
97 RTTestFailed(hTest, "%d,%d,%d: Count is %d, expected %d -> %RU64\n",
98 s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID), c, uContextID);
99 }
100 if (uContextID > UINT32_MAX)
101 {
102 RTTestFailed(hTest, "%d,%d,%d: Value overflow; does not fit anymore: %RU64\n",
103 s, p, c, uContextID);
104 }
105 }
106
107 RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
108 com::Shutdown();
109
110 /*
111 * Summary.
112 */
113 return RTTestSummaryAndDestroy(hTest);
114}
115
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