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
16 #include "UTTest_dm_service_load.h"
17
18 #include <unistd.h>
19
20 #include "dm_constants.h"
21 #include "dm_service_load.h"
22 #include "if_system_ability_manager.h"
23 #include "iservice_registry.h"
24 #include "system_ability_definition.h"
25
26 namespace OHOS {
27 namespace DistributedHardware {
SetUp()28 void DmServiceLoadTest::SetUp()
29 {
30 }
31
TearDown()32 void DmServiceLoadTest::TearDown()
33 {
34 }
35
SetUpTestCase()36 void DmServiceLoadTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void DmServiceLoadTest::TearDownTestCase()
41 {
42 }
43
44 namespace {
HWTEST_F(DmServiceLoadTest, LoadDMService_001, testing::ext::TestSize.Level0)45 HWTEST_F(DmServiceLoadTest, LoadDMService_001, testing::ext::TestSize.Level0)
46 {
47 int32_t ret = DmServiceLoad::GetInstance().LoadDMService();
48 ASSERT_EQ(ret, DM_OK);
49 ret = DmServiceLoad::GetInstance().LoadDMService();
50 ASSERT_EQ(ret, DM_OK);
51 }
52
HWTEST_F(DmServiceLoadTest, SetLoadFinish_001, testing::ext::TestSize.Level0)53 HWTEST_F(DmServiceLoadTest, SetLoadFinish_001, testing::ext::TestSize.Level0)
54 {
55 DmServiceLoad::GetInstance().SetLoadFinish();
56 int32_t systemAbilityId = 1000;
57 sptr<IRemoteObject> remoteObject = nullptr;
58 DMLoadCallbackTest dmLoadCallback;
59 dmLoadCallback.OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject);
60 dmLoadCallback.OnLoadSystemAbilityFail(systemAbilityId);
61 ASSERT_EQ(DmServiceLoad::GetInstance().isDMServiceLoading_, false);
62 }
63 }
64 } // namespace DistributedHardware
65 } // namespace OHOS
66