• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "profile_event_notifier_proxy.h"
19 #include "distributed_device_profile_client.h"
20 #include "utils.h"
21 
22 namespace OHOS {
23 namespace DeviceProfile {
24 using namespace testing;
25 using namespace testing::ext;
26 
27 class ProfileEventNotifierProxyTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
35 class StorageProfileEventCallback : public IProfileEventCallback {
36 public:
37     int result = 0;
38 };
39 
SetUpTestCase()40 void ProfileEventNotifierProxyTest::SetUpTestCase()
41 {
42     DTEST_LOG << "SetUpTestCase" << std::endl;
43 }
44 
TearDownTestCase()45 void ProfileEventNotifierProxyTest::TearDownTestCase()
46 {
47     DTEST_LOG << "TearDownTestCase" << std::endl;
48 }
49 
SetUp()50 void ProfileEventNotifierProxyTest::SetUp()
51 {
52     DTEST_LOG << "SetUp" << std::endl;
53 }
54 
TearDown()55 void ProfileEventNotifierProxyTest::TearDown()
56 {
57     DTEST_LOG << "TearDown" << std::endl;
58 }
59 
60 /**
61  * @tc.name: OnSyncCompleted_001
62  * @tc.desc: OnSyncCompleted
63  * @tc.type: FUNC
64  * @tc.require: I4NY1T
65  */
66 HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_001, TestSize.Level3)
67 {
68     auto syncCb = std::make_shared<StorageProfileEventCallback>();
69     sptr<ProfileEventNotifierStub> stub(new ProfileEventNotifierStub(syncCb));
70     sptr<ProfileEventNotifierProxy> proxy(new ProfileEventNotifierProxy(stub));
71     SyncResult syncResults;
72     proxy->OnSyncCompleted(syncResults);
73     EXPECT_EQ(syncCb->result, 0);
74 }
75 
76 /**
77  * @tc.name: OnSyncCompleted_001
78  * @tc.desc: OnSyncCompleted
79  * @tc.type: FUNC
80  * @tc.require: I4NY1T
81  */
82 HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_002, TestSize.Level3)
83 {
84     auto syncCb = std::make_shared<StorageProfileEventCallback>();
85     sptr<ProfileEventNotifierStub> stub(new ProfileEventNotifierStub(syncCb));
86     sptr<ProfileEventNotifierProxy> proxy(new ProfileEventNotifierProxy(stub));
87     SyncResult syncResults;
88     syncResults.emplace("testdeviceid", SUCCEEDED);
89     proxy->OnSyncCompleted(syncResults);
90     EXPECT_EQ(syncCb->result, 0);
91 }
92 
93 /**
94  * @tc.name: OnProfileChanged_001
95  * @tc.desc: OnProfileChanged
96  * @tc.type: FUNC
97  * @tc.require: I4NY1T
98  */
99 HWTEST_F(ProfileEventNotifierProxyTest, OnProfileChanged_001, TestSize.Level3)
100 {
101     auto syncCb = std::make_shared<StorageProfileEventCallback>();
102     sptr<ProfileEventNotifierStub> stub(new ProfileEventNotifierStub(syncCb));
103     sptr<ProfileEventNotifierProxy> proxy(new ProfileEventNotifierProxy(stub));
104     ProfileChangeNotification notification;
105     proxy->OnProfileChanged(notification);
106     EXPECT_EQ(syncCb->result, 0);
107 }
108 }
109 }