CbmRoot
Loading...
Searching...
No Matches
_GTestCbmStsDigi.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmStsAddress.h"
6#include "CbmStsDigi.h"
7
8#include <boost/archive/binary_iarchive.hpp>
9#include <boost/archive/binary_oarchive.hpp>
10
11#include "compareStsDigi.h"
12#include "gtest/gtest-spi.h"
13#include "gtest/gtest.h"
14
15static const int32_t kTestAddress = CbmStsAddress::GetAddress(5, 6, 1, 8, 0, 0, 1);
16
17
18TEST(_GTestCbmStsDigi, CheckDefaultConstructor)
19{
20 // Test disabled. CbmStsDigi doesn't initialize its members in the default constructor on purpose.
21
22 // Create object
23 // CbmStsDigi test;
24
25 // const int32_t defaultAddr = CbmStsAddress::GetAddress(0, 0, 0, 0, 0, 0, 1);
26
27 // compareStsDigiDataMembers(test, defaultAddr, 0, 0, ECbmModuleId::kSts, 0);
28
29 // CbmStsDigi* test1 = new CbmStsDigi();
30
31 // compareStsDigiDataMembers(*test1, defaultAddr, 0, 0, ECbmModuleId::kSts, 0);
32}
33
34TEST(_GTestCbmStsDigi, CheckStandardConstructor)
35{
36 // Create object
37 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
38
40
41 CbmStsDigi* test1 = new CbmStsDigi(kTestAddress, 42, 987654321, 23);
42
44}
45
46TEST(_GTestCbmStsDigi, CheckCopyConstructor)
47{
48 // Create object
49 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
50
52
53 // Create object by copy constructing
54 // test should be equal to test2 and
55 // test should not be changed
56 CbmStsDigi test2 {test};
57
59
60 // Test if the original object wasn't changed
62}
63
64TEST(_GTestCbmStsDigi, CheckAssignmentOperator)
65{
66
67 // Create object
68 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
69
71
72 // Create object by copy assignment
73 // test should be equal to test2 and
74 // test should not be changed
75 CbmStsDigi test2;
76 test2 = test;
77
79
80 // Test if the original object wasn't changed
82}
83
84TEST(_GTestCbmStsDigi, CheckMoveConstructor)
85{
86 // Create object
87 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
88
90
91 // Create object by move constructing
92 CbmStsDigi test2 {std::move(test)};
93
95
96 // For objects with simple types move fall back to copy so
97 // the original object is kept unchanged
99}
100
101TEST(_GTestCbmStsDigi, CheckAssignmentMoveConstructor)
102{
103 // Create object
104 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
105
107
108 // Create object by move constructing
109 CbmStsDigi test2 {};
110 test2 = std::move(test);
111
113
114 // For objects with simple types move fall back to copy so
115 // the original object is kept unchanged
117}
118
119TEST(_GTestCbmStsDigi, CheckSetTime)
120{
121 // Create object
122 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
123
125
126 test.SetTime(897654321.0);
127
129}
130
131TEST(_GTestCbmStsDigi, CheckToString)
132{
133 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
134
136
137 std::string expected =
138 "StsDigi: address " + std::to_string(kTestAddress) + " | channel 42 | charge 23 | time 987654321";
139
140 EXPECT_STREQ(expected.c_str(), test.ToString().c_str());
141}
142
143
144TEST(_GTestCbmStsDigi, CheckGetClassName)
145{
146 CbmStsDigi test(kTestAddress, 42, 987654321, 23);
147
149
150 EXPECT_STREQ("CbmStsDigi", test.GetClassName());
151}
152
153TEST(_GTestCbmStsDigi, CheckSerialization)
154{
155 CbmStsDigi write(kTestAddress, 42, 987654321, 23);
156 std::stringstream s;
157 boost::archive::binary_oarchive outArchive(s);
158 outArchive << write;
159 CbmStsDigi read;
160 boost::archive::binary_iarchive inArchive(s);
161 inArchive >> read;
163}
@ kSts
Silicon Tracking System.
static const int32_t kTestAddress
TEST(_GTestCbmStsDigi, CheckDefaultConstructor)
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
std::string ToString() const
XPU_D void SetTime(uint32_t dNewTime)
Definition CbmStsDigi.h:138
static const char * GetClassName()
Class name (static)
Definition CbmStsDigi.h:99
void compareStsDigiDataMembers(CbmStsDigi &test, int32_t address, uint16_t charge, uint16_t channel, ECbmModuleId systemid, int64_t time)
int32_t GetAddress(uint32_t unit=0, uint32_t ladder=0, uint32_t halfladder=0, uint32_t module=0, uint32_t sensor=0, uint32_t side=0, uint32_t version=kCurrentVersion)
Construct address.