+/*
+ Misc tests that just don't fit in another bucket.
+*/
+static int misc( ) {
+ int errors = 0;
+ char buf[1024];
+
+ SIcbreg( NULL, SI_CB_SECURITY, test_cb, NULL ); // coverage only, no return value no verification
+ SIcbreg( si_ctx, SI_CB_SECURITY, test_cb, NULL );
+
+ buf[0] = 0;
+ SIgetaddr( si_ctx, buf );
+ errors += fail_if_true( buf[0] == 0, "get address failed" );
+ fprintf( stderr, "<INFO> get address returns (%s)\n", buf );
+
+ fprintf( stderr, "<INFO> misc module finished with %d errors\n", errors );
+ return errors;
+}
+
+
+/*
+ New session (accept) testing.
+*/
+static int new_sess( ) {
+ int errors = 0;
+ char buf[1024];
+ struct tp_blk *tpptr;
+ int status;
+
+ tpptr = SInew( TP_BLK );
+ tpptr->fd = 3;
+ tpptr->flags |= TPF_LISTENFD;
+
+ tpem_set_accept_fd( -1 ); // accept will "fail" for coverage
+ status = SInewsession( si_ctx, tpptr );
+ errors += fail_if_true( status != SI_ERROR, "newsession did not fail when accept fails" );
+
+ tpem_set_accept_fd( 5 ); // accept will return a good fd
+ SIcbreg( si_ctx, SI_CB_SECURITY, test_cb_err, NULL ); // register error and drive new session for error coverage
+ status = SInewsession( si_ctx, tpptr );
+ errors += fail_if_true( status >= 0, "newsession did failed when accept was good" );
+
+ tpem_set_accept_fd( 6 ); // accept will return a good fd
+ SIset_tflags( si_ctx, SI_TF_NODELAY | SI_TF_FASTACK ); // flip options for coverage in new sess
+ SIcbreg( si_ctx, SI_CB_CONN, test_cb, NULL ); // drive connection for coverage
+ SIcbreg( si_ctx, SI_CB_SECURITY, test_cb, NULL );
+ status = SInewsession( si_ctx, tpptr );
+ errors += fail_if_true( status < 0, "newsession did failed when accept was good" );
+
+ fprintf( stderr, "<INFO> new_sess module finished with %d errors\n", errors );
+ return errors;
+}
+
+/*
+ Send tests
+*/
+static int send_tests( ) {
+ int errors = 0;
+ char buf[1024];
+ int len;
+ int state;
+
+ len = snprintf( buf, 100, "Heaven knows I'm miserable now!" );
+
+ state = SIsendt( si_ctx, 9999, buf, len );
+ errors += fail_if_true( state >= 0, "send given fd out of range did not fail" );
+
+ state = SIsendt( si_ctx, -1, buf, len );
+ errors += fail_if_true( state >= 0, "send given neg fd did not fail" );
+
+ SIsendt( si_ctx, 6, buf, len );
+
+ tpem_set_send_err( 99 );
+ SIsendt( si_ctx, 6, buf, len );
+
+ tpem_set_send_err( 0 );
+ tpem_set_sel_blk( 1 );
+ SIsendt( si_ctx, 6, buf, len );
+
+ tpem_set_sel_blk( 0 );
+ tpem_set_selef_fd( 6 ); // will cause send to fail and fd6 to close
+ SIsendt( si_ctx, 6, buf, len );
+
+ return errors;
+}
+
+
+// ----------------------------------------------------------------------------------------
+