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

Public Member Functions

 CPPUNIT_TEST_SUITE (GetPotTest)
 
 CPPUNIT_TEST (testVariables)
 
 CPPUNIT_TEST (testSections)
 
 CPPUNIT_TEST (testSubSections)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setup_inputfile ()
 
void setUp ()
 
void testVariables ()
 
void testSections ()
 
void testSubSections ()
 

Protected Attributes

std::stringstream inputfile
 
GetPot input
 

Detailed Description

Definition at line 21 of file getpot_test.C.

Member Function Documentation

GetPotTest::CPPUNIT_TEST ( testVariables  )
GetPotTest::CPPUNIT_TEST ( testSections  )
GetPotTest::CPPUNIT_TEST ( testSubSections  )
GetPotTest::CPPUNIT_TEST_SUITE ( GetPotTest  )
GetPotTest::CPPUNIT_TEST_SUITE_END ( )
void GetPotTest::setUp ( )

Definition at line 79 of file getpot_test.C.

80  {
81  this->setup_inputfile();
82  input.parse_input_stream(inputfile);
83  }
std::stringstream inputfile
Definition: getpot_test.C:34
void setup_inputfile()
Definition: getpot_test.C:40
GetPot input
Definition: getpot_test.C:36
void GetPotTest::setup_inputfile ( )

Definition at line 40 of file getpot_test.C.

41  {
42 
43  const char* text =
44  "[Section1]\n"
45  "\n"
46  " var1 = '5.0'\n"
47  "\n"
48  " [./SubSection1]\n"
49  "\n"
50  " var2 = 'blah'\n"
51  "\n"
52  "[]\n"
53  "\n"
54  "[Section2]\n"
55  "\n"
56  " #var3 = '5'\n"
57  "\n"
58  " [./Subsection2]\n"
59  "\n"
60  " var4 = 'false'\n"
61  "\n"
62  " [./Subsection3]\n"
63  "\n"
64  " var5 = '6.02e23'\n"
65  "\n"
66  " [../../Subsection4]\n"
67  "\n"
68  " var6 = '42'\n"
69  "\n"
70  "[]\n"
71  "\n"
72  "[Section3]\n"
73  "\n"
74  " unused_var = 'not_used'\n";
75 
76  inputfile << text;
77  }
std::stringstream inputfile
Definition: getpot_test.C:34
void GetPotTest::testSections ( )

Definition at line 118 of file getpot_test.C.

119  {
120  // GetPot stores the '/' at the end of each section name
121  CPPUNIT_ASSERT(input.have_section("Section1/"));
122  CPPUNIT_ASSERT(input.have_section("Section1/SubSection1/"));
123  CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/"));
124  CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/Subsection3/"));
125  CPPUNIT_ASSERT(input.have_section("Section2/Subsection4/"));
126  CPPUNIT_ASSERT(input.have_section("Section3/"));
127 
128  // But we don't need to supply the trailing '/'
129  CPPUNIT_ASSERT(input.have_section("Section1"));
130  CPPUNIT_ASSERT(input.have_section("Section1/SubSection1"));
131  CPPUNIT_ASSERT(input.have_section("Section2/Subsection2/Subsection3"));
132 
133  // No such thing as this section
134  CPPUNIT_ASSERT(!input.have_section("ImNotASection/"));
135  }
GetPot input
Definition: getpot_test.C:36
void GetPotTest::testSubSections ( )

Definition at line 137 of file getpot_test.C.

References CPPUNIT_TEST_SUITE_REGISTRATION().

138  {
139  typedef std::vector<std::string>::size_type sz;
140  typedef std::string str;
141 
142  const std::vector<std::string> subsections1 =
143  input.get_subsection_names("Section1");
144 
145  CPPUNIT_ASSERT_EQUAL(subsections1.size(), sz(1));
146  CPPUNIT_ASSERT_EQUAL(subsections1[0], str("SubSection1"));
147 
148  const std::vector<std::string> subsections1_1 =
149  input.get_subsection_names("Section1/Subsection1");
150 
151  CPPUNIT_ASSERT(subsections1_1.empty());
152 
153  const std::vector<std::string> subsections2 =
154  input.get_subsection_names("Section2");
155 
156  CPPUNIT_ASSERT_EQUAL(subsections2.size(), sz(2));
157  CPPUNIT_ASSERT_EQUAL(subsections2[0], str("Subsection2"));
158  CPPUNIT_ASSERT_EQUAL(subsections2[1], str("Subsection4"));
159 
160  const std::vector<std::string> subsections2_2 =
161  input.get_subsection_names("Section2/Subsection2");
162 
163  CPPUNIT_ASSERT_EQUAL(subsections2_2.size(), sz(1));
164  CPPUNIT_ASSERT_EQUAL(subsections2_2[0], str("Subsection3"));
165 
166  const std::vector<std::string> subsections2_4 =
167  input.get_subsection_names("Section2/Subsection4");
168 
169  CPPUNIT_ASSERT(subsections2_4.empty());
170 
171  const std::vector<std::string> subsections3 =
172  input.get_subsection_names("Section3");
173 
174  CPPUNIT_ASSERT(subsections3.empty());
175  }
GetPot input
Definition: getpot_test.C:36
void GetPotTest::testVariables ( )

Definition at line 85 of file getpot_test.C.

References libMesh::Real.

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

Member Data Documentation

GetPot GetPotTest::input
protected

Definition at line 36 of file getpot_test.C.

std::stringstream GetPotTest::inputfile
protected

Definition at line 34 of file getpot_test.C.


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