1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 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"
48 #include "rmr_nng_private.h"
51 #include "test_nng_em.c"
52 #include "sr_nng_static.c"
54 #include "test_support.c"
57 Dummy for testing here
59 extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
62 static int hdr_test( ) {
69 int payload_len = 2049;
72 ctx = (uta_ctx_t *) malloc( sizeof( *ctx ) );
73 ctx->trace_data_len = 0;
74 ctx->my_name = strdup( "my-dummy-host-name-and-port:xxxx" );
76 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
77 hdr = (uta_mhdr_t *) msg->header;
78 hlen = RMR_HDR_LEN( hdr );
80 fprintf( stderr, "<INFO> struct len= %d msg len= %d %d\n", (int) sizeof( uta_mhdr_t ), hlen, htonl( hlen ) );
81 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ), "header len (a) not size of struct when no trace data is present" );
83 len = (int) sizeof( uta_mhdr_t ) + payload_len; // expected size of transport buffer allocated
84 errors += fail_not_equal( len, msg->alloc_len, "alloc len (a) not expected size" );
87 ctx->trace_data_len = trace_len; // alloc messages with tracing buffer in place
88 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
89 hdr = (uta_mhdr_t *) msg->header;
90 hlen = RMR_HDR_LEN( hdr );
91 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 ) );
92 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ) + trace_len, "header len (a) was not header + trace data size (b)" );
94 len = RMR_TR_LEN( hdr );
95 errors += fail_not_equal( len, trace_len, "trace len in header (a) not expected value (b)" );
97 len = RMR_D1_LEN( hdr );
98 errors += fail_not_equal( len, 0, "d1 len in header (a) not expected value (b)" );
100 len = RMR_D2_LEN( hdr );
101 errors += fail_not_equal( len, 0, "d2 len in header (a) not expected value (b)" );
104 // -------------------------------------------------------------------------------------------
107 fprintf( stderr, "<INFO> all msg header tests pass\n" );