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
// *****************************************************************************
/*!
  \file      tests/unit/Control/TestStringParser.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 Control/StringParser
  \details   Unit tests for Control/StringParser
*/
// *****************************************************************************

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

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

#ifndef DOXYGEN_GENERATING_OUTPUT

namespace tut {

//! All tests in group inherited from this base
struct StringParser_common {
  // tk::StringParser only has a protected constructor: designed to be used as a
  // base class
  struct parser : tk::StringParser {
    explicit parser( const std::string& f ) : StringParser( f ) {}
    explicit parser( int argc, char** argv ) : StringParser( argc, argv ) {}
    const std::string& string() const { return m_string; }
  };
};

//! Test group shortcuts
using StringParser_group =
  test_group< StringParser_common, MAX_TESTS_IN_GROUP >;
using StringParser_object = StringParser_group::object;

//! Define test group
static StringParser_group StringParser( "Control/StringParser" );

//! Test definitions for group

//! Test if constructor stores string passed in as std::string
template<> template<>
void StringParser_object::test< 1 >() {
  set_test_name( "ctor stores string passed in" );

  parser p( "blah" );
  ensure_equals( "string passed in doesn't match", p.string(), "blah" );
}

//! Test if constructor stores string passed in as argc, argv
template<> template<>
void StringParser_object::test< 2 >() {
  set_test_name( "ctor stores argc,argv passed in" );

  int argc = 3;
  char s1[] = "executable";
  char s2[] = "banana";
  char s3[] = "apple";
  char* argv[] = { s1, s2, s3 };
  parser p( argc, argv );
  // Constructor ignores argv[0]
  ensure_equals( "string passed in doesn't match", p.string(), "banana apple " );
}

} // tut::

#endif  // DOXYGEN_GENERATING_OUTPUT