VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/testcase/tstAudioTestService.cpp@ 90518

Last change on this file since 90518 was 90518, checked in by vboxsync, 3 years ago

Audio/ValKit: Fixed tstAudioTestService (some options were missing). ​bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: tstAudioTestService.cpp 90518 2021-08-04 13:19:37Z vboxsync $ */
2/** @file
3 * Audio testcase - Tests for the Audio Test Service (ATS).
4 */
5
6/*
7 * Copyright (C) 2021 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
23#include <iprt/errcore.h>
24#include <iprt/file.h>
25#include <iprt/initterm.h>
26#include <iprt/mem.h>
27#include <iprt/rand.h>
28#include <iprt/stream.h>
29#include <iprt/string.h>
30#include <iprt/test.h>
31
32#include "../AudioTestService.h"
33#include "../AudioTestServiceClient.h"
34
35
36static size_t g_cToRead = _1M;
37static size_t g_cbRead = 0;
38
39
40/** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
41static DECLCALLBACK(int) tstTestSetSendReadCallback(void const *pvUser,
42 const char *pszTag, void *pvBuf, size_t cbBuf, size_t *pcbRead)
43{
44 RT_NOREF(pvUser, pszTag);
45
46 size_t cbToRead = RT_MIN(g_cToRead - g_cbRead, cbBuf);
47 if (cbToRead)
48 {
49 memset(pvBuf, 0x42, cbToRead);
50 g_cbRead += cbToRead;
51 }
52
53 *pcbRead = cbToRead;
54
55 return VINF_SUCCESS;
56}
57
58int main(int argc, char **argv)
59{
60 RTR3InitExe(argc, &argv, 0);
61
62 /*
63 * Initialize IPRT and create the test.
64 */
65 RTTEST hTest;
66 int rc = RTTestInitAndCreate("tstAudioTestService", &hTest);
67 if (rc)
68 return rc;
69 RTTestBanner(hTest);
70
71 ATSCALLBACKS Callbacks;
72 RT_ZERO(Callbacks);
73 Callbacks.pfnTestSetSendRead = tstTestSetSendReadCallback;
74
75 ATSCLIENT Client;
76
77 ATSSERVER Srv;
78 rc = AudioTestSvcCreate(&Srv);
79 RTTEST_CHECK_RC_OK(hTest, rc);
80 if (RT_SUCCESS(rc))
81 {
82 RTGETOPTUNION Val;
83 RT_ZERO(Val);
84
85 Val.psz = "server";
86 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_MODE, &Val);
87 RTTEST_CHECK_RC_OK(hTest, rc);
88
89 Val.u16 = ATS_TCP_DEF_BIND_PORT_HOST;
90 rc = AudioTestSvcHandleOption(&Srv, ATSTCPOPT_BIND_PORT, &Val);
91 RTTEST_CHECK_RC_OK(hTest, rc);
92
93 rc = AudioTestSvcInit(&Srv, &Callbacks);
94 RTTEST_CHECK_RC_OK(hTest, rc);
95 if (RT_SUCCESS(rc))
96 {
97 rc = AudioTestSvcStart(&Srv);
98 RTTEST_CHECK_RC_OK(hTest, rc);
99 if (RT_SUCCESS(rc))
100 {
101 rc = AudioTestSvcClientCreate(&Client);
102 RTTEST_CHECK_RC_OK(hTest, rc);
103
104 Val.psz = "client";
105 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_MODE, &Val);
106 RTTEST_CHECK_RC_OK(hTest, rc);
107
108 Val.psz = ATS_TCP_DEF_CONNECT_HOST_ADDR_STR;
109 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_ADDRESS, &Val);
110 RTTEST_CHECK_RC_OK(hTest, rc);
111
112 Val.u16 = ATS_TCP_DEF_CONNECT_PORT_GUEST;
113 rc = AudioTestSvcClientHandleOption(&Client, ATSTCPOPT_CONNECT_PORT, &Val);
114 RTTEST_CHECK_RC_OK(hTest, rc);
115
116 rc = AudioTestSvcClientConnect(&Client);
117 RTTEST_CHECK_RC_OK(hTest, rc);
118 }
119 }
120 }
121
122 if (RT_SUCCESS(rc))
123 {
124 char szTemp[RTPATH_MAX];
125 rc = RTPathTemp(szTemp, sizeof(szTemp));
126 RTTEST_CHECK_RC_OK(hTest, rc);
127 if (RT_SUCCESS(rc))
128 {
129 char szFile[RTPATH_MAX];
130 rc = RTPathJoin(szFile, sizeof(szFile), szTemp, "tstAudioTestService");
131 RTTEST_CHECK_RC_OK(hTest, rc);
132 if (RT_SUCCESS(rc))
133 {
134 rc = AudioTestSvcClientTestSetDownload(&Client, "ignored", szFile);
135 RTTEST_CHECK_RC_OK(hTest, rc);
136 }
137
138 rc = RTFileDelete(szFile);
139 RTTEST_CHECK_RC_OK(hTest, rc);
140 }
141 }
142
143 rc = AudioTestSvcClientClose(&Client);
144 RTTEST_CHECK_RC_OK(hTest, rc);
145
146 rc = AudioTestSvcShutdown(&Srv);
147 RTTEST_CHECK_RC_OK(hTest, rc);
148
149 /*
150 * Summary
151 */
152 return RTTestSummaryAndDestroy(hTest);
153}
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