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 #include <gtest/gtest.h>
17
18 #include "utils.h"
19
20 #define private public
21 #include "distributed_device_profile_client.h"
22 #include "distributed_device_profile_proxy.h"
23 #include "iprofile_event_callback.h"
24 #undef private
25
26 namespace OHOS {
27 namespace DeviceProfile {
28 using namespace testing;
29 using namespace testing::ext;
30
31 class ProfileProxyTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void ProfileProxyTest::SetUpTestCase()
40 {
41 DTEST_LOG << "SetUpTestCase" << std::endl;
42 }
43
TearDownTestCase()44 void ProfileProxyTest::TearDownTestCase()
45 {
46 DTEST_LOG << "TearDownTestCase" << std::endl;
47 }
48
SetUp()49 void ProfileProxyTest::SetUp()
50 {
51 DTEST_LOG << "SetUp" << std::endl;
52 }
53
TearDown()54 void ProfileProxyTest::TearDown()
55 {
56 DTEST_LOG << "TearDown" << std::endl;
57 }
58
59 /**
60 * @tc.name: PutDeviceProfile_001
61 * @tc.desc: put device profile with test service
62 * @tc.type: FUNC
63 * @tc.require: I51HKG
64 */
65 HWTEST_F(ProfileProxyTest, PutDeviceProfile_001, TestSize.Level3)
66 {
67 auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService();
68 if (dps == nullptr) {
69 return;
70 }
71
72 SyncResult syncResults;
73 IProfileEventCallback eventCb;
74 eventCb.OnSyncCompleted(syncResults);
75 DTEST_LOG << "sync results completed" << std::endl;
76
77 ServiceCharacteristicProfile profile;
78 profile.SetServiceId("test");
79 profile.SetServiceType("test");
80 nlohmann::json jsonData;
81 profile.SetCharacteristicProfileJson(jsonData.dump());
82 int32_t result = dps->PutDeviceProfile(profile);
83 DTEST_LOG << "result: " << result << std::endl;
84 EXPECT_NE(result, ERR_INVALID_DATA);
85 }
86
87 /**
88 * @tc.name: DeleteDeviceProfile_001
89 * @tc.desc: delete an empty profile
90 * @tc.type: FUNC
91 * @tc.require: I51HKG
92 */
93 HWTEST_F(ProfileProxyTest, DeleteDeviceProfile_001, TestSize.Level3)
94 {
95 auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService();
96 if (dps == nullptr) {
97 return;
98 }
99
100 std::string serviceId = "";
101 int32_t result = dps->DeleteDeviceProfile(serviceId);
102 DTEST_LOG << "result: " << result << std::endl;
103 EXPECT_NE(result, ERR_INVALID_DATA);
104 }
105
106 /**
107 * @tc.name: SyncDeviceProfile_001
108 * @tc.desc: sync device profile
109 * @tc.type: FUNC
110 * @tc.require: I51HKG
111 */
112 HWTEST_F(ProfileProxyTest, SyncDeviceProfile_001, TestSize.Level3)
113 {
114 auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService();
115 if (dps == nullptr) {
116 return;
117 }
118
119 ProfileChangeNotification changeNotification;
120 IProfileEventCallback eventCb;
121 eventCb.OnProfileChanged(changeNotification);
122 DTEST_LOG << "profile changed" << std::endl;
123
124 SyncOptions syncOptions;
125 sptr<IRemoteObject> profileEventNotifier;
126 int32_t result = dps->SyncDeviceProfile(syncOptions, profileEventNotifier);
127 DTEST_LOG << "result: " << result << std::endl;
128 EXPECT_NE(result, ERR_INVALID_DATA);
129 }
130 }
131 }