1 /*
2 * Copyright (c) 2022-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 "gtest/gtest.h"
17 #include "concurrent_task_service.h"
18
19 namespace OHOS {
20 namespace FFRT_TEST {
21 using namespace testing;
22 using namespace testing::ext;
23 using namespace OHOS::ConcurrentTask;
24
25
26 class ConcurrentTaskServiceTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase()34 void ConcurrentTaskServiceTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void ConcurrentTaskServiceTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void ConcurrentTaskServiceTest::SetUp()
43 {
44 }
45
TearDown()46 void ConcurrentTaskServiceTest::TearDown()
47 {
48 }
49
50 /**
51 * @tc.name: QueryIntervalTest
52 * @tc.desc: Test whether the QueryInterval interface are normal.
53 * @tc.type: FUNC
54 */
55 HWTEST_F(ConcurrentTaskServiceTest, QueryIntervalTest, TestSize.Level1)
56 {
57 int queryItem = 0;
58 IpcIntervalReply IpcQueryRs = {87, 657, 357, 214};
59 ConcurrentTaskService queInt;
60 queInt.QueryInterval(queryItem, IpcQueryRs);
61 EXPECT_NE(IpcQueryRs.tid, -1);
62 }
63
64 /**
65 * @tc.name: QueryDeadlineTest
66 * @tc.desc: Test whether the QueryDeadline interface are normal.
67 * @tc.type: FUNC
68 */
69 HWTEST_F(ConcurrentTaskServiceTest, QueryDeadlineTest, TestSize.Level1)
70 {
71 int queryItem = 0;
72 IpcDeadlineReply IpcDdlReply = { false };
73 std::unordered_map<std::string, std::string> payload;
74 payload["1111"] = "60";
75 payload["2222"] = "90";
76 ConcurrentTaskService queInt;
77 queInt.QueryDeadline(queryItem, IpcDdlReply, payload);
78 EXPECT_FALSE(payload.empty());
79 }
80
81 /**
82 * @tc.name: IpcToQueryRsTest
83 * @tc.desc: Test whether the IpcToQueryRsTest interface are normal.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(ConcurrentTaskServiceTest, IpcToQueryRsTest, TestSize.Level1)
87 {
88 IpcIntervalReply ipcQueryRs;
89 ipcQueryRs.rtgId = 1;
90 ipcQueryRs.tid = 2;
91 ipcQueryRs.paramA = 3;
92 ipcQueryRs.paramB = 4;
93 ipcQueryRs.bundleName = "testBundle";
94
95 IntervalReply expectedQueryRs;
96 expectedQueryRs.rtgId = 1;
97 expectedQueryRs.tid = 2;
98 expectedQueryRs.paramA = 3;
99 expectedQueryRs.paramB = 4;
100 expectedQueryRs.bundleName = "testBundle";
101
102 ConcurrentTaskService service;
103 IntervalReply actualQueryRs = service.IpcToQueryRs(ipcQueryRs);
104
105 EXPECT_EQ(expectedQueryRs.rtgId, actualQueryRs.rtgId);
106 EXPECT_EQ(expectedQueryRs.tid, actualQueryRs.tid);
107 EXPECT_EQ(expectedQueryRs.paramA, actualQueryRs.paramA);
108 EXPECT_EQ(expectedQueryRs.paramB, actualQueryRs.paramB);
109 EXPECT_EQ(expectedQueryRs.bundleName, actualQueryRs.bundleName);
110 }
111
112 /**
113 * @tc.name: QueryRsToIpcTest
114 * @tc.desc: Test whether the QueryRsToIpcTest interface are normal.
115 * @tc.type: FUNC
116 */
117 HWTEST_F(ConcurrentTaskServiceTest, QueryRsToIpcTest, TestSize.Level1)
118 {
119 IntervalReply queryRs;
120 queryRs.paramB = 4;
121 queryRs.tid = 2;
122 queryRs.paramA = 3;
123 queryRs.rtgId = 1;
124 queryRs.bundleName = "mockedBundleName";
125
126 ConcurrentTaskService service;
127 IpcIntervalReply actualIpcQueryRs = service.QueryRsToIpc(queryRs);
128
129 EXPECT_EQ(actualIpcQueryRs.rtgId, queryRs.rtgId);
130 EXPECT_EQ(actualIpcQueryRs.tid, queryRs.tid);
131 EXPECT_EQ(actualIpcQueryRs.paramA, queryRs.paramA);
132 EXPECT_EQ(actualIpcQueryRs.paramB, queryRs.paramB);
133 EXPECT_EQ(actualIpcQueryRs.bundleName, queryRs.bundleName);
134 }
135
136 /**
137 * @tc.name: IpcToDdlReplyTest
138 * @tc.desc: Test whether the IpcToDdlReplyTest interface are normal.
139 * @tc.type: FUNC
140 */
141 HWTEST_F(ConcurrentTaskServiceTest, IpcToDdlReplyTest, TestSize.Level1)
142 {
143 IpcDeadlineReply IpcDdlReply;
144 IpcDdlReply.setStatus = 123;
145
146 DeadlineReply expectedDdlReply;
147 expectedDdlReply.setStatus = IpcDdlReply.setStatus;
148
149 ConcurrentTaskService service;
150 DeadlineReply resultDdlReply = service.IpcToDdlReply(IpcDdlReply);
151
152 EXPECT_EQ(expectedDdlReply.setStatus, resultDdlReply.setStatus);
153 }
154
155 /**
156 * @tc.name: SetAudioDeadline
157 * @tc.desc: Test whether the SetAudioDeadline interface are normal.
158 * @tc.type: FUNC
159 */
160 HWTEST_F(ConcurrentTaskServiceTest, SetAudioDeadlineTest, TestSize.Level1)
161 {
162 int queryItem = AUDIO_DDL_CREATE_GRP;
163 IpcIntervalReply IpcQueryRs = { 0 };
164 ConcurrentTaskService queInt;
165 queInt.SetAudioDeadline(queryItem, -1, -1, IpcQueryRs);
166 EXPECT_NE(IpcQueryRs.rtgId, -1);
167 queryItem = AUDIO_DDL_ADD_THREAD;
168 queInt.SetAudioDeadline(queryItem, gettid(), IpcQueryRs.rtgId, IpcQueryRs);
169 EXPECT_EQ(IpcQueryRs.paramA, 0);
170 queryItem = AUDIO_DDL_REMOVE_THREAD;
171 queInt.SetAudioDeadline(queryItem, gettid(), IpcQueryRs.rtgId, IpcQueryRs);
172 EXPECT_EQ(IpcQueryRs.paramA, 0);
173 queryItem = AUDIO_DDL_DESTROY_GRP;
174 queInt.SetAudioDeadline(queryItem, -1, IpcQueryRs.rtgId, IpcQueryRs);
175 EXPECT_EQ(IpcQueryRs.paramA, 0);
176 }
177
178 } // namespace FFRT_TEST
179 } // namespace OHOS
180