This source file includes following definitions.
- last_frame_delay_
- VerifyValue
- ConsumeTest
- ProvideInput
- TEST_P
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/strings/stringprintf.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_pull_fifo.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
static int kChannels = 2;
static const int kMaxFramesInFifo = 2048;
class AudioPullFifoTest
: public testing::TestWithParam<int> {
public:
AudioPullFifoTest()
: pull_fifo_(kChannels, kMaxFramesInFifo, base::Bind(
&AudioPullFifoTest::ProvideInput, base::Unretained(this))),
audio_bus_(AudioBus::Create(kChannels, kMaxFramesInFifo)),
fill_value_(0),
last_frame_delay_(-1) {}
virtual ~AudioPullFifoTest() {}
void VerifyValue(const float data[], int size, float start_value) {
float value = start_value;
for (int i = 0; i < size; ++i) {
ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i;
}
}
void ConsumeTest(int frames_to_consume) {
int start_value = 0;
SCOPED_TRACE(base::StringPrintf("Checking frames_to_consume %d",
frames_to_consume));
pull_fifo_.Consume(audio_bus_.get(), frames_to_consume);
for (int j = 0; j < kChannels; ++j) {
VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value);
}
start_value += frames_to_consume;
EXPECT_LT(last_frame_delay_, audio_bus_->frames());
}
virtual void ProvideInput(int frame_delay, AudioBus* audio_bus) {
ASSERT_GT(frame_delay, last_frame_delay_);
last_frame_delay_ = frame_delay;
EXPECT_EQ(audio_bus->channels(), audio_bus_->channels());
EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo);
for (int i = 0; i < audio_bus->frames(); ++i) {
for (int j = 0; j < audio_bus->channels(); ++j) {
audio_bus->channel(j)[i] = fill_value_;
}
fill_value_++;
}
}
protected:
AudioPullFifo pull_fifo_;
scoped_ptr<AudioBus> audio_bus_;
int fill_value_;
int last_frame_delay_;
DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest);
};
TEST_P(AudioPullFifoTest, Consume) {
ConsumeTest(GetParam());
}
INSTANTIATE_TEST_CASE_P(
AudioPullFifoTest, AudioPullFifoTest,
testing::Values(544, 512, 512, 512, 512, 2048, 544, 441, 440, 433, 500));
}