Ensure RT incremental update not applied early
[ric-plt/lib/rmr.git] / test / tools_static_test.c
index f1c2ffc..250f834 100644 (file)
        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.
@@ -40,6 +65,7 @@ static char* get_ifname( ) {
        struct  ifaddrs *ifs;           // pointer to head
        struct  ifaddrs *ele;           // pointer into the list
        char*   rstr = NULL;            // return string
+       char    octs[NI_MAXHOST+1];
 
 
        if( (l = (if_addrs_t *) malloc( sizeof( if_addrs_t ) )) == NULL ) {
@@ -55,12 +81,20 @@ static char* get_ifname( ) {
        getifaddrs( &ifs );
        for( ele = ifs; ele; ele = ele->ifa_next ) {
                if( ele && strcmp( ele->ifa_name, "lo" ) ) {
-                       rstr = strdup( ele->ifa_name );
-                       break;
+                       memset( octs, 0, sizeof( octs ) );
+                       getnameinfo( ele->ifa_addr, sizeof( struct sockaddr_in6 ),  octs, NI_MAXHOST, NULL, 0, NI_NUMERICHOST );
+                       if( *octs ) {
+                               rstr = strdup( ele->ifa_name );
+                               fprintf( stderr, "<INFO> found interface with address: %s\n", rstr );
+                               break;
+                       }
                }
        }
 
        free( l );
+       if( rstr == NULL ) {
+               fprintf( stderr, "<ERROR> no interface with an address was found!\n" );
+       }
        return rstr;
 }
 
@@ -120,6 +154,8 @@ static int tools_test( ) {
        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;
 
@@ -140,6 +176,7 @@ 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
 
        // ------------ my_ip stuff -----------------------------------------------------------------
 
@@ -198,8 +235,12 @@ static int tools_test( ) {
                }
 
                free( ip );
+       } else {
+               fprintf( stderr, "<SKIP> test skipped because no interface with address could be found on system" );
        }
 
+       errors += ztbf_test();                                  // test the zero term buffer fill function
+
 // -------------------------------------------------------------------------------------------------
 
        return !!errors;                        // 1 or 0 regardless of count