Rewrote file test.

BUG=
TEST=

Review URL: https://webrtc-codereview.appspot.com/391004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1668 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2012-02-10 12:14:54 +00:00
parent 5e954814a8
commit 6b3bb89f12
4 changed files with 83 additions and 125 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -38,6 +38,7 @@ void AfterStreamingFixture::SwitchToManualMicrophone() {
EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_));
TEST_LOG("You need to speak manually into the microphone for this test.\n");
TEST_LOG("Please start speaking now.\n");
Sleep(2000);
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "after_streaming_fixture.h"
#include "testsupport/fileutils.h"
class FileTest : public AfterStreamingFixture {
protected:
// Creates the string åäö.pcm.
std::string CreateTrickyFilenameInUtf8() {
char filename[16] = { 0xc3, 0xa5, 0xc3, 0xa4, 0xc3, 0xb6, 0 };
return std::string(filename) + ".pcm";
}
};
TEST_F(FileTest, ManualRecordToFileForThreeSecondsAndPlayback) {
SwitchToManualMicrophone();
std::string recording_filename =
webrtc::test::OutputPath() + CreateTrickyFilenameInUtf8();
TEST_LOG("Recording to %s for 3 seconds.\n", recording_filename.c_str());
EXPECT_EQ(0, voe_file_->StartRecordingMicrophone(recording_filename.c_str()));
Sleep(3000);
EXPECT_EQ(0, voe_file_->StopRecordingMicrophone());
TEST_LOG("Playing back %s.\n", recording_filename.c_str());
EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
channel_, recording_filename.c_str()));
// Play the file to the user and ensure the is-playing-locally
// and scaling methods also work. The clip is 3 seconds long.
Sleep(250);
EXPECT_EQ(1, voe_file_->IsPlayingFileLocally(channel_));
Sleep(1500);
TEST_LOG("Decreasing level by 50%%.\n");
EXPECT_EQ(0, voe_file_->ScaleLocalFilePlayout(channel_, 0.5f));
Sleep(1500);
EXPECT_EQ(0, voe_file_->IsPlayingFileLocally(channel_));
}
TEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
webrtc::CodecInst send_codec;
voe_codec_->GetSendCodec(channel_, send_codec);
std::string recording_filename =
webrtc::test::OutputPath() + "playout.wav";
TEST_LOG("Recording playout to %s.\n", recording_filename.c_str());
EXPECT_EQ(0, voe_file_->StartRecordingPlayout(
channel_, recording_filename.c_str(), &send_codec));
Sleep(3000);
EXPECT_EQ(0, voe_file_->StopRecordingPlayout(channel_));
TEST_LOG("Playing back the recording in looping mode.\n");
EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
channel_, recording_filename.c_str(), true, false,
webrtc::kFileFormatWavFile));
Sleep(2000);
EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
Sleep(2000);
// We should still be playing since we're looping.
EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
// Try scaling as well.
TEST_LOG("Decreasing level by 50%%.\n");
EXPECT_EQ(0, voe_file_->ScaleFileAsMicrophonePlayout(channel_, 0.5f));
Sleep(1000);
EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
@ -983,129 +983,6 @@ int VoETestManager::DoStandardTest() {
if (TestStartStreaming(channel0_transport) != 0) return -1;
if (TestStartPlaying() != 0) return -1;
////////
// File
#ifdef _TEST_FILE_
TEST_LOG("\n\n+++ File tests +++\n\n");
// test of UTF8 using swedish letters åäö
char fileName[64];
fileName[0] = (char) 0xc3;
fileName[1] = (char) 0xa5;
fileName[2] = (char) 0xc3;
fileName[3] = (char) 0xa4;
fileName[4] = (char) 0xc3;
fileName[5] = (char) 0xb6;
fileName[6] = '.';
fileName[7] = 'p';
fileName[8] = 'c';
fileName[9] = 'm';
fileName[10] = 0;
// test of UTF8 using japanese Hirigana "ぁあ"letter small A and letter A
/* fileName[0] = (char)0xe3;
fileName[1] = (char)0x81;
fileName[2] = (char)0x81;
fileName[3] = (char)0xe3;
fileName[4] = (char)0x81;
fileName[5] = (char)0x82;
fileName[6] = '.';
fileName[7] = 'p';
fileName[8] = 'c';
fileName[9] = 'm';
fileName[10] = 0;
*/
// Part of the cyrillic alpabet
// Ф Х Ѡ Ц Ч Ш Щ Ъ ЪІ Ь Ѣ
const char* recName = GetFilename(fileName);
// Generated with
#if _WIN32
/* char tempFileNameUTF8[200];
int err = WideCharToMultiByte(CP_UTF8,0,L"åäö", -1, tempFileNameUTF8,
sizeof(tempFileNameUTF8), NULL, NULL);
*/
#endif
//Stop the current file
TEST_LOG("Stop playing file as microphone \n");
TEST_MUSTPASS(voe_file_->StopPlayingFileAsMicrophone(0));
TEST_LOG("==> Talk into the microphone \n");
SLEEP(1000);
TEST_LOG("Record mic for 3 seconds in PCM format\n");
TEST_MUSTPASS(voe_file_->StartRecordingMicrophone(recName));
SLEEP(3000);
TEST_MUSTPASS(voe_file_->StopRecordingMicrophone());
TEST_LOG("Play out the recorded file...\n");
TEST_MUSTPASS(voe_file_->StartPlayingFileLocally(0, recName));
SLEEP(2000);
#ifndef _INSTRUMENTATION_TESTING_
TEST_LOG("After 2 seconds we should still be playing\n");
TEST_MUSTPASS(!voe_file_->IsPlayingFileLocally(0));
#endif
TEST_LOG("Set scaling\n");
TEST_MUSTPASS(voe_file_->ScaleLocalFilePlayout(0,(float)0.11));
SLEEP(1100);
TEST_LOG("After 3.1 seconds we should NOT be playing\n");
TEST_MUSTPASS(voe_file_->IsPlayingFileLocally(0));
CodecInst codec;
TEST_LOG("Record speaker for 3 seconds to wav file\n");
memset(&codec, 0, sizeof(CodecInst));
strcpy(codec.plname, "pcmu");
codec.plfreq = 8000;
codec.channels = 1;
codec.pacsize = 160;
codec.pltype = 0;
codec.rate = 64000;
TEST_MUSTPASS(voe_file_->StartRecordingPlayout(0,recName,&codec));
SLEEP(3000);
TEST_MUSTPASS(voe_file_->StopRecordingPlayout(0));
TEST_LOG("Play file as mic, looping for 3 seconds\n");
TEST_MUSTPASS(voe_file_->StartPlayingFileAsMicrophone(0,
recName,
1,
0,
kFileFormatWavFile));
SLEEP(3000);
TEST_LOG("After 3 seconds we should still be playing\n");
TEST_MUSTPASS(!voe_file_->IsPlayingFileAsMicrophone(0));
SLEEP(600);
TEST_LOG("After 3.6 seconds we should still be playing\n");
TEST_MUSTPASS(!voe_file_->IsPlayingFileAsMicrophone(0));
TEST_LOG("Set scaling\n");
TEST_MUSTPASS(voe_file_->ScaleFileAsMicrophonePlayout(0,(float)0.11));
SLEEP(200);
TEST_LOG("Stop playing file as microphone\n");
TEST_MUSTPASS(voe_file_->StopPlayingFileAsMicrophone(0));
TEST_LOG("==> Start playing a file as microphone again \n");
TEST_MUSTPASS(voe_file_->StartPlayingFileAsMicrophone(0, AudioFilename(),
true, true));
#else
TEST_LOG("\n\n+++ File tests NOT ENABLED +++\n");
#endif // #ifdef _TEST_FILE_
#ifdef _XTENDED_TEST_FILE_
// Create unique trace files for this test
TEST_MUSTPASS(voe_base_->SetTraceFileName(GetFilename("VoEFile_trace.txt")));
TEST_MUSTPASS(voe_base_->SetDebugTraceFileName(GetFilename(
"VoEFile_trace_debug.txt")));
// turn off default AGC during these tests
TEST_MUSTPASS(voe_apm_->SetAgcStatus(false));
int res = xtend.TestFile(voe_file_);
#ifndef MAC_IPHONE
TEST_MUSTPASS(voe_apm_->SetAgcStatus(true)); // restore AGC state
#endif
TEST_MUSTPASS(voe_base_->Terminate());
return res;
#endif
////////////
// Network

View File

@ -40,6 +40,7 @@
'auto_test/standard/codec_before_streaming_test.cc',
'auto_test/standard/codec_test.cc',
'auto_test/standard/dtmf_test.cc',
'auto_test/standard/file_test.cc',
'auto_test/standard/hardware_before_initializing_test.cc',
'auto_test/standard/hardware_before_streaming_test.cc',
'auto_test/standard/hardware_test.cc',