blob: f716378c22954842f305347c2a2010d94603ad66 [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>
E. Scott Daniels412d53d2019-05-20 20:00:52 +000037#include <pthread.h>
38#include <semaphore.h>
E. Scott Daniels8dd46412019-04-16 20:47:54 +000039
40#include <nng/nng.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>
45
E. Scott Daniels412d53d2019-05-20 20:00:52 +000046#include "rmr.h"
47#include "rmr_agnostic.h"
48#include "rmr_nng_private.h"
E. Scott Daniels8dd46412019-04-16 20:47:54 +000049
50#define EMULATE_NNG
51#include "test_nng_em.c"
E. Scott Daniels412d53d2019-05-20 20:00:52 +000052#include "sr_nng_static.c"
E. Scott Daniels8dd46412019-04-16 20:47:54 +000053
54#include "test_support.c"
55
56/*
57 Dummy for testing here
58*/
59extern void rmr_free_msg( rmr_mbuf_t* mbuf ) {
60}
61
62static int hdr_test( ) {
63 int errors = 0;
64 uta_ctx_t* ctx;
65 rmr_mbuf_t* msg;
66 uta_mhdr_t* hdr;
67 int hlen;
68 int len;
69 int payload_len = 2049;
70 int trace_len = 37;
71
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" );
75
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 );
79
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" );
82
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" );
85
86
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)" );
93
94 len = RMR_TR_LEN( hdr );
95 errors += fail_not_equal( len, trace_len, "trace len in header (a) not expected value (b)" );
96
97 len = RMR_D1_LEN( hdr );
98 errors += fail_not_equal( len, 0, "d1 len in header (a) not expected value (b)" );
99
100 len = RMR_D2_LEN( hdr );
101 errors += fail_not_equal( len, 0, "d2 len in header (a) not expected value (b)" );
102
103
104 // -------------------------------------------------------------------------------------------
105
106 if( ! errors ) {
107 fprintf( stderr, "<INFO> all msg header tests pass\n" );
108 }
109 return !! errors;
110}
111
112int main() {
113 return hdr_test();
114}