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_RENDER);
75     EXPECT_EQ(grpId, -1);
76 }
77 
78 /**
79  * @tc.name: QueryHugeItem
80  * @tc.desc: If query a huge item, should return invalid.
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ConcurrentSvcIntfTest, QueryHugeItem, TestSize.Level1)
84 {
85     int grpId = QueryInterval(HUGE_ITEM);
86     EXPECT_LT(grpId, 0);
87 }
88 
89 /**
90  * @tc.name: QueryNagativeItem
91  * @tc.desc: If query a huge item, should return invalid.
92  * @tc.type: FUNC
93  */
94 HWTEST_F(ConcurrentSvcIntfTest, QueryNagativeItem, TestSize.Level1)
95 {
96     int grpId = QueryInterval(-1);
97     EXPECT_LT(grpId, 0);
98 }
99 
100 /**
101  * @tc.name: QuerySystemUid
102  * @tc.desc: Confirm the test binary can execute seteuid function.
103  * @tc.type: FUNC
104  */
105 HWTEST_F(ConcurrentSvcIntfTest, QueryRenderServiceTest, TestSize.Level1)
106 {
107     int grpId = QueryInterval(QUERY_RENDER_SERVICE_MAIN);
108 #if TDD_MUSL
109     EXPECT_GT(grpId, 0);
110 #else
111     (void)grpId;
112 #endif
113 }
114 
115 /**
116  * @tc.name: QuerySystemUid
117  * @tc.desc: Qu.
118  * @tc.type: FUNC
119  */
120 HWTEST_F(ConcurrentSvcIntfTest, QueryInvalidValueTest, TestSize.Level1)
121 {
122     int grpId = QueryInterval(QURRY_TYPE_MAX);
123     EXPECT_LT(grpId, 0);
124 }
125 }
126 }
127