1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019-2021 Nokia
5 Copyright (c) 2018-2021 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 Mmemonic: hdr_static_test.c
23 Abstract: This tests specific properties of the message header
25 Author: E. Scott Daniels
38 #include <semaphore.h>
41 #include <nng/protocol/pubsub0/pub.h>
42 #include <nng/protocol/pubsub0/sub.h>
43 #include <nng/protocol/pipeline0/push.h>
44 #include <nng/protocol/pipeline0/pull.h>
47 #include "rmr_agnostic.h"
50 #define NNG_UNDER_TEST
51 #include "sr_nng_static.c"
53 #include "test_support.c"
56 Dummy for testing here
58 extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
61 static int hdr_test( ) {
68 int payload_len = 2049;
71 ctx = (uta_ctx_t *) malloc( sizeof( *ctx ) );
72 ctx->trace_data_len = 0;
73 ctx->my_name = strdup( "my-dummy-host-name-and-port:xxxx" );
75 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
76 hdr = (uta_mhdr_t *) msg->header;
77 hlen = RMR_HDR_LEN( hdr );
79 fprintf( stderr, "<INFO> struct len= %d msg len= %d %d\n", (int) sizeof( uta_mhdr_t ), hlen, htonl( hlen ) );
80 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ), "header len (a) not size of struct when no trace data is present" );
82 len = (int) sizeof( uta_mhdr_t ) + payload_len; // expected size of transport buffer allocated
83 errors += fail_not_equal( len, msg->alloc_len, "alloc len (a) not expected size" );
86 ctx->trace_data_len = trace_len; // alloc messages with tracing buffer in place
87 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
88 hdr = (uta_mhdr_t *) msg->header;
89 hlen = RMR_HDR_LEN( hdr );
90 fprintf( stderr, "<INFO> with trace data: struct+trace len= %d msg len= %d %d\n", (int) sizeof( uta_mhdr_t )+trace_len, hlen, htonl( hlen ) );
91 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ) + trace_len, "header len (a) was not header + trace data size (b)" );
93 len = RMR_TR_LEN( hdr );
94 errors += fail_not_equal( len, trace_len, "trace len in header (a) not expected value (b)" );
96 len = RMR_D1_LEN( hdr );
97 errors += fail_not_equal( len, 0, "d1 len in header (a) not expected value (b)" );
99 len = RMR_D2_LEN( hdr );
100 errors += fail_not_equal( len, 0, "d2 len in header (a) not expected value (b)" );
103 // -------------------------------------------------------------------------------------------
106 fprintf( stderr, "<INFO> all msg header tests pass\n" );
114 errors += hdr_test();