int main( int argc, char** argv ) {
int errors = 0;
- Jhash* jh;
+ xapp::Jhash* jh;
char* jstr;
std::string sval;
double val;
fprintf( stderr, "read: (%s)\n", jstr );
- jh = new Jhash( jstr );
+ jh = new xapp::Jhash( jstr );
free( jstr );
if( jh == NULL ) {
errors += fail_if( state, "string element check on non-stirng element returned true" );
state = jh->Is_value_ele( (char *) "dues_assistance", 1 );
- errors += fail_if( !state, "string element check on sponser failed" );
+ errors += fail_if( !state, "value element type check on value element reported false" );
state = jh->Is_value_ele( (char *) "current_on_dues", 1 );
- errors += fail_if( state, "string element check on non-stirng element returned true" );
+ errors += fail_if( state, "value element type check on non-value element returned true" );
state = jh->Is_bool_ele( (char *) "current_on_dues", 1 );
errors += fail_if( !state, "string element check on sponser failed" );
// ---- test sussing of elements from arrays -------------------------------------------------
sval = jh->String_ele( (char *) "sponser", 1 );
- errors += fail_if( sval.compare( "" ) == 0, "get string element failed for sponser" );
+ errors += fail_if( sval.compare( "" ) == 0, "get string element failed for sponser (empty string)" );
+ errors += fail_if( sval.compare( "slate" ) != 0, "get string element failed for sponser (wrong value for[1])" );
+
+ sval = jh->String_ele( (char *) "sponser", 0 );
+ errors += fail_if( sval.compare( "slate" ) != 0, "get string element failed for sponser (wrong value for [0])" );
+
+ sval = jh->String_ele( (char *) "sponser", 3 );
+ errors += fail_if( sval.compare( "brick" ) != 0, "get string element failed for sponser (wrong value for [3])" );
val = jh->Value_ele( (char *) "dues_assistance", 1 );
errors += fail_if( val == 0.0, "get value element for dues_assistance was zero" );
val = jh->Value( (char *) "timestamp" );
fprintf( stderr, "<INFO> timestamp: %.10f\n", val );
+ jh->Dump(); // for coverage of debug things
+
// ----- jhashes can be moved, drive that logic for coverage
- Jhash j2( "{}" );
+ xapp::Jhash j2( "{}" );
- Jhash j1 = std::move( *jh ); // drives move constructor function
+ xapp::Jhash j1 = std::move( *jh ); // drives move constructor function
j2 = std::move( j1 ); // drives move operator function
fprintf( stderr, "<INFO> testing for failures; jwrapper error and warning messages expected\n" );
// ---- these shouild all fail to parse, generate warnings to stderr, and drive error handling coverage ----
- jh = new Jhash( (char *) "{ \"bad\": [ [ 1, 2, 3 ], [ 3, 4, 5]] }" ); // drive the exception process for bad json
+ jh = new xapp::Jhash( (char *) "{ \"bad\": [ [ 1, 2, 3 ], [ 3, 4, 5]] }" ); // drive the exception process for bad json
delete jh;
- jh = new Jhash( (char *) " \"bad\": 5 }" ); // no opening brace
+ jh = new xapp::Jhash( (char *) " \"bad\": 5 }" ); // no opening brace
state = jh->Parse_errors();
errors += fail_if( !state, "parse errors check returned false when known errors exist" );
delete jh;
- jh = new Jhash( (char *) "{ \"bad\": fred }" ); // no quotes
+ jh = new xapp::Jhash( (char *) "{ \"bad\": fred }" ); // no quotes
delete jh;
- jh = new Jhash( (char *) "{ \"bad: 456, \"good\": 100 }" ); // missing quote; impossible to detect error
+ jh = new xapp::Jhash( (char *) "{ \"bad: 456, \"good\": 100 }" ); // missing quote; impossible to detect error
jh->Dump(); // but dump should provide details
fprintf( stderr, "<INFO> good value=%d\n", (int) val );
delete jh;