25 #ifndef WSTRUCTUREDTEXTPARSER_TEST_H
26 #define WSTRUCTUREDTEXTPARSER_TEST_H
32 #include <cxxtest/TestSuite.h>
34 #include "../exceptions/WParseError.h"
35 #include "../exceptions/WFileNotFound.h"
36 #include "../exceptions/WNotFound.h"
37 #include "../exceptions/WTypeMismatch.h"
38 #include "../WStructuredTextParser.h"
51 using WStructuredTextParser::parseFromFile;
54 TS_ASSERT_THROWS_NOTHING( parseFromFile(
55 boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test.txt" )
58 TS_ASSERT_THROWS( parseFromFile(
59 boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test_invalid.txt" )
62 TS_ASSERT_THROWS( parseFromFile(
63 boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test_doesnotexist.txt" )
74 using WStructuredTextParser::StructuredValueTree;
77 StructuredValueTree t( boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test.txt" ) );
80 TS_ASSERT( t.exists(
"level0/level1/somekv" ) );
82 TS_ASSERT( t.exists(
"level0/level1/level2" ) );
84 TS_ASSERT( !t.exists(
"level0/level1/levelNotExists" ) );
86 TS_ASSERT( t.exists(
"level0/notuniquelevel1" ) );
88 TS_ASSERT( t.exists(
"level0/level1/somekv",
true ) );
89 TS_ASSERT( t.exists(
"level0/level1",
true ) );
90 TS_ASSERT( !t.exists(
"level0/notuniquelevel1",
true ) );
91 TS_ASSERT( t.exists(
"level0/notuniquelevel1/unique",
true ) );
94 TS_ASSERT( t.exists(
"anotherlevel0" ) );
95 TS_ASSERT( t.exists(
"anotherlevel0/avalue" ) );
98 TS_ASSERT( t.exists(
"fileLevelValue",
true ) );
99 TS_ASSERT( t.exists(
"filelevelvalue",
true ) );
102 TS_ASSERT( t.exists(
"Name With Spaces" ) );
103 TS_ASSERT( t.exists(
"Name With Spaces/akey",
true ) );
106 TS_ASSERT( t.count(
"level0/level1/somekv" ) == 1 );
108 TS_ASSERT( t.count(
"level0/level1/level2" ) == 1 );
109 TS_ASSERT( t.count(
"level0/level1/level2",
true ) == 0 );
112 TS_ASSERT( t.count(
"level0/level1/levelNotExists" ) == 0 );
114 TS_ASSERT( t.count(
"level0/notuniquelevel1" ) == 2 );
116 TS_ASSERT( t.count(
"level0/level1",
true ) == 1 );
117 TS_ASSERT( t.count(
"level0/level1" ) == 2 );
118 TS_ASSERT( t.count(
"level0/notuniquelevel1" ) == 2 );
119 TS_ASSERT( t.count(
"level0/notuniquelevel1",
true ) == 0 );
122 TS_ASSERT( t.count(
"filelevelvalue",
true ) == 1 );
123 TS_ASSERT( t.count(
"fileLevelValue",
true ) == 1 );
126 TS_ASSERT( t.count(
"Name With Spaces" ) == 1 );
127 TS_ASSERT( t.count(
"Name With Spaces/akey",
true ) == 1 );
135 using WStructuredTextParser::StructuredValueTree;
138 StructuredValueTree t( boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test.txt" ) );
143 TS_ASSERT_EQUALS( t.getValue< std::string >(
"level0/notuniquekv",
"default" ),
"hello hallo" );
145 TS_ASSERT( t.getValue< std::string >(
"level0/notuniquelevel1/somekv",
"default" ) ==
"abc" );
146 TS_ASSERT_EQUALS( t.getValue< std::string >(
"level0/uniquekv",
"default" ),
"hello" );
149 TS_ASSERT( t.getValue< std::string >(
"level0/notuniquelevel1/unique",
"default" ) ==
"yes" );
152 TS_ASSERT( t.getValue< std::string >(
"level0/notexists",
"default" ) ==
"default" );
155 TS_ASSERT( t.getValue< std::string >(
"level0/level1",
"default" ) ==
"something" );
158 TS_ASSERT( t.getValue< std::string >(
"anotherlevel0/avalue",
"default" ) ==
"hey" );
161 std::vector< std::string > defs;
163 TS_ASSERT( t.getValues< std::string >(
"level0/notuniquelevel1/somekv", defs ).size() == 2 );
164 TS_ASSERT( ( *t.getValues< std::string >(
"level0/notuniquelevel1/somekv", defs ).begin() ) ==
"abc" );
165 TS_ASSERT( ( *( t.getValues< std::string >(
"level0/notuniquelevel1/somekv", defs ).begin() + 1 ) ) ==
"def" );
168 TS_ASSERT( t.getValues< std::string >(
"level0/notexists", defs ).size() == 0 );
170 TS_ASSERT( t.getValues< std::string >(
"level0/notexists" ).size() == 0 );
173 TS_ASSERT_THROWS( t.operator[]< std::string >(
"level0/notexists" ),
const WNotFound& );
177 TS_ASSERT_THROWS( t.operator[]<
size_t >(
"level0/notuniquekv" ),
const WTypeMismatch& );
178 TS_ASSERT( t.operator[]<
size_t >(
"level0/level1/somekv" ) == 123 );
181 TS_ASSERT( t.getValues< std::string >(
"filelevelvalue", defs ).size() == 1 );
182 TS_ASSERT( t.getValues< std::string >(
"fileLevelValue", defs ).size() == 1 );
185 TS_ASSERT( t.getValue< std::string >(
"Name With Spaces/akey",
"nooo" ) ==
"value" );
193 using WStructuredTextParser::StructuredValueTree;
196 StructuredValueTree t( boost::filesystem::path( W_FIXTURE_PATH +
"WStructuredTextParser_test.txt" ) );
199 StructuredValueTree level0;
200 TS_ASSERT_THROWS_NOTHING( level0 = *( t.getSubTrees(
"level0" ).begin() ) );
201 TS_ASSERT( level0.count(
"uniquekv",
true ) == 1 );
203 std::vector< StructuredValueTree > v = level0.getSubTrees(
"notuniquelevel1" );
204 TS_ASSERT( v.size() == 2 );
Thrown whenever a file was not found.
Indicates invalid value which could not be found.
Indicates invalid input in a parser.
Test parsing and query functionality.
void testSubTreeQuery()
Test the getSubTree functionality.
void testQuery()
This method tests the basic query features of WStructuredTextParser::StructuredValueTree.
void testEmptyAndCount()
This method test the basic empty and count features of WStructuredTextParser::StructuredValueTree.
void testParseFromFile()
Test whether the parser loads the file and handles invalid files.
Indicates invalid type of something.