feat(routing): Support session based routing
[ric-plt/lib/rmr.git] / test / mbuf_api_static_test.c
index 8598136..93ab45c 100644 (file)
@@ -1,14 +1,14 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-        Copyright (c) 2019 Nokia 
-        Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019 Nokia
+           Copyright (c) 2018-2019 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0
+          http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@
 /*
        Mmemonic:       mbuf_api_static_test.c
        Abstract:       Test the message buffer  funcitons. These are meant to be included at compile
 /*
        Mmemonic:       mbuf_api_static_test.c
        Abstract:       Test the message buffer  funcitons. These are meant to be included at compile
-                               time by the test driver.  
+                               time by the test driver.
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
 
        Author:         E. Scott Daniels
        Date:           3 April 2019
@@ -44,6 +44,7 @@ int mbuf_api_test( ) {
        int i;
        int state;
        int errors = 0;
        int i;
        int state;
        int errors = 0;
+       char*   buf;
        rmr_mbuf_t*     mbuf;
        unsigned char src_buf[256];
 
        rmr_mbuf_t*     mbuf;
        unsigned char src_buf[256];
 
@@ -73,7 +74,7 @@ int mbuf_api_test( ) {
        rmr_bytes2payload( mbuf, src_buf, 8192 );                                               // bust the limit
        errors += fail_if( mbuf->state == RMR_OK, "huge buf copy to payload returned good state in mbuf" );
        errors += fail_if( errno == 0, "huge buf copy to payload returned good state in errno" );
        rmr_bytes2payload( mbuf, src_buf, 8192 );                                               // bust the limit
        errors += fail_if( mbuf->state == RMR_OK, "huge buf copy to payload returned good state in mbuf" );
        errors += fail_if( errno == 0, "huge buf copy to payload returned good state in errno" );
-       
+
 
        snprintf( src_buf, sizeof( src_buf ), "This is some text in the buffer" );
        rmr_str2payload( mbuf, src_buf );                                                       // this uses bytes2payload, so only one invocation needed
 
        snprintf( src_buf, sizeof( src_buf ), "This is some text in the buffer" );
        rmr_str2payload( mbuf, src_buf );                                                       // this uses bytes2payload, so only one invocation needed
@@ -131,8 +132,8 @@ int mbuf_api_test( ) {
        errno = 0;
        c = rmr_get_meid( NULL, NULL );
        errors += fail_if( c != NULL, "get meid with nil message buffer" );
        errno = 0;
        c = rmr_get_meid( NULL, NULL );
        errors += fail_if( c != NULL, "get meid with nil message buffer" );
-       errors += fail_if( errno == 0, "(errno bad) get meid with nil msg buffer" ); 
-       
+       errors += fail_if( errno == 0, "(errno bad) get meid with nil msg buffer" );
+
        c = rmr_get_meid( mbuf, NULL );                 // should allocate and return c
        errors += fail_if( c == NULL, "get meid with nil dest pointer (did not allocate a buffer)" );
        errors += fail_if( strcmp( c, "test-meid" ) != 0, "did not get expected meid from mbuffer" );
        c = rmr_get_meid( mbuf, NULL );                 // should allocate and return c
        errors += fail_if( c == NULL, "get meid with nil dest pointer (did not allocate a buffer)" );
        errors += fail_if( strcmp( c, "test-meid" ) != 0, "did not get expected meid from mbuffer" );
@@ -216,7 +217,7 @@ int mbuf_api_test( ) {
        state = rmr_get_trlen( NULL );                                                          // coverage test on nil check
        errors += fail_not_equal( state, 0, "get trace length with nil msg didn't return expected 0 status" );
 
        state = rmr_get_trlen( NULL );                                                          // coverage test on nil check
        errors += fail_not_equal( state, 0, "get trace length with nil msg didn't return expected 0 status" );
 
-       
+
        src_buf[0] = 0;
        state = rmr_set_trace( mbuf, "foo bar was here", 17 );          // should force a realloc
        errors += fail_not_equal( state, 17, "bytes copied to trace (a) did not match expected size (b)" );
        src_buf[0] = 0;
        state = rmr_set_trace( mbuf, "foo bar was here", 17 );          // should force a realloc
        errors += fail_not_equal( state, 17, "bytes copied to trace (a) did not match expected size (b)" );
@@ -248,7 +249,21 @@ int mbuf_api_test( ) {
        errors+= fail_not_equal( state, 0, "compare of pulled trace info did not match" );
 
        i = rmr_get_trlen( mbuf );
        errors+= fail_not_equal( state, 0, "compare of pulled trace info did not match" );
 
        i = rmr_get_trlen( mbuf );
-       
+
+
+       // ------------- source field tests ------------------------------------------------------------
+       // we cannot force anything into the message source field, so no way to test the content, but we
+       // can test pointers and expected nils
+
+       buf = rmr_get_src( NULL, src_buf );                                     // coverage test for nil msg check
+       errors += fail_not_nil( buf, "rmr_get_src returned a pointer when given a nil message" );
+
+       buf = rmr_get_src( mbuf, NULL );                                        // coverage test for nil dst check
+       errors += fail_not_nil( buf, "rmr_get_src returned a pointer when given a nil dest buffer" );
+
+       buf = rmr_get_src( mbuf, src_buf );
+       errors += fail_not_equal( buf, src_buf, "rmr_get_src didn't return expexted buffer pointer" );
+
 
        return errors > 0;                      // overall exit code bad if errors
 }
 
        return errors > 0;                      // overall exit code bad if errors
 }