Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: media/base/audio_hash_unittest.cc

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "base/macros.h" 8 #include "base/macros.h"
7 #include "media/base/audio_bus.h" 9 #include "media/base/audio_bus.h"
8 #include "media/base/audio_hash.h" 10 #include "media/base/audio_hash.h"
9 #include "media/base/fake_audio_render_callback.h" 11 #include "media/base/fake_audio_render_callback.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace media { 14 namespace media {
13 15
14 static const int kChannelCount = 2; 16 static const int kChannelCount = 2;
15 static const int kFrameCount = 1024; 17 static const int kFrameCount = 1024;
16 18
17 class AudioHashTest : public testing::Test { 19 class AudioHashTest : public testing::Test {
18 public: 20 public:
19 AudioHashTest() 21 AudioHashTest()
20 : bus_one_(AudioBus::Create(kChannelCount, kFrameCount)), 22 : bus_one_(AudioBus::Create(kChannelCount, kFrameCount)),
21 bus_two_(AudioBus::Create(kChannelCount, kFrameCount)), 23 bus_two_(AudioBus::Create(kChannelCount, kFrameCount)),
22 fake_callback_(0.01) { 24 fake_callback_(0.01) {
23 25
24 // Fill each channel in each bus with unique data. 26 // Fill each channel in each bus with unique data.
25 GenerateUniqueChannels(bus_one_.get()); 27 GenerateUniqueChannels(bus_one_.get());
26 GenerateUniqueChannels(bus_two_.get()); 28 GenerateUniqueChannels(bus_two_.get());
27 } 29 }
28 30
29 void GenerateUniqueChannels(AudioBus* audio_bus) { 31 void GenerateUniqueChannels(AudioBus* audio_bus) {
30 // Use an AudioBus wrapper to avoid an extra memcpy when filling channels. 32 // Use an AudioBus wrapper to avoid an extra memcpy when filling channels.
31 scoped_ptr<AudioBus> wrapped_bus = AudioBus::CreateWrapper(1); 33 std::unique_ptr<AudioBus> wrapped_bus = AudioBus::CreateWrapper(1);
32 wrapped_bus->set_frames(audio_bus->frames()); 34 wrapped_bus->set_frames(audio_bus->frames());
33 35
34 // Since FakeAudioRenderCallback generates only a single channel of unique 36 // Since FakeAudioRenderCallback generates only a single channel of unique
35 // audio data, we need to fill each channel manually. 37 // audio data, we need to fill each channel manually.
36 for (int ch = 0; ch < audio_bus->channels(); ++ch) { 38 for (int ch = 0; ch < audio_bus->channels(); ++ch) {
37 wrapped_bus->SetChannelData(0, audio_bus->channel(ch)); 39 wrapped_bus->SetChannelData(0, audio_bus->channel(ch));
38 fake_callback_.Render(wrapped_bus.get(), 0, 0); 40 fake_callback_.Render(wrapped_bus.get(), 0, 0);
39 } 41 }
40 } 42 }
41 43
42 ~AudioHashTest() override {} 44 ~AudioHashTest() override {}
43 45
44 protected: 46 protected:
45 scoped_ptr<AudioBus> bus_one_; 47 std::unique_ptr<AudioBus> bus_one_;
46 scoped_ptr<AudioBus> bus_two_; 48 std::unique_ptr<AudioBus> bus_two_;
47 FakeAudioRenderCallback fake_callback_; 49 FakeAudioRenderCallback fake_callback_;
48 50
49 DISALLOW_COPY_AND_ASSIGN(AudioHashTest); 51 DISALLOW_COPY_AND_ASSIGN(AudioHashTest);
50 }; 52 };
51 53
52 // Ensure the same data hashes the same. 54 // Ensure the same data hashes the same.
53 TEST_F(AudioHashTest, Equivalence) { 55 TEST_F(AudioHashTest, Equivalence) {
54 AudioHash hash_one; 56 AudioHash hash_one;
55 hash_one.Update(bus_one_.get(), bus_one_->frames()); 57 hash_one.Update(bus_one_.get(), bus_one_->frames());
56 58
(...skipping 17 matching lines...) Expand all
74 EXPECT_NE(original_hash.ToString(), swapped_hash.ToString()); 76 EXPECT_NE(original_hash.ToString(), swapped_hash.ToString());
75 } 77 }
76 78
77 // Ensure channel order matters to the hash. 79 // Ensure channel order matters to the hash.
78 TEST_F(AudioHashTest, ChannelOrder) { 80 TEST_F(AudioHashTest, ChannelOrder) {
79 AudioHash original_hash; 81 AudioHash original_hash;
80 original_hash.Update(bus_one_.get(), bus_one_->frames()); 82 original_hash.Update(bus_one_.get(), bus_one_->frames());
81 83
82 // Reverse channel order for the same sample data. 84 // Reverse channel order for the same sample data.
83 const int channels = bus_one_->channels(); 85 const int channels = bus_one_->channels();
84 scoped_ptr<AudioBus> swapped_ch_bus = AudioBus::CreateWrapper(channels); 86 std::unique_ptr<AudioBus> swapped_ch_bus = AudioBus::CreateWrapper(channels);
85 swapped_ch_bus->set_frames(bus_one_->frames()); 87 swapped_ch_bus->set_frames(bus_one_->frames());
86 for (int i = channels - 1; i >= 0; --i) 88 for (int i = channels - 1; i >= 0; --i)
87 swapped_ch_bus->SetChannelData(channels - (i + 1), bus_one_->channel(i)); 89 swapped_ch_bus->SetChannelData(channels - (i + 1), bus_one_->channel(i));
88 90
89 AudioHash swapped_hash; 91 AudioHash swapped_hash;
90 swapped_hash.Update(swapped_ch_bus.get(), swapped_ch_bus->frames()); 92 swapped_hash.Update(swapped_ch_bus.get(), swapped_ch_bus->frames());
91 93
92 EXPECT_NE(original_hash.ToString(), swapped_hash.ToString()); 94 EXPECT_NE(original_hash.ToString(), swapped_hash.ToString());
93 } 95 }
94 96
(...skipping 30 matching lines...) Expand all
125 TEST_F(AudioHashTest, HashIgnoresUpdateOrder) { 127 TEST_F(AudioHashTest, HashIgnoresUpdateOrder) {
126 AudioHash full_hash; 128 AudioHash full_hash;
127 full_hash.Update(bus_one_.get(), bus_one_->frames()); 129 full_hash.Update(bus_one_.get(), bus_one_->frames());
128 130
129 AudioHash half_hash; 131 AudioHash half_hash;
130 half_hash.Update(bus_one_.get(), bus_one_->frames() / 2); 132 half_hash.Update(bus_one_.get(), bus_one_->frames() / 2);
131 133
132 // Create a new bus representing the second half of |bus_one_|. 134 // Create a new bus representing the second half of |bus_one_|.
133 const int half_frames = bus_one_->frames() / 2; 135 const int half_frames = bus_one_->frames() / 2;
134 const int channels = bus_one_->channels(); 136 const int channels = bus_one_->channels();
135 scoped_ptr<AudioBus> half_bus = AudioBus::CreateWrapper(channels); 137 std::unique_ptr<AudioBus> half_bus = AudioBus::CreateWrapper(channels);
136 half_bus->set_frames(half_frames); 138 half_bus->set_frames(half_frames);
137 for (int i = 0; i < channels; ++i) 139 for (int i = 0; i < channels; ++i)
138 half_bus->SetChannelData(i, bus_one_->channel(i) + half_frames); 140 half_bus->SetChannelData(i, bus_one_->channel(i) + half_frames);
139 141
140 half_hash.Update(half_bus.get(), half_bus->frames()); 142 half_hash.Update(half_bus.get(), half_bus->frames());
141 EXPECT_EQ(full_hash.ToString(), half_hash.ToString()); 143 EXPECT_EQ(full_hash.ToString(), half_hash.ToString());
142 } 144 }
143 145
144 // Ensure approximate hashes pass verification. 146 // Ensure approximate hashes pass verification.
145 TEST_F(AudioHashTest, VerifySimilarHash) { 147 TEST_F(AudioHashTest, VerifySimilarHash) {
(...skipping 13 matching lines...) Expand all
159 // Twiddle the values too much... 161 // Twiddle the values too much...
160 for (int i = 0; i < bus_one_->frames(); ++i) 162 for (int i = 0; i < bus_one_->frames(); ++i)
161 channel[i] += 0.0001f; 163 channel[i] += 0.0001f;
162 164
163 AudioHash hash_three; 165 AudioHash hash_three;
164 hash_three.Update(bus_one_.get(), bus_one_->frames()); 166 hash_three.Update(bus_one_.get(), bus_one_->frames());
165 EXPECT_NE(hash_one.ToString(), hash_three.ToString()); 167 EXPECT_NE(hash_one.ToString(), hash_three.ToString());
166 } 168 }
167 169
168 } // namespace media 170 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698