+ ep->notify = 1;
+ #ifdef NNG_UNDER_TEST
+ state = uta_link2( ep );
+ #else
+ state = uta_link2( ctx, ep );
+ #endif
+ errors += fail_if_true( state, "link2 did not return false when given a bad target name" );
+
+ #ifdef NNG_UNDER_TEST
+ state = uta_link2( NULL );
+ #else
+ state = uta_link2( ctx, NULL );
+ errors += fail_if_true( state, "link2 did not return false when given nil ep pointer" );
+
+ state = uta_link2( NULL, ep );
+ #endif
+ errors += fail_if_true( state, "link2 did not return false when given nil pointer" );
+
+ ep->name = strdup( "localhost:5512" );
+ ep->open = 1;
+ #ifdef NNG_UNDER_TEST
+ state = uta_link2( ep ); // drive for coverage
+ #else
+ state = uta_link2( ctx, ep );
+ #endif
+ errors += fail_if_false( state, "link2 did returned false when given open ep" );
+
+ #ifndef NNG_UNDER_TEST
+ ep->open = 0; // context is used only if ep not open, so to check this test close the ep
+ ep->notify = 1;
+ state = rt_link2_ep( NULL, ep );
+ errors += fail_if_true( state, "rt_link2_ep returned true when given bad context" );
+
+ state = rt_link2_ep( ctx, NULL );
+ errors += fail_if_true( state, "rt_link2_ep returned true when given bad ep" );
+
+ ep->open = 1;
+ state = rt_link2_ep( ctx, ep );
+ errors += fail_if_false( state, "rt_link2_ep returned false when given an open ep" );
+
+ ep->open = 0;
+ state = rt_link2_ep( ctx, ep );
+ errors += fail_if_false( state, "rt_link2_ep returned false when given a closed ep" );
+
+ ep->open = 1;
+ uta_ep_failed( ep );
+ errors += fail_if_true( ep->open, "uta_ep_failed didn't set open flag to false" );
+
+ #endif
+
+
+ // ----------------- test the meid support for looking up an endpoint based on the meid in the message -----
+
+ ctx->rtable = NULL;
+ ctx->my_name = strdup( "my_host_name" ); // set up to load a rtable
+ ctx->my_ip = strdup( "192.168.1.30" );
+ if( ctx && ctx->seed_rt_fname != NULL ) {
+ free( ctx->seed_rt_fname );
+ ctx->seed_rt_fname = NULL;
+ }
+ gen_rt( ctx ); // generate a route table with meid entries and hang off ctx
+
+ mbuf = rmr_alloc_msg( ctx, 2048 ); // buffer to play with
+ mbuf->len = 100;
+ rmr_str2meid( mbuf, "meid1" ); // id that we know is in the map
+
+ #ifdef NNG_UNDER_TEST
+ ep = NULL; // force to nil so we see it go non-nil
+ state = epsock_meid( ctx->rtable, mbuf, &nn_sock, &ep );
+ errors += fail_if_nil( ep, "ep was nil when looking up ep with known meid in message" );
+ errors += fail_not_equal( state, 1, "state was not true when looking up ep with known meid in message" );
+
+ rmr_str2meid( mbuf, "XXXmeid1" ); // id that we know is NOT in the map
+ state = epsock_meid( ctx->rtable, mbuf, &nn_sock, &ep );
+ // it is NOT a valid check to test ep for nil -- epsock_mied doesn't guarentee ep is set/cleared when state is false
+ errors += fail_not_equal( state, 0, "state was not false when looking up ep with unknown meid in message" );
+ #else
+ ep = NULL; // force to nil so we see it go non-nil
+ state = epsock_meid( ctx, ctx->rtable, mbuf, &nn_sock, &ep );
+ errors += fail_if_nil( ep, "ep was nil when looking up ep with known meid in message" );
+ errors += fail_not_equal( state, 1, "state was not true when looking up ep with known meid in message" );
+
+ state = epsock_meid( ctx, ctx->rtable, mbuf, &nn_sock, &ep ); // a second call to drive open == true check for coverage
+ errors += fail_if_nil( ep, "ep was nil when looking up ep with known meid in message; on open ep" );
+ errors += fail_not_equal( state, 1, "state was not true when looking up ep with known meid in message; on open ep" );
+
+ rmr_str2meid( mbuf, "XXXmeid1" ); // id that we know is NOT in the map
+ state = epsock_meid( ctx, ctx->rtable, mbuf, &nn_sock, &ep );
+ // it is NOT a valid check to test ep for nil -- epsock_mied doesn't guarentee ep is set/cleared when state is false
+ errors += fail_not_equal( state, 0, "state was not false when looking up ep with unknown meid in message" );
+
+ state = epsock_meid( NULL, ctx->rtable, mbuf, &nn_sock, &ep );
+ errors += fail_not_equal( state, 0, "epsock_meid returned true when given nil context" );
+
+ state = epsock_meid( ctx, ctx->rtable, mbuf, NULL, &ep );
+ errors += fail_not_equal( state, 0, "epsock_meid returned true when given nil socket pointer" );
+ #endif
+
+ // ------------ debugging and such; coverage only calls ----------------------------------------------------------
+ ep_stats( ctx->rtable, NULL, "name", NULL, NULL ); // ensure no crash when given nil pointer
+ rt_epcounts( ctx->rtable, "testing" );
+ rt_epcounts( NULL, "testing" );
+
+ buf = ensure_nlterm( NULL );
+ errors += fail_if_nil( buf, "ensure nlterm returned null pointer when given nil ptr" );
+ if( buf ) {
+ errors += fail_not_equal( strlen( buf ), 1, "ensure nlterm returned incorrect length string when given nil pointer" );
+ free( buf );
+ }
+
+ buf = ensure_nlterm( strdup( "x" ) ); // should return "x\n"
+ errors += fail_if_nil( buf, "ensure nlterm returned null pointer when given single char string" );
+ if( buf ) {
+ errors += fail_not_equal( strlen( buf ), 2, "ensure nlterm returned incorrect length string when given single char string" );
+ free( buf );
+ }
+
+ buf = strdup( "x\n" );
+ buf2 = ensure_nlterm( buf ); // buffer returned should be the same
+ if( fail_not_pequal( buf, buf2, "ensure nlterm returned new buffer for one char string with newline" ) ) {
+ errors++;
+ free( buf2 );
+ }
+ free( buf );
+
+ buf = strdup( "Missing our trips to Gloria's for papossas.\n" );
+ buf2 = ensure_nlterm( buf ); // buffer returned should be the same
+ if( fail_not_pequal( buf, buf2, "ensure nlterm returned new buffer for string with newline" ) ) {
+ errors++;
+ free( buf2 );
+ }
+ free( buf );
+
+ buf = ensure_nlterm( strdup( "Stand up and cheer!" ) ); // force addition of newline
+ if( buf ) {
+ errors += fail_not_equal( strcmp( buf, "Stand up and cheer!\n" ), 0, "ensure nlterm didn't add newline" );
+ free( buf );
+ buf = NULL;
+ }
+
+
+ // ------------- route manager request/response funcitons -------------------------------------------------------
+ {
+ rmr_mbuf_t* smsg;
+
+ smsg = rmr_alloc_msg( ctx, 1024 );
+ send_rt_ack( ctx, smsg, "123456", 0, "no reason" );
+
+ pctx = mk_dummy_ctx();
+ ctx->rtg_whid = -1;
+ state = send_update_req( pctx, ctx );
+ errors += fail_not_equal( state, 0, "send_update_req did not return 0" );
+
+ ctx->rtg_whid = rmr_wh_open( ctx, "localhost:19289" );
+ state = send_update_req( pctx, ctx );
+ errors += fail_if_equal( state, 0, "send_update_req to an open whid did not return 0" );
+ }
+
+
+ // ------------- si only; fd to ep conversion functions ---------------------------------------------------------
+ #ifndef NNG_UNDER_TEST
+ ep2 = (endpoint_t *) malloc( sizeof( *ep ) );
+
+ fd2ep_init( ctx );
+ fd2ep_add( ctx, 10, ep2 );
+
+ ep = fd2ep_get( ctx, 10 );
+ errors += fail_if_nil( ep, "fd2ep did not return pointer for known mapping" );
+ errors += fail_if_false( ep == ep2, "fd2ep did not return same pointer that was added" );
+
+ ep = fd2ep_get( ctx, 20 );
+ errors += fail_not_nil( ep, "fd2ep did returned a pointer for unknown mapping" );
+
+ ep = fd2ep_del( ctx, 10 );
+ errors += fail_if_nil( ep, "fd2ep delete did not return pointer for known mapping" );
+ errors += fail_if_false( ep == ep2, "fd2ep delete did not return same pointer that was added" );
+
+ ep = fd2ep_del( ctx, 20 );
+ errors += fail_not_nil( ep, "fd2ep delete returned a pointer for unknown mapping" );
+ #endif
+
+ // ---------------- misc coverage tests --------------------------------------------------------------------------
+ collect_things( NULL, NULL, NULL, NULL, NULL ); // these both return null, these test NP checks
+ collect_things( NULL, NULL, NULL, NULL, (void *) 1234 ); // the last is an invalid pointer, but check needed to force check on previous param
+ del_rte( NULL, NULL, NULL, NULL, NULL );
+
+ ctx = mk_dummy_ctx();
+ roll_tables( ctx ); // drive nil rt check
+
+
+
+ // ------ specific edge case tests -------------------------------------------------------------------------------
+ errors += lg_clone_test( );