+ // ------------ trace data tests ----------------------------------------------------------------
+ // CAUTION: to support standalone mbuf api tests, the underlying buffer reallocation functions are NOT used
+ // if this is driven by the mbuf_api_test.c driver
+
+ mbuf = test_mk_msg( 2048, 0 ); // initially no trace size to force realloc
+
+ state = TRACE_OFFSET( mbuf->header ) - PAYLOAD_OFFSET( mbuf->header ); // no trace data, payload and trace offset should be the same
+ errors += fail_not_equal( state, 0, "trace offset and payload offset do NOT match when trace data is absent" );
+
+ state = rmr_get_trlen( mbuf );
+ errors += fail_not_equal( state, 0, "initial trace len reported (a) does not match expected (b)" );
+
+ state = rmr_set_trace( NULL, src_buf, 100 ); // coverage test on nil check
+ errors += fail_not_equal( state, 0, "set trace with nil msg didn't return expected 0 status" );
+
+ state = rmr_set_trace( mbuf, src_buf, 0 ); // coverage test on length check
+ errors += fail_not_equal( state, 0, "set trace with 0 len didn't return expected 0 status" );
+
+ state = rmr_get_trace( NULL, src_buf, 100 ); // coverage test on nil check
+ errors += fail_not_equal( state, 0, "get trace with nil msg didn't return expected 0 status" );
+
+ state = rmr_get_trace( mbuf, NULL, 100 ); // coverage test on nil check
+ errors += fail_not_equal( state, 0, "get trace with nil dest 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)" );
+
+ state = rmr_get_trace( mbuf, src_buf, 17 );
+ errors += fail_not_equal( state, 17, "bytes retrieved from trace (a) did not match expected size (b)" );
+
+ state = rmr_get_trlen( mbuf );
+ errors += fail_not_equal( state, 17, "trace len reported (a) does not match expected (b)" );
+ state = strcmp( src_buf, "foo bar was here" );
+ errors+= fail_not_equal( state, 0, "compare of pulled trace info did not match" );
+
+ state = TRACE_OFFSET( mbuf->header ) - PAYLOAD_OFFSET( mbuf->header ); // when there is a trace area these should NOT be the same
+ errors += fail_if_equal( state, 0, "trace offset and payload offset match when trace data is present" );
+
+
+ // second round of trace testing, allocating a message with a trace size that matches
+ mbuf = test_mk_msg( 2048, 17 ); // trace size that matches what we'll stuff in, no realloc
+ state = rmr_get_trlen( mbuf );
+ errors += fail_not_equal( state, 17, "alloc with trace size: initial trace len reported (a) does not match expected (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)" );
+
+ state = rmr_get_trace( mbuf, src_buf, 17 );
+ errors += fail_not_equal( state, 17, "bytes retrieved from trace (a) did not match expected size (b)" );
+ state = strcmp( src_buf, "foo bar was here" );
+ 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( (int) buf, (int) src_buf, "rmr_get_src didn't return expexted buffer pointer" );