Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gtest/TestAudioBuffers.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include <stdint.h>
7
#include "AudioBufferUtils.h"
8
#include "gtest/gtest.h"
9
#include <vector>
10
11
const uint32_t FRAMES = 256;
12
13
void test_for_number_of_channels(const uint32_t channels)
14
0
{
15
0
  const uint32_t samples = channels * FRAMES;
16
0
17
0
  mozilla::AudioCallbackBufferWrapper<float> mBuffer(channels);
18
0
  mozilla::SpillBuffer<float, 128> b(channels);
19
0
  std::vector<float> fromCallback(samples, 0.0);
20
0
  std::vector<float> other(samples, 1.0);
21
0
22
0
  // Set the buffer in the wrapper from the callback
23
0
  mBuffer.SetBuffer(fromCallback.data(), FRAMES);
24
0
25
0
  // Fill the SpillBuffer with data.
26
0
  ASSERT_TRUE(b.Fill(other.data(), 15) == 15);
27
0
  ASSERT_TRUE(b.Fill(other.data(), 17) == 17);
28
0
  for (uint32_t i = 0; i < 32 * channels; i++) {
29
0
    other[i] = 0.0;
30
0
  }
31
0
32
0
  // Empty it in the AudioCallbackBufferWrapper
33
0
  ASSERT_TRUE(b.Empty(mBuffer) == 32);
34
0
35
0
  // Check available return something reasonnable
36
0
  ASSERT_TRUE(mBuffer.Available() == FRAMES - 32);
37
0
38
0
  // Fill the buffer with the rest of the data
39
0
  mBuffer.WriteFrames(other.data() + 32 * channels, FRAMES - 32);
40
0
41
0
  // Check the buffer is now full
42
0
  ASSERT_TRUE(mBuffer.Available() == 0);
43
0
44
0
  for (uint32_t i = 0 ; i < samples; i++) {
45
0
    ASSERT_TRUE(fromCallback[i] == 1.0) <<
46
0
      "Difference at " << i << " (" << fromCallback[i] << " != " << 1.0 <<
47
0
      ")\n";
48
0
  }
49
0
50
0
  ASSERT_TRUE(b.Fill(other.data(), FRAMES) == 128);
51
0
  ASSERT_TRUE(b.Fill(other.data(), FRAMES) == 0);
52
0
  ASSERT_TRUE(b.Empty(mBuffer) == 0);
53
0
}
54
55
TEST(AudioBuffers, Test)
56
0
{
57
0
  for (uint32_t ch = 1; ch <= 8; ++ch) {
58
0
    test_for_number_of_channels(ch);
59
0
  }
60
0
}