blob: ccf4101bb57dab7ec5d1b3f2ced7d31b6e4c2ba3 [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(){
Don Turnerdcb55a42018-07-19 20:21:16 +010028 mBuilder.setAudioApi(AudioApi::OpenSLES);
Don Turner7dcf25d2018-07-18 15:21:07 +010029 Result r = mBuilder.openStream(&mStream);
30 EXPECT_EQ(r, Result::OK) << "Failed to open stream " << convertToText(r);
Don Turnerdcb55a42018-07-19 20:21:16 +010031 EXPECT_EQ(mStream->getAudioApi(), AudioApi::OpenSLES) << "Stream is not using OpenSLES";
32
Don Turner7dcf25d2018-07-18 15:21:07 +010033 return (r == Result::OK);
34 }
35
36 void closeStream(){
37 Result r = mStream->close();
38 if (r != Result::OK){
39 FAIL() << "Failed to close stream. " << convertToText(r);
40 }
41 }
42
43 AudioStreamBuilder mBuilder;
44 AudioStream *mStream = nullptr;
45
46};
47
48TEST_F(StreamOpen, ForOpenSLESDefaultSampleRateIsUsed){
49
50 DefaultStreamValues::SampleRate = 44100;
Don Turnerdcb55a42018-07-19 20:21:16 +010051
Don Turner7dcf25d2018-07-18 15:21:07 +010052 openStream();
Don Turnerdcb55a42018-07-19 20:21:16 +010053 ASSERT_EQ(mStream->getSampleRate(), 44100);
Don Turner7dcf25d2018-07-18 15:21:07 +010054 closeStream();
55}
56
57TEST_F(StreamOpen, ForOpenSLESDefaultFramesPerBurstIsUsed){
58
59 DefaultStreamValues::FramesPerBurst = 128;
60 openStream();
Don Turnerdcb55a42018-07-19 20:21:16 +010061 ASSERT_EQ(mStream->getFramesPerBurst(), 128);
Don Turner7dcf25d2018-07-18 15:21:07 +010062 closeStream();
63}
64
65TEST_F(StreamOpen, ForOpenSLESDefaultChannelCountIsUsed){
66
67 DefaultStreamValues::ChannelCount = 1;
68 openStream();
Don Turnerdcb55a42018-07-19 20:21:16 +010069 ASSERT_EQ(mStream->getChannelCount(), 1);
Don Turner7dcf25d2018-07-18 15:21:07 +010070 closeStream();
71}