CbmRoot
_GTestCbmDefs.cxx
Go to the documentation of this file.
1 #include "CbmDetectorList.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
15  DetectorId detIdFromEnum;
16  int detId;
17  TString detName;
19 };
20 
21 // Base class to use the same basic setup for parameterized and
22 // non-parameterized tests
23 // Here one defines everything which is common for all the different
24 // test cases
25 template<class T>
26 class _TestCbmDetectorListBase : public T {
27 protected:
28  CbmDetectorList fList;
29 
30 
31  virtual void SetUp() {}
32 
33  virtual void TearDown() {}
34 };
35 
36 // This is the derived class for the non-parameterized test cases.
37 class CbmDetectorListTest : public _TestCbmDetectorListBase<testing::Test> {};
38 
39 // This is the derived class for the parameterized test cases.
41  public _TestCbmDetectorListBase<testing::TestWithParam<InOutStructure>> {
42 protected:
43  DetectorId detIdFromEnum;
44  Int_t detId;
45  TString detName;
47 
48  virtual void SetUp() {
49  InOutStructure const& p = GetParam();
50 
52  detId = p.detId;
53  detName = p.detName;
55  }
56 };
57 
58 TEST(CbmDetectorList, outOfBounds) {
59  CbmDetectorList fList;
60  TString retName;
61 
62  fList.GetSystemName(111, retName);
63  EXPECT_EQ("unknown", retName);
64 
65  fList.GetSystemName(-111, retName);
66  EXPECT_EQ("unknown", retName);
67 
68  fList.GetSystemNameCaps(111, retName);
69  EXPECT_EQ("unknown", retName);
70 
71  fList.GetSystemNameCaps(-111, retName);
72  EXPECT_EQ("UNKNOWN", retName);
73 }
74 
75 TEST_P(CbmDetectorListParamTest, checkUniqueIdCreation) {
76  TString retName;
77  fList.GetSystemName(detIdFromEnum, retName);
78  EXPECT_EQ(detName, retName);
79 
80  fList.GetSystemName(detId, retName);
81  EXPECT_EQ(detName, retName);
82 
83  fList.GetSystemNameCaps(detIdFromEnum, retName);
84  EXPECT_EQ(detNameUppercase, retName);
85 
86  fList.GetSystemNameCaps(detId, retName);
87  EXPECT_EQ(detNameUppercase, retName);
88 }
89 
90 InOutStructure val1 = {kREF, 0, "ref", "REF"};
91 InOutStructure val2 = {kMVD, 1, "mvd", "MVD"};
92 InOutStructure val3 = {kSTS, 2, "sts", "STS"};
93 InOutStructure val4 = {kRICH, 3, "rich", "RICH"};
94 InOutStructure val5 = {kMUCH, 4, "much", "MUCH"};
95 InOutStructure val6 = {kTRD, 5, "trd", "TRD"};
96 InOutStructure val7 = {kTOF, 6, "tof", "TOF"};
97 InOutStructure val8 = {kECAL, 7, "ecal", "ECAL"};
98 InOutStructure val9 = {kPSD, 8, "unknown", "PSD"};
99 InOutStructure val10 = {kSTT, 9, "unknown", "UNKNOWN"};
100 InOutStructure val11 = {kFHODO, 10, "fhodo", "FHODO"};
101 InOutStructure val12 = {kTutDet, 11, "tutdet", "TUTDET"};
102 InOutStructure val13 = {kNOFDETS, 12, "unknown", "UNKNOWN"};
103 
104 INSTANTIATE_TEST_CASE_P(TestAllParameters,
106  ::testing::Values(val1,
107  val2,
108  val3,
109  val4,
110  val5,
111  val6,
112  val7,
113  val8,
114  val9,
115  val10,
116  val11,
117  val12));
val6
InOutStructure val6
Definition: _GTestCbmDefs.cxx:95
NicaCbmDetectorID::kMUCH
const UInt_t kMUCH
Definition: CbmDetectorID.h:22
InOutStructure
Definition: _GTestCbmDefs.cxx:14
INSTANTIATE_TEST_CASE_P
INSTANTIATE_TEST_CASE_P(TestAllParameters, CbmDetectorListParamTest, ::testing::Values(val1, val2, val3, val4, val5, val6, val7, val8, val9, val10, val11, val12))
CbmDetectorListParamTest::SetUp
virtual void SetUp()
Definition: _GTestCbmDefs.cxx:48
CbmDetectorListParamTest::detId
Int_t detId
Definition: _GTestCbmDefs.cxx:44
CbmDetectorListParamTest
Definition: _GTestCbmDefs.cxx:41
val8
InOutStructure val8
Definition: _GTestCbmDefs.cxx:97
val13
InOutStructure val13
Definition: _GTestCbmDefs.cxx:102
NicaCbmDetectorID::kRICH
const UInt_t kRICH
Definition: CbmDetectorID.h:18
val2
InOutStructure val2
Definition: _GTestCbmDefs.cxx:91
NicaCbmDetectorID::kMVD
const UInt_t kMVD
Definition: CbmDetectorID.h:17
NicaCbmDetectorID::kECAL
const UInt_t kECAL
Definition: CbmDetectorID.h:20
val3
InOutStructure val3
Definition: _GTestCbmDefs.cxx:92
NicaCbmDetectorID::kSTS
const UInt_t kSTS
Definition: CbmDetectorID.h:16
val4
InOutStructure val4
Definition: _GTestCbmDefs.cxx:93
TEST
TEST(CbmDetectorList, outOfBounds)
Definition: _GTestCbmDefs.cxx:58
InOutStructure::detName
TString detName
Definition: _GTestCbmDefs.cxx:17
val7
InOutStructure val7
Definition: _GTestCbmDefs.cxx:96
CbmDetectorListParamTest::detIdFromEnum
DetectorId detIdFromEnum
Definition: _GTestCbmDefs.cxx:43
CbmDetectorListTest
Definition: _GTestCbmDefs.cxx:37
_TestCbmDetectorListBase::TearDown
virtual void TearDown()
Definition: _GTestCbmDefs.cxx:33
val5
InOutStructure val5
Definition: _GTestCbmDefs.cxx:94
val11
InOutStructure val11
Definition: _GTestCbmDefs.cxx:100
CbmDetectorListParamTest::detName
TString detName
Definition: _GTestCbmDefs.cxx:45
val10
InOutStructure val10
Definition: _GTestCbmDefs.cxx:99
_TestCbmDetectorListBase::SetUp
virtual void SetUp()
Definition: _GTestCbmDefs.cxx:31
val9
InOutStructure val9
Definition: _GTestCbmDefs.cxx:98
_TestCbmDetectorListBase::fList
CbmDetectorList fList
Definition: _GTestCbmDefs.cxx:28
TEST_P
TEST_P(CbmDetectorListParamTest, checkUniqueIdCreation)
Definition: _GTestCbmDefs.cxx:75
NicaCbmDetectorID::kTOF
const UInt_t kTOF
Definition: CbmDetectorID.h:15
val1
InOutStructure val1
Definition: _GTestCbmDefs.cxx:90
_TestCbmDetectorListBase
Definition: _GTestCbmDefs.cxx:26
NicaCbmDetectorID::kTRD
const UInt_t kTRD
Definition: CbmDetectorID.h:19
NicaCbmDetectorID::kPSD
const UInt_t kPSD
Definition: CbmDetectorID.h:21
CbmDetectorListParamTest::detNameUppercase
TString detNameUppercase
Definition: _GTestCbmDefs.cxx:46
val12
InOutStructure val12
Definition: _GTestCbmDefs.cxx:101
InOutStructure::detNameUppercase
TString detNameUppercase
Definition: _GTestCbmDefs.cxx:18
InOutStructure::detIdFromEnum
DetectorId detIdFromEnum
Definition: _GTestCbmDefs.cxx:15
InOutStructure::detId
int detId
Definition: _GTestCbmDefs.cxx:16