VirtualBox

source: vbox/trunk/src/VBox/HostServices/testcase/tstHGCMSvc.cpp@ 100765

Last change on this file since 100765 was 99775, checked in by vboxsync, 19 months ago

*: Mark functions as static if not used outside of a given compilation unit. Enables the compiler to optimize inlining, reduces the symbol tables, exposes unused functions and in some rare cases exposes mismtaches between function declarations and definitions, but most importantly reduces the number of parfait reports for the extern-function-no-forward-declaration category. This should not result in any functional changes, bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: tstHGCMSvc.cpp 99775 2023-05-12 12:21:58Z vboxsync $ */
2/** @file
3 * HGCM Service Testcase.
4 */
5
6/*
7 * Copyright (C) 2009-2023 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/hgcmsvc.h>
33#include <iprt/initterm.h>
34#include <iprt/test.h>
35
36/** Test the getString member function. Indirectly tests the getPointer
37 * and getBuffer APIs.
38 * @param hTest an running IPRT test
39 * @param type the type that the parameter should be set to before
40 * calling getString
41 * @param pcch the value that the parameter should be set to before
42 * calling getString, and also the address (!) which we
43 * expect getString to return. Stricter than needed of
44 * course, but I was feeling lazy.
45 * @param cb the size that the parameter should be set to before
46 * calling getString, and also the size which we expect
47 * getString to return.
48 * @param rcExp the expected return value of the call to getString.
49 */
50static void doTestGetString(VBOXHGCMSVCPARM *pParm, RTTEST hTest, uint32_t type,
51 const char *pcch, uint32_t cb, int rcExp)
52{
53 /* An RTTest API like this, which would print out an additional line
54 * of context if a test failed, would be nice. This is because the
55 * line number alone doesn't help much here, given that this is a
56 * subroutine called many times. */
57 /*
58 RTTestContextF(hTest,
59 ("doTestGetString, type=%u, pcch=%p, acp=%u, rcExp=%Rrc",
60 type, pcch, acp, rcExp));
61 */
62 HGCMSvcSetPv(pParm, (void *)pcch, cb);
63 pParm->type = type; /* in case we don't want VBOX_HGCM_SVC_PARM_PTR */
64 const char *pcch2 = NULL;
65 uint32_t cb2 = 0;
66 int rc = HGCMSvcGetCStr(pParm, &pcch2, &cb2);
67 RTTEST_CHECK_RC(hTest, rc, rcExp);
68 if (RT_SUCCESS(rcExp))
69 {
70 RTTEST_CHECK_MSG_RETV(hTest, (pcch2 == pcch),
71 (hTest, "expected %p, got %p", pcch, pcch2));
72 RTTEST_CHECK_MSG_RETV(hTest, (cb2 == cb),
73 (hTest, "expected %u, got %u", cb, cb2));
74 }
75}
76
77/** Run some unit tests on the getString method and indirectly test
78 * getPointer and getBuffer as well. */
79static void testGetString(VBOXHGCMSVCPARM *pParm, RTTEST hTest)
80{
81 RTTestSub(hTest, "HGCM string parameter handling");
82 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_32BIT, "test", 3,
83 VERR_INVALID_PARAMETER);
84 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 5,
85 VINF_SUCCESS);
86 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 3,
87 VERR_BUFFER_OVERFLOW);
88 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test\xf0", 6,
89 VERR_INVALID_UTF8_ENCODING);
90 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 0,
91 VERR_INVALID_PARAMETER);
92 doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, (const char *)0x1, 5,
93 VERR_INVALID_PARAMETER);
94 RTTestSubDone(hTest);
95}
96
97int main()
98{
99 /*
100 * Init the runtime, test and say hello.
101 */
102 RTTEST hTest;
103 int rc = RTTestInitAndCreate("tstHGCMSvc", &hTest);
104 if (rc)
105 return rc;
106 RTTestBanner(hTest);
107
108 /*
109 * Run the test.
110 */
111 VBOXHGCMSVCPARM parm;
112 testGetString(&parm, hTest);
113
114 /*
115 * Summary
116 */
117 return RTTestSummaryAndDestroy(hTest);
118}
119
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