Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / audio / sounds / wav_audio_handler_unittest.cc
blobd4ec83a5838243c5df7d488a7146780a0f8d29b4
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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_piece.h"
9 #include "media/audio/sounds/test_data.h"
10 #include "media/audio/sounds/wav_audio_handler.h"
11 #include "media/base/audio_bus.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace media {
16 TEST(WavAudioHandlerTest, SampleDataTest) {
17 WavAudioHandler handler(base::StringPiece(kTestAudioData,
18 arraysize(kTestAudioData)));
19 ASSERT_EQ(2u, handler.num_channels());
20 ASSERT_EQ(16u, handler.bits_per_sample());
21 ASSERT_EQ(48000u, handler.sample_rate());
22 ASSERT_EQ(1u, handler.total_frames());
23 ASSERT_EQ(20u, handler.GetDuration().InMicroseconds());
25 ASSERT_EQ(4U, handler.data().size());
26 const char kData[] = "\x01\x00\x01\x00";
27 ASSERT_EQ(base::StringPiece(kData, arraysize(kData) - 1), handler.data());
29 scoped_ptr<AudioBus> bus = AudioBus::Create(
30 handler.num_channels(), handler.data().size() / handler.num_channels());
32 size_t bytes_written;
33 ASSERT_TRUE(handler.CopyTo(bus.get(), 0, &bytes_written));
34 ASSERT_EQ(static_cast<size_t>(handler.data().size()), bytes_written);
37 } // namespace media