Home | History | Annotate | Download | only in standard
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/test/testsupport/fileutils.h"
     12 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
     13 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
     14 
     15 
     16 class FileTest : public AfterStreamingFixture {
     17  protected:
     18   // Creates the string .pcm.
     19 // TODO(henrika): enable this test once CreateTrickyFilenameInUtf8 no longer
     20 // prevents compilation on Windows. Likely webrtc/base can be used here.
     21 #if 0
     22   std::string CreateTrickyFilenameInUtf8() {
     23     char filename[16] = { (char)0xc3, (char)0xa5,
     24                           (char)0xc3, (char)0xa4,
     25                           (char)0xc3, (char)0xb6,
     26                           static_cast<char>(0) };
     27     return std::string(filename) + ".pcm";
     28   }
     29 #endif  // 0
     30 };
     31 
     32 // TODO(henrika): enable this test once CreateTrickyFilenameInUtf8 no longer
     33 // prevents compilation on Windows. Likely webrtc/base can be used here.
     34 #if 0
     35 TEST_F(FileTest, ManualRecordToFileForThreeSecondsAndPlayback) {
     36   if (!FLAGS_include_timing_dependent_tests) {
     37     TEST_LOG("Skipping test - running in slow execution environment...\n");
     38     return;
     39   }
     40 
     41   SwitchToManualMicrophone();
     42 
     43   std::string recording_filename =
     44       webrtc::test::OutputPath() + CreateTrickyFilenameInUtf8();
     45 
     46   TEST_LOG("Recording to %s for 3 seconds.\n", recording_filename.c_str());
     47   EXPECT_EQ(0, voe_file_->StartRecordingMicrophone(recording_filename.c_str()));
     48   Sleep(3000);
     49   EXPECT_EQ(0, voe_file_->StopRecordingMicrophone());
     50 
     51   TEST_LOG("Playing back %s.\n", recording_filename.c_str());
     52   EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
     53       channel_, recording_filename.c_str()));
     54 
     55   // Play the file to the user and ensure the is-playing-locally.
     56   // The clip is 3 seconds long.
     57   Sleep(250);
     58   EXPECT_EQ(1, voe_file_->IsPlayingFileLocally(channel_));
     59   Sleep(1500);
     60 }
     61 #endif  // 0
     62 
     63 TEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
     64   webrtc::CodecInst send_codec;
     65   voe_codec_->GetSendCodec(channel_, send_codec);
     66 
     67   std::string recording_filename =
     68       webrtc::test::OutputPath() + "playout.wav";
     69 
     70   TEST_LOG("Recording playout to %s.\n", recording_filename.c_str());
     71   EXPECT_EQ(0, voe_file_->StartRecordingPlayout(
     72       channel_, recording_filename.c_str(), &send_codec));
     73   Sleep(3000);
     74   EXPECT_EQ(0, voe_file_->StopRecordingPlayout(channel_));
     75 
     76   TEST_LOG("Playing back the recording in looping mode.\n");
     77   EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
     78       channel_, recording_filename.c_str(), true, false,
     79       webrtc::kFileFormatWavFile));
     80 
     81   Sleep(2000);
     82   EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
     83   Sleep(2000);
     84   // We should still be playing since we're looping.
     85   EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
     86 }
     87