+
+
+ ep = (endpoint_t *) malloc( sizeof( *ep ) );
+ pthread_mutex_init( &ep->gate, NULL );
+ ep->name = strdup( "worm" );
+ ep->addr = NULL;
+ #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
+ 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" );
+ 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
+
+
+ // ------------- 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