blob: 82a01a83c631bc143a35261cdee225b58be7b335 [file] [log] [blame]
E. Scott Daniels8dd46412019-04-16 20:47:54 +00001// : vi ts=4 sw=4 noet :
2/*
3==================================================================================
E. Scott Daniels5efb1e62019-05-02 17:09:35 +00004 Copyright (c) 2019 Nokia
E. Scott Daniels8790bf02019-04-23 12:59:28 +00005 Copyright (c) 2018-2019 AT&T Intellectual Property.
E. Scott Daniels8dd46412019-04-16 20:47:54 +00006
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
10
E. Scott Daniels8790bf02019-04-23 12:59:28 +000011 http://www.apache.org/licenses/LICENSE-2.0
E. Scott Daniels8dd46412019-04-16 20:47:54 +000012
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==================================================================================
19*/
20
21/*
22 Mmemonic: hdr_static_test.c
23 Abstract: This tests specific properties of the message header
24
25 Author: E. Scott Daniels
26 Date: 12 April 2019
27*/
28
29#include <unistd.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <strings.h>
33#include <errno.h>
34#include <string.h>
35#include <stdint.h>
36#include <netdb.h>
37
38#include <nng/nng.h>
39#include <nng/protocol/pubsub0/pub.h>
40#include <nng/protocol/pubsub0/sub.h>
41#include <nng/protocol/pipeline0/push.h>
42#include <nng/protocol/pipeline0/pull.h>
43
44#include "../src/common/include/rmr.h"
45#include "../src/common/include/rmr_agnostic.h"
46#include "../src/nng/include/rmr_nng_private.h"
47
48#define EMULATE_NNG
49#include "test_nng_em.c"
50#include "../src/nng/src/sr_nng_static.c"
51
52#include "test_support.c"
53
54/*
55 Dummy for testing here
56*/
57extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
58}
59
60static int hdr_test( ) {
61 int errors = 0;
62 uta_ctx_t* ctx;
63 rmr_mbuf_t* msg;
64 uta_mhdr_t* hdr;
65 int hlen;
66 int len;
67 int payload_len = 2049;
68 int trace_len = 37;
69
70 ctx = (uta_ctx_t *) malloc( sizeof( *ctx ) );
71 ctx->trace_data_len = 0;
72 ctx->my_name = strdup( "my-dummy-host-name-and-port:xxxx" );
73
74 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
75 hdr = (uta_mhdr_t *) msg->header;
76 hlen = RMR_HDR_LEN( hdr );
77
78 fprintf( stderr, "<INFO> struct len= %d msg len= %d %d\n", (int) sizeof( uta_mhdr_t ), hlen, htonl( hlen ) );
79 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ), "header len (a) not size of struct when no trace data is present" );
80
81 len = (int) sizeof( uta_mhdr_t ) + payload_len; // expected size of transport buffer allocated
82 errors += fail_not_equal( len, msg->alloc_len, "alloc len (a) not expected size" );
83
84
85 ctx->trace_data_len = trace_len; // alloc messages with tracing buffer in place
86 msg = alloc_zcmsg( ctx, NULL, payload_len, 0 ); // header len here should just be len of our struct
87 hdr = (uta_mhdr_t *) msg->header;
88 hlen = RMR_HDR_LEN( hdr );
89 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 ) );
90 errors += fail_not_equal( hlen, (int) sizeof( uta_mhdr_t ) + trace_len, "header len (a) was not header + trace data size (b)" );
91
92 len = RMR_TR_LEN( hdr );
93 errors += fail_not_equal( len, trace_len, "trace len in header (a) not expected value (b)" );
94
95 len = RMR_D1_LEN( hdr );
96 errors += fail_not_equal( len, 0, "d1 len in header (a) not expected value (b)" );
97
98 len = RMR_D2_LEN( hdr );
99 errors += fail_not_equal( len, 0, "d2 len in header (a) not expected value (b)" );
100
101
102 // -------------------------------------------------------------------------------------------
103
104 if( ! errors ) {
105 fprintf( stderr, "<INFO> all msg header tests pass\n" );
106 }
107 return !! errors;
108}
109
110int main() {
111 return hdr_test();
112}