| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/modules/media_file/media_file.h" | 12 #include "webrtc/modules/media_file/media_file.h" |
| 13 #include "webrtc/system_wrappers/include/sleep.h" | 13 #include "webrtc/system_wrappers/include/sleep.h" |
| 14 #include "webrtc/test/testsupport/fileutils.h" | 14 #include "webrtc/test/testsupport/fileutils.h" |
| 15 #include "webrtc/test/testsupport/gtest_disable.h" | |
| 16 | 15 |
| 17 class MediaFileTest : public testing::Test { | 16 class MediaFileTest : public testing::Test { |
| 18 protected: | 17 protected: |
| 19 void SetUp() { | 18 void SetUp() { |
| 20 // Use number 0 as the the identifier and pass to CreateMediaFile. | 19 // Use number 0 as the the identifier and pass to CreateMediaFile. |
| 21 media_file_ = webrtc::MediaFile::CreateMediaFile(0); | 20 media_file_ = webrtc::MediaFile::CreateMediaFile(0); |
| 22 ASSERT_TRUE(media_file_ != NULL); | 21 ASSERT_TRUE(media_file_ != NULL); |
| 23 } | 22 } |
| 24 void TearDown() { | 23 void TearDown() { |
| 25 webrtc::MediaFile::DestroyMediaFile(media_file_); | 24 webrtc::MediaFile::DestroyMediaFile(media_file_); |
| 26 media_file_ = NULL; | 25 media_file_ = NULL; |
| 27 } | 26 } |
| 28 webrtc::MediaFile* media_file_; | 27 webrtc::MediaFile* media_file_; |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 TEST_F(MediaFileTest, DISABLED_ON_IOS( | 30 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 32 DISABLED_ON_ANDROID(StartPlayingAudioFileWithoutError))) { | 31 #define MAYBE_StartPlayingAudioFileWithoutError \ |
| 32 DISABLED_StartPlayingAudioFileWithoutError |
| 33 #else |
| 34 #define MAYBE_StartPlayingAudioFileWithoutError \ |
| 35 StartPlayingAudioFileWithoutError |
| 36 #endif |
| 37 TEST_F(MediaFileTest, MAYBE_StartPlayingAudioFileWithoutError) { |
| 33 // TODO(leozwang): Use hard coded filename here, we want to | 38 // TODO(leozwang): Use hard coded filename here, we want to |
| 34 // loop through all audio files in future | 39 // loop through all audio files in future |
| 35 const std::string audio_file = webrtc::test::ProjectRootPath() + | 40 const std::string audio_file = webrtc::test::ProjectRootPath() + |
| 36 "data/voice_engine/audio_tiny48.wav"; | 41 "data/voice_engine/audio_tiny48.wav"; |
| 37 ASSERT_EQ(0, media_file_->StartPlayingAudioFile( | 42 ASSERT_EQ(0, media_file_->StartPlayingAudioFile( |
| 38 audio_file.c_str(), | 43 audio_file.c_str(), |
| 39 0, | 44 0, |
| 40 false, | 45 false, |
| 41 webrtc::kFileFormatWavFile)); | 46 webrtc::kFileFormatWavFile)); |
| 42 | 47 |
| 43 ASSERT_EQ(true, media_file_->IsPlaying()); | 48 ASSERT_EQ(true, media_file_->IsPlaying()); |
| 44 | 49 |
| 45 webrtc::SleepMs(1); | 50 webrtc::SleepMs(1); |
| 46 | 51 |
| 47 ASSERT_EQ(0, media_file_->StopPlaying()); | 52 ASSERT_EQ(0, media_file_->StopPlaying()); |
| 48 } | 53 } |
| 49 | 54 |
| 50 TEST_F(MediaFileTest, DISABLED_ON_IOS(WriteWavFile)) { | 55 #if defined(WEBRTC_IOS) |
| 56 #define MAYBE_WriteWavFile DISABLED_WriteWavFile |
| 57 #else |
| 58 #define MAYBE_WriteWavFile WriteWavFile |
| 59 #endif |
| 60 TEST_F(MediaFileTest, MAYBE_WriteWavFile) { |
| 51 // Write file. | 61 // Write file. |
| 52 static const size_t kHeaderSize = 44; | 62 static const size_t kHeaderSize = 44; |
| 53 static const size_t kPayloadSize = 320; | 63 static const size_t kPayloadSize = 320; |
| 54 webrtc::CodecInst codec = { | 64 webrtc::CodecInst codec = { |
| 55 0, "L16", 16000, static_cast<int>(kPayloadSize), 1 | 65 0, "L16", 16000, static_cast<int>(kPayloadSize), 1 |
| 56 }; | 66 }; |
| 57 std::string outfile = webrtc::test::OutputPath() + "wavtest.wav"; | 67 std::string outfile = webrtc::test::OutputPath() + "wavtest.wav"; |
| 58 ASSERT_EQ(0, | 68 ASSERT_EQ(0, |
| 59 media_file_->StartRecordingAudioFile( | 69 media_file_->StartRecordingAudioFile( |
| 60 outfile.c_str(), webrtc::kFileFormatWavFile, codec)); | 70 outfile.c_str(), webrtc::kFileFormatWavFile, codec)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 87 uint8_t header[kHeaderSize]; | 97 uint8_t header[kHeaderSize]; |
| 88 ASSERT_EQ(1u, fread(header, kHeaderSize, 1, f)); | 98 ASSERT_EQ(1u, fread(header, kHeaderSize, 1, f)); |
| 89 EXPECT_EQ(0, memcmp(kExpectedHeader, header, kHeaderSize)); | 99 EXPECT_EQ(0, memcmp(kExpectedHeader, header, kHeaderSize)); |
| 90 | 100 |
| 91 uint8_t payload[kPayloadSize]; | 101 uint8_t payload[kPayloadSize]; |
| 92 ASSERT_EQ(1u, fread(payload, kPayloadSize, 1, f)); | 102 ASSERT_EQ(1u, fread(payload, kPayloadSize, 1, f)); |
| 93 EXPECT_EQ(0, memcmp(kFakeData, payload, kPayloadSize)); | 103 EXPECT_EQ(0, memcmp(kFakeData, payload, kPayloadSize)); |
| 94 | 104 |
| 95 EXPECT_EQ(0, fclose(f)); | 105 EXPECT_EQ(0, fclose(f)); |
| 96 } | 106 } |
| OLD | NEW |