~christopher-hunt08/maus/beam_selection_development

« back to all changes in this revision

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

  • Committer: Chris Rogers
  • Date: 2012-10-13 18:43:00 UTC
  • mfrom: (663.6.137 merge)
  • mto: (663.6.204 merge)
  • mto: This revision was merged to the branch mainline in revision 680.
  • Revision ID: chris.rogers@stfc.ac.uk-20121013184300-ry9q81m45dmtgejr
Bring control room branch into line with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
namespace MAUS {
22
22
 
23
23
 
24
 
  class MyInputter : public InputBase<int> {
 
24
  class MyInputter : public InputBase<int*> {
25
25
  public:
26
 
    MyInputter() : InputBase<int>("TestClass") {}
27
 
    MyInputter(const MyInputter& mr) : InputBase<int>(mr) {}
 
26
    MyInputter() : InputBase<int*>("TestClass") {}
 
27
    MyInputter(const MyInputter& mr) : InputBase<int*>(mr) {}
28
28
    virtual ~MyInputter() {}
29
29
 
30
30
  private:
31
31
    virtual void _birth(const std::string&) {}
32
32
    virtual void _death() {}
33
33
 
34
 
    virtual int* _emitter() {
 
34
    virtual int* _emitter_cpp() {
35
35
      return new int(27);
36
36
    }
37
37
 
 
38
 
38
39
  private:
39
40
    FRIEND_TEST(InputBaseTest, TestConstructor);
40
41
    FRIEND_TEST(InputBaseTest, TestCopyConstructor);
45
46
    MyInputter_squeal() : MyInputter() {}
46
47
 
47
48
  private:
48
 
    virtual int* _emitter() {
 
49
    virtual int* _emitter_cpp() {
49
50
      throw Squeal(Squeal::recoverable,
50
 
                   "Expected Test Squeal in _emitter",
51
 
                   "int* _emitter(int* t) const");
 
51
                   "Expected Test Squeal in _emitter_cpp",
 
52
                   "int* _emitter_cpp()");
52
53
    }
53
54
  };
54
55
 
57
58
    MyInputter_exception() : MyInputter() {}
58
59
 
59
60
  private:
60
 
    virtual int* _emitter() {
 
61
    virtual int* _emitter_cpp() {
61
62
      throw std::exception();
62
63
    }
63
64
  };
67
68
    MyInputter_otherexcept() : MyInputter() {}
68
69
 
69
70
  private:
70
 
    virtual int* _emitter() {throw 17;}
 
71
    virtual int* _emitter_cpp() {throw 17;}
71
72
  };
72
73
 
73
74
  TEST(InputBaseTest, TestConstructor) {
94
95
    }
95
96
    catch(...) {
96
97
      ASSERT_TRUE(false)
97
 
        <<"Fail: Birth function failed. Check ModuleBaseTest"
98
 
        << std::endl;
 
98
        << "Fail: Birth function failed. Check ModuleBaseTest"
 
99
        << std::endl;
99
100
    }
100
101
  }
101
102
 
106
107
    }
107
108
    catch(...) {
108
109
      ASSERT_TRUE(false)
109
 
        <<"Fail: Death function failed. Check ModuleBaseTest"
110
 
        << std::endl;
 
110
        << "Fail: Death function failed. Check ModuleBaseTest"
 
111
        << std::endl;
111
112
    }
112
113
  }
113
114
 
114
115
  TEST(InputBaseTest, TestEmitter) {
115
116
    MyInputter mm;
116
117
 
117
 
    int* i = mm.emitter();
 
118
    int* i = mm.emitter_cpp();
118
119
 
119
120
    ASSERT_TRUE(*i == 27)
120
 
      <<"Fail: _emitter method not called properly"
121
 
      <<std::endl;
 
121
      << "Fail: _emitter_cpp method not called properly"
 
122
      << std::endl;
122
123
 
123
124
    /////////////////////////////////////////////////////
124
125
    MyInputter_squeal mm_s;
125
126
    try {
126
 
      mm_s.emitter();
 
127
      mm_s.emitter_cpp();
127
128
    }
128
129
    catch(...) {
129
130
      ASSERT_TRUE(false)
130
 
        << "Fail: Squeal should have been handled"
131
 
        << std::endl;
 
131
        << "Fail: Squeal should have been handled"
 
132
        << std::endl;
132
133
    }
133
134
 
134
135
    /////////////////////////////////////////////////////
135
136
    MyInputter_exception mm_e;
136
137
    try {
137
 
      mm_e.emitter();
 
138
      mm_e.emitter_cpp();
138
139
    }
139
140
    catch(...) {
140
141
      ASSERT_TRUE(false)
141
 
        << "Fail: Exception should have been handled"
142
 
        << std::endl;
 
142
        << "Fail: Exception should have been handled"
 
143
        << std::endl;
143
144
    }
144
145
 
145
146
    /////////////////////////////////////////////////////
146
147
    MyInputter_otherexcept mm_oe;
147
148
    try {
148
 
      mm_oe.emitter();
 
149
      mm_oe.emitter_cpp();
149
150
      ASSERT_TRUE(false)
150
 
        << "Fail: No exception thrown"
151
 
        << std::endl;
 
151
        << "Fail: No exception thrown"
 
152
        << std::endl;
152
153
    }
153
154
    catch(UnhandledException& e) {}
154
155
    catch(...) {
155
156
      ASSERT_TRUE(false)
156
 
        << "Fail: Expected exception of type UnhandledException to be thrown"
157
 
        << std::endl;
 
157
        << "Fail: Expected exception of type UnhandledException to be thrown"
 
158
        << std::endl;
158
159
    }
159
160
 
160
161
    delete i;