signal-all.cpp 1.6 KB
Newer Older
Bergé's avatar
   
Bergé committed
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
//
// Created by corentin on 7/3/19.
//

#include <boost/foreach.hpp>

#include <dynamic-graph/debug.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/signal-array.h>
#include <dynamic-graph/tracer.h>
#include <dynamic-graph/signal-cast-helper.h>

#include <assert.h>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>


#define BOOST_TEST_MODULE signal_array



using boost::test_tools::output_test_stream;

dynamicgraph::SignalArray_const<double> sig;

using namespace std;
using namespace dynamicgraph;
using namespace dynamicgraph::command;


BOOST_AUTO_TEST_CASE (test_array) {
    SignalBase<int> sigBa("add test");
    SignalArray_const<int> sigArr_C(1);
    sigArr_C.operator<<(sigBa);
    sigArr_C.operator<<(sigBa);
    BOOST_CHECK_EQUAL(2, sigArr_C.getSize());

    SignalArray<int> sigArr(1);
    sigArr.operator<<(sigBa);
    sigArr.operator<<(sigBa);
    BOOST_CHECK_EQUAL(2,sigArr.getSize());

    SignalBase<int> sigB("constructor test");
    SignalArray<int> sigA(2);
    sigA << sigB;
    sigA.operator<<(sigB);
    SignalArray_const<int> sig_C(sigA);
    BOOST_CHECK_EQUAL(sigA.getSize(),sig_C.getSize());
}

BOOST_AUTO_TEST_CASE(test_base)
{
    SignalBase<int> sigB("test");
    sigB.setReady();
    BOOST_CHECK_EQUAL(true,sigB.getReady());
}

BOOST_AUTO_TEST_CASE(test_cast_helper)
{
    DefaultCastRegisterer<int> defaultCR;
    std::istringstream iss;
    iss.str("1");
    defaultCR.cast(iss);

    try{
        std::istringstream iss_fail;
        iss.str("test");
        defaultCR.cast(iss_fail);
    } catch(ExceptionSignal e){
        //Take int, not string
    }
}