Changeset - 4d01ee44e4e5
[Not reviewed]
stream
0 3 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-12-03 14:58:04
hy@ozderya.net
added simple tests for Source class and minor improvements
3 files changed with 68 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/source.cpp
Show inline comments
 
@@ -26,6 +26,7 @@ void Source::connect(Sink* sink)
 
    Q_ASSERT(!sinks.contains(sink));
 

	
 
    sinks.append(sink);
 
    sink->setNumChannels(numChannels(), hasX());
 
}
 

	
 
void Source::disconnect(Sink* sink)
 
@@ -43,10 +44,10 @@ void Source::feedOut(const SamplePack& d
 
    }
 
}
 

	
 
void Source::feedNumChannels(unsigned nc, bool x) const
 
void Source::updateNumChannels() const
 
{
 
    for (auto sink : sinks)
 
    {
 
        sink->setNumChannels(nc, x);
 
        sink->setNumChannels(numChannels(), hasX());
 
    }
 
}
src/source.h
Show inline comments
 
@@ -41,8 +41,9 @@ public:
 
protected:
 
    /// Feeds "in" given data to connected sinks
 
    void feedOut(const SamplePack& data) const;
 
    /// Updates "number of channels" of connected sinks
 
    void feedNumChannels(unsigned nc, bool x = false) const;
 
    /// Updates "number of channels" of connected sinks. Must be
 
    /// called when num. channels or hasX changes.
 
    void updateNumChannels() const;
 

	
 
private:
 
    QList<Sink*> sinks;
tests/test.cpp
Show inline comments
 
@@ -63,7 +63,6 @@ public:
 
            _hasX = false;
 
        };
 

	
 
public:
 
    void feedIn(const SamplePack& data)
 
        {
 
            REQUIRE(data.numChannels() == numChannels());
 
@@ -119,3 +118,65 @@ TEST_CASE("sink", "[memory, stream]")
 
    REQUIRE(follower.numChannels() == 2);
 
    REQUIRE(follower.hasX() == true);
 
}
 

	
 
class TestSource : public Source
 
{
 
public:
 
    int _numChannels;
 
    bool _hasX;
 

	
 
    TestSource(unsigned nc, bool x)
 
        {
 
            _numChannels = nc;
 
            _hasX = x;
 
        };
 

	
 
    virtual unsigned numChannels() const
 
        {
 
            return _numChannels;
 
        };
 

	
 
    virtual bool hasX() const
 
        {
 
            return _hasX;
 
        };
 

	
 
    void _feed(const SamplePack& data) const
 
        {
 
            feedOut(data);
 
        };
 

	
 
    void _setNumChannels(unsigned nc, bool x)
 
        {
 
            _numChannels = nc;
 
            _hasX = x;
 

	
 
            updateNumChannels();
 
        };
 
};
 

	
 
TEST_CASE("source", "[memory, stream]")
 
{
 
    TestSink sink;
 

	
 
    TestSource source(3, false);
 

	
 
    REQUIRE(source.numChannels() == 3);
 
    REQUIRE(source.hasX() == false);
 

	
 
    source.connect(&sink);
 
    REQUIRE(sink.numChannels() == 3);
 
    REQUIRE(sink.hasX() == false);
 

	
 
    source._setNumChannels(5, true);
 
    REQUIRE(sink.numChannels() == 5);
 
    REQUIRE(sink.hasX() == true);
 

	
 
    SamplePack pack(100, 5, true);
 
    source._feed(pack);
 
    REQUIRE(sink.totalFed == 100);
 

	
 
    source.disconnect(&sink);
 
    source._feed(pack);
 
    REQUIRE(sink.totalFed == 100);
 
}
0 comments (0 inline, 0 general)