X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=test%2Fjhash_test.cpp;h=7bb36148ad788f1fa9884d648231660a92519887;hb=79451ff52d5d6420728e896f22cc2f98e4738c49;hp=972e6e6ecda498c351549c785bc0497cc0eeef05;hpb=8ec1e3c2dec6ba4fa83fe63e4207d47b4b0f3b3f;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/test/jhash_test.cpp b/test/jhash_test.cpp index 972e6e6..7bb3614 100644 --- a/test/jhash_test.cpp +++ b/test/jhash_test.cpp @@ -80,7 +80,7 @@ static char* read_jstring( char* fname ) { int main( int argc, char** argv ) { int errors = 0; - Jhash* jh; + xapp::Jhash* jh; char* jstr; std::string sval; double val; @@ -94,7 +94,7 @@ int main( int argc, char** argv ) { fprintf( stderr, "read: (%s)\n", jstr ); - jh = new Jhash( jstr ); + jh = new xapp::Jhash( jstr ); free( jstr ); if( jh == NULL ) { @@ -204,9 +204,9 @@ int main( int argc, char** argv ) { 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" ); @@ -224,7 +224,14 @@ int main( int argc, char** argv ) { // ---- 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" ); @@ -238,11 +245,13 @@ int main( int argc, char** argv ) { val = jh->Value( (char *) "timestamp" ); fprintf( stderr, " 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 @@ -251,18 +260,18 @@ int main( int argc, char** argv ) { fprintf( stderr, " 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, " good value=%d\n", (int) val ); delete jh;