• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "auth_device_profile_listener.h"
17 #include "auth_deviceprofile.h"
18 #include <gtest/gtest.h>
19 
20 #include "auth_log.h"
21 #include "device_profile_listener.h"
22 #include "lnn_app_bind_interface.h"
23 #include "softbus_error_code.h"
24 #include "trust_device_profile.h"
25 
26 namespace OHOS {
27 using namespace testing;
28 using namespace testing::ext;
29 
30 class AuthDeviceProfileTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase()38 void AuthDeviceProfileTest::SetUpTestCase() { }
39 
TearDownTestCase()40 void AuthDeviceProfileTest::TearDownTestCase() { }
41 
SetUp()42 void AuthDeviceProfileTest::SetUp() { }
43 
TearDown()44 void AuthDeviceProfileTest::TearDown() { }
45 
OnDeviceBound(const char * udid,const char * groupInfo)46 static void OnDeviceBound(const char *udid, const char *groupInfo)
47 {
48     (void)udid;
49     (void)groupInfo;
50     AUTH_LOGI(AUTH_TEST, "deviceBound success!");
51 }
52 
OnDeviceNotTrusted(const char * udid,int32_t localUserId)53 static void OnDeviceNotTrusted(const char *udid, int32_t localUserId)
54 {
55     (void)udid;
56     (void)localUserId;
57     AUTH_LOGI(AUTH_TEST, "device is not trusted!");
58 }
59 
60 static DeviceProfileChangeListener g_deviceProfilePara = {
61     .onDeviceProfileAdd = OnDeviceBound,
62     .onDeviceProfileDeleted = OnDeviceNotTrusted,
63 };
64 
65 /*
66  * @tc.name: TRUST_DEVICE_PROFILE_ADD_TEST_001
67  * @tc.desc:
68  * @tc.type: FUNC
69  * @tc.require:
70  */
71 HWTEST_F(AuthDeviceProfileTest, TRUST_DEVICE_PROFILE_ADD_TEST_001, TestSize.Level1)
72 {
73     RegisterToDp(&g_deviceProfilePara);
74     std::unique_ptr<AuthToDeviceProfile::AuthDeviceProfileListener> myFunc_ =
75         std::make_unique<AuthToDeviceProfile::AuthDeviceProfileListener>();
76     AuthToDeviceProfile::TrustDeviceProfile profile;
77     int32_t ret = myFunc_->OnTrustDeviceProfileAdd(profile);
78     EXPECT_EQ(ret, SOFTBUS_OK);
79 }
80 
81 /*
82  * @tc.name: TRUST_DEVICE_PROFILE_DELETE_TEST_002
83  * @tc.desc:
84  * @tc.type: FUNC
85  * @tc.require:
86  */
87 HWTEST_F(AuthDeviceProfileTest, TRUST_DEVICE_PROFILE_DELETE_TEST_002, TestSize.Level1)
88 {
89     RegisterToDp(&g_deviceProfilePara);
90     std::unique_ptr<AuthToDeviceProfile::AuthDeviceProfileListener> myFunc_ =
91         std::make_unique<AuthToDeviceProfile::AuthDeviceProfileListener>();
92     AuthToDeviceProfile::TrustDeviceProfile profile;
93     int32_t ret = myFunc_->OnTrustDeviceProfileDelete(profile);
94     EXPECT_EQ(ret, SOFTBUS_OK);
95 }
96 
97 /*
98  * @tc.name: IS_POTENTIAL_TRUSTED_DEVCIE_TEST_003
99  * @tc.desc:
100  * @tc.type: FUNC
101  * @tc.require:
102  */
103 HWTEST_F(AuthDeviceProfileTest, IS_POTENTIAL_DEVCIE_TEST_003, TestSize.Level1)
104 {
105     const char *deviceIdHash = nullptr;
106     bool ret = IsPotentialTrustedDeviceDp(deviceIdHash, true);
107     EXPECT_TRUE(!ret);
108     deviceIdHash = "dev/ice%Id()Hash()";
109     ret = IsPotentialTrustedDeviceDp(deviceIdHash, true);
110     EXPECT_TRUE(!ret);
111 }
112 } // namespace OHOS
113