CbmRoot
Loading...
Searching...
No Matches
_GTestCbmTrdDetectorId.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmTrdAddress.h"
6
7#include <TString.h>
8
9#include <iostream>
10
11#include <gtest/gtest-spi.h>
12#include <gtest/gtest.h>
13using std::cout;
14using std::endl;
15
16// Structure to pass filenames together with expected response into the
17// parametrized test
18struct InOutStructure {
19 int layer;
20 int module;
21 int sector;
22 int row;
23 int column;
24 int result;
25};
26
27// Base class to use the same basic setup for parameterized and
28// non-parameterized tests
29// Here one defines everything which is common for all the different
30// test cases
31template<class T>
32class _TestCbmTrdAddressBase : public T {
33protected:
35
36
37 virtual void SetUp() {}
38
39 virtual void TearDown() {}
40};
41
42// This is the derived class for the non-parameterized test cases.
43class CbmTrdAddressTest : public _TestCbmTrdAddressBase<testing::Test> {
44};
45
46TEST_F(CbmTrdAddressTest, CheckDefaultSettings)
47{
48 int32_t layerid = 0;
49 int32_t moduleid = 0;
50 int32_t sectorid = 0;
51 int32_t rowid = 0;
52 int32_t columnid = 0;
53 int32_t detInfo_array[5] = {layerid, moduleid, sectorid, rowid, columnid};
54
55 int32_t retVal = fTrdId.GetAddress(layerid, moduleid, sectorid, rowid, columnid);
56 EXPECT_EQ(0, retVal);
57}
58
59// This is the derived class for the parameterized test cases.
60class CbmTrdAddressParamTest : public _TestCbmTrdAddressBase<testing::TestWithParam<InOutStructure>> {
61protected:
62 int32_t detInfo_array[5];
63 int32_t modInfo_array[5];
64 int32_t result;
65
66 virtual void SetUp()
67 {
68 InOutStructure const& p = GetParam();
69
70 detInfo_array[0] = p.layer;
71 detInfo_array[1] = p.module;
72 detInfo_array[2] = p.sector;
73 detInfo_array[3] = p.row;
74 detInfo_array[4] = p.column;
75
76 result = p.result;
77
83 }
84};
85
86
87TEST_P(CbmTrdAddressParamTest, checkUniqueIdCreation)
88{
89 int32_t uniqueId =
90 fTrdId.GetAddress(detInfo_array[0], detInfo_array[1], detInfo_array[2], detInfo_array[3], detInfo_array[4]);
91 EXPECT_EQ(result, uniqueId);
92
93 int32_t systemId = fTrdId.GetSystemId(uniqueId);
94 EXPECT_EQ(kTrd, systemId);
95
96 /*
97 int32_t sectorNr = fTrdId.GetSector(uniqueId);
98 EXPECT_EQ(detInfo_array[5], sectorNr);
99
100 int32_t modId = fTrdId.SetDetectorInfo(modInfo_array);
101 int32_t newUniqueId = fTrdId.SetSector(modId, detInfo_array[5]);
102 EXPECT_EQ(result, newUniqueId);
103
104 int32_t newModId = fTrdId.GetModuleId(newUniqueId);
105 EXPECT_EQ(modId, newModId);
106*/
107}
108
109InOutStructure val1 = {0, 0, 0, 0, 0, 0};
110InOutStructure val2 = {kTrd, 0, 0, 0, 0, 5};
111InOutStructure val3 = {0, 1, 0, 0, 0, 32};
112InOutStructure val4 = {0, 0, 1, 0, 0, 512};
113InOutStructure val5 = {0, 0, 0, 1, 0, 4096};
114InOutStructure val6 = {0, 0, 0, 0, 1, 131072};
115InOutStructure val7 = {0, 0, 0, 0, 0, 33554432};
116InOutStructure val8 = {kTrd, 1, 1, 1, 1, 33690149};
117InOutStructure val9 = {kTrd, 3, 3, 2, 34, 105129573};
118InOutStructure val10 = {kTrd, 2, 3, 3, 17, 69350981};
119InOutStructure val11 = {0, 0, 0, 8, 0, 32768};
120InOutStructure val12 = {kTrd, 2, 3, 5, 17, 69359173};
121
122
123/*
124INSTANTIATE_TEST_CASE_P(TestAllParameters,
125 CbmTrdAddressParamTest,
126 ::testing::Values(val1, val2, val3, val4, val5,
127 val6, val7, val8, val9, val10,
128 val11, val12));
129
130// This is the derived class for the parameterized test cases.
131class CbmTrdAddressParamTest1 : public _TestCbmTrdAddressBase<
132 testing::TestWithParam<InOutStructure> >
133{
134 protected:
135 int32_t detInfo_array[5];
136 int32_t result_array[5];
137 int32_t uniqueId;
138
139 virtual void SetUp() {
140 InOutStructure const& p = GetParam();
141 uniqueId=p.result;
142 result_array[0] = p.layer;
143 result_array[1] = p.module;
144 result_array[2] = p.sector;
145 result_array[3] = p.row;
146 result_array[4] = p.column;
147 }
148};
149
150
151TEST_P(CbmTrdAddressParamTest1, checkExtractInfoFromUniqueId)
152{
153 int32_t* retVal = fTrdId.GetAddress(uniqueId);
154 for ( int i=0;i<5;i++) {
155 EXPECT_EQ(result_array[i], retVal[i]);
156 }
157}
158
159
160INSTANTIATE_TEST_CASE_P(TestAllParameters,
161 CbmTrdAddressParamTest1,
162 ::testing::Values(val1, val2, val3, val4, val5,
163 val6, val7, val8, val9, val10,
164 val11, val12));
165
166*/
@ kTrd
Transition Radiation Detector.
Helper class to convert unique channel ID back and forth.
InOutStructure val6
TEST_P(CbmTrdAddressParamTest, checkUniqueIdCreation)
InOutStructure val4
InOutStructure val1
InOutStructure val8
InOutStructure val5
InOutStructure val9
InOutStructure val12
InOutStructure val7
InOutStructure val3
InOutStructure val11
InOutStructure val10
InOutStructure val2
TEST_F(CbmTrdAddressTest, CheckDefaultSettings)