Classes | Namespaces | Macros | Functions
DumpUtils_test.cc File Reference

Unit test for utilities in DumpUtils.h. More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/DumpUtils.h"
#include <TVector3.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <array>
#include <sstream>

Go to the source code of this file.

Classes

struct  lar::dump::VectorDumper< std::array< T, 3U > >
 

Namespaces

 lar
 LArSoft-specific namespace.
 
 lar::dump
 Namespace for LArSoft dumping utilities.
 

Macros

#define BOOST_TEST_MODULE   DumpUtils_test
 

Functions

void ArrayTest_STLarray ()
 
void ArrayTest_STLvector ()
 
void ArrayTest_carray ()
 
void ArrayTest_cptr ()
 
void ArrayTest_array ()
 
void ArrayTest_ptr ()
 
void ArrayTest ()
 
void ArrayDocumentationTest ()
 
void VectorTest_STLvector ()
 
void VectorTest_STLlist ()
 
void VectorTest ()
 
void VectorDocumentationTest ()
 
void Vector3Dtest_TVector3 ()
 
void Vector3Dtest_carray ()
 
void Vector3Dtest_cptr ()
 
void Vector3Dtest_array ()
 
void Vector3Dtest_ptr ()
 
void Vector3Dtest ()
 
void Vector3DstreamOutputDocumentationTest ()
 
void Vector3DstringConcatDocumentationTest ()
 
void Vector3DstringAppendDocumentationTest ()
 
void Vector3DdocumentationTest ()
 
void Vector3DspecializationTest ()
 
 BOOST_AUTO_TEST_CASE (DumpArrays_testcase)
 
 BOOST_AUTO_TEST_CASE (DumpVectors_testcase)
 
 BOOST_AUTO_TEST_CASE (Dump3Dvectors_testcase)
 

Detailed Description

Unit test for utilities in DumpUtils.h.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
February 28, 2017

Definition in file DumpUtils_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   DumpUtils_test

Definition at line 11 of file DumpUtils_test.cc.

Function Documentation

void ArrayDocumentationTest ( )

Definition at line 99 of file DumpUtils_test.cc.

99  {
100 
101  std::ostringstream sstr;
102 
103  /* This is the code as in the documentation:
104  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
105  * double const data[5] = { 1., 2., 3., 4., 6. };
106  * std::cout << "Data: " << lar::dump::array<5>(data) << std::endl;
107  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108  * which is promised to return:
109  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110  * Data: { 1; 2; 3; 4; 6 }
111  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112  */
113 
114  double const data[5] = { 1., 2., 3., 4., 6. };
115  std::cout << "Data: " << lar::dump::array<5>(data) << std::endl;
116 
117  sstr << lar::dump::array<5>(data);
118  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
119 
120 } // ArrayDocumentationTest()
QTextStream & endl(QTextStream &s)
void ArrayTest ( )

Definition at line 86 of file DumpUtils_test.cc.

86  {
87 
92  ArrayTest_ptr();
94 
95 } // ArrayTest()
void ArrayTest_STLvector()
void ArrayTest_ptr()
void ArrayTest_STLarray()
void ArrayTest_cptr()
void ArrayTest_array()
void ArrayTest_carray()
void ArrayTest_array ( )

Definition at line 68 of file DumpUtils_test.cc.

68  {
69  std::ostringstream sstr;
70  double array[5] = { 1., 2., 3., 4., 6. };
71  sstr << lar::dump::array<5>(array);
72  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
73  BOOST_TEST
74  (std::string(lar::dump::array<5>(array)) == "{ 1; 2; 3; 4; 6 }");
75 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void ArrayTest_carray ( )

Definition at line 50 of file DumpUtils_test.cc.

50  {
51  std::ostringstream sstr;
52  float const array[5] = { 1., 2., 3., 4., 6. };
53  sstr << lar::dump::array<5>(array);
54  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
55  BOOST_TEST
56  (std::string(lar::dump::array<5>(array)) == "{ 1; 2; 3; 4; 6 }");
57 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void ArrayTest_cptr ( )

Definition at line 59 of file DumpUtils_test.cc.

59  {
60  std::ostringstream sstr;
61  float const array[5] = { 1., 2., 3., 4., 6. };
62  float const* ptr = array;
63  sstr << lar::dump::array<5>(ptr);
64  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
65  BOOST_TEST(std::string(lar::dump::array<5>(ptr)) == "{ 1; 2; 3; 4; 6 }");
66 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void ArrayTest_ptr ( )

Definition at line 77 of file DumpUtils_test.cc.

77  {
78  std::ostringstream sstr;
79  double array[5] = { 1., 2., 3., 4., 6. };
80  double* ptr = array;
81  sstr << lar::dump::array<5>(ptr);
82  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
83  BOOST_TEST(std::string(lar::dump::array<5>(ptr)) == "{ 1; 2; 3; 4; 6 }");
84 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void ArrayTest_STLarray ( )

Definition at line 30 of file DumpUtils_test.cc.

30  {
31  std::ostringstream sstr;
32  // BUG the double brace syntax is required to work around clang bug 21629
33  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
34  std::array<float, 5> const array = {{ 1., 2., 3., 4., 6. }};
35  sstr << lar::dump::array<5>(array);
36  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
37  BOOST_TEST
38  (std::string(lar::dump::array<5>(array)) == "{ 1; 2; 3; 4; 6 }");
39 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void ArrayTest_STLvector ( )

Definition at line 41 of file DumpUtils_test.cc.

41  {
42  std::ostringstream sstr;
43  std::vector<float> const array = { 1., 2., 3., 4., 6. };
44  sstr << lar::dump::array<5>(array);
45  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
46  BOOST_TEST
47  (std::string(lar::dump::array<5>(array)) == "{ 1; 2; 3; 4; 6 }");
48 }
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
BOOST_AUTO_TEST_CASE ( DumpArrays_testcase  )

Definition at line 357 of file DumpUtils_test.cc.

357  {
358 
359  ArrayTest();
360 
362 
363 } // BOOST_AUTO_TEST_CASE(DumpArrays_testcase)
void ArrayTest()
void ArrayDocumentationTest()
BOOST_AUTO_TEST_CASE ( DumpVectors_testcase  )

Definition at line 366 of file DumpUtils_test.cc.

366  {
367 
368  VectorTest();
369 
371 
372 } // BOOST_AUTO_TEST_CASE(DumpVectors_testcase)
void VectorDocumentationTest()
void VectorTest()
BOOST_AUTO_TEST_CASE ( Dump3Dvectors_testcase  )

Definition at line 375 of file DumpUtils_test.cc.

375  {
376 
377  Vector3Dtest();
378 
380 
382 
383 } // BOOST_AUTO_TEST_CASE(Dump3Dvectors_testcase)
void Vector3Dtest()
void Vector3DdocumentationTest()
void Vector3DspecializationTest()
void Vector3DdocumentationTest ( )

Definition at line 308 of file DumpUtils_test.cc.

308  {
312 } // Vector3DdocumentationTest()
void Vector3DstringAppendDocumentationTest()
void Vector3DstringConcatDocumentationTest()
void Vector3DstreamOutputDocumentationTest()
void Vector3DspecializationTest ( )

Definition at line 343 of file DumpUtils_test.cc.

343  {
344 
345  std::ostringstream sstr;
346 
347  std::array<float, 3U> v;
348  v.fill(0.0);
349  sstr << lar::dump::vector3D(v);
350  BOOST_TEST(sstr.str() == "{ 0; 0; 0 }");
351 
352 } // Vector3DspecializationTest()
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
void Vector3DstreamOutputDocumentationTest ( )

Definition at line 232 of file DumpUtils_test.cc.

232  {
233 
234  std::ostringstream sstr;
235 
236  /* This is the code as in the documentation:
237  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
238  * TVector3 pos;
239  * std::cout << "Position: " << lar::dump::vector3D(pos) << std::endl;
240  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241  * which is promised to return:
242  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243  * Position: { 0, 0, 0 }
244  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245  */
246 
247  TVector3 pos;
248  std::cout << "Position: " << lar::dump::vector3D(pos) << std::endl;
249 
250  sstr << lar::dump::vector3D(pos);
251  BOOST_TEST(sstr.str() == "{ 0; 0; 0 }");
252 
253 } // Vector3DstreamOutputDocumentationTest()
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
QTextStream & endl(QTextStream &s)
void Vector3DstringAppendDocumentationTest ( )

Definition at line 281 of file DumpUtils_test.cc.

281  {
282 
283  std::ostringstream sstr;
284 
285  /* This is the code that should have been in the documentation:
286  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
287  * TVector3 pos;
288  * std::string s = "Position: ";
289  * s += lar::dump::vector3D(pos);
290  * std::cout << s << std::endl;
291  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292  * which is promised to return:
293  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
294  * Position: { 0, 0, 0 }
295  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296  */
297 
298  TVector3 pos;
299  std::string s = "Position: ";
300  s += lar::dump::vector3D(pos);
301  std::cout << s << std::endl;
302 
303  BOOST_TEST(s == "Position: { 0; 0; 0 }");
304 
305 } // Vector3DstringAppendDocumentationTest()
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
void Vector3DstringConcatDocumentationTest ( )

Definition at line 256 of file DumpUtils_test.cc.

256  {
257 
258  std::ostringstream sstr;
259 
260  /* This is the code as in the documentation:
261  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
262  * TVector3 pos;
263  * std::runtime_error e("Position: " + lar::dump::vector3D(pos));
264  * std::cout << e.what() << std::endl;
265  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266  * which is promised to return:
267  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268  * Position: { 0, 0, 0 }
269  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270  */
271 
272  TVector3 pos;
273  std::runtime_error e("Position: " + lar::dump::vector3D(pos));
274  std::cout << e.what() << std::endl;
275 
276  BOOST_TEST(std::string(e.what()) == "Position: { 0; 0; 0 }");
277 
278 } // Vector3DstringConcatDocumentationTest()
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
const double e
QTextStream & endl(QTextStream &s)
void Vector3Dtest ( )

Definition at line 220 of file DumpUtils_test.cc.

220  {
221 
227 
228 } // Vector3Dtest()
void Vector3Dtest_cptr()
void Vector3Dtest_TVector3()
void Vector3Dtest_carray()
void Vector3Dtest_ptr()
void Vector3Dtest_array()
void Vector3Dtest_array ( )

Definition at line 202 of file DumpUtils_test.cc.

202  {
203  std::ostringstream sstr;
204  double array[3] = { 1., 2., 4. };
205  sstr << lar::dump::vector3D(array);
206  BOOST_TEST(sstr.str() == "{ 1; 2; 4 }");
207  BOOST_TEST(std::string(lar::dump::vector3D(array)) == "{ 1; 2; 4 }");
208 }
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void Vector3Dtest_carray ( )

Definition at line 185 of file DumpUtils_test.cc.

185  {
186  std::ostringstream sstr;
187  float const array[3] = { 1., 2., 4. };
188  sstr << lar::dump::vector3D(array);
189  BOOST_TEST(sstr.str() == "{ 1; 2; 4 }");
190  BOOST_TEST(std::string(lar::dump::vector3D(array)) == "{ 1; 2; 4 }");
191 }
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void Vector3Dtest_cptr ( )

Definition at line 193 of file DumpUtils_test.cc.

193  {
194  std::ostringstream sstr;
195  float const array[3] = { 1., 2., 4. };
196  float const* ptr = array;
197  sstr << lar::dump::vector3D(ptr);
198  BOOST_TEST(sstr.str() == "{ 1; 2; 4 }");
199  BOOST_TEST(std::string(lar::dump::vector3D(ptr)) == "{ 1; 2; 4 }");
200 }
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void Vector3Dtest_ptr ( )

Definition at line 210 of file DumpUtils_test.cc.

210  {
211  std::ostringstream sstr;
212  double array[3] = { 1., 2., 4. };
213  double* ptr = array;
214  sstr << lar::dump::vector3D(ptr);
215  BOOST_TEST(sstr.str() == "{ 1; 2; 4 }");
216  BOOST_TEST(std::string(lar::dump::vector3D(ptr)) == "{ 1; 2; 4 }");
217 }
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
void Vector3Dtest_TVector3 ( )

Definition at line 177 of file DumpUtils_test.cc.

177  {
178  std::ostringstream sstr;
179  TVector3 pos( 1., 2., 4. );
180  sstr << lar::dump::vector3D(pos);
181  BOOST_TEST(sstr.str() == "{ 1; 2; 4 }");
182  BOOST_TEST(std::string(lar::dump::vector3D(pos)) == "{ 1; 2; 4 }");
183 }
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
std::string string
Definition: nybbler.cc:12
void VectorDocumentationTest ( )

Definition at line 151 of file DumpUtils_test.cc.

151  {
152 
153  std::ostringstream sstr;
154 
155  /* This is the code as in the documentation:
156  *
157  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
158  * std::vector<double> data = { 1., 2., 3., 4., 6. };
159  * std::cout << "Data: " << lar::dump::vector(data) << std::endl;
160  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161  * which is promised to return:
162  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163  * Data: { 1; 2; 3; 4; 6 }
164  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165  */
166 
167  std::vector<double> data = { 1., 2., 3., 4., 6. };
168  std::cout << "Data: " << lar::dump::vector(data) << std::endl;
169 
170  sstr << lar::dump::array<5>(data);
171  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
172 
173 } // VectorDocumentationTest()
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
QTextStream & endl(QTextStream &s)
void VectorTest ( )

Definition at line 142 of file DumpUtils_test.cc.

142  {
143 
146 
147 } // VectorTest()
void VectorTest_STLvector()
void VectorTest_STLlist()
void VectorTest_STLlist ( )

Definition at line 133 of file DumpUtils_test.cc.

133  {
134  std::ostringstream sstr;
135  std::list<float> const v = { 1., 2., 3., 4., 6. };
136  sstr << lar::dump::vector(v);
137  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
138  BOOST_TEST
139  (std::string(lar::dump::vector(v)) == "{ 1; 2; 3; 4; 6 }");
140 } // VectorTest_STLlist()
std::string string
Definition: nybbler.cc:12
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void VectorTest_STLvector ( )

Definition at line 124 of file DumpUtils_test.cc.

124  {
125  std::ostringstream sstr;
126  std::vector<float> const v = { 1., 2., 3., 4., 6. };
127  sstr << lar::dump::vector(v);
128  BOOST_TEST(sstr.str() == "{ 1; 2; 3; 4; 6 }");
129  BOOST_TEST
130  (std::string(lar::dump::vector(v)) == "{ 1; 2; 3; 4; 6 }");
131 } // VectorTest_STLvector()
std::string string
Definition: nybbler.cc:12
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265