1 /*
2 * Copyright (c) 2022-2023 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 #include "dms_client_test.h"
16
17 #include "ability_manager_errors.h"
18 #include "distributed_parcel_helper.h"
19 #include "if_system_ability_manager.h"
20 #include "ipc_skeleton.h"
21 #include "iservice_registry.h"
22 #include "string_ex.h"
23 #include "system_ability_definition.h"
24 #include "test_log.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace DistributedSchedule {
31 namespace {
32 const std::string TYPE = "type";
33 const std::string DEVICE_ID = "123456789ABCD";
34 }
35
SetUpTestCase()36 void DistributedClientTest::SetUpTestCase()
37 {
38 DTEST_LOG << "DistributedClientTest::SetUpTestCase" << std::endl;
39 }
40
TearDownTestCase()41 void DistributedClientTest::TearDownTestCase()
42 {
43 DTEST_LOG << "DistributedClientTest::TearDownTestCase" << std::endl;
44 }
45
SetUp()46 void DistributedClientTest::SetUp()
47 {
48 DTEST_LOG << "DistributedClientTest::SetUp" << std::endl;
49 }
50
TearDown()51 void DistributedClientTest::TearDown()
52 {
53 DTEST_LOG << "DistributedClientTest::TearDown" << std::endl;
54 }
55
DSchedEventNotify(EventNotify & notify)56 void BusinessHandlerTest::DSchedEventNotify(EventNotify ¬ify)
57 {
58 }
59
GetDmsProxy()60 sptr<IRemoteObject> DistributedClientTest::GetDmsProxy()
61 {
62 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
63 EXPECT_TRUE(samgrProxy != nullptr);
64 if (samgrProxy == nullptr) {
65 HILOG_ERROR("fail to get samgr.");
66 return nullptr;
67 }
68 return nullptr;
69 }
70
71 /**
72 * @tc.name: RegisterDSchedEventListener_001
73 * @tc.desc: RegisterDSchedEventListener
74 * @tc.type: FUNC
75 * @tc.require: I64FU7
76 */
77 HWTEST_F(DistributedClientTest, RegisterDSchedEventListener_001, TestSize.Level3)
78 {
79 DTEST_LOG << "DistributedClientTest RegisterDSchedEventListener_001 start" << std::endl;
80 sptr<IRemoteObject> proxy = GetDmsProxy();
81 if (proxy == nullptr) {
82 return;
83 }
84 sptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new BusinessHandlerTest());
85 int32_t result = distributedClient_.RegisterDSchedEventListener(TYPE, listener);
86 EXPECT_TRUE(result != ERR_NONE);
87 DTEST_LOG << "DistributedClientTest RegisterDSchedEventListener_001 end" << std::endl;
88 }
89
90 /**
91 * @tc.name: UnRegisterDSchedEventListener_001
92 * @tc.desc: UnRegisterDSchedEventListener
93 * @tc.type: FUNC
94 * @tc.require: I64FU7
95 */
96 HWTEST_F(DistributedClientTest, UnRegisterDSchedEventListener_001, TestSize.Level3)
97 {
98 DTEST_LOG << "DistributedClientTest UnRegisterDSchedEventListener_001 start" << std::endl;
99 sptr<IRemoteObject> proxy = GetDmsProxy();
100 if (proxy == nullptr) {
101 return;
102 }
103 sptr<IDSchedEventListener> listener = sptr<IDSchedEventListener>(new BusinessHandlerTest());
104 int32_t result = distributedClient_.UnRegisterDSchedEventListener(TYPE, listener);
105 EXPECT_EQ(result, ERR_NONE);
106 DTEST_LOG << "DistributedClientTest UnRegisterDSchedEventListener_001 end" << std::endl;
107 }
108 }
109 }