~aleteoryx/muditaos

ref: b00548440b4d37ee2806f0760a949b23b7e14aa8 muditaos/module-audio/Audio/test/TestStream.cpp -rw-r--r-- 2.2 KiB
b0054844 — Lefucjusz [BH-2020] Fix double-free in DecoderMP3 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "TestStream.hpp"

#include <Audio/AbstractStream.hpp>

#include <memory>
#include <utility>

using ::audio::AbstractStream;
using testing::audio::TestStream;

TestStream::TestStream(std::size_t blockSize) : bufSize(blockSize)
{
    data = std::make_unique<std::uint8_t[]>(bufSize);
}

const AbstractStream::Span TestStream::getDataSpan() const
{
    return AbstractStream::Span{data.get(), bufSize};
}

bool TestStream::push(void *data, std::size_t dataSize)
{
    return true;
}

bool TestStream::push(const AbstractStream::Span &span)
{
    if (span.dataSize != bufSize) {
        return false;
    }

    for (std::size_t i = 0; i < span.dataSize; i++) {
        data.get()[i] = span.data[i];
    }

    return true;
}

bool TestStream::push()
{
    return true;
}

bool TestStream::pop(AbstractStream::Span &span)
{
    return true;
}

bool TestStream::reserve(AbstractStream::Span &span)
{
    span = Span{.data = data.get(), .dataSize = bufSize};
    return true;
}

void TestStream::commit()
{}

void TestStream::release()
{}

bool TestStream::peek(AbstractStream::Span &span)
{
    return true;
}

void TestStream::consume()
{}

void TestStream::unpeek()
{}

void TestStream::reset()
{}

void TestStream::setData(uint8_t value)
{
    for (std::size_t i = 0; i < bufSize; i++) {
        data.get()[i] = value;
    }
}

bool TestStream::checkData(const Span &span)
{
    if (span.dataSize != bufSize) {
        return false;
    }

    for (std::size_t i = 0; i < bufSize; i++) {
        if (data.get()[i] != span.data[i]) {
            return false;
        }
    }

    return true;
}

void TestStream::registerListener(EventListener *listener)
{}

void TestStream::unregisterListeners(EventListener *listener)
{}

auto TestStream::getInputTraits() const noexcept -> Traits
{
    return Traits{.blockSize = bufSize, .format = ::audio::nullFormat};
}

auto TestStream::getOutputTraits() const noexcept -> Traits
{
    return Traits{.blockSize = bufSize, .format = ::audio::nullFormat};
}

bool TestStream::isEmpty() const noexcept
{
    return false;
}

bool TestStream::isFull() const noexcept
{
    return false;
}