• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include "define_ut.h"
17 using namespace testing::ext;
18 using namespace std;
19 namespace Hdc {
SetUpTestCase()20 void HdcDefineTest::SetUpTestCase() {}
21 
TearDownTestCase()22 void HdcDefineTest::TearDownTestCase() {}
23 
SetUp()24 void HdcDefineTest::SetUp() {}
25 
TearDown()26 void HdcDefineTest::TearDown() {}
27 
InstanceHSession()28 HSession HdcDefineTest::InstanceHSession()
29 {
30     return new(std::nothrow) HdcSession();
31 }
32 
InstanceHChannel()33 HChannel HdcDefineTest::InstanceHChannel()
34 {
35     return new(std::nothrow) HdcChannel();
36 }
37 
38 /*
39  * @tc.name: TestToDisplayConnectionStr
40  * @tc.desc: Check the return of ToDisplayConnectionStr method.
41  * @tc.type: FUNC
42  */
43 HWTEST_F(HdcDefineTest, TestToDisplayConnectionStr, TestSize.Level1)
44 {
45     HSession session = HdcDefineTest::InstanceHSession();
46     session->connectKey = "7001005458323933328a259b97233900";
47     session->sessionId = 2867909239;
48     session->connType = 0;
49     session->isRunningOk = true;
50     session->faultInfo = "";
51     session->commandCount = 1;
52     std::string result = "HdcServer [ sessionId:2867909239 connectKey:700******900(L:32) "
53     "connType:0 connect state:1 faultInfo: commandCount:1 ]";
54     ASSERT_EQ(session->ToDisplayConnectionStr(), result);
55 
56     delete session;
57 }
58 
59 /*
60  * @tc.name: TestToDisplayChannelStr1
61  * @tc.desc: Check the return of ToDisplayConnectionStr method.
62  * @tc.type: FUNC
63  */
64 HWTEST_F(HdcDefineTest, TestToDisplayChannelStr1, TestSize.Level1)
65 {
66     HChannel channel = HdcDefineTest::InstanceHChannel();
67     channel->connectKey = "7001005458323933328a259b97233900";
68     channel->channelId = 2867909239;
69     channel->commandFlag = 3000;
70     channel->commandParameters = "send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/";
71     channel->startTime = 22121121212;
72     channel->endTime = 22121121312;
73     channel->isSuccess = true;
74     channel->faultInfo = "";
75     std::string result = "HdcServerForClient [ channelId:2867909239 connectKey:700******900(L:32) "
76     "command flag:3000 command parameters:send remote -cwd \"D:\\test\\script0408\\scripts\\\" "
77     "main.py /data/ command result:1 command take time:100ms faultInfo: ]";
78     ASSERT_EQ(channel->ToDisplayChannelStr(), result);
79 
80     delete channel;
81 }
82 
83 /*
84  * @tc.name: TestToDisplayChannelStr2
85  * @tc.desc: Check the return of ToDisplayConnectionStr method.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(HdcDefineTest, TestToDisplayChannelStr2, TestSize.Level1)
89 {
90     HChannel channel = HdcDefineTest::InstanceHChannel();
91     channel->connectKey = "7001005458323933328a259b97233900";
92     channel->channelId = 2867909239;
93     channel->commandFlag = 3000;
94     channel->commandParameters = "send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/  ";
95     channel->startTime = 22121121212;
96     channel->endTime = 22121121312;
97     channel->isSuccess = true;
98     channel->faultInfo = "";
99     std::string result = "HdcServerForClient [ channelId:2867909239 connectKey:700******900(L:32) "
100         "command flag:3000 command parameters:send remote -cwd \"D:\\test\\script0408\\scripts\\\" "
101         "main.py /data/   command result:1 command take time:100ms faultInfo: ]";
102     ASSERT_EQ(channel->ToDisplayChannelStr(), result);
103 
104     delete channel;
105 }
106 }