This source file includes following definitions.
- VerifyValue
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "media/base/audio_fifo.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class AudioFifoTest : public testing::Test {
public:
AudioFifoTest() {}
virtual ~AudioFifoTest() {}
void VerifyValue(const float data[], int size, float value) {
for (int i = 0; i < size; ++i)
ASSERT_FLOAT_EQ(value, data[i]) << "i=" << i;
}
protected:
DISALLOW_COPY_AND_ASSIGN(AudioFifoTest);
};
TEST_F(AudioFifoTest, Construct) {
static const int kChannels = 6;
static const int kMaxFrameCount = 128;
AudioFifo fifo(kChannels, kMaxFrameCount);
EXPECT_EQ(fifo.frames(), 0);
}
TEST_F(AudioFifoTest, Push) {
static const int kChannels = 2;
static const int kMaxFrameCount = 128;
AudioFifo fifo(kChannels, kMaxFrameCount);
{
SCOPED_TRACE("Push 50%");
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2);
EXPECT_EQ(fifo.frames(), 0);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), bus->frames());
fifo.Clear();
}
{
SCOPED_TRACE("Push 100%");
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
EXPECT_EQ(fifo.frames(), 0);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), bus->frames());
fifo.Clear();
}
}
TEST_F(AudioFifoTest, Consume) {
static const int kChannels = 2;
static const int kMaxFrameCount = 128;
AudioFifo fifo(kChannels, kMaxFrameCount);
{
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), kMaxFrameCount);
}
{
SCOPED_TRACE("Consume 50%");
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2);
fifo.Consume(bus.get(), 0, bus->frames());
EXPECT_TRUE(fifo.frames() == bus->frames());
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), kMaxFrameCount);
}
{
SCOPED_TRACE("Consume 100%");
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
fifo.Consume(bus.get(), 0, bus->frames());
EXPECT_EQ(fifo.frames(), 0);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), kMaxFrameCount);
}
}
TEST_F(AudioFifoTest, FramesInFifo) {
static const int kChannels = 2;
static const int kMaxFrameCount = 64;
AudioFifo fifo(kChannels, kMaxFrameCount);
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, 1);
int n = 0;
while (fifo.frames() < kMaxFrameCount) {
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), ++n);
}
EXPECT_EQ(fifo.frames(), kMaxFrameCount);
while (fifo.frames() > 0) {
fifo.Consume(bus.get(), 0, bus->frames());
EXPECT_EQ(fifo.frames(), --n);
}
EXPECT_EQ(fifo.frames(), 0);
scoped_ptr<AudioBus> bus2 =
AudioBus::Create(kChannels, (kMaxFrameCount / 4) - 1);
const int frames_in_fifo = bus2->frames();
fifo.Push(bus2.get());
EXPECT_EQ(fifo.frames(), frames_in_fifo);
for (int n = 0; n < kMaxFrameCount; ++n) {
fifo.Push(bus2.get());
fifo.Consume(bus2.get(), 0, frames_in_fifo);
EXPECT_EQ(fifo.frames(), frames_in_fifo);
}
}
TEST_F(AudioFifoTest, VerifyDataValues) {
static const int kChannels = 2;
static const int kFrameCount = 2;
static const int kFifoFrameCount = 5 * kFrameCount;
AudioFifo fifo(kChannels, kFifoFrameCount);
scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount);
EXPECT_EQ(fifo.frames(), 0);
EXPECT_EQ(bus->frames(), kFrameCount);
int value = 1;
while (fifo.frames() < kFifoFrameCount) {
for (int j = 0; j < bus->channels(); ++j)
std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), bus->frames() * value);
++value;
}
EXPECT_EQ(fifo.frames(), kFifoFrameCount);
value = 1;
int n = 1;
const int frames_to_consume = bus->frames() / 2;
while (fifo.frames() > 0) {
fifo.Consume(bus.get(), 0, frames_to_consume);
for (int j = 0; j < bus->channels(); ++j)
VerifyValue(bus->channel(j), frames_to_consume, value);
if (n++ % 2 == 0)
++value;
}
EXPECT_EQ(fifo.frames(), 0);
value = 1;
for (int j = 0; j < bus->channels(); ++j)
std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value);
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), bus->frames());
for (int i = 0; i < 5 * kFifoFrameCount; i++) {
fifo.Consume(bus.get(), 0, bus->frames());
for (int j = 0; j < bus->channels(); ++j) {
VerifyValue(bus->channel(j), bus->channels(), value);
std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value + 1);
}
fifo.Push(bus.get());
EXPECT_EQ(fifo.frames(), bus->frames());
++value;
}
}
}