• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "cJSON.h"
19 #include "clip/clip_plugin.h"
20 #include "serializable/serializable.h"
21 
22 namespace OHOS::MiscServices {
23 using namespace testing::ext;
24 class ClipPluginTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     void SetUp();
29     void TearDown();
30 };
31 
SetUpTestCase(void)32 void ClipPluginTest::SetUpTestCase(void) { }
33 
TearDownTestCase(void)34 void ClipPluginTest::TearDownTestCase(void) { }
35 
SetUp(void)36 void ClipPluginTest::SetUp(void) { }
37 
TearDown(void)38 void ClipPluginTest::TearDown(void) { }
39 
40 class CustomClipPlugin : public ClipPlugin {
41 public:
SetPasteData(const GlobalEvent & event,const std::vector<uint8_t> & data)42     int32_t SetPasteData(const GlobalEvent &event, const std::vector<uint8_t> &data) override
43     {
44         (void)event;
45         (void)data;
46         return 0;
47     }
48 
GetPasteData(const GlobalEvent & event,std::vector<uint8_t> & data)49     std::pair<int32_t, int32_t> GetPasteData(const GlobalEvent &event, std::vector<uint8_t> &data) override
50     {
51         (void)event;
52         (void)data;
53         return std::make_pair(0, 0);
54     }
55 };
56 
57 /**
58  * @tc.name: MarshalTest001
59  * @tc.desc: Marshal.
60  * @tc.type: FUNC
61  * @tc.require:
62  * @tc.author:
63  */
64 HWTEST_F(ClipPluginTest, MarshalTest001, TestSize.Level0)
65 {
66     std::string PLUGIN_NAME_VAL = "distributed_clip";
__anon42c298600102(ClipPlugin *plugin) 67     auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
68         ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
69     };
70     std::shared_ptr<ClipPlugin> clipPlugin;
71     clipPlugin = std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
72     DistributedData::Serializable::json node;
73     ClipPlugin::GlobalEvent globalEvent;
74     std::string networkId = "networkId";
75     int32_t result = clipPlugin->PublishServiceState(networkId, ClipPlugin::ServiceStatus::CONNECT_SUCC);
76     ASSERT_TRUE(globalEvent.Marshal(node));
77 }
78 
79 /**
80  * @tc.name: UnmarshalTest001
81  * @tc.desc: Unmarshal.
82  * @tc.type: FUNC
83  * @tc.require:
84  * @tc.author:
85  */
86 HWTEST_F(ClipPluginTest, UnmarshalTest001, TestSize.Level0)
87 {
88     std::string str = R"({
89         {"version", 1},
90         {"frameNum", 100},
91         {"user", "testUser"},
92         {"seqId", 12345},
93         {"expiration", 1000},
94         {"status", "active"},
95         {"deviceId", "123456"},
96         {"account", "testAcount"},
97         {"dataType", "image"},
98         {"syncTime", 2000},
99     })";
100     DistributedData::Serializable::json node = cJSON_Parse(str.c_str());
101     ClipPlugin::GlobalEvent globalEvent;
102     ASSERT_FALSE(globalEvent.Unmarshal(node));
103     cJSON_Delete(node);
104 }
105 
106 /**
107  * @tc.name: PublishServiceStateTest
108  * @tc.desc: PublishServiceState.
109  * @tc.type: FUNC
110  * @tc.require:
111  * @tc.author:
112  */
113 HWTEST_F(ClipPluginTest, PublishServiceStateTest, TestSize.Level0)
114 {
115     CustomClipPlugin clipPlugin;
116     std::string networkId = "testNetworkId";
117     int32_t result = clipPlugin.PublishServiceState(networkId, ClipPlugin::ServiceStatus::CONNECT_SUCC);
118     ASSERT_EQ(0, result);
119 }
120 
121 /**
122  * @tc.name: CloseTest
123  * @tc.desc: Close.
124  * @tc.type: FUNC
125  * @tc.require:
126  * @tc.author:
127  */
128 HWTEST_F(ClipPluginTest, CloseTest, TestSize.Level0)
129 {
130     CustomClipPlugin clipPlugin;
131     int32_t user = 0;
132     bool isNeedClear = true;
133     int32_t result = clipPlugin.Close(user);
134     ASSERT_EQ(0, result);
135 }
136 
137 /**
138  * @tc.name: RegisterDelayCallbackTest
139  * @tc.desc: RegisterDelayCallback.
140  * @tc.type: FUNC
141  * @tc.require:
142  * @tc.author:
143  */
144 HWTEST_F(ClipPluginTest, RegisterDelayCallbackTest, TestSize.Level0)
145 {
146     CustomClipPlugin clipPlugin;
147     ClipPlugin::DelayDataCallback dataCallback = nullptr;
148     ClipPlugin::DelayEntryCallback entryCallback = nullptr;
149     clipPlugin.RegisterDelayCallback(dataCallback, entryCallback);
150     ASSERT_TRUE(true);
151 }
152 
153 /**
154  * @tc.name: GetPasteDataEntryTest
155  * @tc.desc: GetPasteDataEntry.
156  * @tc.type: FUNC
157  * @tc.require:
158  * @tc.author:
159  */
160 HWTEST_F(ClipPluginTest, GetPasteDataEntryTest, TestSize.Level0)
161 {
162     CustomClipPlugin clipPlugin;
163     ClipPlugin::GlobalEvent event;
164     uint32_t recordId = 0;
165     std::string utdId = "";
166     std::vector<uint8_t> rawData;
167     int32_t result = clipPlugin.GetPasteDataEntry(event, recordId, utdId, rawData);
168     ASSERT_EQ(0, result);
169 }
170 
171 /**
172  * @tc.name: ChangeStoreStatusTest
173  * @tc.desc: ChangeStoreStatus.
174  * @tc.type: FUNC
175  * @tc.require:
176  * @tc.author:
177  */
178 HWTEST_F(ClipPluginTest, ChangeStoreStatusTest, TestSize.Level0)
179 {
180     CustomClipPlugin clipPlugin;
181     uint32_t userId = 0;
182     clipPlugin.ChangeStoreStatus(userId);
183     ASSERT_TRUE(true);
184 }
185 
186 /**
187  * @tc.name: NeedSyncTopEventTest
188  * @tc.desc: NeedSyncTopEvent.
189  * @tc.type: FUNC
190  * @tc.require:
191  * @tc.author:
192  */
193 HWTEST_F(ClipPluginTest, NeedSyncTopEventTest, TestSize.Level0)
194 {
195     CustomClipPlugin clipPlugin;
196     bool result = clipPlugin.NeedSyncTopEvent();
197     ASSERT_EQ(result, false);
198     ClipPlugin::PreSyncCallback preSyncCB;
199     clipPlugin.RegisterPreSyncCallback(preSyncCB);
200     ClipPlugin::PreSyncMonitorCallback preSyncMonitorCB;
201     clipPlugin.RegisterPreSyncMonitorCallback(preSyncMonitorCB);
202     clipPlugin.SendPreSyncEvent(0);
203 }
204 
205 /**
206  * @tc.name: RegCreatorTest001
207  * @tc.desc: RegCreator.
208  * @tc.type: FUNC
209  * @tc.require:
210  * @tc.author:
211  */
212 HWTEST_F(ClipPluginTest, RegCreatorTestTest001, TestSize.Level0)
213 {
214     std::string name = "testFactory";
215     ClipPlugin::Factory *factory = nullptr;
216     bool result = ClipPlugin::RegCreator(name, factory);
217     EXPECT_FALSE(result);
218 }
219 
220 /**
221  * @tc.name: DestroyPluginTest001
222  * @tc.desc: DestroyPlugin.
223  * @tc.type: FUNC
224  * @tc.require:
225  * @tc.author:
226  */
227 HWTEST_F(ClipPluginTest, DestroyPluginTest001, TestSize.Level0)
228 {
229     std::string name = "testPlugin";
230     ClipPlugin *plugin = nullptr;
231     EXPECT_FALSE(ClipPlugin::DestroyPlugin(name, plugin));
232 }
233 } // namespace OHOS::MiscServices
234