1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// *****************************************************************************
/*!
  \file      tests/unit/Base/TestPrintTaggedTuple.cpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Unit tests for TaggedTuple printer
*/
// *****************************************************************************

#include <sstream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "NoWarning/tut.hpp"<--- Include file: "NoWarning/tut.hpp" not found.

#include "TUTConfig.hpp"<--- Include file: "TUTConfig.hpp" not found.
#include "PrintTaggedTuple.hpp"

#ifndef DOXYGEN_GENERATING_OUTPUT

namespace tut {

//! All tests in group inherited from this base
struct PrintTaggedTuple_common {
  // Tags
  DEFTAG( name );
  DEFTAG( age );
  DEFTAG( email );
  DEFTAG( tag1 );
  DEFTAG( tag2 );
  DEFTAG( tag3 );

  using MemberList = brigand::list<
    name,  std::string,
    age,   int,
    email, std::string,
    tag1,  tk::TaggedTuple< brigand::list <
              tag2, std::string,
              tag3, std::string > > >;

  // Define a tagged tuple: odd template arguments are tags, even ones are types
  using record = tk::TaggedTuple< MemberList >;

  // Constructor
  PrintTaggedTuple_common() {
    tup.get< name >() = "Bob";
    tup.get< age >() = 32;
    tup.get< email >() = "bob@google.com";
    auto& t1 = tup.get< tag1 >();
    t1.get< tag2 >() = "string2";
    t1.get< tag3 >() = "string3";
  }

  record tup;
};

//! Test group shortcuts
using PrintTaggedTuple_group =
  test_group< PrintTaggedTuple_common, MAX_TESTS_IN_GROUP >;
using PrintTaggedTuple_object = PrintTaggedTuple_group::object;

//! Define test group
static PrintTaggedTuple_group PrintTaggedTuple( "Base/PrintTaggedTuple" );

//! Test definitions for group

//! Test operator<< of TaggedTuple
template<> template<>
void PrintTaggedTuple_object::test< 1 >() {
  set_test_name( "operator<<" );

  std::stringstream s;
  s << tup;
  ensure_equals( "operator<<(TaggedTuple)", s.str(), "name = Bob age = 32 "
    "email = bob@google.com tag1 = { tag2 = string2 tag3 = string3 } " );
}

//! Test print()
template<> template<>
void PrintTaggedTuple_object::test< 2 >() {
  set_test_name( "print()" );

  std::stringstream s;
  tk::print( s, tup );
  ensure_equals( "print()", s.str(), "name = Bob age = 32 "
    "email = bob@google.com tag1 = { tag2 = string2 tag3 = string3 } " );
}

} // tut::

#endif  // DOXYGEN_GENERATING_OUTPUT