blob: 4e09d5c33bb2fdda702d84f34af84849f0343b04 [file] [log] [blame]
Don Turner7dcf25d2018-07-18 15:21:07 +01001#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
20using namespace oboe;
21
22
23class StreamOpen : public ::testing::Test {
24
25protected:
26
27 bool openStream(){
28 Result r = mBuilder.openStream(&mStream);
29 EXPECT_EQ(r, Result::OK) << "Failed to open stream " << convertToText(r);
30 return (r == Result::OK);
31 }
32
33 void closeStream(){
34 Result r = mStream->close();
35 if (r != Result::OK){
36 FAIL() << "Failed to close stream. " << convertToText(r);
37 }
38 }
39
40 AudioStreamBuilder mBuilder;
41 AudioStream *mStream = nullptr;
42
43};
44
45TEST_F(StreamOpen, ForOpenSLESDefaultSampleRateIsUsed){
46
47 DefaultStreamValues::SampleRate = 44100;
48 openStream();
49 if (mStream->getAudioApi() == AudioApi::OpenSLES){
50 ASSERT_EQ(mStream->getSampleRate(), 44100);
51 }
52 closeStream();
53}
54
55TEST_F(StreamOpen, ForOpenSLESDefaultFramesPerBurstIsUsed){
56
57 DefaultStreamValues::FramesPerBurst = 128;
58 openStream();
59 if (mStream->getAudioApi() == AudioApi::OpenSLES){
60 ASSERT_EQ(mStream->getFramesPerBurst(), 128);
61 }
62 closeStream();
63}
64
65TEST_F(StreamOpen, ForOpenSLESDefaultChannelCountIsUsed){
66
67 DefaultStreamValues::ChannelCount = 1;
68 openStream();
69 if (mStream->getAudioApi() == AudioApi::OpenSLES){
70 ASSERT_EQ(mStream->getChannelCount(), 1);
71 }
72 closeStream();
73}