1 /*
2 *
3 * Copyright (C) 2014-2017, OFFIS e.V.
4 * All rights reserved. See COPYRIGHT file for details.
5 *
6 * This software and supporting documentation were developed by
7 *
8 * OFFIS e.V.
9 * R&D Division Health
10 * Escherweg 2
11 * D-26121 Oldenburg, Germany
12 *
13 *
14 * Module: ofstd
15 *
16 * Author: Jan Schlamelcher
17 *
18 * Purpose: unit test for OFtuple
19 *
20 */
21
22 // Disable some warnings.
23 // We're testing if a tuple containing floats can be initialized from a tuple of
24 // ints, which is required by the standard. But this gives precision warnings
25 // on some compilers / at some settings and we don't want to see these warnings.
26 #ifdef __GNUG__
27 #pragma GCC diagnostic ignored "-Wconversion"
28 #elif defined(_MSC_VER)
29 #pragma warning(disable: 4244)
30 #endif
31
32 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
33
34 #define OFTEST_OFSTD_ONLY
35 #include "dcmtk/ofstd/oftest.h"
36 #include "dcmtk/ofstd/oftuple.h"
37 #include "dcmtk/ofstd/ofstring.h"
38
OFTEST(ofstd_tuple)39 OFTEST(ofstd_tuple)
40 {
41 OFtuple<int,OFBool,OFString> t0, t1( 3, OFFalse, "Hello World" ), t2, t3;
42
43 OFCHECK( (OFtuple_size<OFtuple<int,OFBool,const char*> >::value) == 3 );
44 OFCHECK( OFget<0>( t1 ) == 3 && !OFget<1>( t1 ) && OFget<2>( t1 ) == "Hello World" );
45 t0 = t1;
46 t2 = t3;
47 OFswap( t1, t3 );
48 OFCHECK( t3 == t0 && t1 == t2 );
49 t1.swap( t0 );
50 OFCHECK( t3 == t1 && t2 == t0 );
51
52 int i = 42;
53 OFBool b = OFTrue;
54 const char* cstr( "Thomas Theisman" );
55
56 t2 = OFtie( i, b, cstr );
57
58 OFCHECK( OFget<0>( t2 ) == 42 && OFget<1>( t2 ) && OFget<2>( t2 ) == "Thomas Theisman" );
59
60 OFString s;
61 OFtie( i, b, s ) = OFmake_tuple( 23, OFFalse, "Edward Saganami" );
62
63 OFCHECK( i == 23 && !b && s == "Edward Saganami" );
64
65 OFtuple<float,float,float,float> t4( 5.2f, 3.1f, 2.4f, 9.1f ), t5( OFmake_tuple( 4, 6, 9, 27 ) );
66
67 OFCHECK( t4 != t5 && t4 > t5 && t5 <= t4 && !( t4 == t5 ) );
68 t4 = t5;
69 OFCHECK( !( t4 < t5 ) && t4 <= t5 );
70
71 OFtie( OFignore, s ) = OFMake_pair( OFString( "Hello World" ), OFString( "My name is John" ) );
72 OFCHECK( s == "My name is John" );
73 }
74
75