1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
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.
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.
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/>.
19
#include "gtest/gtest.h"
21
#include "src/common_cpp/JsonCppProcessors/TestBranchProcessor.hh"
23
// Test conversion from cpp -> json -> cap
26
namespace TestBranchProcessorTest {
28
class TestBranchProcessorTestClass : public ::testing::Test {
30
virtual void SetUp() {
31
// Fill Cpp TestBranch
32
_proc = new TestBranchProcessor();
33
_testbranch = new MAUS::TestBranch();
36
virtual void TearDown() {
37
// Fill Cpp TestBranch
42
MAUS::TestBranch *_testbranch;
43
TestBranchProcessor *_proc;
46
TEST_F(TestBranchProcessorTestClass, CheckInitialSetup) {
47
MAUS::TestChild *testchild = _testbranch->GetChildByValue();
48
EXPECT_EQ(testchild, _testbranch->GetRequiredChildByRef());
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());
61
TEST_F(TestBranchProcessorTestClass, CppToJsonWithNULLRequiredRef) {
62
_testbranch->SetRequiredChildByRef(NULL);
63
_testbranch->SetNotRequiredChildByRef(_testbranch->GetChildByValue());
65
Json::Value *json_out = NULL;
66
if (json_out) {;} // dummy to kill gcc warning, does nothing
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());
73
TEST_F(TestBranchProcessorTestClass, CppToJsonWithNULLNotRequiredRef) {
74
_testbranch->SetRequiredChildByRef(_testbranch->GetChildByValue());
75
_testbranch->SetNotRequiredChildByRef(NULL);
77
Json::Value *json_out = NULL;
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());