• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "heartbeat_ut.h"
16 #include "securec.h"
17 #include "serial_struct.h"
18 
19 using namespace testing::ext;
20 namespace Hdc {
SetUpTestCase()21 void HdcHeartbeatTest::SetUpTestCase() {}
TearDownTestCase()22 void HdcHeartbeatTest::TearDownTestCase() {}
SetUp()23 void HdcHeartbeatTest::SetUp() {}
TearDown()24 void HdcHeartbeatTest::TearDown() {}
25 
26 HWTEST_F(HdcHeartbeatTest, TestAddHeartbeatCount, TestSize.Level0)
27 {
28     HdcHeartbeat heartbeat;
29     int count = heartbeat.heartbeatCount;
30     heartbeat.AddHeartbeatCount();
31     ASSERT_EQ(heartbeat.heartbeatCount, count + 1);
32 }
33 
34 HWTEST_F(HdcHeartbeatTest, TestAddMessageCount, TestSize.Level0)
35 {
36     HdcHeartbeat heartbeat;
37     int count = heartbeat.messageCount;
38     heartbeat.AddMessageCount();
39     ASSERT_EQ(heartbeat.messageCount, count + 1);
40 }
41 
42 HWTEST_F(HdcHeartbeatTest, TestGetHeartbeatCount, TestSize.Level0)
43 {
44     HdcHeartbeat heartbeat;
45     int count = heartbeat.heartbeatCount;
46     ASSERT_EQ(heartbeat.GetHeartbeatCount(), count);
47 }
48 
49 HWTEST_F(HdcHeartbeatTest, TestToString, TestSize.Level0)
50 {
51     HdcHeartbeat heartbeat;
52     std::string str = heartbeat.ToString();
53     std::stringstream ss;
54     ss << "heartbeat count is " << heartbeat.heartbeatCount << " and messages count is " << heartbeat.messageCount;
55     ASSERT_EQ(str, ss.str());
56 }
57 
58 HWTEST_F(HdcHeartbeatTest, TestHandleRecvHeartbeatMsg, TestSize.Level0)
59 {
60     HdcSessionBase::HeartbeatMsg heartbeatMsg;
61     HdcHeartbeat heartbeat;
62     int count = rand();
63     heartbeatMsg.heartbeatCount = count;
64     std::string s = SerialStruct::SerializeToString(heartbeatMsg);
65     std::string str = heartbeat.HandleRecvHeartbeatMsg(
66         reinterpret_cast<uint8_t *>(const_cast<char *>(s.c_str())), s.size());
67     std::stringstream ss;
68     ss << "heartbeat count is " << count;
69     ASSERT_EQ(str, ss.str());
70 }
71 
72 HWTEST_F(HdcHeartbeatTest, TestSupportHeartbeat, TestSize.Level0)
73 {
74     HdcHeartbeat heartbeat;
75     bool supportHeartbeat = true;
76     heartbeat.SetSupportHeartbeat(supportHeartbeat);
77     ASSERT_EQ(heartbeat.supportHeartbeat, supportHeartbeat);
78     ASSERT_EQ(heartbeat.GetSupportHeartbeat(), supportHeartbeat);
79 }
80 }