1 // vim: ts=4 sw=4 noet:
3 --------------------------------------------------------------------------------
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 --------------------------------------------------------------------------------
21 Mnemonic: test_rmr_em.c.
22 Abstract: Emulates some RMR functions (message receipt mostly)
23 so that we can unit test.
25 This file should be included by the test programme BEFORE
26 any module which uses RMR functions is included
28 Date: 10 December 2019
29 Author: E. Scott Daniels
33 #include <rmr/RIC_message_types.h>
37 The first call will generate a timeout for testing. All others will
38 succeed with a message.
40 extern rmr_mbuf_t* RMR_torcv_msg( void* ctx, rmr_mbuf_t* old_msg, int ms_to ) {
41 static int timeout = 0;
42 static int hcheck = 0;
44 if( old_msg == NULL ) {
45 old_msg = rmr_alloc_msg( ctx, 256 );
46 if( old_msg == NULL ) {
51 timeout = ! timeout; // every other message results in a timeout
53 old_msg->state = RMR_ERR_TIMEOUT;
57 if( !hcheck ) { // send one health check message
58 old_msg->mtype = RIC_HEALTH_CHECK_REQ;
65 snprintf( old_msg->payload, rmr_payload_size( old_msg ), "DUMMY MESSAGE" );
66 old_msg->mtype = TEST_MTYPE;
67 old_msg->len = strlen( old_msg->payload );
75 Always successful if a message was passed in.
77 extern rmr_mbuf_t* RMR_rts_msg( void* ctx, rmr_mbuf_t* msg ) {
86 Generates "short" reads 9 out of 10 times so that we can
87 drive the buffer construction code that otherwise wouldn't
88 be driven since long reads are usually the case.
90 extern int Read( int fd, char* dest, int max ) {
91 static int count = -1;
96 return read( fd, dest, max ); // return long read
99 return read( fd, dest, 3 ); // short read
102 // ----------- defines that point included code here --------------------
103 #define rmr_torcv_msg RMR_torcv_msg
104 #define rmr_rts_msg RMR_rts_msg