From 5c99519db8e2f90870f07146af70a9e8ea5a61a7 Mon Sep 17 00:00:00 2001 From: liupeng298 Date: Mon, 12 May 2025 12:09:33 +0000 Subject: [PATCH 1/4] add test/unittest/common/include/define_ut.h. Signed-off-by: liupeng298 --- test/unittest/common/include/define_ut.h | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/unittest/common/include/define_ut.h diff --git a/test/unittest/common/include/define_ut.h b/test/unittest/common/include/define_ut.h new file mode 100644 index 00000000..23328659 --- /dev/null +++ b/test/unittest/common/include/define_ut.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HDC_DEFINE_TEST_H +#include +#include +#include "define_plus.h" +namespace Hdc { +class HdcDefineTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + HSession InstanceHSession(); + HChannel InstanceHChannel(); + +private: +}; +} // namespace Hdc +#endif // HDC_DEFINE_TEST_H \ No newline at end of file -- Gitee From 0a1ca8ee53a2c3b842d1a9c23723bddbae6ff85f Mon Sep 17 00:00:00 2001 From: liupeng298 Date: Mon, 12 May 2025 12:11:13 +0000 Subject: [PATCH 2/4] add test/unittest/common/define_test.cpp. Signed-off-by: liupeng298 --- test/unittest/common/define_test.cpp | 105 +++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 test/unittest/common/define_test.cpp diff --git a/test/unittest/common/define_test.cpp b/test/unittest/common/define_test.cpp new file mode 100644 index 00000000..d511eab9 --- /dev/null +++ b/test/unittest/common/define_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +using namespace testing::ext; +using namespace std; +namespace Hdc { +void HdcDefineTest::SetUpTestCase() {} + +void HdcDefineTest::TearDownTestCase() {} + +void HdcDefineTest::SetUp() {} + +void HdcDefineTest::TearDown() {} + +HSession HdcDefineTest::InstanceHSession() +{ + return new(std::nothrow) HdcSession(); +} + +HChannel HdcDefineTest::InstanceHChannel() +{ + return new(std::nothrow) HdcChannel(); +} + +/* + * @tc.name: TestToDisplayConnectionStr + * @tc.desc: Check the return of ToDisplayConnectionStr method. + * @tc.type: FUNC + */ +HWTEST_F(HdcDefineTest, TestToDisplayConnectionStr, TestSize.Level1) +{ + HSession session = HdcDefineTest::InstanceHSession(); + session->connectKey = "7001005458323933328a259b97233900"; + session->sessionId = "2867909239"; + session->connType = 0; + session->isRunningOk = true; + session->faultInfo = ""; + session->commandCount = 1; + std::string result = "HdcServer [ sessionId:2867909239 connectKey:700******900(L:32) \ + connType:0 connect state:1 faultInfo: commandCount:1 ]"; + ASSERT_EQ(session->ToDisplayConnectionStr(), result); + + delete session; +} + +/* + * @tc.name: TestToDisplayChannelStr1 + * @tc.desc: Check the return of ToDisplayConnectionStr method. + * @tc.type: FUNC + */ +HWTEST_F(HdcDefineTest, TestToDisplayChannelStr1, TestSize.Level1) +{ + HChannel channel = HdcDefineTest::InstanceHChannel(); + channel->connectKey = "7001005458323933328a259b97233900"; + channel->channelId = "2867909239"; + channel->commandFlag = 3000; + channel->commandParameters = "send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/"; + channel->startTime = 22121121212; + channel->endTime = 22121121312; + channel->isSuccess = true; + channel->faultInfo = ""; + std::string result = "HdcServerForClient [ channelId:2867909239 connectKey:700******900(L:32) \ + command flag:3000 command parameters:send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/\ + command result:1 command take time:100ms faultInfo: ]"; + ASSERT_EQ(channel->ToDisplayChannelStr(), result); + + delete channel; +} + +/* + * @tc.name: TestToDisplayChannelStr2 + * @tc.desc: Check the return of ToDisplayConnectionStr method. + * @tc.type: FUNC + */ +HWTEST_F(HdcDefineTest, TestToDisplayChannelStr2, TestSize.Level1) +{ + HChannel channel = HdcDefineTest::InstanceHChannel(); + channel->connectKey = "7001005458323933328a259b97233900"; + channel->channelId = "2867909239"; + channel->commandFlag = 3000; + channel->commandParameters = "send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/ "; + channel->startTime = 22121121212; + channel->endTime = 22121121312; + channel->isSuccess = true; + channel->faultInfo = ""; + std::string result = "HdcServerForClient [ channelId:2867909239 connectKey:700******900(L:32) \ + command flag:3000 command parameters:send remote -cwd \"D:\\test\\script0408\\scripts\\\" main.py /data/ \ + command result:1 command take time:100ms faultInfo: ]"; + ASSERT_EQ(channel->ToDisplayChannelStr(), result); + + delete channel; +} -- Gitee From 1045830f62c3814a97e04aed93fb55d16bf9b70e Mon Sep 17 00:00:00 2001 From: liupeng298 Date: Mon, 12 May 2025 12:12:06 +0000 Subject: [PATCH 3/4] update test/BUILD.gn. Signed-off-by: liupeng298 --- test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/BUILD.gn b/test/BUILD.gn index 1adda232..2e3147c3 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -37,6 +37,7 @@ hdc_common_sources = [ "${hdc_path}/src/common/transfer.cpp", "${hdc_path}/src/common/usb.cpp", "${hdc_path}/src/common/uv_status.cpp", + "${hdc_path}/src/common/define_test.cpp", ] hdc_daemon_sources = [ -- Gitee From 3979feb83e4628e675f6b8a14dd665c1599116bb Mon Sep 17 00:00:00 2001 From: liupeng298 Date: Mon, 12 May 2025 13:25:48 +0000 Subject: [PATCH 4/4] update test/unittest/common/define_test.cpp. Signed-off-by: liupeng298 --- test/unittest/common/define_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/common/define_test.cpp b/test/unittest/common/define_test.cpp index d511eab9..bff12218 100644 --- a/test/unittest/common/define_test.cpp +++ b/test/unittest/common/define_test.cpp @@ -103,3 +103,4 @@ HWTEST_F(HdcDefineTest, TestToDisplayChannelStr2, TestSize.Level1) delete channel; } +} \ No newline at end of file -- Gitee