1 /*
2 * Copyright (c) 2024 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_distributed_hardware_load.h"
17
18 #include <iostream>
19
20 #include "dm_log.h"
21 #include "dm_constants.h"
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUp()25 void DmDistributedHardwareLoadTest::SetUp()
26 {
27 }
28
TearDown()29 void DmDistributedHardwareLoadTest::TearDown()
30 {
31 }
32
SetUpTestCase()33 void DmDistributedHardwareLoadTest::SetUpTestCase()
34 {
35 }
36
TearDownTestCase()37 void DmDistributedHardwareLoadTest::TearDownTestCase()
38 {
39 }
40
41 HWTEST_F(DmDistributedHardwareLoadTest, LoadDistributedHardwareFwk_001, testing::ext::TestSize.Level0)
42 {
43 DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk();
44 DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount();
45 uint32_t ret = DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount();
46 EXPECT_EQ(ret, DM_OK);
47 }
48
49 HWTEST_F(DmDistributedHardwareLoadTest, InitDistributedHardwareLoadCount_001, testing::ext::TestSize.Level0)
50 {
51 DmDistributedHardwareLoad::GetInstance().InitDistributedHardwareLoadCount();
52 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
53 EXPECT_EQ(ret, DM_OK);
54 }
55
56 HWTEST_F(DmDistributedHardwareLoadTest, GetDistributedHardwareLoadCount_001, testing::ext::TestSize.Level0)
57 {
58 DmDistributedHardwareLoad::GetInstance().GetDistributedHardwareLoadCount();
59 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
60 EXPECT_EQ(ret, DM_OK);
61 }
62
63 HWTEST_F(DmDistributedHardwareLoadTest, OnLoadSystemAbilitySuccess_001, testing::ext::TestSize.Level0)
64 {
65 int32_t systemAbilityId = 4800;
66 sptr<IRemoteObject> remoteObject = nullptr;
67 sptr<DistributedHardwareLoadCallback> distributedHardwareLoadCallback_(new DistributedHardwareLoadCallback());
68 distributedHardwareLoadCallback_->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject);
69 uint32_t ret = DmDistributedHardwareLoad::GetInstance().distributedHardwareLoadCount_;
70 EXPECT_EQ(ret, DM_OK);
71 }
72
73 HWTEST_F(DmDistributedHardwareLoadTest, Sha256_001, testing::ext::TestSize.Level0)
74 {
75 std::shared_ptr<Crypto> crypto = std::make_shared<Crypto>();
76 std::string text;
77 bool isUpper = false;
78 std::string ret = crypto->Sha256(text, isUpper);
79 EXPECT_NE(ret.empty(), true);
80 }
81
82 HWTEST_F(DmDistributedHardwareLoadTest, GetCryptoAdapter_001, testing::ext::TestSize.Level0)
83 {
84 std::string soName = "soName";
85 auto ret = DmAdapterManager::GetInstance().GetCryptoAdapter(soName);
86 EXPECT_EQ(ret, nullptr);
87 }
88
89 HWTEST_F(DmDistributedHardwareLoadTest, GetUdidHash_001, testing::ext::TestSize.Level0)
90 {
91 std::string deviceId;
92 char deviceIdHash[DM_MAX_DEVICE_ID_LEN] = {0};
93 auto ret = Crypto::GetUdidHash(deviceId, reinterpret_cast<uint8_t *>(deviceIdHash));
94 EXPECT_EQ(ret, DM_OK);
95 }
96
97 HWTEST_F(DmDistributedHardwareLoadTest, GetUdidHash_002, testing::ext::TestSize.Level0)
98 {
99 std::string deviceId;
100 unsigned char *udidHash = nullptr;
101 auto ret = Crypto::GetUdidHash(deviceId, udidHash);
102 EXPECT_EQ(ret, ERR_DM_FAILED);
103 }
104
105 HWTEST_F(DmDistributedHardwareLoadTest, GetGroupIdHash_001, testing::ext::TestSize.Level0)
106 {
107 std::string groupId = "123456789";
108 std::string str = Crypto::GetGroupIdHash(groupId);
109 EXPECT_EQ(str.empty(), false);
110 }
111
112 HWTEST_F(DmDistributedHardwareLoadTest, ConvertHexStringToBytes_001, testing::ext::TestSize.Level0)
113 {
114 unsigned char *outBuf = nullptr;
115 const char *inBuf = nullptr;
116 auto ret = Crypto::ConvertHexStringToBytes(outBuf, 0, inBuf, 0);
117 EXPECT_EQ(ret, ERR_DM_FAILED);
118 }
119 } // namespace DistributedHardware
120 } // namespace OHOS
121