CbmRoot
_GTestCbmDigi.cxx
Go to the documentation of this file.
1 #include "CbmDigi.h"
2 
3 #include "CbmMatch.h"
4 
5 #include "gtest/gtest-spi.h"
6 #include "gtest/gtest.h"
7 
8 #include <utility> // std::forward
9 
10 // Since CbmDigi is an abstract base class which can't be instantiated directly we have
11 // to create a derived class without any data members which simply forwards the function
12 // calls to the abstract base class
13 
14 class CbmTestDigi : public CbmDigi {
15 
16 public:
17  CbmTestDigi() : CbmDigi() { ; }
18 
20  CbmTestDigi(const CbmTestDigi& digi) : CbmDigi(digi) { ; }
21 
23  CbmTestDigi(CbmTestDigi&& digi) : CbmDigi(std::forward<CbmTestDigi>(digi)) {
24  ;
25  }
26 
28  virtual ~CbmTestDigi() { ; }
29 
32  if (this != &other) { CbmDigi::operator=(other); }
33  return *this;
34  }
35 
38  if (this != &other) {
39  CbmDigi::operator=(std::forward<CbmTestDigi>(other));
40  }
41  return *this;
42  }
43 
45  Int_t GetAddress() const { return CbmDigi::GetAddress(); }
46 
47 
49  Int_t GetSystemId() const { return CbmDigi::GetSystemId(); };
50 
51 
53  Double_t GetTime() const { return CbmDigi::GetTime(); }
54 
55  std::string ToString() const { return CbmDigi::ToString(); }
56 };
57 
58 #include "compareDigi.h"
59 
60 TEST(_GTestCbmDigi, CheckDefaultConstructor) {
61  // Create abstract base class via derived class
62  CbmTestDigi test;
63 
64  compareDigiDataMembers(test, -111, 0., -111, -111.);
65 
66  CbmTestDigi* test1 = new CbmTestDigi();
67 
68  compareDigiDataMembers(*test1, -111, 0., -111, -111.);
69 }
70 
71 TEST(_GTestCbmDigi, CheckCopyConstructor) {
72  // Create abstract base class via derived class
73  CbmTestDigi test;
74 
75  compareDigiDataMembers(test, -111, 0., -111, -111.);
76 
77  // Create object by copy constructing
78  // test should be equal to test2 and test should be existing
79  CbmTestDigi test2 {test};
80 
81  compareDigiDataMembers(test2, -111, 0., -111, -111.);
82 
83  // Test if the original object wasn't changed
84  compareDigiDataMembers(test, -111, 0., -111, -111.);
85 }
86 
87 TEST(_GTestCbmDigi, CheckAssignmentOperator) {
88  // Create abstract base class via derived class
89  CbmTestDigi test;
90 
91  compareDigiDataMembers(test, -111, 0., -111, -111.);
92 
93  // Create object by copy constructing
94  // test should be equal to test2 and test should be existing
95  CbmTestDigi test2;
96  test2 = test;
97 
98  compareDigiDataMembers(test2, -111, 0., -111, -111.);
99 
100  // Test if the original object wasn't changed
101  compareDigiDataMembers(test, -111, 0., -111, -111.);
102 
103 
104  // Create object by copy constructing
105  // test should be equal to test2 and test should be existing
106  CbmTestDigi test3;
107  test3 = test;
108 
109  compareDigiDataMembers(test3, -111, 0., -111, -111.);
110 
111  // Test if the original object wasn't changed
112  compareDigiDataMembers(test, -111, 0., -111, -111.);
113 }
114 
115 TEST(_GTestCbmDigi, CheckMoveConstructor) {
116  // Create abstract base class via derived class
117  // After creation there is no CbmMatch added such
118  // that the pointer is a nullptr
119  CbmTestDigi test;
120 
121  compareDigiDataMembers(test, -111, 0., -111, -111.);
122 
123  // Create object by move constructing
124  // test2 should now contain the pointer to the CbmMatch object and
125  // test should contain a nullptr
126  CbmTestDigi test2 {std::move(test)};
127 
128  compareDigiDataMembers(test2, -111, 0., -111, -111.);
129 
130  compareDigiDataMembers(test, -111, 0., -111, -111.);
131 }
132 
133 TEST(_GTestCbmDigi, CheckAssignmentMoveConstructor) {
134  // Create abstract base class via derived class
135  // After creation there is no CbmMatch added such
136  // that the pointer is a nullptr
137  CbmTestDigi test;
138 
139  compareDigiDataMembers(test, -111, 0., -111, -111.);
140 
141  // Create object by move constructing
142  // test2 should now contain the pointer to the CbmMatch object and
143  // test should contain a nullptr
144  CbmTestDigi test2; // = std::move(test);
145  test2 = std::move(test);
146 
147 
148  compareDigiDataMembers(test2, -111, 0., -111, -111.);
149 
150  compareDigiDataMembers(test, -111, 0., -111, -111.);
151 }
152 
153 TEST(_GTestCbmDigi, CheckToString) {
154  CbmTestDigi test;
155 
156  compareDigiDataMembers(test, -111, 0., -111, -111.);
157 
158  EXPECT_STREQ("Digi: System -111 | address -111 | time -111 | charge 0",
159  test.ToString().c_str());
160 }
CbmTestDigi::CbmTestDigi
CbmTestDigi(CbmTestDigi &&digi)
Definition: _GTestCbmDigi.cxx:23
CbmTestDigi::CbmTestDigi
CbmTestDigi()
Definition: _GTestCbmDigi.cxx:17
CbmStsAddress::GetAddress
Int_t GetAddress(UInt_t unit=0, UInt_t ladder=0, UInt_t halfladder=0, UInt_t module=0, UInt_t sensor=0, UInt_t side=0, UInt_t version=kCurrentVersion)
Construct address.
Definition: CbmStsAddress.cxx:90
CbmTestDigi::operator=
CbmTestDigi & operator=(const CbmTestDigi &other)
Definition: _GTestCbmDigi.cxx:31
CbmTestDigi::GetAddress
Int_t GetAddress() const
Definition: _GTestCbmDigi.cxx:45
CbmTestDigi::operator=
CbmTestDigi & operator=(CbmTestDigi &&other)
Definition: _GTestCbmDigi.cxx:37
CbmMatch.h
compareDigi.h
CbmTestDigi::ToString
std::string ToString() const
Definition: _GTestCbmDigi.cxx:55
TEST
TEST(_GTestCbmDigi, CheckDefaultConstructor)
Definition: _GTestCbmDigi.cxx:60
CbmStsAddress::GetSystemId
ECbmModuleId GetSystemId(Int_t address)
Get system Id (should be ECbmModuleId::kSts)
Definition: CbmStsAddress.cxx:190
CbmTestDigi::~CbmTestDigi
virtual ~CbmTestDigi()
Definition: _GTestCbmDigi.cxx:28
CbmTestDigi::GetTime
Double_t GetTime() const
Definition: _GTestCbmDigi.cxx:53
CbmTestDigi::CbmTestDigi
CbmTestDigi(const CbmTestDigi &digi)
Definition: _GTestCbmDigi.cxx:20
CbmTestDigi
Definition: _GTestCbmDigi.cxx:14
compareDigiDataMembers
void compareDigiDataMembers(CbmTestDigi &test, Int_t address, Double_t charge, Int_t systemid, Double_t time)
Definition: compareDigi.h:4
Cbm::ToString
std::string ToString(const T &value)
Definition: CbmUtils.h:16
CbmTestDigi::GetSystemId
Int_t GetSystemId() const
Definition: _GTestCbmDigi.cxx:49