• 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 #include "host_app.h"
16 #include "host_app_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace Hdc {
SetUpTestCase()21 void HdcHostAppTest::SetUpTestCase() {}
TearDownTestCase()22 void HdcHostAppTest::TearDownTestCase() {}
SetUp()23 void HdcHostAppTest::SetUp()
24 {
25 #ifdef UT_DEBUG
26     Base::SetLogLevel(LOG_ALL);
27 #else
28     Base::SetLogLevel(LOG_OFF);
29 #endif
30 }
TearDown()31 void HdcHostAppTest::TearDown() {}
32 
33 HWTEST_F(HdcHostAppTest, Test_HdcHostApp, TestSize.Level0)
34 {
35     // case1: default struct HTaskInfo with isStableBuf set to true.
36     HTaskInfo taskInfo = new TaskInformation();
37     taskInfo->isStableBuf = true;
38     HdcHostApp hostApp1(taskInfo);
39     EXPECT_EQ(hostApp1.commandBegin, CMD_APP_BEGIN);
40     EXPECT_EQ(hostApp1.commandData, CMD_APP_DATA);
41     EXPECT_EQ(hostApp1.originLocalDir, "");
42     EXPECT_TRUE(hostApp1.isStableBuf);
43 
44     // case2: default struct HTaskInfo with isStableBuf set to false.
45     taskInfo->isStableBuf = false;
46     HdcHostApp hostApp2(taskInfo);
47     EXPECT_EQ(hostApp2.commandBegin, CMD_APP_BEGIN);
48     EXPECT_EQ(hostApp2.commandData, CMD_APP_DATA);
49     EXPECT_EQ(hostApp2.originLocalDir, "");
50     EXPECT_FALSE(hostApp2.isStableBuf);
51 
52     delete taskInfo;
53 }
54 
55 HWTEST_F(HdcHostAppTest, Test_CommandDispatch, TestSize.Level0)
56 {
57     HTaskInfo taskInfo = new TaskInformation();
58     HdcHostApp hostApp(taskInfo);
59     uint8_t payload = 10;
60 
61     // command invalid.
62     EXPECT_FALSE(hostApp.CommandDispatch(CMD_APP_BEGIN, &payload, 10));
63 
64     delete taskInfo;
65 }
66 
67 HWTEST_F(HdcHostAppTest, Test_BeginInstall, TestSize.Level3)
68 {
69     HTaskInfo taskInfo = new TaskInformation();
70     HdcHostApp hostApp(taskInfo);
71     HdcTransferBase::CtxFile ctxFile;
72 
73     // case1: empty input command.
74     const char* emptyCommand = "";
75     EXPECT_FALSE(hostApp.BeginInstall(&ctxFile, emptyCommand));
76 
77     delete taskInfo;
78 }
79 }