Testcase for A1 Healthcheck added.
[ric-app/hw.git] / test / test_rmr.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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 ==================================================================================
18 /*
19  * test_rmr_healthcheck.h
20  *
21  *  Created on: Mar, 2020
22  *  Author: Shraboni Jana
23  */
24
25 #ifndef TEST_TEST_RMR_H_
26 #define TEST_TEST_RMR_H_
27 #include<iostream>
28 #include<gtest/gtest.h>
29 #include "xapp.hpp"
30
31 #define HC_MSG_SIZE 512
32
33 using namespace std;
34
35 TEST(RMR, Sender){
36
37         int total_num_msgs = 2;
38         int num_attempts = 10;
39
40         std::unique_ptr<XappRmr> rmr;
41         rmr = std::make_unique<XappRmr>("4560",num_attempts);
42         rmr->xapp_rmr_init();
43         rmr->set_listen(false);
44
45         xapp_rmr_header hdr;
46         hdr.message_type = RIC_HEALTH_CHECK_REQ;
47
48     for(int i = 0; i < total_num_msgs; i++){
49         std::string temp="HelloWorld: RMR Health Check"+ std::to_string(i);
50         int n = temp.length();
51         char strMsg[n+1];
52         std::strcpy(strMsg,temp.c_str());
53
54         clock_gettime(CLOCK_REALTIME, &(hdr.ts));
55         hdr.payload_length = n+1;
56
57         bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
58         ASSERT_TRUE(res);
59         usleep(1);
60      }
61     ASSERT_TRUE(true);
62 }
63  TEST(RMR, Receiver){
64          //initialize rmr
65          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
66          XappRmr *rmr = new XappRmr("4560");
67          rmr->xapp_rmr_init();
68          sleep(10);
69          rmr->set_listen(false);
70          rmr->xapp_rmr_receive(std::move(*mp_handler), rmr);
71          ASSERT_TRUE(true);
72  };
73
74
75 #endif /* TEST_TEST_RMR_H_ */