~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to tests/cpp_unit/API/OutputBaseTest.cc

  • Committer: Christopher Hunt
  • Date: 2015-06-18 14:48:59 UTC
  • mfrom: (697.69.1 merge)
  • mto: (697.69.2 merge_hunt)
  • mto: This revision was merged to the branch mainline in revision 708.
  • Revision ID: christopher.hunt08@imperial.ac.uk-20150618144859-rki5ma1lv8722w41
Merged in latest trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
15
15
 *
16
16
 */
 
17
 
 
18
#include <Python.h>
17
19
#include "gtest/gtest.h"
18
20
#include "gtest/gtest_prod.h"
19
21
#include "src/common_cpp/API/OutputBase.hh"
21
23
namespace MAUS {
22
24
 
23
25
 
24
 
  class MyOutputter : public OutputBase<int*> {
 
26
  class MyOutputter : public OutputBase {
25
27
    public:
26
 
      MyOutputter() : OutputBase<int*>("TestClass") {}
27
 
      MyOutputter(const MyOutputter& mr) : OutputBase<int*>(mr) {}
 
28
      MyOutputter() : OutputBase("TestClass") {}
 
29
      MyOutputter(const MyOutputter& mr) : OutputBase(mr) {}
28
30
      virtual ~MyOutputter() {}
29
31
 
30
32
    private:
31
33
      virtual void _birth(const std::string&) {}
32
34
      virtual void _death() {}
33
35
 
34
 
      virtual bool _save(int* i) {
 
36
      virtual bool _save(PyObject* i) {
35
37
        if (!i) { throw NullInputException(_classname); }
36
 
        return *i == 27? true : false;
 
38
        return i == Py_True;
37
39
      }
38
40
 
39
41
    private:
46
48
      MyOutputter_maus_exception() : MyOutputter() {}
47
49
 
48
50
    private:
49
 
      virtual bool _save(int* i) {
 
51
      virtual bool _save(PyObject* i) {
50
52
        throw MAUS::Exception(MAUS::Exception::recoverable,
51
53
           "Expected Test MAUS::Exception in _save",
52
54
           "int* _save(int* t) const");
58
60
      MyOutputter_exception() : MyOutputter() {}
59
61
 
60
62
    private:
61
 
      virtual bool _save(int* i) {
 
63
      virtual bool _save(PyObject* i) {
62
64
        throw std::exception();
63
65
      }
64
66
  };
68
70
      MyOutputter_otherexcept() : MyOutputter() {}
69
71
 
70
72
    private:
71
 
      virtual bool _save(int* i) {throw 17;}
 
73
      virtual bool _save(PyObject* i) {throw 17;}
72
74
  };
73
75
 
74
76
  TEST(OutputBaseTest, TestConstructor) {
115
117
  TEST(OutputBaseTest, TestSaveSpill) {
116
118
    MyOutputter mm;
117
119
 
118
 
    int* i1 = new int(27);
119
 
    int* i2 = new int(19);
120
 
 
121
 
    ASSERT_TRUE(mm.save(i1))
 
120
    ASSERT_EQ(Py_True, mm.save_pyobj(Py_True))
122
121
      <<"Fail: _save method not called properly didn't return 'true' for save(new int(27))"
123
122
      <<std::endl;
124
123
 
125
 
    ASSERT_FALSE(mm.save(i2))
 
124
    ASSERT_EQ(Py_False, mm.save_pyobj(Py_False))
126
125
      <<"Fail: _save method not called properly didn't return 'false' for save(new int(19))"
127
126
      <<std::endl;
128
127
 
129
128
    /////////////////////////////////////////////////////
130
129
    MyOutputter mm2;
131
 
    int* dub = 0;
132
 
    ASSERT_FALSE(mm2.save(dub));
 
130
    ASSERT_EQ(Py_False, mm2.save_pyobj(NULL));
133
131
    /////////////////////////////////////////////////////
134
132
    MyOutputter_maus_exception mm_s;
135
133
    try {
136
 
      mm_s.save(i1);
 
134
      mm_s.save_pyobj(Py_True);
137
135
    }
138
136
    catch (...) {
139
137
      ASSERT_TRUE(false)
144
142
    /////////////////////////////////////////////////////
145
143
    MyOutputter_exception mm_e;
146
144
    try {
147
 
      mm_e.save(i1);
 
145
      mm_e.save_pyobj(Py_True);
148
146
    }
149
147
    catch (...) {
150
148
      ASSERT_TRUE(false)
155
153
    /////////////////////////////////////////////////////
156
154
    MyOutputter_otherexcept mm_oe;
157
155
    try {
158
 
      mm_oe.save(i1);
 
156
      mm_oe.save_pyobj(Py_True);
159
157
      ASSERT_TRUE(false)
160
158
        << "Fail: No exception thrown"
161
159
        << std::endl;
166
164
        << "Fail: Expected exception of type UnhandledException to be thrown"
167
165
        << std::endl;
168
166
    }
169
 
 
170
 
    delete i1;
171
 
    delete i2;
172
167
  }
173
168
}// end of namespace
 
169