blob: 32be4424cd85ba9fce12341a9ddc8324df74866c [file] [log] [blame]
Phil Burkd2a8a532020-07-01 18:16:28 -07001#include <oboe/Oboe.h>/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18#include <oboe/Oboe.h>
19#include "../src/aaudio/AAudioLoader.h"
20
21using namespace oboe;
22
23class AAudioDirect : public ::testing::Test {
24public:
Phil Burka358bca2020-07-01 18:16:28 -070025
26 /**
27 * @return true if AAudio NOT supported
28 */
29 bool openAAudio() {
Phil Burkd2a8a532020-07-01 18:16:28 -070030 mAAudioLoader = AAudioLoader::getInstance();
Phil Burka358bca2020-07-01 18:16:28 -070031 return (mAAudioLoader->open() != 0);
32 }
33
34 void createBuilder() {
Phil Burkd2a8a532020-07-01 18:16:28 -070035 ASSERT_NE(mAAudioLoader, nullptr);
36 ASSERT_EQ(0, mAAudioLoader->open());
37 ASSERT_NE(mAAudioLoader->createStreamBuilder, nullptr);
38 aaudio_result_t result = mAAudioLoader->createStreamBuilder(&mBuilder);
39 ASSERT_NE(mBuilder, nullptr);
40 ASSERT_EQ(result, 0);
41 }
42
43 void openCloseStream() {
44 AAudioStream *stream = nullptr;
45 aaudio_result_t result = mAAudioLoader->builder_openStream(mBuilder, &stream);
46 ASSERT_EQ(result, 0);
47 ASSERT_NE(stream, nullptr);
48
49 result = mAAudioLoader->stream_close(stream);
50 ASSERT_EQ(result, 0);
51 }
52
53 AAudioStreamBuilder *mBuilder = nullptr;
54 AAudioLoader *mAAudioLoader = nullptr;
55};
56
Phil Burka358bca2020-07-01 18:16:28 -070057TEST_F(AAudioDirect, InstantiateAAudioLoader) {
58 AAudioLoader *aaudioLoader = AAudioLoader::getInstance();
59 ASSERT_NE(aaudioLoader, nullptr);
Phil Burkd2a8a532020-07-01 18:16:28 -070060}
61
Phil Burka358bca2020-07-01 18:16:28 -070062TEST_F(AAudioDirect, OpenCloseHighLatencyStream) {
63 if (openAAudio()) return;
Phil Burkd2a8a532020-07-01 18:16:28 -070064 createBuilder();
65 mAAudioLoader->builder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_NONE);
66 openCloseStream();
67}
68
Phil Burka358bca2020-07-01 18:16:28 -070069TEST_F(AAudioDirect, OpenCloseLowLatencyStream) {
70 if (openAAudio()) return;
Phil Burkd2a8a532020-07-01 18:16:28 -070071 createBuilder();
72 mAAudioLoader->builder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
73 openCloseStream();
74}