feat(routing): Support session based routing
[ric-plt/lib/rmr.git] / test / rmr_nng_api_static_test.c
index 3d09f28..cefc09f 100644 (file)
@@ -1,14 +1,14 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-        Copyright (c) 2019 Nokia 
-        Copyright (c) 2018-2019 AT&T Intellectual Property.
+           Copyright (c) 2019 Nokia
+           Copyright (c) 2018-2019 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.
    You may obtain a copy of the License at
 
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0
+          http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,7 +23,7 @@
        Abstract:       Specific tests related to the API functions in rmr_nng.c/rmr.c.
                                This should be included by a driver, but only the main RMr
                                driver and there likely not be a specific stand alone driver
        Abstract:       Specific tests related to the API functions in rmr_nng.c/rmr.c.
                                This should be included by a driver, but only the main RMr
                                driver and there likely not be a specific stand alone driver
-                               for just this small set of tests because of the depth of the 
+                               for just this small set of tests because of the depth of the
                                library needed to test at this level.
 
                                The message buffer specific API tests are in a different static
                                library needed to test at this level.
 
                                The message buffer specific API tests are in a different static
@@ -130,7 +130,7 @@ static int rmr_api_test( ) {
        } else {
                errors += fail_if( v < 0, "rmr_payload_size returned invalid size for good message" );
        }
        } else {
                errors += fail_if( v < 0, "rmr_payload_size returned invalid size for good message" );
        }
-       
+
        v = rmr_get_rcvfd( NULL );
        errors += fail_if( v >= 0, "rmr_get_rcvfd returned a valid file descriptor when given nil context" );
        v = rmr_get_rcvfd( rmc );
        v = rmr_get_rcvfd( NULL );
        errors += fail_if( v >= 0, "rmr_get_rcvfd returned a valid file descriptor when given nil context" );
        v = rmr_get_rcvfd( rmc );
@@ -139,6 +139,10 @@ static int rmr_api_test( ) {
        msg2 = rmr_send_msg( NULL, NULL );                      // drive for coverage
        errors += fail_not_nil( msg2, "send_msg returned msg pointer when given a nil message and context" );
 
        msg2 = rmr_send_msg( NULL, NULL );                      // drive for coverage
        errors += fail_not_nil( msg2, "send_msg returned msg pointer when given a nil message and context" );
 
+       msg->state = 0;
+       msg = rmr_send_msg( NULL, msg );
+       errors += fail_if( msg->state == 0, "rmr_send_msg did not set msg state when msg given with nil context" );
+
        // --- sends will fail with a no endpoint error until a dummy route table is set, so we test fail case first.
        msg->len = 100;
        msg->mtype = 1;
        // --- sends will fail with a no endpoint error until a dummy route table is set, so we test fail case first.
        msg->len = 100;
        msg->mtype = 1;
@@ -194,17 +198,28 @@ static int rmr_api_test( ) {
        rmr_rts_msg( rmc, NULL );
        errors += fail_if( errno == 0, "rmr_rts_msg did not set errno when given a nil message" );
 
        rmr_rts_msg( rmc, NULL );
        errors += fail_if( errno == 0, "rmr_rts_msg did not set errno when given a nil message" );
 
+       msg->state = 0;
+       msg = rmr_rts_msg( NULL, msg );                 // should set state in msg
+       errors += fail_if_equal( msg->state, 0, "rmr_rts_msg did not set state when given valid message but no context" );
+       
+
        msg = rmr_rts_msg( rmc, msg );                  // return the buffer to the sender
        errors += fail_if_nil( msg, "rmr_rts_msg did not return a message pointer" );
        errors += fail_if( errno != 0, "rmr_rts_msg did not reset errno" );
 
 
        snprintf( msg->xaction, 17, "%015d", 16 );              // dummy transaction id (emulation generates, this should arrive after a few calls to recv)
        msg = rmr_rts_msg( rmc, msg );                  // return the buffer to the sender
        errors += fail_if_nil( msg, "rmr_rts_msg did not return a message pointer" );
        errors += fail_if( errno != 0, "rmr_rts_msg did not reset errno" );
 
 
        snprintf( msg->xaction, 17, "%015d", 16 );              // dummy transaction id (emulation generates, this should arrive after a few calls to recv)
+
+       msg->state = 0;
+       msg = rmr_call( NULL, msg );
+       errors += fail_if( msg->state == 0, "rmr_call did not set message state when given message with nil context" );
+
+       msg->mtype = 0;
        msg = rmr_call( rmc, msg );                                             // this call should return a message as we can anticipate a dummy message in
        errors += fail_if_nil( msg, "rmr_call returned a nil message on call expected to succeed" );
        if( msg ) {
                errors += fail_not_equal( msg->state, RMR_OK, "rmr_call did not properly set state on successful return" );
        msg = rmr_call( rmc, msg );                                             // this call should return a message as we can anticipate a dummy message in
        errors += fail_if_nil( msg, "rmr_call returned a nil message on call expected to succeed" );
        if( msg ) {
                errors += fail_not_equal( msg->state, RMR_OK, "rmr_call did not properly set state on successful return" );
-               errors += fail_if( errno != 0, "rmr_call did not properly set errno on successful return" );
+               errors += fail_not_equal( errno, 0, "rmr_call did not properly set errno (a) on successful return" );
        }
 
        snprintf( wbuf, 17, "%015d", 14 );                              // if we call receive we should find this in the first 15 tries
        }
 
        snprintf( wbuf, 17, "%015d", 14 );                              // if we call receive we should find this in the first 15 tries
@@ -221,7 +236,7 @@ static int rmr_api_test( ) {
        }
 
        errors += fail_if( i >= 16, "did not find expected message on queue" );
        }
 
        errors += fail_if( i >= 16, "did not find expected message on queue" );
-               
+
        if( ! msg ) {
                msg = rmr_alloc_msg( rmc, 2048 );                               // something buggered above; get a new one
        }
        if( ! msg ) {
                msg = rmr_alloc_msg( rmc, 2048 );                               // something buggered above; get a new one
        }
@@ -240,6 +255,11 @@ static int rmr_api_test( ) {
        rmr_free_msg( msg2 );
 
 
        rmr_free_msg( msg2 );
 
 
+       msg2 = rmr_torcv_msg( NULL, NULL, 10 );
+       errors += fail_not_nil( msg2, "rmr_torcv_msg returned a pointer when given nil information" );
+       msg2 = rmr_torcv_msg( rmc, NULL, 10 );
+       errors += fail_if_nil( msg2, "rmr_torcv_msg did not return a message pointer when given a nil old msg" );
+
        // ---  test timeout receive; our dummy epoll function will return 1 ready on first call and 0 ready (timeout emulation) on second
        //              however we must drain the swamp (queue) first, so run until we get a timeout error, or 20 and report error if we get to 20.
        msg = NULL;
        // ---  test timeout receive; our dummy epoll function will return 1 ready on first call and 0 ready (timeout emulation) on second
        //              however we must drain the swamp (queue) first, so run until we get a timeout error, or 20 and report error if we get to 20.
        msg = NULL;
@@ -270,12 +290,12 @@ static int rmr_api_test( ) {
        errors += fail_not_equal( state, 17, "len of trace data (a) returned after msg allocation was not expected size (b)" );
        state = strcmp( wbuf, "1904308620110417" );
        errors += fail_not_equal( state, 0, "trace data returned after tralloc was not correct" );
        errors += fail_not_equal( state, 17, "len of trace data (a) returned after msg allocation was not expected size (b)" );
        state = strcmp( wbuf, "1904308620110417" );
        errors += fail_not_equal( state, 0, "trace data returned after tralloc was not correct" );
-       
+
        em_send_failures = 1;
        send_n_msgs( rmc, 30 );                 // send 30 messages with emulation failures
        em_send_failures = 0;
 
        em_send_failures = 1;
        send_n_msgs( rmc, 30 );                 // send 30 messages with emulation failures
        em_send_failures = 0;
 
-       
+
        rmr_close( NULL );                      // drive for coverage
        rmr_close( rmc );                       // no return to check; drive for coverage
 
        rmr_close( NULL );                      // drive for coverage
        rmr_close( rmc );                       // no return to check; drive for coverage