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