blob: b38c44d3d4c6cd116327c7849aff2b68f0105bf2 [file] [log] [blame]
Keun young Park5eba08f2012-03-26 18:31:29 -07001/*
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
28class AudioPlayerDummy: public AudioLocal {
29public:
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
38 AudioPlayerDummy()
39 : mSamplingRate(AudioHardware::ESamplingRateInvald),
40 mPrepareCalled(false),
41 mdoStartPlaybackOrRecordCalled(false),
42 mdoContinuePlaybackOrRecordCalled(false),
43 mdoStopCalled(false)
44 {
45
46 }
47
48 virtual bool doPrepare(AudioHardware::SamplingRate samplingRate, int samplesInOneGo) {
49 mPlaybackUnit = samplesInOneGo * 4;
50 LOGV("doPrepare");
51 return true;
52 };
53
54 virtual bool doPlaybackOrRecord(android::sp<Buffer>& buffer) {
55 buffer->increaseHandled(mPlaybackUnit);
56 return true;
57 };
58
59 virtual void doStop() {
60 LOGV("doStop");
61 };
62
63
64};
65
66class AudioLocalTest : public AudioPlayTestCommon {
67public:
68 virtual ~AudioLocalTest() {};
69
70protected:
71 android::sp<AudioHardware> createAudioHw() {
72 android::sp<AudioHardware> hw(new AudioPlayerDummy());
73 return hw;
74 }
75};
76
77TEST_F(AudioLocalTest, PlayAllTest) {
78 playAll(1);
79}
80
81TEST_F(AudioLocalTest, PlayAllRepeatTest) {
82 playAll(4);
83}
84
85TEST_F(AudioLocalTest, StartStopTest) {
86 repeatPlayStop();
87}
88
89TEST_F(AudioLocalTest, WrongUsageTest) {
90 playWrongUsage();
91}
92