1 | /* $Id: tstAudioTestService.cpp 89805 2021-06-21 06:27:05Z 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 |
|
---|
36 | static size_t g_cToRead = _1M;
|
---|
37 | static size_t g_cbRead = 0;
|
---|
38 |
|
---|
39 |
|
---|
40 | /** @copydoc ATSCALLBACKS::pfnTestSetSendRead */
|
---|
41 | static 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 |
|
---|
58 | int 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 = AudioTestSvcInit(&Srv, "127.0.0.1", ATS_TCP_HOST_DEFAULT_PORT, &Callbacks);
|
---|
79 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
80 | if (RT_SUCCESS(rc))
|
---|
81 | {
|
---|
82 | rc = AudioTestSvcStart(&Srv);
|
---|
83 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
84 | if (RT_SUCCESS(rc))
|
---|
85 | {
|
---|
86 | rc = AudioTestSvcClientConnect(&Client, "127.0.0.1", ATS_TCP_HOST_DEFAULT_PORT);
|
---|
87 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (RT_SUCCESS(rc))
|
---|
92 | {
|
---|
93 | char szTemp[RTPATH_MAX];
|
---|
94 | rc = RTPathTemp(szTemp, sizeof(szTemp));
|
---|
95 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
96 | if (RT_SUCCESS(rc))
|
---|
97 | {
|
---|
98 | char szFile[RTPATH_MAX];
|
---|
99 | rc = RTPathJoin(szFile, sizeof(szFile), szTemp, "tstAudioTestService");
|
---|
100 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
101 | if (RT_SUCCESS(rc))
|
---|
102 | {
|
---|
103 | rc = AudioTestSvcClientTestSetDownload(&Client, "ignored", szFile);
|
---|
104 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
105 | }
|
---|
106 |
|
---|
107 | rc = RTFileDelete(szFile);
|
---|
108 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | rc = AudioTestSvcClientClose(&Client);
|
---|
113 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
114 |
|
---|
115 | rc = AudioTestSvcShutdown(&Srv);
|
---|
116 | RTTEST_CHECK_RC_OK(hTest, rc);
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * Summary
|
---|
120 | */
|
---|
121 | return RTTestSummaryAndDestroy(hTest);
|
---|
122 | }
|
---|