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 "daemon_app.h"
16 #include "daemon_app_test.h"
17
18 using namespace testing::ext;
19
20 namespace Hdc {
SetUpTestCase()21 void HdcDaemonAppTest::SetUpTestCase() {}
TearDownTestCase()22 void HdcDaemonAppTest::TearDownTestCase() {}
SetUp()23 void HdcDaemonAppTest::SetUp()
24 {
25 #ifdef UT_DEBUG
26 Base::SetLogLevel(LOG_ALL);
27 #else
28 Base::SetLogLevel(LOG_OFF);
29 #endif
30 }
TearDown()31 void HdcDaemonAppTest::TearDown() {}
32
33 HWTEST_F(HdcDaemonAppTest, Test_HdcDaemonApp, TestSize.Level0)
34 {
35 HTaskInfo taskInfo = new TaskInformation();
36
37 // case: default struct HTaskInfo with isStableBuf set to true.
38 HdcDaemonApp daemonApp1(taskInfo);
39 EXPECT_EQ(daemonApp1.commandBegin, CMD_APP_BEGIN);
40 EXPECT_EQ(daemonApp1.commandData, CMD_APP_DATA);
41 EXPECT_EQ(daemonApp1.funcAppModFinish, nullptr);
42
43 delete taskInfo;
44 }
45
46 HWTEST_F(HdcDaemonAppTest, Test_CommandDispatch, TestSize.Level0)
47 {
48 HTaskInfo taskInfo = new TaskInformation();
49 HdcDaemonApp daemonApp(taskInfo);
50 uint8_t payload = 10;
51
52 // invalid command.
53 EXPECT_FALSE(daemonApp.CommandDispatch(CMD_APP_BEGIN, &payload, 10));
54
55 delete taskInfo;
56 }
57
58 HWTEST_F(HdcDaemonAppTest, Test_ReadyForRelease, TestSize.Level0)
59 {
60 HTaskInfo taskInfo = new TaskInformation();
61 HdcDaemonApp daemonApp(taskInfo);
62 daemonApp.refCount = 1;
63
64 // case1: default valid case.
65 EXPECT_FALSE(daemonApp.ReadyForRelease());
66
67 delete taskInfo;
68 }
69
70 HWTEST_F(HdcDaemonAppTest, Test_MakeCtxForAppCheck, TestSize.Level3)
71 {
72 HTaskInfo taskInfo = new TaskInformation();
73 HdcDaemonApp daemonApp(taskInfo);
74 daemonApp.ctxNow.master = true;
75 daemonApp.ctxNow.transferConfig.optionalName = "test.hap";
76
77 uint8_t payload = 10;
78 daemonApp.MakeCtxForAppCheck(&payload, 10);
79 EXPECT_FALSE(daemonApp.ctxNow.master);
80 EXPECT_EQ(daemonApp.ctxNow.localPath, "/data/local/tmp/test.hap");
81
82 delete taskInfo;
83 }
84 }