OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "media/audio/sounds/wav_audio_handler.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
8 #include "base/macros.h" | 12 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
11 #include "media/audio/sounds/test_data.h" | 14 #include "media/audio/sounds/test_data.h" |
12 #include "media/audio/sounds/wav_audio_handler.h" | |
13 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 | 17 |
16 namespace media { | 18 namespace media { |
17 namespace { | 19 namespace { |
18 // WAV header comes first in the test data. | 20 // WAV header comes first in the test data. |
19 const size_t kWavHeaderSize = 12; | 21 const size_t kWavHeaderSize = 12; |
20 const size_t kWavDataSizeIndex = 4; | 22 const size_t kWavDataSizeIndex = 4; |
21 | 23 |
22 // "fmt " header comes next. | 24 // "fmt " header comes next. |
(...skipping 17 matching lines...) Expand all Loading... |
40 ASSERT_EQ(2u, handler->num_channels()); | 42 ASSERT_EQ(2u, handler->num_channels()); |
41 ASSERT_EQ(16u, handler->bits_per_sample()); | 43 ASSERT_EQ(16u, handler->bits_per_sample()); |
42 ASSERT_EQ(48000u, handler->sample_rate()); | 44 ASSERT_EQ(48000u, handler->sample_rate()); |
43 ASSERT_EQ(1u, handler->total_frames()); | 45 ASSERT_EQ(1u, handler->total_frames()); |
44 ASSERT_EQ(20u, handler->GetDuration().InMicroseconds()); | 46 ASSERT_EQ(20u, handler->GetDuration().InMicroseconds()); |
45 | 47 |
46 ASSERT_EQ(4U, handler->data().size()); | 48 ASSERT_EQ(4U, handler->data().size()); |
47 const char kData[] = "\x01\x00\x01\x00"; | 49 const char kData[] = "\x01\x00\x01\x00"; |
48 ASSERT_EQ(base::StringPiece(kData, arraysize(kData) - 1), handler->data()); | 50 ASSERT_EQ(base::StringPiece(kData, arraysize(kData) - 1), handler->data()); |
49 | 51 |
50 scoped_ptr<AudioBus> bus = | 52 std::unique_ptr<AudioBus> bus = |
51 AudioBus::Create(handler->num_channels(), | 53 AudioBus::Create(handler->num_channels(), |
52 handler->data().size() / handler->num_channels()); | 54 handler->data().size() / handler->num_channels()); |
53 | 55 |
54 size_t bytes_written = 0u; | 56 size_t bytes_written = 0u; |
55 ASSERT_TRUE(handler->CopyTo(bus.get(), 0, &bytes_written)); | 57 ASSERT_TRUE(handler->CopyTo(bus.get(), 0, &bytes_written)); |
56 ASSERT_EQ(static_cast<size_t>(handler->data().size()), bytes_written); | 58 ASSERT_EQ(static_cast<size_t>(handler->data().size()), bytes_written); |
57 } | 59 } |
58 | 60 |
59 TEST(WavAudioHandlerTest, TestZeroChannelsIsNotValid) { | 61 TEST(WavAudioHandlerTest, TestZeroChannelsIsNotValid) { |
60 // Read in the sample data and modify the channel field to hold |00|00|. | 62 // Read in the sample data and modify the channel field to hold |00|00|. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 EXPECT_TRUE(handler); | 185 EXPECT_TRUE(handler); |
184 ASSERT_EQ(2u, handler->num_channels()); | 186 ASSERT_EQ(2u, handler->num_channels()); |
185 ASSERT_EQ(16u, handler->bits_per_sample()); | 187 ASSERT_EQ(16u, handler->bits_per_sample()); |
186 ASSERT_EQ(48000u, handler->sample_rate()); | 188 ASSERT_EQ(48000u, handler->sample_rate()); |
187 ASSERT_EQ(0u, handler->total_frames()); | 189 ASSERT_EQ(0u, handler->total_frames()); |
188 ASSERT_EQ(0u, handler->GetDuration().InMicroseconds()); | 190 ASSERT_EQ(0u, handler->GetDuration().InMicroseconds()); |
189 ASSERT_EQ(0u, handler->data().size()); | 191 ASSERT_EQ(0u, handler->data().size()); |
190 } | 192 } |
191 | 193 |
192 } // namespace media | 194 } // namespace media |
OLD | NEW |