Audacity 3.2.0
AudioSegmentSampleViewTest.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AudioSegmentSampleViewTest.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12
13#include <catch2/catch.hpp>
14
15TEST_CASE("AudioSegmentSampleView", "Copy returns expected values when")
16{
17 SECTION("AudioSegmentSampleView is silent")
18 {
19 AudioSegmentSampleView sut { 3 };
20 std::vector<float> buffer(4);
21 std::fill(buffer.begin(), buffer.end(), 1.f);
22 SECTION("and asked MORE values than it holds.")
23 {
24 sut.Copy(buffer.data(), 4u);
25 REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 0.f, 0.f });
26 }
27 SECTION("and asked FEWER values than it holds.")
28 {
29 sut.Copy(buffer.data(), 2u);
30 REQUIRE(buffer == std::vector<float> { 0.f, 0.f, 1.f, 1.f });
31 }
32 }
33
34 SECTION("AudioSegmentSampleView is NOT silent")
35 {
36 const auto segment1 = std::make_shared<std::vector<float>>(
37 std::vector<float> { 1.f, 2.f, 3.f });
38 const auto segment2 = std::make_shared<std::vector<float>>(
39 std::vector<float> { 4.f, 5.f, 6.f });
40 constexpr auto start = 2u;
41 constexpr auto length = 3u;
42 AudioSegmentSampleView sut { { segment1, segment2 }, start, length };
43
44 SECTION("and asked MORE values than it holds.")
45 {
46 std::vector<float> out(4u);
47 std::fill(out.begin(), out.end(), 123.f);
48 sut.Copy(out.data(), out.size());
49 REQUIRE(out == std::vector<float> { 3.f, 4.f, 5.f, 0.f });
50 }
51 SECTION("and asked FEWER values than it holds.")
52 {
53 std::vector<float> out(2u);
54 sut.Copy(out.data(), out.size());
55 REQUIRE(out == std::vector<float> { 3.f, 4.f });
56 }
57 }
58}
An audio segment is either a whole clip or the silence between clips. Views allow shared references t...
TEST_CASE("AudioSegmentSampleView", "Copy returns expected values when")