Scarab  v2.9.1
Project 8 C++ Utility Library
test_yaml.cc
Go to the documentation of this file.
1 /*
2  * test_yaml.cc
3  *
4  * Created on: Jan 19, 2016
5  * Author: bidishasen97
6  *
7  * Usage: test_yaml [filename]
8  */
9 
10 #include "param.hh"
11 #include "param_yaml.hh"
12 #include "logger.hh"
13 
14 using namespace scarab;
15 
16 LOGGER( slog, "test_yaml" );
17 
18 int main( int argc, char** argv )
19 {
20  if( argc < 2 )
21  {
22  LERROR( slog, "Please provide the test YAML file to be read: test_yaml.yaml" );
23  return -1;
24  }
25 
26  //read file
27  param_input_yaml t_input;
28  param_ptr_t t_param_location( t_input.read_file( argv[1] ) );
29  if( ! t_param_location )
30  {
31  LERROR( slog, "File did not read!" );
32  return -1;
33  }
34 
35  LINFO( slog, "File read and parsed: \n" << *t_param_location );
36 
37  LINFO( slog, "Checking types" );
38  if( ! t_param_location->is_node() )
39  {
40  LERROR( slog, "Top level is not a node" );
41  }
42  else
43  {
44  const param_node& t_top = t_param_location->as_node();
45  if( ! t_top["array"].is_array() )
46  {
47  LERROR( slog, "\"array\" is not an array" );
48  }
49  if( ! t_top["node"].is_node() )
50  {
51  LERROR( slog, "\"node\" is not a node" );
52  }
53  if( ! t_top["value-bool"].is_value() )
54  {
55  LERROR( slog, "\"value-bool\" is not a value" );
56  }
57  else
58  {
59  if( ! t_top["value-bool"]().is_bool() )
60  {
61  LERROR( slog, "\"value-bool\" is not bool" );
62  }
63  }
64  if( ! t_top["value-float"].is_value() )
65  {
66  LERROR( slog, "\"value-float\" is not a value" );
67  }
68  else
69  {
70  if( ! t_top["value-float"]().is_double() )
71  {
72  LERROR( slog, "\"value-float\" is not float" );
73  }
74  }
75  if( ! t_top["value-int"].is_value() )
76  {
77  LERROR( slog, "\"value-int\" is not a value" );
78  }
79  else
80  {
81  if( ! t_top["value-int"]().is_int() )
82  {
83  LERROR( slog, "\"value-int\" is not int" );
84  }
85  }
86  if( ! t_top["value-string"].is_value() )
87  {
88  LERROR( slog, "\"value-string\" is not a value" );
89  }
90  else
91  {
92  if( ! t_top["value-string"]().is_string() )
93  {
94  LERROR( slog, "\"value-string\" is not string" );
95  }
96  }
97  if( ! t_top["value-unsigned"].is_value() )
98  {
99  LERROR( slog, "\"value-unsigned\" is not a value" );
100  }
101  else
102  {
103  if( ! t_top["value-unsigned"]().is_uint() )
104  {
105  LERROR( slog, "\"value-unsigned\" is not unsigned" );
106  }
107  }
108  LINFO( slog, "If there were no errors, then the type tests passed" );
109  }
110 
111 
112  //write file
113  param_output_yaml t_output;
114  bool t_did_write_file = t_output.write_file( *t_param_location, "test_output.yaml" );
115 
116  if( ! t_did_write_file )
117  {
118  LERROR( slog, "File did not write!" );
119  return -1;
120  }
121 
122  LINFO( slog, "File written successfully (test_output.yaml)" );
123  return 0;
124 }
virtual param_ptr_t read_file(const std::string &a_filename, const param_node &a_options=param_node())
Definition: param_yaml.cc:33
LOGGER(mtlog, "authentication")
#define LERROR(...)
Definition: logger.hh:370
virtual bool write_file(const param &a_to_write, const std::string &a_filename, const param_node &a_options=param_node())
Definition: param_yaml.cc:184
Contains the logger class and macros, based on Kasper&#39;s KLogger class.
Convert Param to YAML.
Definition: param_yaml.hh:62
#define LINFO(...)
Definition: logger.hh:367
Convert YAML to Param.
Definition: param_yaml.hh:34
std::unique_ptr< param > param_ptr_t
Definition: param_base.hh:23
param_node & as_node()
int main(int argc, char **argv)
Definition: test_yaml.cc:18