Files
        @ 1e7920e956a9
    
        
              Branch filter: 
        
    Location: tempo-plotter/tests/test_stream.cpp
        
            
            1e7920e956a9
            4.7 KiB
            text/x-c++hdr
        
        
    
    added stream channelinfomodel accessor
    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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213  | /*
  Copyright © 2018 Hasan Yavuz Özderya
  This file is part of serialplot.
  serialplot is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  serialplot is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "stream.h"
#include "catch.hpp"
#include "test_helpers.h"
TEST_CASE("construction of stream with default values", "[memory, stream]")
{
    // default values are an empty stream with no channels
    Stream s;
    REQUIRE(s.numChannels() == 0);
    REQUIRE(!s.hasX());
    REQUIRE(s.numSamples() == 0);
}
TEST_CASE("construction of stream with parameters", "[memory, stream]")
{
    Stream s(4, true, 100);
    REQUIRE(s.numChannels() == 4);
    REQUIRE(s.hasX());
    REQUIRE(s.numSamples() == 100);
    for (unsigned i = 0; i < 4; i++)
    {
        const StreamChannel* c = s.channel(i);
        REQUIRE(c != NULL);
        REQUIRE(c->index() == i);
    }
}
TEST_CASE("changing stream number of channels via sink", "[memory, stream, sink]")
{
    Stream s;
    TestSource so(3, false);
    so.connect(&s);
    // nc=3, x= false
    REQUIRE(s.numChannels() == 3);
    REQUIRE(!s.hasX());
    for (unsigned i = 0; i < 3; i++)
    {
        const StreamChannel* c = s.channel(i);
        REQUIRE(c != NULL);
        REQUIRE(c->index() == i);
    }
    // increase nc value, add X
    so._setNumChannels(5, true);
    REQUIRE(s.numChannels() == 5);
    REQUIRE(s.hasX());
    for (unsigned i = 0; i < 5; i++)
    {
        const StreamChannel* c = s.channel(i);
        REQUIRE(c != NULL);
        REQUIRE(c->index() == i);
    }
    // reduce nc value, remove X
    so._setNumChannels(1, false);
    REQUIRE(s.numChannels() == 1);
    REQUIRE(!s.hasX());
    for (unsigned i = 0; i < 1; i++)
    {
        const StreamChannel* c = s.channel(i);
        REQUIRE(c != NULL);
        REQUIRE(c->index() == i);
    }
}
TEST_CASE("adding data to a stream with no X", "[memory, stream, data, sink]")
{
    Stream s(3, false, 10);
    // prepare data
    SamplePack pack(5, 3, false);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        for (unsigned i = 0; i < 5; i++)
        {
            pack.data(ci)[i] = i;
        }
    }
    TestSource so(3, false);
    so.connect(&s);
    // test
    so._feed(pack);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        const StreamChannel* c = s.channel(ci);
        const FrameBuffer* y = c->yData();
        for (unsigned i = 0; i < 5; i++)
        {
            REQUIRE(y->sample(i) == 0);
        }
        for (unsigned i = 5; i < 10; i++)
        {
            REQUIRE(y->sample(i) == i-5);
        }
    }
}
TEST_CASE("adding data to a stream with X", "[memory, stream, data, sink]")
{
    Stream s(3, true, 10);
    // prepare data
    SamplePack pack(5, 3, true);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        for (unsigned i = 0; i < 5; i++)
        {
            pack.data(ci)[i] = i;
        }
    }
    // x data
    for (unsigned i = 0; i < 5; i++)
    {
        pack.xData()[i] = i+10;
    }
    TestSource so(3, true);
    so.connect(&s);
    // test
    so._feed(pack);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        const StreamChannel* c = s.channel(ci);
        const FrameBuffer* y = c->yData();
        for (unsigned i = 0; i < 5; i++)
        {
            REQUIRE(y->sample(i) == 0);
        }
        for (unsigned i = 5; i < 10; i++)
        {
            REQUIRE(y->sample(i) == i-5);
        }
    }
    // check x
    const FrameBuffer* x = s.channel(0)->xData();
    for (unsigned i = 0; i < 5; i++)
    {
        REQUIRE(x->sample(i) == 0);
    }
    for (unsigned i = 5; i < 10; i++)
    {
        REQUIRE(x->sample(i) == (i-5)+10);
    }
}
TEST_CASE("paused stream shoulnd't store data", "[memory, stream, pause]")
{
    Stream s(3, false, 10);
    // prepare data
    SamplePack pack(5, 3, false);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        for (unsigned i = 0; i < 5; i++)
        {
            pack.data(ci)[i] = i;
        }
    }
    TestSource so(3, false);
    so.connect(&s);
    // test
    s.pause(true);
    so._feed(pack);
    for (unsigned ci = 0; ci < 3; ci++)
    {
        const StreamChannel* c = s.channel(ci);
        const FrameBuffer* y = c->yData();
        for (unsigned i = 0; i < 10; i++)
        {
            REQUIRE(y->sample(i) == 0);
        }
    }
}
 |