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 TEST_F(MediaFileTest, DISABLED_StartPlayingAudioFileWithoutError) { |
| 32 #else |
| 33 TEST_F(MediaFileTest, StartPlayingAudioFileWithoutError) { |
| 34 #endif |
33 // TODO(leozwang): Use hard coded filename here, we want to | 35 // TODO(leozwang): Use hard coded filename here, we want to |
34 // loop through all audio files in future | 36 // loop through all audio files in future |
35 const std::string audio_file = webrtc::test::ProjectRootPath() + | 37 const std::string audio_file = webrtc::test::ProjectRootPath() + |
36 "data/voice_engine/audio_tiny48.wav"; | 38 "data/voice_engine/audio_tiny48.wav"; |
37 ASSERT_EQ(0, media_file_->StartPlayingAudioFile( | 39 ASSERT_EQ(0, media_file_->StartPlayingAudioFile( |
38 audio_file.c_str(), | 40 audio_file.c_str(), |
39 0, | 41 0, |
40 false, | 42 false, |
41 webrtc::kFileFormatWavFile)); | 43 webrtc::kFileFormatWavFile)); |
42 | 44 |
43 ASSERT_EQ(true, media_file_->IsPlaying()); | 45 ASSERT_EQ(true, media_file_->IsPlaying()); |
44 | 46 |
45 webrtc::SleepMs(1); | 47 webrtc::SleepMs(1); |
46 | 48 |
47 ASSERT_EQ(0, media_file_->StopPlaying()); | 49 ASSERT_EQ(0, media_file_->StopPlaying()); |
48 } | 50 } |
49 | 51 |
50 TEST_F(MediaFileTest, DISABLED_ON_IOS(WriteWavFile)) { | 52 #if defined(WEBRTC_IOS) |
| 53 TEST_F(MediaFileTest, DISABLED_WriteWavFile) { |
| 54 #else |
| 55 TEST_F(MediaFileTest, WriteWavFile) { |
| 56 #endif |
51 // Write file. | 57 // Write file. |
52 static const size_t kHeaderSize = 44; | 58 static const size_t kHeaderSize = 44; |
53 static const size_t kPayloadSize = 320; | 59 static const size_t kPayloadSize = 320; |
54 webrtc::CodecInst codec = { | 60 webrtc::CodecInst codec = { |
55 0, "L16", 16000, static_cast<int>(kPayloadSize), 1 | 61 0, "L16", 16000, static_cast<int>(kPayloadSize), 1 |
56 }; | 62 }; |
57 std::string outfile = webrtc::test::OutputPath() + "wavtest.wav"; | 63 std::string outfile = webrtc::test::OutputPath() + "wavtest.wav"; |
58 ASSERT_EQ(0, | 64 ASSERT_EQ(0, |
59 media_file_->StartRecordingAudioFile( | 65 media_file_->StartRecordingAudioFile( |
60 outfile.c_str(), webrtc::kFileFormatWavFile, codec)); | 66 outfile.c_str(), webrtc::kFileFormatWavFile, codec)); |
(...skipping 26 matching lines...) Expand all Loading... |
87 uint8_t header[kHeaderSize]; | 93 uint8_t header[kHeaderSize]; |
88 ASSERT_EQ(1u, fread(header, kHeaderSize, 1, f)); | 94 ASSERT_EQ(1u, fread(header, kHeaderSize, 1, f)); |
89 EXPECT_EQ(0, memcmp(kExpectedHeader, header, kHeaderSize)); | 95 EXPECT_EQ(0, memcmp(kExpectedHeader, header, kHeaderSize)); |
90 | 96 |
91 uint8_t payload[kPayloadSize]; | 97 uint8_t payload[kPayloadSize]; |
92 ASSERT_EQ(1u, fread(payload, kPayloadSize, 1, f)); | 98 ASSERT_EQ(1u, fread(payload, kPayloadSize, 1, f)); |
93 EXPECT_EQ(0, memcmp(kFakeData, payload, kPayloadSize)); | 99 EXPECT_EQ(0, memcmp(kFakeData, payload, kPayloadSize)); |
94 | 100 |
95 EXPECT_EQ(0, fclose(f)); | 101 EXPECT_EQ(0, fclose(f)); |
96 } | 102 } |
OLD | NEW |