X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fwormhole_static_test.c;h=25d2ccaafbf960ce5049172605f58b1f3f204f5a;hb=45b2e235900859e2ec6498d6e718ba9c17fedf1f;hp=f2d4bf6e763bb616bc488454341039b0d2dc7114;hpb=a41c6f5f26b3a44009f4aff3df3f83b9a79ace01;p=ric-plt%2Flib%2Frmr.git diff --git a/test/wormhole_static_test.c b/test/wormhole_static_test.c index f2d4bf6..25d2cca 100644 --- a/test/wormhole_static_test.c +++ b/test/wormhole_static_test.c @@ -34,9 +34,11 @@ #include #include #include +#include +#include -#include "../src/common/include/rmr.h" -#include "../src/common/include/rmr_agnostic.h" +#include "rmr.h" +#include "rmr_agnostic.h" /* @@ -47,6 +49,7 @@ static int worm_test( ) { uta_ctx_t* ctx; // context needed to test load static rt char wbuf[1024]; int errors = 0; // number errors found + int state = 0; int i; void* p; @@ -54,13 +57,9 @@ static int worm_test( ) { int whid = -1; int last_whid; - ctx = (uta_ctx_t *) malloc( sizeof( uta_ctx_t ) ); - if( ctx == NULL ) { - fail_if_nil( ctx, "could not allocate dummy context" ); - return 1; - } - memset( ctx, 0, sizeof( *ctx ) ); + ctx = mk_dummy_ctx(); ctx->my_name = strdup( "tester" ); + ctx->my_ip = strdup( "30.4.19.86:1111" ); gen_rt( ctx ); @@ -117,6 +116,7 @@ static int worm_test( ) { } fail_if_nil( mbuf, "wh_send_msg returned a nil message buffer when given a nil context" ); + while( mbuf ) { if( !(mbuf = rmr_wh_send_msg( ctx, 50, mbuf )) ) { // test for coverage errors += fail_if_nil( mbuf, "send didn't return an mbuf (skip rest of send tests)" ); @@ -135,7 +135,25 @@ static int worm_test( ) { break; } + // ---- wormhole state ----------- + state = rmr_wh_state( NULL, 0 ); + errors += fail_if_equal( state, RMR_OK, "wh_state with bad context did not return error" ); + + state = rmr_wh_state( ctx, -1 ); + errors += fail_if_equal( state, RMR_OK, "wh_state with bad whid did not return error" ); + + whid = rmr_wh_open( ctx, "localhost:9219" ); + if( ! fail_if_equal( whid, -1, "skipping some wh_state tests: no whid returned" ) ) { + state = rmr_wh_state( ctx, whid ); + errors += fail_not_equal( state, RMR_OK, "wh_state on an open wh did not return OK" ); + + rmr_wh_close( ctx, whid ); + state = rmr_wh_state( ctx, whid ); + errors += fail_if_equal( state, RMR_OK, "wh_state on a closed wh returned OK" ); + whid = -1; + } + // ----------------------------------------------------------------------- // WARNING: these tests destroy the context, so they MUST be last if( mbuf ) { // only if we got an mbuf errno = 0;