1 #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
21 using namespace oboe;
22
23 class AAudioDirect : public ::testing::Test {
24 public:
25
26 /**
27 * @return true if AAudio NOT supported
28 */
openAAudio()29 bool openAAudio() {
30 mAAudioLoader = AAudioLoader::getInstance();
31 return (mAAudioLoader->open() != 0);
32 }
33
createBuilder()34 void createBuilder() {
35 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
openCloseStream()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
TEST_F(AAudioDirect,InstantiateAAudioLoader)57 TEST_F(AAudioDirect, InstantiateAAudioLoader) {
58 AAudioLoader *aaudioLoader = AAudioLoader::getInstance();
59 ASSERT_NE(aaudioLoader, nullptr);
60 }
61
TEST_F(AAudioDirect,OpenCloseHighLatencyStream)62 TEST_F(AAudioDirect, OpenCloseHighLatencyStream) {
63 if (openAAudio()) return;
64 createBuilder();
65 mAAudioLoader->builder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_NONE);
66 openCloseStream();
67 }
68
TEST_F(AAudioDirect,OpenCloseLowLatencyStream)69 TEST_F(AAudioDirect, OpenCloseLowLatencyStream) {
70 if (openAAudio()) return;
71 createBuilder();
72 mAAudioLoader->builder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
73 openCloseStream();
74 }
75