- char* tokens[127];
- char* buf = "2,Fred,Wilma,Barney,Betty,Dino,Pebbles,Bambam,Mr. Slate,Gazoo";
- char* dbuf; // duplicated buf since C marks a const string is unumtable
- char* hname;
- uta_ctx_t ctx; // context for uta_lookup test
- void* if_list;
-
-
- // ------------------ tokenise tests -----------------------------------------------------------
- dbuf = strdup( buf );
- i = uta_tokenise( dbuf, tokens, 127, ',' );
- errors += fail_not_equal( i, 10, "unexpected number of tokens returned (comma sep)" );
- for( j = 0; j < i; j++ ) {
- //fprintf( stderr, ">>>> [%d] (%s)\n", j, tokens[j] );
- errors += fail_if_nil( tokens[j], "token from buffer" );
- }
- errors += fail_not_equal( strcmp( tokens[4], "Betty" ), 0, "4th token wasn't 'Betty'" );
-
- free( dbuf );
- dbuf = strdup( buf );
- i = uta_tokenise( dbuf, tokens, 127, '|' );
- errors += fail_not_equal( i, 1, "unexpected number of tokens returned (bar sep)" );
- free( dbuf );
-
- // ------------ has str tests -----------------------------------------------------------------
- j = uta_has_str( buf, "Mr. Slate", ',', 1 ); // should fail (-1) because user should use strcmp in this situation
- errors += fail_if_true( j >= 0, "test to ensure has str rejects small max" );
-
- j = uta_has_str( buf, "Mr. Slate", ',', 27 );
- errors += fail_if_true( j < 0, "has string did not find Mr. Slate" );
-
- j = uta_has_str( buf, "Mrs. Slate", ',', 27 );
- errors += fail_if_true( j >= 0, "has string not found Mrs. Slate" );
-
- // ------------ host name 2 ip tests ---------------------------------------------------------
- hname = uta_h2ip( "192.168.1.2" );
- errors += fail_not_equal( strcmp( hname, "192.168.1.2" ), 0, "h2ip did not return IP address when given address" );
- errors += fail_if_nil( hname, "h2ip did not return a pointer" );
-
- hname = uta_h2ip( "yahoo.com" );
- errors += fail_if_nil( hname, "h2ip did not return a pointer" );
-
- hname = uta_h2ip( "yahoo.com:1234" ); // should ignore the port
- errors += fail_if_nil( hname, "h2ip did not return a pointer" );
-
- // ------------ rtg lookup test -------------------------------------------------------------
- ctx.rtg_port = 0;
- ctx.rtg_addr = NULL;
-
- i = uta_lookup_rtg( NULL ); // ensure it handles a nil context
- errors += fail_if_true( i, "rtg lookup returned that it found something when not expected to (nil context)" );