1 /*
2 * Copyright (C) 2012 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 #include <unistd.h>
17
18 #include <gtest/gtest.h>
19 #include <utils/threads.h>
20 #include <utils/StrongPointer.h>
21
22 #include <audio/AudioLocal.h>
23 #include <audio/Buffer.h>
24 #include <Log.h>
25
26 #include "AudioPlayTestCommon.h"
27
28 class AudioPlayerDummy: public AudioLocal {
29 public:
30 AudioHardware::SamplingRate mSamplingRate;
31 android::sp<Buffer> mBufferPassed;
32 bool mPrepareCalled;
33 bool mdoStartPlaybackOrRecordCalled;
34 bool mdoContinuePlaybackOrRecordCalled;
35 bool mdoStopCalled;
36 int mPlaybackUnit;
37
AudioPlayerDummy()38 AudioPlayerDummy()
39 : mSamplingRate(AudioHardware::ESamplingRateInvald),
40 mPrepareCalled(false),
41 mdoStartPlaybackOrRecordCalled(false),
42 mdoContinuePlaybackOrRecordCalled(false),
43 mdoStopCalled(false)
44 {
45
46 }
47
doPrepare(AudioHardware::SamplingRate samplingRate,int samplesInOneGo)48 virtual bool doPrepare(AudioHardware::SamplingRate samplingRate, int samplesInOneGo) {
49 mPlaybackUnit = samplesInOneGo * 4;
50 LOGV("doPrepare");
51 return true;
52 };
53
doPlaybackOrRecord(android::sp<Buffer> & buffer)54 virtual bool doPlaybackOrRecord(android::sp<Buffer>& buffer) {
55 buffer->increaseHandled(mPlaybackUnit);
56 return true;
57 };
58
doStop()59 virtual void doStop() {
60 LOGV("doStop");
61 };
62
63
64 };
65
66 class AudioLocalTest : public AudioPlayTestCommon {
67 public:
~AudioLocalTest()68 virtual ~AudioLocalTest() {};
69
70 protected:
createAudioHw()71 android::sp<AudioHardware> createAudioHw() {
72 android::sp<AudioHardware> hw(new AudioPlayerDummy());
73 return hw;
74 }
75 };
76
TEST_F(AudioLocalTest,PlayAllTest)77 TEST_F(AudioLocalTest, PlayAllTest) {
78 playAll(1);
79 }
80
TEST_F(AudioLocalTest,PlayAllRepeatTest)81 TEST_F(AudioLocalTest, PlayAllRepeatTest) {
82 playAll(4);
83 }
84
TEST_F(AudioLocalTest,StartStopTest)85 TEST_F(AudioLocalTest, StartStopTest) {
86 repeatPlayStop();
87 }
88
TEST_F(AudioLocalTest,WrongUsageTest)89 TEST_F(AudioLocalTest, WrongUsageTest) {
90 playWrongUsage();
91 }
92
93