~mwinter4/maus/ckov-update

« back to all changes in this revision

Viewing changes to tests/cpp_unit/JsonCppProcessors/TestBranchProcessorTest.cc

  • Committer: Chris Rogers
  • Date: 2013-02-01 13:08:06 UTC
  • mfrom: (659.1.57 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20130201130806-kkxs626x4loudqsm
Tags: MAUS-v0.4, MAUS-v0.4.3
MAUS-v0.4.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
 
2
 *
 
3
 * MAUS is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation, either version 3 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * MAUS is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include <string>
 
18
 
 
19
#include "gtest/gtest.h"
 
20
 
 
21
#include "src/common_cpp/JsonCppProcessors/TestBranchProcessor.hh"
 
22
 
 
23
// Test conversion from cpp -> json -> cap
 
24
 
 
25
namespace MAUS {
 
26
namespace TestBranchProcessorTest {
 
27
 
 
28
class TestBranchProcessorTestClass : public ::testing::Test {
 
29
 protected:
 
30
  virtual void SetUp() {
 
31
    // Fill Cpp TestBranch
 
32
    _proc = new TestBranchProcessor();
 
33
    _testbranch = new MAUS::TestBranch();
 
34
  }
 
35
 
 
36
  virtual void TearDown() {
 
37
    // Fill Cpp TestBranch
 
38
    delete _testbranch;
 
39
    delete _proc;
 
40
  }
 
41
 
 
42
  MAUS::TestBranch *_testbranch;
 
43
  TestBranchProcessor *_proc;
 
44
};
 
45
 
 
46
TEST_F(TestBranchProcessorTestClass, CheckInitialSetup) {
 
47
  MAUS::TestChild *testchild = _testbranch->GetChildByValue();
 
48
  EXPECT_EQ(testchild, _testbranch->GetRequiredChildByRef());
 
49
}
 
50
 
 
51
TEST_F(TestBranchProcessorTestClass, CppToJson) {
 
52
  Json::Value *json_out = NULL;
 
53
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Birth());
 
54
  ASSERT_NO_THROW(json_out = _proc->CppToJson(*_testbranch, ""));
 
55
  ASSERT_TRUE(json_out);
 
56
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::GetInstance()
 
57
                  .ResolveReferences(*json_out));
 
58
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Death());
 
59
}
 
60
 
 
61
TEST_F(TestBranchProcessorTestClass, CppToJsonWithNULLRequiredRef) {
 
62
  _testbranch->SetRequiredChildByRef(NULL);
 
63
  _testbranch->SetNotRequiredChildByRef(_testbranch->GetChildByValue());
 
64
 
 
65
  Json::Value *json_out = NULL;
 
66
  if (json_out) {;} // dummy to kill gcc warning, does nothing
 
67
 
 
68
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Birth());
 
69
  ASSERT_THROW(json_out = _proc->CppToJson(*_testbranch, ""), Squeal);
 
70
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Death());
 
71
}
 
72
 
 
73
TEST_F(TestBranchProcessorTestClass, CppToJsonWithNULLNotRequiredRef) {
 
74
  _testbranch->SetRequiredChildByRef(_testbranch->GetChildByValue());
 
75
  _testbranch->SetNotRequiredChildByRef(NULL);
 
76
 
 
77
  Json::Value *json_out = NULL;
 
78
 
 
79
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Birth());
 
80
  ASSERT_NO_THROW(json_out = _proc->CppToJson(*_testbranch, ""));
 
81
  ASSERT_TRUE(json_out);
 
82
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::GetInstance().
 
83
                                                  ResolveReferences(*json_out));
 
84
  ASSERT_NO_THROW(ReferenceResolver::CppToJson::RefManager::Death());
 
85
}
 
86
}
 
87
}