Home | History | Annotate | Download | only in test
      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, PlayTest) {
     53     ClientImpl* client = reinterpret_cast<ClientImpl*>(mClient);
     54     android::sp<RemoteAudio>& audio(client->getAudio());
     55     const int maxPositive = 10000;
     56     const int signalFreq = AudioHardware::ESampleRate_44100/100;
     57     const int samples = 8192*2;
     58     android::sp<Buffer> buffer = AudioSignalFactory::generateSineWave(AudioHardware::E2BPS,
     59             maxPositive, AudioHardware::ESampleRate_44100, signalFreq, samples);
     60     int id;
     61     android::String8 name("1");
     62     ASSERT_TRUE(audio->downloadData(name, buffer, id));
     63     ASSERT_TRUE(audio->startPlayback(true, AudioHardware::ESampleRate_44100,
     64             AudioHardware::EModeVoice, 100, id, 1));
     65     ASSERT_TRUE(audio->waitForPlaybackCompletion());
     66     ASSERT_TRUE(id == audio->getDataId(name));
     67     android::String8 name2("2");
     68     ASSERT_TRUE(audio->getDataId(name2) < 0);
     69 }
     70 
     71 TEST_F(ClientInterfaceTest, RecordTest) {
     72     ClientImpl* client = reinterpret_cast<ClientImpl*>(mClient);
     73     android::sp<RemoteAudio>& audio(client->getAudio());
     74     const int maxPositive = 10000;
     75     const int signalFreq = AudioHardware::ESampleRate_44100 / 100;
     76     const int samples = 44100 * 4;
     77     android::sp<Buffer> buffer(new Buffer(samples * 2, samples * 2, false));
     78 
     79     ASSERT_TRUE(audio->startRecording(false, AudioHardware::ESampleRate_44100,
     80             AudioHardware::EModeVoice, 100, buffer));
     81     ASSERT_TRUE(audio->waitForRecordingCompletion());
     82     ASSERT_TRUE(buffer->amountHandled() == (samples * 2));
     83 }
     84