CI: Add silent cmake SonarCloud scan
[ric-plt/lib/rmr.git] / test / rmr_si_rcv_static_test.c
index ad543a0..b040359 100644 (file)
@@ -1,8 +1,8 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-           Copyright (c) 2019-2020 Nokia
-           Copyright (c) 2018-2020 AT&T Intellectual Property.
+           Copyright (c) 2019-2021 Nokia
+           Copyright (c) 2018-2021 AT&T Intellectual Property.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -150,6 +150,7 @@ static int rmr_rcv_test( ) {
        }
 
        rmr_rts_msg( NULL, NULL );                      // drive for coverage
+       errors += fail_if( errno == 0, "rmr_rts_msg did not set errno when given a nil context "  );
        rmr_rts_msg( rmc, NULL );
        errors += fail_if( errno == 0, "rmr_rts_msg did not set errno when given a nil message "  );
 
@@ -225,6 +226,42 @@ static int rmr_rcv_test( ) {
        rmr_close( rmc );                       // no return to check; drive for coverage
 
 
+       // ------- receive specific is deprecated, but we still test to keep sonar happy ---------------
+
+       rmr_rcv_specific( NULL, NULL, "12345", 0 );             // drive for error handling coverage
+       rmr_rcv_specific( NULL, msg, "12345", 2 );
+
+       strncpy( wbuf, "dummy message", sizeof( wbuf ) );
+       msg = mk_populated_msg( 1024, 0, 0, -1, strlen( wbuf ) + 1 );
+       strncpy( msg->payload, wbuf, msg->len );
+       msg = rmr_send_msg( rmc, msg );                                         // give specific something to chew on
+
+       strncpy( msg->payload, wbuf, msg->len );
+       msg->mtype = 0;
+       rmr_str2xact( msg, "12345" );                                           // should allow rcv to find it
+       msg = rmr_send_msg( rmc, msg );
+
+       msg = rmr_rcv_specific( rmc, NULL, "12345", 2 );
+       if( msg ) {
+               errors += fail_if( msg->state != 0, "rmr_rcv_specific failed to find the expected message" );
+       } else {
+               errors++;
+               fprintf( stderr, "<FAIL> rcv specific expected to return a message and did not\n" );
+       }
+
+       strncpy( wbuf, "dummy message", sizeof( wbuf ) );
+       msg = mk_populated_msg( 1024, 0, 0, -1, strlen( wbuf ) + 1 );
+       strncpy( msg->payload, wbuf, msg->len );
+       msg = rmr_send_msg( rmc, msg );                                         // give specific something to chew on
+
+       fprintf( stderr, "<INFO> starting rmr_rcv_specific test for no expected message\n" );
+       strncpy( msg->payload, wbuf, msg->len );
+       msg->mtype = 0;
+       rmr_str2xact( msg, "72345" );                                           // rcv should not find it
+       msg = rmr_send_msg( rmc, msg );
+       msg = rmr_rcv_specific( rmc, msg, "12345", 2 );
+       fail_if_nil( msg, "rmr_rcv_specific expected to retun nil message did  not" );
+
        // --------------- phew, done ------------------------------------------------------------------------------
 
        if( ! errors ) {
@@ -233,5 +270,5 @@ static int rmr_rcv_test( ) {
                fprintf( stderr, "<INFO> receive tests failures noticed \n" );
        }
 
-       return !!errors;
+       return errors;
 }