test/test_streamaligner.cpp
/** test case for enabling/disabling streams **/
test case for enabling/disabling streams
test case for enabling / disabling streams
BOOST_AUTO_TEST_CASE(stream_enable_test)
{
    std::cout<<"\n*** STREAM_ALIGNER [TEST 2] ***\n";
    StreamAligner<NUMBER_OF_STREAMS> aligner; 
    aligner.setTimeout(base::Time::fromSeconds(2.0));
    const size_t N = 4;
    int s1 = aligner.registerStream<std::string, N>( &test_callback, base::Time::fromSeconds(1.0)); 
    int s2 = aligner.registerStream<std::string, N>( &test_callback, base::Time::fromSeconds(0), 1);
    aligner.push<std::string, N>( s1, base::Time::fromSeconds(1.0), std::string("a")); 
    aligner.push<std::string, N>( s2, base::Time::fromSeconds(2.0), std::string("b")); 
    BOOST_CHECK(aligner.isStreamActive(s2) == true);
    aligner.disableStream(s2);
    BOOST_CHECK(aligner.isStreamActive(s2) == false);
    last_sample = ""; aligner.step(); BOOST_CHECK(last_sample == "a");
    last_sample = ""; aligner.step(); BOOST_CHECK(last_sample == "b");
    aligner.push<std::string, N>(s1, base::Time::fromSeconds(3.0), std::string("c"));
    last_sample = ""; aligner.step(); BOOST_CHECK(last_sample == "c");
    aligner.push<std::string, N>(s2, base::Time::fromSeconds(4.0), std::string("d")); 
    BOOST_CHECK(aligner.isStreamActive(s2) == true);
    aligner.push<std::string, N>(s1, base::Time::fromSeconds(5.0), std::string("e")); 
    last_sample = ""; aligner.step(); BOOST_CHECK(last_sample == "d");
    last_sample = ""; aligner.step(); BOOST_CHECK(last_sample == "");
}
BOOST_AUTO_TEST_CASE ( stream_enable_test ) { std :: cout << " \n \n " ; StreamAligner < NUMBER_OF_STREAMS > aligner ; aligner . setTimeout ( base :: Time :: fromSeconds ( 2.0 ) ) ; const size_t N = 4 ; int s1 = aligner . registerStream < std :: string , N > ( & test_callback , base :: Time :: fromSeconds ( 1.0 ) ) ; int s2 = aligner . registerStream < std :: string , N > ( & test_callback , base :: Time :: fromSeconds ( 0 ) , 1 ) ; aligner . push < std :: string , N > ( s1 , base :: Time :: fromSeconds ( 1.0 ) , std :: string ( " " ) ) ; aligner . push < std :: string , N > ( s2 , base :: Time :: fromSeconds ( 2.0 ) , std :: string ( " " ) ) ; BOOST_CHECK ( aligner . isStreamActive ( s2 ) == true ) ; aligner . disableStream ( s2 ) ; BOOST_CHECK ( aligner . isStreamActive ( s2 ) == false ) ; last_sample = " " ; aligner . step ( ) ; BOOST_CHECK ( last_sample == " " ) ; last_sample = " " ; aligner . step ( ) ; BOOST_CHECK ( last_sample == " " ) ; aligner . push < std :: string , N > ( s1 , base :: Time :: fromSeconds ( 3.0 ) , std :: string ( " " ) ) ; last_sample = " " ; aligner . step ( ) ; BOOST_CHECK ( last_sample == " " ) ; aligner . push < std :: string , N > ( s2 , base :: Time :: fromSeconds ( 4.0 ) , std :: string ( " " ) ) ; BOOST_CHECK ( aligner . isStreamActive ( s2 ) == true ) ; aligner . push < std :: string , N > ( s1 , base :: Time :: fromSeconds ( 5.0 ) , std :: string ( " " ) ) ; last_sample = " " ; aligner . step ( ) ; BOOST_CHECK ( last_sample == " " ) ; last_sample = " " ; aligner . step ( ) ; BOOST_CHECK ( last_sample == " " ) ; }
test case for enabling/disabling streams
test case for enabling / disabling streams
/** callback, period_time, (optional) priority **/ /** we should still be able to read out the disabled stream **/ /** since s2 is disabled, we directly get c, without waiting for the timout **/ /** this should reenable s2 **/ /** and we get the s2 sample **/ /** but have to wait for the next s1 sample, since timout is not over **/