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 <map>
17 #include <string>
18 #include <unistd.h>
19 #include <iostream>
20 #include "gtest/gtest.h"
21 #include "concurrent_task_log.h"
22 #include "concurrent_task_client.h"
23
24 namespace OHOS {
25 namespace ConcurrentTask {
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::ConcurrentTask;
29 using namespace std;
30
31 constexpr int HUGE_ITEM = 1000000;
32
33 class ConcurrentSvcIntfTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 };
40
QueryInterval(int item)41 static int QueryInterval(int item)
42 {
43 IntervalReply rs;
44 rs.rtgId = -1;
45 cout << "start to query renderService" <<endl;
46 OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().QueryInterval(
47 item, rs);
48 return rs.rtgId;
49 }
50
SetUpTestCase()51 void ConcurrentSvcIntfTest::SetUpTestCase()
52 {
53 }
54
TearDownTestCase()55 void ConcurrentSvcIntfTest::TearDownTestCase()
56 {
57 }
58
SetUp()59 void ConcurrentSvcIntfTest::SetUp()
60 {
61 }
62
TearDown()63 void ConcurrentSvcIntfTest::TearDown()
64 {
65 }
66
67 /**
68 * @tc.name: QueryBeforeGetPriv
69 * @tc.desc: Before get privlege, render query result should be wrong
70 * @tc.type: FUNC
71 */
72 HWTEST_F(ConcurrentSvcIntfTest, QueryBeforeGetPriv, TestSize.Level1)
73 {
74 int grpId = QueryInterval(QUERY_UI);
75 EXPECT_EQ(grpId, -1);
76 grpId = QueryInterval(QUERY_RENDER);
77 EXPECT_EQ(grpId, -1);
78 grpId = QueryInterval(QUERY_RENDER_SERVICE);
79 EXPECT_EQ(grpId, -1);
80 grpId = QueryInterval(QUERY_COMPOSER);
81 EXPECT_EQ(grpId, -1);
82 grpId = QueryInterval(QUERY_HARDWARE);
83 EXPECT_EQ(grpId, -1);
84 grpId = QueryInterval(QUERY_EXECUTOR_START);
85 EXPECT_EQ(grpId, -1);
86 grpId = QueryInterval(QUERY_RENDER_SERVICE_RENDER);
87 EXPECT_EQ(grpId, -1);
88 }
89
90 /**
91 * @tc.name: QueryHugeItem
92 * @tc.desc: If query a huge item, should return invalid.
93 * @tc.type: FUNC
94 */
95 HWTEST_F(ConcurrentSvcIntfTest, QueryHugeItem, TestSize.Level1)
96 {
97 int grpId = QueryInterval(HUGE_ITEM);
98 EXPECT_LT(grpId, 0);
99 }
100
101 /**
102 * @tc.name: QueryNagativeItem
103 * @tc.desc: If query a huge item, should return invalid.
104 * @tc.type: FUNC
105 */
106 HWTEST_F(ConcurrentSvcIntfTest, QueryNagativeItem, TestSize.Level1)
107 {
108 int grpId = QueryInterval(-1);
109 EXPECT_LT(grpId, 0);
110 }
111
112 /**
113 * @tc.name: QuerySystemUid
114 * @tc.desc: Confirm the test binary can execute seteuid function.
115 * @tc.type: FUNC
116 */
117 HWTEST_F(ConcurrentSvcIntfTest, QueryRenderServiceTest, TestSize.Level1)
118 {
119 int grpId = QueryInterval(QUERY_RENDER_SERVICE_MAIN);
120 #if TDD_MUSL
121 EXPECT_GT(grpId, 0);
122 #else
123 (void)grpId;
124 #endif
125 }
126
127 /**
128 * @tc.name: QuerySystemUid
129 * @tc.desc: Qu.
130 * @tc.type: FUNC
131 */
132 HWTEST_F(ConcurrentSvcIntfTest, QueryInvalidValueTest, TestSize.Level1)
133 {
134 int grpId = QueryInterval(QURRY_TYPE_MAX);
135 EXPECT_LT(grpId, 0);
136 }
137 }
138 }
139