X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Ftools_static_test.c;h=6f95fe56ee32138201762bd4c7ded9c5b504aaf7;hb=ce1c741c01e8387cb095dac5e36a4d8ad91d006d;hp=9e156ec6919e33b109f674662254996a3eadea75;hpb=68d09fa5028e47e763c44c30647da31e77eda64a;p=ric-plt%2Flib%2Frmr.git diff --git a/test/tools_static_test.c b/test/tools_static_test.c index 9e156ec..6f95fe5 100644 --- a/test/tools_static_test.c +++ b/test/tools_static_test.c @@ -31,6 +31,31 @@ Date: 3 April 2019 */ +// ------------ zero termianted buffer --------------------------------------------------------- +static int ztbf_test() { + int errors = 0; + char buf[128]; + char* sshort = "Stand up and cheer! Cheer long and loud for old Ohio."; + char* slong = "Now is the time for the bobcat in the forest to make its way back to Court St for a round of pints at the Pub."; + int l1; + + l1 = zt_buf_fill( buf, sshort, 64 ); + errors += fail_not_equal( l1, strlen( sshort ), "zt_buf_fill of short buf returned unexpected len" ); + errors += fail_not_equal( l1, strlen( buf ), "zt_buf_fill of short buf returned len did not match strlen" ); + + l1 = zt_buf_fill( buf, slong, 64 ); + errors += fail_if_equal( l1, strlen( slong ), "zt_buf_fill of long buf returned unexpected len" ); + errors += fail_not_equal( l1, strlen( buf ), "zt_buf_fill of long buf returned len did not match strlen" ); + + l1 = zt_buf_fill( buf, sshort, strlen( sshort ) ); // edge case of exact size + errors += fail_not_equal( l1, strlen( sshort )-1, "zt_buf_fill exact length edge case failed" ); + + l1 = zt_buf_fill( buf, sshort, 1 ); // unrealistic edge case + errors += fail_not_equal( l1, 0, "zt_buf_fill dest len == 1 test failed" ); + + return errors; +} + /* Returns an interface name that is valid in this environment (keeps us from having to know/guess a name to test with. @@ -77,6 +102,8 @@ static int tools_test( ) { void* if_list; + uta_dump_env(); + // ------------------ tokenise tests ----------------------------------------------------------- dbuf = strdup( buf ); i = uta_tokenise( dbuf, tokens, 127, ',' ); @@ -107,14 +134,19 @@ static int tools_test( ) { 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" ); + free( hname ); hname = uta_h2ip( "yahoo.com" ); errors += fail_if_nil( hname, "h2ip did not return a pointer" ); + free( hname ); hname = uta_h2ip( "yahoo.com:1234" ); // should ignore the port errors += fail_if_nil( hname, "h2ip did not return a pointer" ); + free( hname ); // ------------ rtg lookup test ------------------------------------------------------------- +#ifdef KEEP + // pub/sub route table generator is deprecated and should be removed at this point ctx.rtg_port = 0; ctx.rtg_addr = NULL; @@ -135,21 +167,9 @@ static int tools_test( ) { unsetenv( "RMR_RTG_SVC" ); // this should fail as the default name (rtg) will be unknown during testing i = uta_lookup_rtg( &ctx ); errors += fail_if_true( i, "rtg lookup returned that it found something when not expected to" ); +#endif -/* -//==== moved out of generic tools ========== - // -------------- test link2 stuff ---------------------------------------------------------- - i = uta_link2( "bad" ); // should fail - errors += fail_if_true( i >= 0, "uta_link2 didn't fail when given bad address" ); - - i = uta_link2( "nohost:-1234" ); - errors += fail_if_true( i >= 0, "uta_link2 did not failed when given a bad (negative) port " ); - - i = uta_link2( "nohost:1234" ); // nn should go off and set things up, but it will never successd, but uta_ call should - errors += fail_if_true( i < 0, "uta_link2 failed when not expected to" ); -*/ - - // ------------ my ip stuff ----------------------------------------------------------------- + // ------------ my_ip stuff ----------------------------------------------------------------- if_list = mk_ip_list( "1235" ); errors += fail_if_nil( if_list, "mk_ip_list returned nil pointer" ); @@ -188,6 +208,7 @@ static int tools_test( ) { ip = get_default_ip( if_list ); if( ip ) { + free( ip ); } else { errors += fail_if_nil( ip, "get_defaul_ip returned nil pointer when valid pointer expected" ); } @@ -203,8 +224,12 @@ static int tools_test( ) { } else { errors += fail_if_nil( if_list, "mk_ip_list with a specific interface name returned a nil list" ); } + + free( ip ); } + errors += ztbf_test(); // test the zero term buffer fill function + // ------------------------------------------------------------------------------------------------- return !!errors; // 1 or 0 regardless of count