FLAME  devel
 All Classes Functions Variables Typedefs Enumerations Pages
test_config.cpp
1 #define BOOST_TEST_MODULE config
2 #define BOOST_TEST_DYN_LINK
3 #include <boost/test/unit_test.hpp>
4 
5 #include <math.h>
6 
7 #include "flame/config.h"
8 
9 BOOST_AUTO_TEST_CASE(config_getset)
10 {
11  Config C;
12 
13  C.set<double>("hello", 4.2);
14 
15  BOOST_CHECK_CLOSE(C.get<double>("hello"), 4.2, 0.1);
16 
17  BOOST_CHECK_THROW(C.get<double>("world"), key_error);
18 
19  BOOST_CHECK_CLOSE(C.get<double>("world", 5.2), 5.2, 0.1);
20 }
21 
22 static const char config_print_stmt_input[] =
23 "X = 14;\n"
24 "print(X);\n"
25 "Y = \"test\";\n"
26 "print(Y);\n"
27 "foo : bar, x=\"y\";\n"
28 "baz : LINE = (foo);\n";
29 
30 BOOST_AUTO_TEST_CASE(config_print_stmt)
31 {
32  std::ostringstream strm;
33  GLPSParser parse;
34  parse.setPrinter(&strm);
35 
36  std::auto_ptr<Config> conf(parse.parse_byte(config_print_stmt_input, sizeof(config_print_stmt_input)-1));
37 
38  BOOST_CHECK_EQUAL(strm.str(), "On line 2 : 14\n" "On line 4 : \"test\"\n");
39 }
void setPrinter(std::ostream *)
Set output for lexer/parser error messages.
Definition: config.cpp:356
void set(const std::string &name, typename boost::call_traits< typename detail::is_config_value< T >::type >::param_type val)
Definition: config.h:175
Interface to lattice file parser.
Definition: config.h:240
Associative configuration container.
Definition: config.h:66
Config * parse_byte(const char *s, size_t len, const char *path=NULL)
Parse from byte buffer.
Definition: config.cpp:403