CbmRoot
_GTestCbmPsdHit.cxx
Go to the documentation of this file.
1 #include "CbmPsdHit.h"
2 
3 #include "gtest/gtest-spi.h"
4 #include "gtest/gtest.h"
5 
6 #include "comparePsdHit.h"
7 
8 TEST(_GTestCbmPsdHit, CheckDefaultConstructor) {
9  // Create object
10  CbmPsdHit test;
11 
12  comparePsdHitDataMembers(test, -1, -1.);
13 
14  CbmPsdHit* test1 = new CbmPsdHit();
15 
16  comparePsdHitDataMembers(*test1, -1, -1.);
17 }
18 
19 TEST(_GTestCbmPsdHit, CheckStandardConstructor) {
20  // Create object
21  CbmPsdHit test(5, 6.7);
22 
23  comparePsdHitDataMembers(test, 5, 6.7);
24 
25  CbmPsdHit* test1 = new CbmPsdHit(2, 8.9);
26 
27  comparePsdHitDataMembers(*test1, 2, 8.9);
28 }
29 
30 TEST(_GTestCbmPsdHit, CheckCopyConstructor) {
31  // Create object
32  CbmPsdHit test(5, 6.7);
33 
34  comparePsdHitDataMembers(test, 5, 6.7);
35 
36  // Create object by copy constructing
37  // test should be equal to test2 and
38  // test should not be changed
39  CbmPsdHit test2 {test};
40 
41  comparePsdHitDataMembers(test2, 5, 6.7);
42 
43  // Test if the original object wasn't changed
44  comparePsdHitDataMembers(test, 5, 6.7);
45 }
46 
47 TEST(_GTestCbmPsdHit, CheckAssignmentOperator) {
48  // Create object
49  CbmPsdHit test(5, 6.7);
50 
51  comparePsdHitDataMembers(test, 5, 6.7);
52 
53  // Create object by copy constructing
54  // test should be equal to test2 and
55  // test should not be changed
56  CbmPsdHit test2 {};
57  test2 = test;
58 
59  comparePsdHitDataMembers(test2, 5, 6.7);
60 
61  // Test if the original object wasn't changed
62  comparePsdHitDataMembers(test, 5, 6.7);
63 }
64 
65 TEST(_GTestCbmPsdHit, CheckMoveConstructor) {
66  // Create object
67  CbmPsdHit test(5, 6.7);
68 
69  comparePsdHitDataMembers(test, 5, 6.7);
70 
71  // Create object by copy constructing
72  // test should be equal to test2 and
73  // test should not be changed
74  CbmPsdHit test2 {std::move(test)};
75 
76  comparePsdHitDataMembers(test2, 5, 6.7);
77 
78  // For objects with simple types move fall back to copy so
79  // the original object is kept unchanged
80  comparePsdHitDataMembers(test, 5, 6.7);
81 }
82 
83 TEST(_GTestCbmPsdHit, CheckAssignmentMoveConstructor) {
84  // Create object
85  CbmPsdHit test(5, 6.7);
86 
87  comparePsdHitDataMembers(test, 5, 6.7);
88 
89  // Create object by copy constructing
90  // test should be equal to test2 and
91  // test should not be changed
92  CbmPsdHit test2 {};
93  test2 = std::move(test);
94 
95  comparePsdHitDataMembers(test2, 5, 6.7);
96 
97  // For objects with simple types move fall back to copy so
98  // the original object is kept unchanged
99  comparePsdHitDataMembers(test, 5, 6.7);
100 }
101 
102 
103 TEST(_GTestCbmPsdHit, CheckPrint) {
104  // Create object
105  CbmPsdHit test(5, 6.7);
106 
107  comparePsdHitDataMembers(test, 5, 6.7);
108 
109  testing::internal::CaptureStdout();
110  test.Print("");
111  std::string output = testing::internal::GetCapturedStdout();
112 
113  EXPECT_STREQ("[INFO] module : 5 ELoss 6.7\n", output.c_str());
114 }
comparePsdHit.h
CbmPsdHit::Print
void Print(Option_t *="") const
Definition: CbmPsdHit.cxx:38
CbmPsdHit.h
TEST
TEST(_GTestCbmPsdHit, CheckDefaultConstructor)
Definition: _GTestCbmPsdHit.cxx:8
comparePsdHitDataMembers
void comparePsdHitDataMembers(CbmPsdHit &test, Int_t moduleid, Double_t edep)
Definition: comparePsdHit.h:4
CbmPsdHit
Definition: CbmPsdHit.h:20