• 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 #define private public
17 #include "distributed_sched_service.h"
18 #undef private
19 #include "distributed_sched_uid_test.h"
20 #include "distributed_sched_test_util.h"
21 #define private public
22 #include "mission/distributed_sched_mission_manager.h"
23 #undef private
24 #include "test_log.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AppExecFwk;
30 
31 namespace OHOS {
32 namespace DistributedSchedule {
33 namespace {
34 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
35 const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
36 constexpr const char* FOUNDATION_PROCESS_NAME = "foundation";
37 constexpr int32_t UID = 10001;
38 const char *PERMS[] = {
39     "ohos.permission.DISTRIBUTED_DATASYNC"
40 };
41 }
42 
SetUpTestCase()43 void DistributedSchedUidTest::SetUpTestCase()
44 {
45     DTEST_LOG << "DistributedSchedUidTest::SetUpTestCase" << std::endl;
46     setuid(UID);
47 }
48 
TearDownTestCase()49 void DistributedSchedUidTest::TearDownTestCase()
50 {
51     DTEST_LOG << "DistributedSchedUidTest::TearDownTestCase" << std::endl;
52 }
53 
TearDown()54 void DistributedSchedUidTest::TearDown()
55 {
56     DTEST_LOG << "DistributedSchedUidTest::TearDown" << std::endl;
57     distributedSchedStub_ = nullptr;
58 }
59 
SetUp()60 void DistributedSchedUidTest::SetUp()
61 {
62     DTEST_LOG << "DistributedSchedUidTest::SetUp" << std::endl;
63     distributedSchedStub_ = new DistributedSchedService();
64     DistributedSchedUtil::MockProcessAndPermission(FOUNDATION_PROCESS_NAME, PERMS, 1);
65 }
66 
67 /**
68  * @tc.name: GetDistributedComponentListInner_001
69  * @tc.desc: check GetDistributedComponentListInner
70  * @tc.type: FUNC
71  */
72 HWTEST_F(DistributedSchedUidTest, GetDistributedComponentListInner_001, TestSize.Level3)
73 {
74     DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 begin" << std::endl;
75     ASSERT_NE(distributedSchedStub_, nullptr);
76     MessageParcel data;
77     MessageParcel reply;
78 
79     int32_t result = distributedSchedStub_->GetDistributedComponentListInner(data, reply);
80     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
81     DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 end" << std::endl;
82 }
83 }
84 }