VirtualBox

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

Last change on this file since 86363 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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