operations_fixture.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 operations_fixture.hpp
3 
4  operations_fixture.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 
21 #include <iostream>
22 #include <TaskContext.hpp>
23 #include "unit.hpp"
24 
25 using namespace std;
26 using namespace boost;
27 using namespace RTT;
28 using namespace RTT::detail;
29 
35 public:
37 
38  TaskContext* tc, *caller;
39 
40  // ref/const-ref tests:
41  double ret;
42  double& m0r() { return ret; }
43  const double& m0cr() { return ret; }
44 
45  // test const std::string& argument for command_ds
46  bool comstr(const std::string& cs) { return !cs.empty(); }
47 
48  double m1r(double& a) { a = 2*a; return a; }
49  double m1cr(const double& a) { return a; }
50 
51  // plain argument tests:
52  void vm0(void) { return; }
53  double m0(void) { return -1.0; }
54  double m1(int i) { if (i ==1) return -2.0; else return 2.0; }
55  double m2(int i, double d) { if ( i == 1 && d == 2.0 ) return -3.0; else return 3.0; }
56  double m3(int i, double d, bool c) { if ( i == 1 && d == 2.0 && c == true) return -4.0; else return 4.0; }
57  double m4(int i, double d, bool c, std::string s) { if ( i == 1 && d == 2.0 && c == true && s == "hello") return -5.0; else return 5.0; }
58  double m5(int i, double d, bool c, std::string s, float f) { if ( i == 1 && d == 2.0 && c == true && s == "hello" && f == 5.0f) return -6.0; else return 6.0; }
59  double m6(int i, double d, bool c, std::string s, float f, char h) { if ( i == 1 && d == 2.0 && c == true && s == "hello" && f == 5.0f && h == 'a') return -7.0; else return 7.0; }
60  double m7(int i, double d, bool c, std::string s, float f, char h, unsigned int st) { if ( i == 1 && d == 2.0 && c == true && s == "hello" && f == 5.0f && h == 'a' && st == 7) return -8.0; else return 8.0; }
61 
62  void *returnAddressOf(int &i) { return &i; }
63  const void *returnAddressOfConst(const int &i) { return &i; }
64 
65  int sleepAndIncrement(int seconds) { sleep(seconds); return ++i; }
66 
67  //exception tests:
68  void m0except(void) { throw std::runtime_error("exception"); }
69 
70  void print(const std::string& what) { cout << "print: " << what <<endl; }
71  void printNumber(const std::string& what, int n) { cout << "print: " << what << n << endl; }
72 
73  bool fail() {
74  throw std::runtime_error("OperationsFixture::fail() called.");
75  return true; // should be ignored anyway.
76  }
77 
78  bool good() {
79  return true;
80  }
81 
82  bool assertBool(bool b) {
83  if (!b)
84  throw std::runtime_error("OperationsFixture::assertBool( b ) failed (arg was false).");
85  return b;
86  }
87 
88  bool isTrue(bool b) {
89  return b;
90  }
91 
92  bool assertEqual(int a, int b)
93  {
94  if (a != b) {
95  cerr << "AssertEqual failed: a != b " << a << " != " << b << "." << endl;
96  throw std::runtime_error("OperationsFixture::assertEqual( a, b ) failed (a != b).");
97  }
98  return a == b;
99  }
100  bool assertMsg( bool b, const std::string& msg) {
101  if ( b == false ) {
102  cout << "Asserted :" << msg << endl;
103  throw std::runtime_error("OperationsFixture::assertMsg( b, msg ) faild (b was false).");
104  }
105  return true; // allow to continue to check other commands.
106  }
107  int increase() { return ++i;}
108 
109  void resetI() { i = 0; }
110  int getI() const { return i; }
111  int i;
112 
113 
115 
116  void createOperationCallerFactories(TaskContext* target);
117  void createOperationCallerFactories0(TaskContext* target);
118  void createOperationCallerFactories1(TaskContext* target);
119  void createOperationCallerFactories2(TaskContext* target);
120  void createOperationCallerFactories3(TaskContext* target);
121  void createOperationCallerFactories4(TaskContext* target);
122  void createOperationCallerFactories5(TaskContext* target);
123  void createOperationCallerFactories6(TaskContext* target);
124  void createOperationCallerFactories7(TaskContext* target);
125 };
double m6(int i, double d, bool c, std::string s, float f, char h)
void print(const std::string &what)
int sleepAndIncrement(int seconds)
bool assertMsg(bool b, const std::string &msg)
Definition: mystd.hpp:163
void printNumber(const std::string &what, int n)
double m5(int i, double d, bool c, std::string s, float f)
double m1r(double &a)
#define RTT_UNIT_API
Definition: unit.hpp:77
const double & m0cr()
printstream cout
Definition: rtstreams.cpp:45
void * returnAddressOf(int &i)
double m4(int i, double d, bool c, std::string s)
double m1cr(const double &a)
basic_ostreams & endl(basic_ostreams &s)
Definition: rtstreams.cpp:110
unsigned int sleep(unsigned int s)
Definition: fosi.cpp:51
double m3(int i, double d, bool c)
bool assertEqual(int a, int b)
double m7(int i, double d, bool c, std::string s, float f, char h, unsigned int st)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
const void * returnAddressOfConst(const int &i)
double m2(int i, double d)
bool comstr(const std::string &cs)


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34