• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_client.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 ConcurrentTaskClientTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void ConcurrentTaskClientTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void ConcurrentTaskClientTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void ConcurrentTaskClientTest::SetUp()
43 {
44 }
45 
TearDown()46 void ConcurrentTaskClientTest::TearDown()
47 {
48 }
49 
50 /**
51  * @tc.name: PushTaskTest
52  * @tc.desc: Test whether the PushTask interface are normal.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(ConcurrentTaskClientTest, ReportDataTest, TestSize.Level1)
56 {
57     uint32_t resType = 0;
58     int64_t value = 3587;
59     std::unordered_map<std::string, std::string> payload;
60     payload["uid"] = "3587";
61     payload["pid"] = "12345";
62     payload["type"] = "appStart";
63     ConcurrentTaskClient::GetInstance().ReportData(resType, value, payload);
64     EXPECT_FALSE(payload.empty());
65 }
66 
67 /**
68  * @tc.name: PushTaskTest
69  * @tc.desc: Test whether the PushTask interface are normal.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(ConcurrentTaskClientTest, ReportSceneInfoTest, TestSize.Level1)
73 {
74     uint32_t type = 0;
75     std::unordered_map<std::string, std::string> payload;
76     ConcurrentTaskClient::GetInstance().ReportSceneInfo(type, payload);
77     payload["uid"] = "3587";
78     payload["value"] = "12345";
79     ConcurrentTaskClient::GetInstance().ReportSceneInfo(type, payload);
80     EXPECT_FALSE(payload.empty());
81 }
82 
83 /**
84  * @tc.name: PushTaskTest
85  * @tc.desc: Test whether the PushTask interface are normal.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(ConcurrentTaskClientTest, QueryIntervalTest, TestSize.Level1)
89 {
90     int queryItem = 3;
91     IntervalReply queryRs = {87, 657, 357, 214};
92     ConcurrentTaskClient::GetInstance().QueryInterval(queryItem, queryRs);
93     EXPECT_TRUE(queryRs.tid != -1);
94 }
95 
96 /**
97  * @tc.name: PushTaskTest
98  * @tc.desc: Test whether the PushTask interface are normal.
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ConcurrentTaskClientTest, StopRemoteObjectTest, TestSize.Level1)
102 {
103     std::unordered_map<std::string, std::string> payload;
104     ConcurrentTaskClient::GetInstance().StopRemoteObject();
105     payload["uid"] = "3587";
106     EXPECT_FALSE(payload.empty());
107 }
108 
109 /**
110  * @tc.name: PushTaskTest
111  * @tc.desc: Test whether the PushTask interface are normal.
112  * @tc.type: FUNC
113 */
114 HWTEST_F(ConcurrentTaskClientTest, QueryDeadlineTest, TestSize.Level1)
115 {
116     int queryItem = 0;
117     DeadlineReply ddlReply = { false };
118     std::unordered_map<pid_t, uint32_t> payload;
119     payload[1111] = 60;
120     payload[2222] = 90;
121     ConcurrentTaskClient::GetInstance().QueryDeadline(queryItem, ddlReply, payload);
122     EXPECT_FALSE(payload.empty());
123 }
124 
125 /**
126  * @tc.name: PushTaskTest
127  * @tc.desc: Test whether the PushTask interface are normal.
128  * @tc.type: FUNC
129 */
130 HWTEST_F(ConcurrentTaskClientTest, SetAudioDeadlineTest, TestSize.Level1)
131 {
132     int queryItem = AUDIO_DDL_CREATE_GRP;
133     IntervalReply queryRs = { 0 };
134     ConcurrentTaskClient::GetInstance().SetAudioDeadline(queryItem, -1, -1, queryRs);
135     EXPECT_TRUE(queryRs.rtgId != -1);
136     queryItem = AUDIO_DDL_ADD_THREAD;
137     ConcurrentTaskClient::GetInstance().SetAudioDeadline(queryItem, gettid(), queryRs.rtgId, queryRs);
138     EXPECT_TRUE(queryRs.paramA == 0);
139     queryItem = AUDIO_DDL_REMOVE_THREAD;
140     ConcurrentTaskClient::GetInstance().SetAudioDeadline(queryItem, gettid(), queryRs.rtgId, queryRs);
141     EXPECT_TRUE(queryRs.paramA == 0);
142     queryItem = AUDIO_DDL_DESTROY_GRP;
143     ConcurrentTaskClient::GetInstance().SetAudioDeadline(queryItem, -1, queryRs.rtgId, queryRs);
144     EXPECT_TRUE(queryRs.paramA == 0);
145 }
146 
147 /**
148  * @tc.name: RequestAuthTest
149  * @tc.desc: Test whether the RequestAuth interface are normal.
150  * @tc.type: FUNC
151 */
152 HWTEST_F(ConcurrentTaskClientTest, RequestAuthTest, TestSize.Level1)
153 {
154     std::unordered_map<std::string, std::string> payload;
155     payload["uid"] = "3587";
156     payload["pid"] = "12345";
157     ConcurrentTaskClient::GetInstance().RequestAuth(payload);
158     EXPECT_FALSE(payload.empty());
159 }
160 }
161 }