MOAB: Mesh Oriented datABase  (version 5.5.0)
fileopts_test.cpp File Reference
#include "moab/FileOptions.hpp"
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
+ Include dependency graph for fileopts_test.cpp:

Go to the source code of this file.

Macros

#define CHECK(A)
 
#define EQUAL(A, B)
 

Functions

int main ()
 

Macro Definition Documentation

◆ CHECK

#define CHECK (   A)
Value:
if( MB_SUCCESS != ( A ) ) \
{ \
std::cerr << "Failure at line " << __LINE__ << ": error code " << ( A ) << std::endl; \
return 1; \
}

Definition at line 31 of file fileopts_test.cpp.

◆ EQUAL

#define EQUAL (   A,
 
)
Value:
if( ( A ) != ( B ) ) \
{ \
std::cerr << "Failure at line " << __LINE__ << ": expected " << ( B ) << " but got " << ( A ) << std::endl; \
return 2; \
}

Definition at line 38 of file fileopts_test.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 45 of file fileopts_test.cpp.

46 {
47  FileOptions tool( "INT1=1;NUL1;STR1=ABC;DBL1=1.0;dbl2=2.0;DBL3=3.0;INT2=2;nul2;NUL3;INT3=3;str2=once upon a "
48  "time;str3==fubar=;;INTS=1-3,5,6;DBLS=1.0,2.0, 3.0;STRS=var1, var2_var2;STRS2=" );
49 
50  std::string s;
51  int i;
52  double d;
53  ErrorCode rval;
54 
55  // test basic get_option method without deleting entry
56  rval = tool.get_option( "STR1", s );
57  CHECK( rval );
58  EQUAL( s, "ABC" );
59 
60  // test basic get_option method again, this time deleting the entry
61  rval = tool.get_option( "STR1", s );
62  CHECK( rval );
63  EQUAL( s, "ABC" );
64 
65  // test basig get_option method with a null option
66  rval = tool.get_option( "NUL2", s );
67  CHECK( rval );
68  EQUAL( s.empty(), true );
69 
70  // test null option
71  rval = tool.get_null_option( "nul1" );
72  CHECK( rval );
73 
74  // try null option method on non-null value
75  rval = tool.get_null_option( "INT1" );
76  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
77 
78  // test integer option
79  rval = tool.get_int_option( "int1", i );
80  CHECK( rval );
81  EQUAL( i, 1 );
82 
83  rval = tool.get_int_option( "int2", i );
84  CHECK( rval );
85  EQUAL( i, 2 );
86 
87  // test integer option on non-integer value
88  rval = tool.get_int_option( "dbl2", i );
89  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
90 
91  // test integer option on null value
92  rval = tool.get_int_option( "NUL3", i );
93  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
94 
95  // test double option
96  rval = tool.get_real_option( "dbl1", d );
97  CHECK( rval );
98  EQUAL( d, 1.0 );
99 
100  rval = tool.get_real_option( "dbl2", d );
101  CHECK( rval );
102  EQUAL( d, 2.0 );
103 
104  rval = tool.get_real_option( "int3", d );
105  CHECK( rval );
106  EQUAL( d, 3.0 );
107 
108  // test real option on non-real value
109  rval = tool.get_real_option( "str2", d );
110  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
111 
112  // test real option on null value
113  rval = tool.get_real_option( "NUL3", d );
114  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
115 
116  // test get a simple string option
117  rval = tool.get_str_option( "DBL3", s );
118  CHECK( rval );
119  EQUAL( s, "3.0" );
120 
121  // test get a string with spaces
122  rval = tool.get_str_option( "STR2", s );
123  CHECK( rval );
124  EQUAL( s, "once upon a time" );
125 
126  // try to get a string value for a null option
127  rval = tool.get_str_option( "nul3", s );
128  EQUAL( rval, MB_TYPE_OUT_OF_RANGE );
129 
130  // We haven't looked at all of the options yet
131  EQUAL( false, tool.all_seen() );
132  rval = tool.get_unseen_option( s );
133  CHECK( rval );
134  EQUAL( s, "str3" );
135 
136  // test options using generic get_option method
137 
138  rval = tool.get_option( "NUL3", s );
139  CHECK( rval );
140  EQUAL( s.empty(), true );
141 
142  rval = tool.get_option( "STR3", s );
143  CHECK( rval );
144  EQUAL( s, "=fubar=" );
145 
146  // test size of options string
147  unsigned l = tool.size();
148  EQUAL( l, 16u );
149 
150  // test ints option
151  std::vector< int > ivals;
152  rval = tool.get_ints_option( "INTS", ivals );
153  CHECK( rval );
154  EQUAL( 5, ivals.size() );
155  EQUAL( 1, ivals[0] );
156  EQUAL( 2, ivals[1] );
157  EQUAL( 3, ivals[2] );
158  EQUAL( 5, ivals[3] );
159  EQUAL( 6, ivals[4] );
160 
161  // test dbls option
162  std::vector< double > vals;
163  rval = tool.get_reals_option( "DBLS", vals );
164  CHECK( rval );
165  EQUAL( 3, vals.size() );
166  EQUAL( 1.0, vals[0] );
167  EQUAL( 2.0, vals[1] );
168  EQUAL( 3.0, vals[2] );
169 
170  // test strs option
171  std::vector< std::string > svals;
172  rval = tool.get_strs_option( "STRS", svals );
173  CHECK( rval );
174  EQUAL( 2, svals.size() );
175  EQUAL( "var1", svals[0] );
176  EQUAL( "var2_var2", svals[1] );
177 
178  svals.clear();
179  rval = tool.get_strs_option( "STRS2", svals );
180  EQUAL( MB_TYPE_OUT_OF_RANGE, rval );
181 
182  // We requested every option
183  EQUAL( true, tool.all_seen() );
184  rval = tool.get_unseen_option( s );
185  EQUAL( MB_ENTITY_NOT_FOUND, rval );
186 
187  // test alternate separator
188 
189  FileOptions tool2( ";+OPT1=ABC+OPT2=" );
190  l = tool2.size();
191  EQUAL( l, 2 );
192 
193  // We haven't looked at all of the options yet
194  EQUAL( false, tool2.all_seen() );
195  rval = tool2.get_unseen_option( s );
196  CHECK( rval );
197  EQUAL( s, "OPT1" );
198 
199  rval = tool2.get_option( "opt1", s );
200  CHECK( rval );
201  EQUAL( s, "ABC" );
202 
203  rval = tool2.get_option( "opt2", s );
204  CHECK( rval );
205  bool e = s.empty();
206  EQUAL( e, true );
207 
208  l = tool2.size();
209  EQUAL( l, 2 );
210 
211  // We requested every option
212  EQUAL( true, tool2.all_seen() );
213  rval = tool2.get_unseen_option( s );
214  EQUAL( MB_ENTITY_NOT_FOUND, rval );
215 
216  // test empty options string
217 
218  FileOptions tool3( ";;;;" );
219  e = tool3.empty();
220  EQUAL( e, true );
221  l = tool3.size();
222  EQUAL( l, 0 );
223  EQUAL( true, tool3.all_seen() );
224 
225  FileOptions tool4( NULL );
226  e = tool4.empty();
227  EQUAL( e, true );
228  l = tool4.size();
229  EQUAL( l, 0 );
230  EQUAL( true, tool4.all_seen() );
231 
232  FileOptions tool5( ";+" );
233  e = tool5.empty();
234  EQUAL( e, true );
235  l = tool5.size();
236  EQUAL( l, 0 );
237  EQUAL( true, tool5.all_seen() );
238 
239  // test copy constructor
240 
241  const FileOptions& tool6( tool2 );
242 
243  rval = tool6.get_option( "opt1", s );
244  CHECK( rval );
245  EQUAL( s, "ABC" );
246 
247  rval = tool6.get_option( "opt2", s );
248  CHECK( rval );
249  e = s.empty();
250  EQUAL( e, true );
251 
252  l = tool6.size();
253  EQUAL( l, 2 );
254 
255  const FileOptions& tool7( tool5 );
256  e = tool7.empty();
257  EQUAL( e, true );
258  l = tool7.size();
259  EQUAL( l, 0 );
260 
261  // test assignment operator
262 
263  FileOptions tool8( tool2 );
264  tool8 = tool;
265  EQUAL( tool8.size(), tool.size() );
266 
267  return 0;
268 }

References moab::FileOptions::all_seen(), CHECK, moab::FileOptions::empty(), EQUAL, ErrorCode, moab::FileOptions::get_int_option(), moab::FileOptions::get_ints_option(), moab::FileOptions::get_null_option(), moab::FileOptions::get_option(), moab::FileOptions::get_real_option(), moab::FileOptions::get_reals_option(), moab::FileOptions::get_str_option(), moab::FileOptions::get_strs_option(), moab::FileOptions::get_unseen_option(), MB_ENTITY_NOT_FOUND, MB_TYPE_OUT_OF_RANGE, and moab::FileOptions::size().