CbmRoot
Loading...
Searching...
No Matches
_GTestCbmDigi.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmDigi.h"
6#include "CbmMatch.h"
7
8#include <utility> // std::forward
9
10#include "gtest/gtest-spi.h"
11#include "gtest/gtest.h"
12
13// Since CbmDigi is an abstract base class which can't be instantiated directly we have
14// to create a derived class without any data members which simply forwards the function
15// calls to the abstract base class
16
17class CbmTestDigi : public CbmDigi {
18
19public:
20 CbmTestDigi() : CbmDigi() { ; }
21
23 CbmTestDigi(const CbmTestDigi& digi) : CbmDigi(digi) { ; }
24
26 CbmTestDigi(CbmTestDigi&& digi) : CbmDigi(std::forward<CbmTestDigi>(digi)) { ; }
27
29 virtual ~CbmTestDigi() { ; }
30
33 {
34 if (this != &other) { CbmDigi::operator=(other); }
35 return *this;
36 }
37
40 {
41 if (this != &other) { CbmDigi::operator=(std::forward<CbmTestDigi>(other)); }
42 return *this;
43 }
44
46 int32_t GetAddress() const { return CbmDigi::GetAddress(); }
47
48
50 int32_t GetSystemId() const { return CbmDigi::GetSystemId(); };
51
52
54 double GetTime() const { return CbmDigi::GetTime(); }
55
56 std::string ToString() const { return CbmDigi::ToString(); }
57};
58
59#include "compareDigi.h"
60
61TEST(_GTestCbmDigi, CheckDefaultConstructor)
62{
63 // Create abstract base class via derived class
64 CbmTestDigi test;
65
66 compareDigiDataMembers(test, -111, 0., -111, -111.);
67
68 CbmTestDigi* test1 = new CbmTestDigi();
69
70 compareDigiDataMembers(*test1, -111, 0., -111, -111.);
71}
72
73TEST(_GTestCbmDigi, CheckCopyConstructor)
74{
75 // Create abstract base class via derived class
76 CbmTestDigi test;
77
78 compareDigiDataMembers(test, -111, 0., -111, -111.);
79
80 // Create object by copy constructing
81 // test should be equal to test2 and test should be existing
82 CbmTestDigi test2 {test};
83
84 compareDigiDataMembers(test2, -111, 0., -111, -111.);
85
86 // Test if the original object wasn't changed
87 compareDigiDataMembers(test, -111, 0., -111, -111.);
88}
89
90TEST(_GTestCbmDigi, CheckAssignmentOperator)
91{
92 // Create abstract base class via derived class
93 CbmTestDigi test;
94
95 compareDigiDataMembers(test, -111, 0., -111, -111.);
96
97 // Create object by copy constructing
98 // test should be equal to test2 and test should be existing
99 CbmTestDigi test2;
100 test2 = test;
101
102 compareDigiDataMembers(test2, -111, 0., -111, -111.);
103
104 // Test if the original object wasn't changed
105 compareDigiDataMembers(test, -111, 0., -111, -111.);
106
107
108 // Create object by copy constructing
109 // test should be equal to test2 and test should be existing
110 CbmTestDigi test3;
111 test3 = test;
112
113 compareDigiDataMembers(test3, -111, 0., -111, -111.);
114
115 // Test if the original object wasn't changed
116 compareDigiDataMembers(test, -111, 0., -111, -111.);
117}
118
119TEST(_GTestCbmDigi, CheckMoveConstructor)
120{
121 // Create abstract base class via derived class
122 // After creation there is no CbmMatch added such
123 // that the pointer is a nullptr
124 CbmTestDigi test;
125
126 compareDigiDataMembers(test, -111, 0., -111, -111.);
127
128 // Create object by move constructing
129 // test2 should now contain the pointer to the CbmMatch object and
130 // test should contain a nullptr
131 CbmTestDigi test2 {std::move(test)};
132
133 compareDigiDataMembers(test2, -111, 0., -111, -111.);
134
135 compareDigiDataMembers(test, -111, 0., -111, -111.);
136}
137
138TEST(_GTestCbmDigi, CheckAssignmentMoveConstructor)
139{
140 // Create abstract base class via derived class
141 // After creation there is no CbmMatch added such
142 // that the pointer is a nullptr
143 CbmTestDigi test;
144
145 compareDigiDataMembers(test, -111, 0., -111, -111.);
146
147 // Create object by move constructing
148 // test2 should now contain the pointer to the CbmMatch object and
149 // test should contain a nullptr
150 CbmTestDigi test2; // = std::move(test);
151 test2 = std::move(test);
152
153
154 compareDigiDataMembers(test2, -111, 0., -111, -111.);
155
156 compareDigiDataMembers(test, -111, 0., -111, -111.);
157}
158
159TEST(_GTestCbmDigi, CheckToString)
160{
161 CbmTestDigi test;
162
163 compareDigiDataMembers(test, -111, 0., -111, -111.);
164
165 EXPECT_STREQ("Digi: System -111 | address -111 | time -111 | charge 0", test.ToString().c_str());
166}
TEST(_GTestCbmDigi, CheckDefaultConstructor)
int32_t GetSystemId() const
virtual ~CbmTestDigi()
int32_t GetAddress() const
CbmTestDigi & operator=(const CbmTestDigi &other)
CbmTestDigi & operator=(CbmTestDigi &&other)
double GetTime() const
CbmTestDigi(CbmTestDigi &&digi)
CbmTestDigi(const CbmTestDigi &digi)
std::string ToString() const
void compareDigiDataMembers(CbmTestDigi &test, int32_t address, double charge, int32_t systemid, double time)
Definition compareDigi.h:10
Hash for CbmL1LinkKey.