1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 #include <utils/String8.h> 18 19 #include <gtest/gtest.h> 20 21 #include <audio/AudioSignalFactory.h> 22 #include <ClientInterface.h> 23 #include <ClientImpl.h> 24 #include <GenericFactory.h> 25 #include <audio/RemoteAudio.h> 26 27 28 29 class ClientInterfaceTest : public testing::Test { 30 protected: 31 ClientInterface* mClient; 32 33 protected: 34 virtual void SetUp() { 35 GenericFactory factory; 36 mClient = factory.createClientInterface(); 37 ASSERT_TRUE(mClient != NULL); 38 android::String8 dummyParam; 39 ASSERT_TRUE(mClient->init(dummyParam)); 40 } 41 42 virtual void TearDown() { 43 delete mClient; 44 mClient = NULL; 45 } 46 }; 47 48 TEST_F(ClientInterfaceTest, InitTest) { 49 // all done in SetUp 50 } 51 52 TEST_F(ClientInterfaceTest, getDeviceInfoTest) { 53 ClientImpl* client = reinterpret_cast<ClientImpl*>(mClient); 54 android::sp<RemoteAudio>& audio(client->getAudio()); 55 android::String8 info; 56 57 ASSERT_TRUE(audio->getDeviceInfo(info)); 58 LOGD("device info %s", info.string()); 59 } 60 61 TEST_F(ClientInterfaceTest, PlayTest) { 62 ClientImpl* client = reinterpret_cast<ClientImpl*>(mClient); 63 android::sp<RemoteAudio>& audio(client->getAudio()); 64 const int maxPositive = 10000; 65 const int signalFreq = AudioHardware::ESampleRate_44100/100; 66 const int samples = 8192*2; 67 android::sp<Buffer> buffer = AudioSignalFactory::generateSineWave(AudioHardware::E2BPS, 68 maxPositive, AudioHardware::ESampleRate_44100, signalFreq, samples); 69 int id; 70 android::String8 name("1"); 71 ASSERT_TRUE(audio->downloadData(name, buffer, id)); 72 ASSERT_TRUE(audio->startPlayback(true, AudioHardware::ESampleRate_44100, 73 AudioHardware::EModeVoice, 100, id, 1)); 74 ASSERT_TRUE(audio->waitForPlaybackCompletion()); 75 ASSERT_TRUE(id == audio->getDataId(name)); 76 android::String8 name2("2"); 77 ASSERT_TRUE(audio->getDataId(name2) < 0); 78 } 79 80 TEST_F(ClientInterfaceTest, RecordTest) { 81 ClientImpl* client = reinterpret_cast<ClientImpl*>(mClient); 82 android::sp<RemoteAudio>& audio(client->getAudio()); 83 const int maxPositive = 10000; 84 const int signalFreq = AudioHardware::ESampleRate_44100 / 100; 85 const int samples = 44100 * 4; 86 android::sp<Buffer> buffer(new Buffer(samples * 2, samples * 2, false)); 87 88 ASSERT_TRUE(audio->startRecording(false, AudioHardware::ESampleRate_44100, 89 AudioHardware::EModeVoice, 100, buffer)); 90 ASSERT_TRUE(audio->waitForRecordingCompletion()); 91 ASSERT_TRUE(buffer->amountHandled() == (samples * 2)); 92 } 93