libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
GetPotTest Class Reference
Inheritance diagram for GetPotTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (GetPotTest)
 
 CPPUNIT_TEST (testVariables)
 
 CPPUNIT_TEST (testSections)
 
 CPPUNIT_TEST (testSubSections)
 
 CPPUNIT_TEST (testCommandLine)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setup_inputfile ()
 
void setUp ()
 
void testVariables ()
 
void testSections ()
 
void testSubSections ()
 
void testCommandLine ()
 

Protected Attributes

std::stringstream inputfile
 
GetPot input
 

Detailed Description

Definition at line 11 of file getpot_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/4]

GetPotTest::CPPUNIT_TEST ( testCommandLine  )

◆ CPPUNIT_TEST() [2/4]

GetPotTest::CPPUNIT_TEST ( testSections  )

◆ CPPUNIT_TEST() [3/4]

GetPotTest::CPPUNIT_TEST ( testSubSections  )

◆ CPPUNIT_TEST() [4/4]

GetPotTest::CPPUNIT_TEST ( testVariables  )

◆ CPPUNIT_TEST_SUITE_END()

GetPotTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

GetPotTest::LIBMESH_CPPUNIT_TEST_SUITE ( GetPotTest  )

◆ setUp()

void GetPotTest::setUp ( )
inline

Definition at line 70 of file getpot_test.C.

71 {
72 this->setup_inputfile();
73 input.parse_input_stream(inputfile);
74 }
std::stringstream inputfile
Definition getpot_test.C:25
GetPot input
Definition getpot_test.C:27
void setup_inputfile()
Definition getpot_test.C:31

References inputfile, and setup_inputfile().

◆ setup_inputfile()

void GetPotTest::setup_inputfile ( )
inline

Definition at line 31 of file getpot_test.C.

32 {
33
34 const char* text =
35 "[Section1]\n"
36 "\n"
37 " var1 = '5.0'\n"
38 "\n"
39 " [./SubSection1]\n"
40 "\n"
41 " var2 = 'blah'\n"
42 "\n"
43 "[]\n"
44 "\n"
45 "[Section2]\n"
46 "\n"
47 " #var3 = '5'\n"
48 "\n"
49 " [./Subsection2]\n"
50 "\n"
51 " var4 = 'false'\n"
52 "\n"
53 " [./Subsection3]\n"
54 "\n"
55 " var5 = '6.02e23'\n"
56 "\n"
57 " [../../Subsection4]\n"
58 "\n"
59 " var6 = '42'\n"
60 "\n"
61 "[]\n"
62 "\n"
63 "[Section3]\n"
64 "\n"
65 " unused_var = 'not_used'\n";
66
67 inputfile << text;
68 }

References inputfile.

Referenced by setUp().

◆ testCommandLine()

void GetPotTest::testCommandLine ( )
inline

Definition at line 171 of file getpot_test.C.

172 {
173 LOG_UNIT_TEST;
174 // Test whether the new dash/underscore agnosticism works
175 //
176 // This means the unit_tests-foo executable *must* be run with
177 // options equivalent to the asserted ones and without options
178 // equivalent to the anti-asserted ones.
179 CPPUNIT_ASSERT(libMesh::on_command_line("--option-with-underscores"));
180 CPPUNIT_ASSERT(libMesh::on_command_line("--option_with_underscores"));
181 CPPUNIT_ASSERT(libMesh::on_command_line("--option-with-dashes"));
182 CPPUNIT_ASSERT(libMesh::on_command_line("--option_with_dashes"));
183 CPPUNIT_ASSERT(!libMesh::on_command_line("--option-with-lies"));
184 CPPUNIT_ASSERT(!libMesh::on_command_line("--option_with_lies"));
185 CPPUNIT_ASSERT_EQUAL(libMesh::command_line_next("--option-with-underscores", 2), 3);
186 CPPUNIT_ASSERT_EQUAL(libMesh::command_line_next("--option_with_underscores", 2), 3);
187 }
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
Definition libmesh.C:1025
bool on_command_line(std::string arg)
Definition libmesh.C:934

References libMesh::command_line_next(), and libMesh::on_command_line().

◆ testSections()

void GetPotTest::testSections ( )
inline

Definition at line 110 of file getpot_test.C.

111 {
112 LOG_UNIT_TEST;
113 // GetPot stores the '/' at the end of each section name
114 CPPUNIT_ASSERT(input.have_section("Section1/"));
115 CPPUNIT_ASSERT(input.have_section("Section1/SubSection1/"));
116 CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/"));
117 CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/Subsection3/"));
118 CPPUNIT_ASSERT(input.have_section("Section2/Subsection4/"));
119 CPPUNIT_ASSERT(input.have_section("Section3/"));
120
121 // But we don't need to supply the trailing '/'
122 CPPUNIT_ASSERT(input.have_section("Section1"));
123 CPPUNIT_ASSERT(input.have_section("Section1/SubSection1"));
124 CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/Subsection3"));
125
126 // No such thing as this section
127 CPPUNIT_ASSERT(!input.have_section("ImNotASection/"));
128 }

References input.

◆ testSubSections()

void GetPotTest::testSubSections ( )
inline

Definition at line 130 of file getpot_test.C.

131 {
132 LOG_UNIT_TEST;
133 typedef std::vector<std::string>::size_type sz;
134 typedef std::string str;
135
136 const std::vector<std::string> subsections1 =
137 input.get_subsection_names("Section1");
138
139 CPPUNIT_ASSERT_EQUAL(subsections1.size(), sz(1));
140 CPPUNIT_ASSERT_EQUAL(subsections1[0], str("SubSection1"));
141
142 const std::vector<std::string> subsections1_1 =
143 input.get_subsection_names("Section1/Subsection1");
144
145 CPPUNIT_ASSERT(subsections1_1.empty());
146
147 const std::vector<std::string> subsections2 =
148 input.get_subsection_names("Section2");
149
150 CPPUNIT_ASSERT_EQUAL(subsections2.size(), sz(2));
151 CPPUNIT_ASSERT_EQUAL(subsections2[0], str("Subsection2"));
152 CPPUNIT_ASSERT_EQUAL(subsections2[1], str("Subsection4"));
153
154 const std::vector<std::string> subsections2_2 =
155 input.get_subsection_names("Section2/Subsection2");
156
157 CPPUNIT_ASSERT_EQUAL(subsections2_2.size(), sz(1));
158 CPPUNIT_ASSERT_EQUAL(subsections2_2[0], str("Subsection3"));
159
160 const std::vector<std::string> subsections2_4 =
161 input.get_subsection_names("Section2/Subsection4");
162
163 CPPUNIT_ASSERT(subsections2_4.empty());
164
165 const std::vector<std::string> subsections3 =
166 input.get_subsection_names("Section3");
167
168 CPPUNIT_ASSERT(subsections3.empty());
169 }

References input.

◆ testVariables()

void GetPotTest::testVariables ( )
inline

Definition at line 76 of file getpot_test.C.

77 {
78 LOG_UNIT_TEST;
79 CPPUNIT_ASSERT( input.have_variable("Section1/var1") );
80 Real var1 = input("Section1/var1", 1.0);
81 CPPUNIT_ASSERT_EQUAL( var1, Real(5));
82
83 CPPUNIT_ASSERT( input.have_variable("Section1/SubSection1/var2") );
84 std::string var2 = input("Section1/SubSection1/var2", "DIE!");
85 CPPUNIT_ASSERT_EQUAL( var2, std::string("blah") );
86
87 // This variable is commented out in the input file so we shouldn't find it.
88 CPPUNIT_ASSERT( !input.have_variable("Section2/var3") );
89 int var3 = input("Section2/var3", 314);
90 CPPUNIT_ASSERT_EQUAL( var3, 314 );
91
92 CPPUNIT_ASSERT( input.have_variable("Section2/Subsection2/var4") );
93 bool var4 = input("Section2/Subsection2/var4", true);
94 CPPUNIT_ASSERT_EQUAL( var4, false );
95
96 CPPUNIT_ASSERT( input.have_variable("Section2/Subsection2/Subsection3/var5") );
97 Real var5 = input("Section2/Subsection2/Subsection3/var5", 3.1415);
98 CPPUNIT_ASSERT_EQUAL( var5, Real(6.02e23));
99
100 CPPUNIT_ASSERT( input.have_variable("Section2/Subsection4/var6") );
101 unsigned int var6 = input("Section2/Subsection4/var6", 21);
102 CPPUNIT_ASSERT_EQUAL(var6, static_cast<unsigned int>(42));
103
104 // We didn't use Section3/unused_var so it should be a UFO
105 std::vector<std::string> ufos = input.unidentified_variables();
106 CPPUNIT_ASSERT_EQUAL( ufos.size(), (std::vector<std::string>::size_type)1 );
107 CPPUNIT_ASSERT_EQUAL( ufos[0], std::string("Section3/unused_var") );
108 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References input, and libMesh::Real.

Member Data Documentation

◆ input

GetPot GetPotTest::input
protected

Definition at line 27 of file getpot_test.C.

Referenced by testSections(), testSubSections(), and testVariables().

◆ inputfile

std::stringstream GetPotTest::inputfile
protected

Definition at line 25 of file getpot_test.C.

Referenced by setUp(), and setup_inputfile().


The documentation for this class was generated from the following file: