public
Fork of psoetens/orocos-rtt
Description: Orocos Real-Time Toolkit
Homepage: www.orocos.org/rtt
Clone URL: git://github.com/doudou/orocos-rtt.git
Janosch Machowinski (author)
Wed Nov 26 07:50:12 -0800 2008
Sylvain Joyeux (committer)
Fri Dec 19 07:31:38 -0800 2008
orocos-rtt / tests / tasks_multiple_test.hpp
100644 121 lines (96 sloc) 3.261 kb
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
/***************************************************************************
tag: Peter Soetens Mon Jan 10 15:59:18 CET 2005 tasks_multiple_test.hpp
 
tasks_multiple_test.hpp - description
-------------------
begin : Mon January 10 2005
copyright : (C) 2005 Peter Soetens
email : peter.soetens@mech.kuleuven.ac.be
 
***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
 
 
#ifndef TASKS_MULTIPLE_TEST_HPP
#define TASKS_MULTIPLE_TEST_HPP
 
#include <cppunit/extensions/HelperMacros.h>
 
#include <PeriodicActivity.hpp>
 
using namespace RTT;
 
 
template<class T>
class DummyTask : public T
{
    unsigned int inits;
    unsigned int steps;
    unsigned int fins;
 
    unsigned int starts;
    unsigned int stops;
    unsigned int okstarts;
    unsigned int okstops;
public:
    DummyTask(int prio, double period)
        : T(prio, period),
          inits(0), steps(0), fins(0),
          starts(0), stops(0),
          okstarts(0), okstops(0) {}
 
    bool start() {
        ++starts;
        if ( T::start() ) {
            ++okstarts;
            return true;
        }
        return false;
    }
    bool stop() {
        ++stops;
        if ( T::stop() ) {
            ++okstops;
            return true;
        }
        return false;
    }
    bool initialize() { ++inits; return true;}
    void step() { ++steps; }
    void finalize() { ++fins; }
    unsigned int nrOfStarts() { return starts;}
    unsigned int nrOfOKStarts() { return okstarts;}
    unsigned int nrOfInits() { return inits;}
    unsigned int nrOfSteps() { return steps;}
    unsigned int nrOfFinals() { return fins;}
    unsigned int nrOfStops() { return stops;}
    unsigned int nrOfOKStops() { return okstops;}
};
 
typedef DummyTask<PeriodicActivity> DummyPTask;
typedef DummyTask<PeriodicActivity> DummyNPTask;
 
/**
* Test for starting and stopping tasks
*/
class ActivitiesMultipleTest
    : public CppUnit::TestFixture
{
public:
    CPPUNIT_TEST_SUITE( ActivitiesMultipleTest );
    // Test Many Activities :
    CPPUNIT_TEST( testMultiple );
    CPPUNIT_TEST_SUITE_END();
 
public:
    void setUp();
 
    void testMultiple();
 
    void tearDown();
 
    std::vector<DummyNPTask*> np_tasks;
 
    typedef std::vector<DummyNPTask*>::iterator NPI;
    typedef std::vector<DummyPTask*>::iterator PI;
 
    std::vector<DummyPTask*> p_tasks;
 
    unsigned int nr_of_p;
    unsigned int nr_of_np;
 
    unsigned int runningP;
    unsigned int runningNp;
 
    std::string errInitNP;
    std::string errStepNP;
    std::string errFinNP;
    std::string errInitP;
    std::string errStepP;
    std::string errFinP;
};
 
#endif