CI: Add silent cmake SonarCloud scan
[ric-plt/lib/rmr.git] / test / lg_buf_static_test.c
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4             Copyright (c) 2020 Nokia
5             Copyright (c) 2020 AT&T Intellectual Property.
6
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
11            http://www.apache.org/licenses/LICENSE-2.0
12
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:       rmr_si_lgb_static_test.c
23         Abstract:       These are specific tests to exercise the ability to receive
24                                 a buffer larger than what was specified as the normal max
25                                 on the init call.
26
27         Author:         E. Scott Daniels
28         Date:           9 April 2020
29 */
30
31 #include <unistd.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <strings.h>
35 #include <errno.h>
36 #include <string.h>
37 #include <stdint.h>
38 #include <pthread.h>
39 #include <semaphore.h>
40
41 #include "rmr.h"
42 #include "rmr_agnostic.h"
43
44 static int rmr_lgbuf_test( ) {
45         int             errors = 0;
46         void*   rmc;                            // route manager context
47         rmr_mbuf_t*     msg;                    // message buffers
48
49         if( (rmc = rmr_init( "4560", 128, FL_NOTHREAD )) == NULL ) {            // use a short "normal max" value
50                 fail_if_nil( rmc, "rmr_init returned a nil pointer when trying to initialise a short normal max"  );
51                 return 1;
52         }
53
54         gen_rt( rmc );                                                  // dummy route table so the send works
55         msg = rmr_alloc_msg( rmc, 4024 );               // payload size, and the msg len must be larger than 128
56         msg->len = 4000;
57         msg->mtype = 1;
58         msg->state = 999;
59         snprintf( msg->payload, msg->len, "Rambling Wreck from Georgia Tech!\n\n" );
60         msg = rmr_send_msg( rmc, msg );
61         if( msg && msg->state != RMR_OK ) {
62                 fprintf( stderr, "<FAIL> lg buf test: send failed? %d\n", msg->state );
63         }
64         rmr_free_msg( msg );
65
66         msg = rmr_torcv_msg( rmc, NULL, 2000 );
67         errors += fail_if( msg == NULL, "rmr_rcv_msg returned nil msg when given nil msg "  );
68         if( msg ) {
69                 errors += fail_not_equal( msg->state, RMR_OK, "receive given nil message did not return msg with good state"  );
70
71                 errors += fail_if_false( msg->len > 128, "expected larger message than the small buffer" );
72         }
73
74         return errors;
75 }