Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 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 | |
| 20 | using namespace oboe; |
| 21 | |
| 22 | |
| 23 | class StreamOpen : public ::testing::Test { |
| 24 | |
| 25 | protected: |
| 26 | |
| 27 | bool openStream(){ |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 28 | mBuilder.setAudioApi(AudioApi::OpenSLES); |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 29 | Result r = mBuilder.openStream(&mStream); |
| 30 | EXPECT_EQ(r, Result::OK) << "Failed to open stream " << convertToText(r); |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 31 | EXPECT_EQ(mStream->getAudioApi(), AudioApi::OpenSLES) << "Stream is not using OpenSLES"; |
| 32 | |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 33 | 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 | |
| 48 | TEST_F(StreamOpen, ForOpenSLESDefaultSampleRateIsUsed){ |
| 49 | |
| 50 | DefaultStreamValues::SampleRate = 44100; |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 51 | |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 52 | openStream(); |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 53 | ASSERT_EQ(mStream->getSampleRate(), 44100); |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 54 | closeStream(); |
| 55 | } |
| 56 | |
| 57 | TEST_F(StreamOpen, ForOpenSLESDefaultFramesPerBurstIsUsed){ |
| 58 | |
| 59 | DefaultStreamValues::FramesPerBurst = 128; |
| 60 | openStream(); |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 61 | ASSERT_EQ(mStream->getFramesPerBurst(), 128); |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 62 | closeStream(); |
| 63 | } |
| 64 | |
| 65 | TEST_F(StreamOpen, ForOpenSLESDefaultChannelCountIsUsed){ |
| 66 | |
| 67 | DefaultStreamValues::ChannelCount = 1; |
| 68 | openStream(); |
Don Turner | dcb55a4 | 2018-07-19 20:21:16 +0100 | [diff] [blame^] | 69 | ASSERT_EQ(mStream->getChannelCount(), 1); |
Don Turner | 7dcf25d | 2018-07-18 15:21:07 +0100 | [diff] [blame] | 70 | closeStream(); |
| 71 | } |