16b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org/*
26b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
36b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *
46b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  Use of this source code is governed by a BSD-style license
56b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  that can be found in the LICENSE file in the root of the source
66b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  tree. An additional intellectual property rights grant can be found
76b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  in the file PATENTS.  All contributing project authors may
86b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
96b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org */
106b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
11956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/test/testsupport/fileutils.h"
12956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
13956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
14ff33bdd9d7d21c1840de1edf03dcee3e0a7210c9phoglund@webrtc.org
156b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
166b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.orgclass FileTest : public AfterStreamingFixture {
176b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org protected:
186b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  // Creates the string åäö.pcm.
196ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org// TODO(henrika): enable this test once CreateTrickyFilenameInUtf8 no longer
206ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org// prevents compilation on Windows. Likely webrtc/base can be used here.
216ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org#if 0
226b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  std::string CreateTrickyFilenameInUtf8() {
23292da241666a872fe84f6c10a48514374df9e99aphoglund@webrtc.org    char filename[16] = { (char)0xc3, (char)0xa5,
24292da241666a872fe84f6c10a48514374df9e99aphoglund@webrtc.org                          (char)0xc3, (char)0xa4,
25292da241666a872fe84f6c10a48514374df9e99aphoglund@webrtc.org                          (char)0xc3, (char)0xb6,
26dbe1e13b5325d38e2ad6c77798cfa8099c23b2a6phoglund@webrtc.org                          static_cast<char>(0) };
276b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org    return std::string(filename) + ".pcm";
286b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  }
296ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org#endif  // 0
306b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org};
316b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
326ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org// TODO(henrika): enable this test once CreateTrickyFilenameInUtf8 no longer
336ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org// prevents compilation on Windows. Likely webrtc/base can be used here.
346ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org#if 0
356b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.orgTEST_F(FileTest, ManualRecordToFileForThreeSecondsAndPlayback) {
36ff33bdd9d7d21c1840de1edf03dcee3e0a7210c9phoglund@webrtc.org  if (!FLAGS_include_timing_dependent_tests) {
378d334d387bff826f8a089c3ec45ad1b5bdcec112phoglund@webrtc.org    TEST_LOG("Skipping test - running in slow execution environment...\n");
38ff33bdd9d7d21c1840de1edf03dcee3e0a7210c9phoglund@webrtc.org    return;
39ff33bdd9d7d21c1840de1edf03dcee3e0a7210c9phoglund@webrtc.org  }
40ff33bdd9d7d21c1840de1edf03dcee3e0a7210c9phoglund@webrtc.org
416b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  SwitchToManualMicrophone();
426b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
436b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  std::string recording_filename =
446b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      webrtc::test::OutputPath() + CreateTrickyFilenameInUtf8();
456b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
466b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  TEST_LOG("Recording to %s for 3 seconds.\n", recording_filename.c_str());
476b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StartRecordingMicrophone(recording_filename.c_str()));
486b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(3000);
496b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StopRecordingMicrophone());
506b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
516b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  TEST_LOG("Playing back %s.\n", recording_filename.c_str());
526b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
536b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      channel_, recording_filename.c_str()));
546b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
556b02eea6acb571175ed220137ec44c841df6f535henrika@webrtc.org  // Play the file to the user and ensure the is-playing-locally.
566b02eea6acb571175ed220137ec44c841df6f535henrika@webrtc.org  // The clip is 3 seconds long.
576b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(250);
586b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(1, voe_file_->IsPlayingFileLocally(channel_));
596b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(1500);
606b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org}
616ac22e6b47f9a6ed70b0a376984b39b9a745dd94henrike@webrtc.org#endif  // 0
626b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
636b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.orgTEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
646b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  webrtc::CodecInst send_codec;
656b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  voe_codec_->GetSendCodec(channel_, send_codec);
666b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
676b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  std::string recording_filename =
686b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      webrtc::test::OutputPath() + "playout.wav";
696b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
706b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  TEST_LOG("Recording playout to %s.\n", recording_filename.c_str());
716b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StartRecordingPlayout(
726b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      channel_, recording_filename.c_str(), &send_codec));
736b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(3000);
746b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StopRecordingPlayout(channel_));
756b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
766b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  TEST_LOG("Playing back the recording in looping mode.\n");
776b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
786b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      channel_, recording_filename.c_str(), true, false,
796b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org      webrtc::kFileFormatWavFile));
806b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org
816b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(2000);
826b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
836b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  Sleep(2000);
846b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  // We should still be playing since we're looping.
856b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org  EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
866b3bb89f1255c2aebd39e2f2add19ddca1b4c058phoglund@webrtc.org}
87