• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include <unistd.h>
18 #include <gtest/gtest.h>
19 
20 #include "datashare_errno.h"
21 #include "datashare_itypes_utils.h"
22 #include "datashare_log.h"
23 #include "datashare_abs_result_set.h"
24 #include "datashare_result_set.h"
25 #include "ikvstore_data_service.h"
26 #include "ipc_types.h"
27 #include "ishared_result_set_stub.h"
28 #include "itypes_util.h"
29 #include "message_parcel.h"
30 #include "gmock/gmock.h"
31 
32 namespace OHOS {
33 namespace DataShare {
34 using namespace testing::ext;
35 class DataShareCommonTest : public testing::Test {
36 public:
SetUpTestCase(void)37     static void SetUpTestCase(void){};
TearDownTestCase(void)38     static void TearDownTestCase(void){};
SetUp()39     void SetUp(){};
TearDown()40     void TearDown(){};
41 };
42 
43 class ResultSetBridgeTest : public OHOS::DataShare::ResultSetBridge {
44 public:
GetAllColumnNames(std::vector<std::string> & columnNames)45     int GetAllColumnNames(std::vector<std::string> &columnNames) override
46     {
47         return 0;
48     }
49 
GetRowCount(int32_t & count)50     int GetRowCount(int32_t &count) override
51     {
52         return 0;
53     }
54 
OnGo(int32_t startRowIndex,int32_t targetRowIndex,Writer & writer)55     int OnGo(int32_t startRowIndex, int32_t targetRowIndex, Writer &writer) override
56     {
57         return 0;
58     }
59 };
60 
61 class MockDataShareAbsResultSet : public DataShareAbsResultSet {
62 public:
63     MOCK_METHOD1(GoToRow, int(int));
64     MOCK_METHOD1(GetRowCount, int(int &));
65     MOCK_METHOD1(GetAllColumnNames, int(std::vector<std::string> &));
66     MOCK_METHOD1(GetColumnCount, int(int &));
67 };
68 
69 class MockDataShareAbsResultSet2 : public DataShareAbsResultSet {
70 public:
71     MOCK_METHOD1(GetAllColumnNames, int(std::vector<std::string> &));
72 };
73 
74 /**
75 * @tc.name: CreateStubTestTest001
76 * @tc.desc: test CreateStub function when resuletset_ = nullptr
77 * @tc.type: FUNC
78 * @tc.require: issueIC7OBM
79 * @tc.precon: None
80 * @tc.step:
81     1.Creat a ISharedResultSetStub object and resuletset_ = nullptr
82     2.call CreateStub function and check the result
83 * @tc.experct: CreateStub failed and reutrn nullptr
84 */
85 HWTEST_F(DataShareCommonTest, CreateStubTest001, TestSize.Level0)
86 {
87     LOG_INFO("DataShareCommonTest CreateStubTest001::Start");
88     std::shared_ptr<DataShareResultSet> resultset;
89     MessageParcel parcel;
90     ISharedResultSetStub stub(resultset);
91     auto result = stub.CreateStub(resultset, parcel);
92     EXPECT_EQ(result, nullptr);
93     LOG_INFO("DataShareCommonTest CreateStubTest001::End");
94 }
95 
96 /**
97 * @tc.name: CreateStubTestTest002
98 * @tc.desc: test CreateStub function when resuletset_ is not nullptr
99 * @tc.type: FUNC
100 * @tc.require: issueIC7OBM
101 * @tc.precon: None
102 * @tc.step:
103     1.Creat a ISharedResultSetStub object and resuletset_ is not nullptr
104     2.call CreateStub function and check the result
105 * @tc.experct: CreateStub succees and not reutrn nullptr
106 */
107 HWTEST_F(DataShareCommonTest, CreateStubTestTest002, TestSize.Level0)
108 {
109     LOG_INFO("DataShareCommonTest CreateStubTestTest002::Start");
110     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
111     MessageParcel parcel;
112     ISharedResultSetStub stub(resultset);
113     auto result = stub.CreateStub(resultset, parcel);
114     EXPECT_NE(result, nullptr);
115     LOG_INFO("DataShareCommonTest CreateStubTestTest002::End");
116 }
117 
118 /**
119 * @tc.name: OnRemoteRequestTest001
120 * @tc.desc: test OnRemoteRequest function when resuletset_ = nullptr
121 * @tc.type: FUNC
122 * @tc.require: issueIC7OBM
123 * @tc.precon: None
124 * @tc.step:
125     1.Creat a ISharedResultSetStub object and resuletset_ = nullptr
126     2.call OnRemoteRequest function and check the result
127 * @tc.experct: OnRemoteRequest failed and reutrn INVALID_FD
128 */
129 HWTEST_F(DataShareCommonTest, OnRemoteRequestTest001, TestSize.Level0)
130 {
131     LOG_INFO("DataShareCommonTest OnRemoteRequestTest001::Start");
132     std::shared_ptr<DataShareResultSet> resultset;
133     ISharedResultSetStub stub(resultset);
134     uint32_t code = 0;
135     MessageParcel data;
136     MessageParcel parcel;
137     MessageOption option;
138     auto result = stub.OnRemoteRequest(code, data, parcel, option);
139     EXPECT_EQ(result, INVALID_FD);
140     LOG_INFO("DataShareCommonTest OnRemoteRequestTest001::End");
141 }
142 
143 /**
144 * @tc.name: HandleGetRowCountRequestTest001
145 * @tc.desc: test HandleGetRowCountRequest function when bridge = nullptr
146 * @tc.type: FUNC
147 * @tc.require: issueIC7OBM
148 * @tc.precon: None
149 * @tc.step:
150     1.Creat a ISharedResultSetStub object and bridge is nullptr
151     2.call HandleGetRowCountRequest function and check the result
152 * @tc.experct: HandleGetRowCountRequest success and write E_ERROR into reply
153 */
154 HWTEST_F(DataShareCommonTest, HandleGetRowCountRequestTest001, TestSize.Level0)
155 {
156     LOG_INFO("DataShareCommonTest HandleGetRowCountRequestTest001::Start");
157     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
158     MessageParcel data;
159     MessageParcel reply;
160     ISharedResultSetStub stub(resultset);
161     auto result = stub.HandleGetRowCountRequest(data, reply);
162     EXPECT_EQ(reply.ReadInt32(), E_ERROR);
163     EXPECT_EQ(result, NO_ERROR);
164     LOG_INFO("DataShareCommonTest HandleGetRowCountRequestTest001::End");
165 }
166 
167 /**
168 * @tc.name: HandleGetRowCountRequestTest002
169 * @tc.desc: test HandleGetRowCountRequest function when bridge is not nullptr
170 * @tc.type: FUNC
171 * @tc.require: issueIC7OBM
172 * @tc.precon: None
173 * @tc.step:
174     1.Creat a ISharedResultSetStub object and bridge is not nullptr
175     2.call HandleGetRowCountRequest function and check the result
176 * @tc.experct: HandleGetRowCountRequest success and write count into reply
177 */
178 HWTEST_F(DataShareCommonTest, HandleGetRowCountRequestTest002, TestSize.Level0)
179 {
180     LOG_INFO("DataShareCommonTest HandleGetRowCountRequestTest002::Start");
181     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
182     resultset->bridge_ = std::make_shared<ResultSetBridgeTest>();
183     MessageParcel data;
184     MessageParcel reply;
185     ISharedResultSetStub stub(resultset);
186     auto result = stub.HandleGetRowCountRequest(data, reply);
187     EXPECT_NE(reply.ReadInt32(), E_ERROR);
188     EXPECT_EQ(result, NO_ERROR);
189     LOG_INFO("DataShareCommonTest HandleGetRowCountRequestTest002::End");
190 }
191 
192 /**
193 * @tc.name: HandleGetAllColumnNamesRequestTest001
194 * @tc.desc: test HandleGetAllColumnNamesRequest function when bridge is nullptr
195 * @tc.type: FUNC
196 * @tc.require: issueIC7OBM
197 * @tc.precon: None
198 * @tc.step:
199     1.Creat a ISharedResultSetStub object and bridge is nullptr
200     2.call HandleGetAllColumnNamesRequest function and check the result
201 * @tc.experct: HandleGetAllColumnNamesRequest success and write E_ERROR into reply
202 */
203 HWTEST_F(DataShareCommonTest, HandleGetAllColumnNamesRequestTest001, TestSize.Level0)
204 {
205     LOG_INFO("DataShareCommonTest HandleGetAllColumnNamesRequestTest001::Start");
206     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
207     MessageParcel data;
208     MessageParcel reply;
209     ISharedResultSetStub stub(resultset);
210     auto result = stub.HandleGetAllColumnNamesRequest(data, reply);
211     EXPECT_EQ(reply.ReadInt32(), E_ERROR);
212     EXPECT_EQ(result, NO_ERROR);
213     LOG_INFO("DataShareCommonTest HandleGetAllColumnNamesRequestTest001::End");
214 }
215 
216 /**
217 * @tc.name: HandleGetAllColumnNamesRequestTest002
218 * @tc.desc: test HandleGetAllColumnNamesRequest function when bridge is not nullptr
219 * @tc.type: FUNC
220 * @tc.require: issueIC7OBM
221 * @tc.precon: None
222 * @tc.step:
223     1.Creat a ISharedResultSetStub object and bridge is not nullptr
224     2.call HandleGetAllColumnNamesRequest function and check the result
225 * @tc.experct: HandleGetAllColumnNamesRequest success and write count into reply
226 */
227 HWTEST_F(DataShareCommonTest, HandleGetAllColumnNamesRequestTest002, TestSize.Level0)
228 {
229     LOG_INFO("DataShareCommonTest HandleGetAllColumnNamesRequestTest002::Start");
230     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
231     resultset->bridge_ = std::make_shared<ResultSetBridgeTest>();
232     MessageParcel data;
233     MessageParcel reply;
234     ISharedResultSetStub stub(resultset);
235     auto result = stub.HandleGetAllColumnNamesRequest(data, reply);
236     EXPECT_NE(reply.ReadInt32(), E_ERROR);
237     EXPECT_EQ(result, NO_ERROR);
238     LOG_INFO("DataShareCommonTest HandleGetAllColumnNamesRequestTest002::End");
239 }
240 
241 /**
242 * @tc.name: HandleOnGoRequestTest001
243 * @tc.desc: test HandleOnGoRequest function when bridge is nullptr
244 * @tc.type: FUNC
245 * @tc.require: issueIC7OBM
246 * @tc.precon: None
247 * @tc.step:
248     1.Creat a ISharedResultSetStub object and bridge is nullptr
249     2.call HandleOnGoRequest function and check the result
250 * @tc.experct: HandleOnGoRequest success and write -1 into reply
251 */
252 HWTEST_F(DataShareCommonTest, HandleOnGoRequestTest001, TestSize.Level0)
253 {
254     LOG_INFO("DataShareCommonTest HandleOnGoRequestTest001::Start");
255     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
256     MessageParcel data;
257     MessageParcel reply;
258     ISharedResultSetStub stub(resultset);
259     auto result = stub.HandleOnGoRequest(data, reply);
260     EXPECT_EQ(reply.ReadInt32(), -1);
261     EXPECT_EQ(result, NO_ERROR);
262     LOG_INFO("DataShareCommonTest HandleOnGoRequestTest001::End");
263 }
264 
265 /**
266 * @tc.name: HandleOnGoRequestTest002
267 * @tc.desc: test HandleOnGoRequest function when bridge is not nullptr
268 * @tc.type: FUNC
269 * @tc.require: issueIC7OBM
270 * @tc.precon: None
271 * @tc.step:
272     1.Creat a ISharedResultSetStub object and bridge is not nullptr
273     2.call HandleOnGoRequest function and check the result
274 * @tc.experct: HandleOnGoRequest success and write count into reply
275 */
276 HWTEST_F(DataShareCommonTest, HandleOnGoRequestTest002, TestSize.Level0)
277 {
278     LOG_INFO("DataShareCommonTest HandleOnGoRequestTest002::Start");
279     std::shared_ptr<DataShareResultSet> resultset = std::make_shared<DataShareResultSet>();
280     resultset->bridge_ = std::make_shared<ResultSetBridgeTest>();
281     MessageParcel data;
282     MessageParcel reply;
283     ISharedResultSetStub stub(resultset);
284     auto result = stub.HandleOnGoRequest(data, reply);
285     EXPECT_NE(reply.ReadInt32(), E_ERROR);
286     EXPECT_EQ(result, NO_ERROR);
287     LOG_INFO("DataShareCommonTest HandleOnGoRequestTest002::End");
288 }
289 
290 /**
291 * @tc.name: GetDataTypeTest001
292 * @tc.desc: test GetDataType function when sharedBlock_ is nullptr
293 * @tc.type: FUNC
294 * @tc.require: issueIC9GIH
295 * @tc.precon: None
296 * @tc.step:
297     1.Creat a DataShareResultSet object and sharedBlock_ is nullptr
298     2.call GetDataType function and check the result
299 * @tc.experct: GetDataType failed and return E_ERROR
300 */
301 HWTEST_F(DataShareCommonTest, GetDataTypeTest001, TestSize.Level0)
302 {
303     LOG_INFO("DataShareCommonTest GetDataTypeTest001::Start");
304     DataShareResultSet dataShareResultSet;
305     int columnIndex = 1;
306     DataShare::DataType dataType;
307     auto result = dataShareResultSet.GetDataType(columnIndex, dataType);
308     EXPECT_EQ(result, E_ERROR);
309     LOG_INFO("DataShareCommonTest GetDataTypeTest001::End");
310 }
311 
312 /**
313 * @tc.name: CheckStateTest001
314 * @tc.desc: test CheckState function when columnIndex >= 0
315 * @tc.type: FUNC
316 * @tc.require: issueIC9GIH
317 * @tc.precon: None
318 * @tc.step:
319     1.Creat a DataShareResultSet object
320     2.call CheckState function when columnIndex >= 0 and check the result
321 * @tc.experct: CheckState failed and return E_INVALID_COLUMN_INDEX
322 */
323 HWTEST_F(DataShareCommonTest, CheckStateTest001, TestSize.Level0)
324 {
325     LOG_INFO("DataShareCommonTest CheckStateTest001::Start");
326     DataShareResultSet dataShareResultSet;
327     int columnIndex = 1;
328     auto result = dataShareResultSet.CheckState(columnIndex);
329     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
330     LOG_INFO("DataShareCommonTest CheckStateTest001::End");
331 }
332 
333 /**
334 * @tc.name: CheckStateTest002
335 * @tc.desc: test CheckState function when columnIndex < 0
336 * @tc.type: FUNC
337 * @tc.require: issueIC9GIH
338 * @tc.precon: None
339 * @tc.step:
340     1.Creat a DataShareResultSet object
341     2.call CheckState function when columnIndex < 0 and check the result
342 * @tc.experct: CheckState failed and return E_INVALID_COLUMN_INDEX
343 */
344 HWTEST_F(DataShareCommonTest, CheckStateTest002, TestSize.Level0)
345 {
346     LOG_INFO("DataShareCommonTest CheckState002::Start");
347     DataShareResultSet dataShareResultSet;
348     int columnIndex = -1;
349     auto result = dataShareResultSet.CheckState(columnIndex);
350     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
351     LOG_INFO("DataShareCommonTest CheckState002::End");
352 }
353 
354 /**
355 * @tc.name: MarshalTest001
356 * @tc.desc: test Marshal function when resultset = nullptr
357 * @tc.type: FUNC
358 * @tc.require: issueICCAXH
359 * @tc.precon: None
360 * @tc.step:
361     1.Creat a DataShareResultSet object when resultset = nullptr
362     2.call Marshal function and check the result
363 * @tc.experct: Marshal failed and return false
364 */
365 HWTEST_F(DataShareCommonTest, MarshalTest001, TestSize.Level0)
366 {
367     LOG_INFO("DataShareCommonTest MarshalTest001::Start");
368     DataShareResultSet dataShareResultSet;
369     std::shared_ptr<DataShareResultSet> resultset = nullptr;
370     MessageParcel parcel;
371     auto result = dataShareResultSet.Marshal(resultset, parcel);
372     EXPECT_FALSE(result);
373     LOG_INFO("DataShareCommonTest MarshalTest001::End");
374 }
375 
376 /**
377 * @tc.name: UnmarshalTest001
378 * @tc.desc: test Unmarshal function
379 * @tc.type: FUNC
380 * @tc.require: issueICCAXH
381 * @tc.precon: None
382 * @tc.step:
383     1.Creat a DataShareResultSet object
384     2.call Unmarshal function and check the result
385 * @tc.experct: Unmarshal failed and return nullptr
386 */
387 HWTEST_F(DataShareCommonTest, UnmarshalTest001, TestSize.Level0)
388 {
389     LOG_INFO("DataShareCommonTest UnmarshalTest001::Start");
390     DataShareResultSet dataShareResultSet;
391     MessageParcel parcel;
392     auto result = dataShareResultSet.Unmarshal(parcel);
393     EXPECT_EQ(result, nullptr);
394     LOG_INFO("DataShareCommonTest UnmarshalTest001::End");
395 }
396 
397 /**
398 * @tc.name: UnmarshallingTest001
399 * @tc.desc: test Unmarshalling function when parcel is nullptr
400 * @tc.type: FUNC
401 * @tc.require: issueIC9GIH
402 * @tc.precon: None
403 * @tc.step:
404     1.Creat a ITypesUtil object and parcel is nullptr
405     2.call Unmarshalling function and check the result
406 * @tc.experct: Unmarshalling failed and return false
407 */
408 HWTEST_F(DataShareCommonTest, UnmarshallingTest001, TestSize.Level0)
409 {
410     LOG_INFO("DataShareCommonTest UnmarshallingTest001::Start");
411     ITypesUtil::Predicates predicates;
412     MessageParcel parcel;
413     auto result = ITypesUtil::Unmarshalling(predicates, parcel);
414     EXPECT_FALSE(result);
415     LOG_INFO("DataShareCommonTest UnmarshallingTest001::End");
416 }
417 
418 /**
419 * @tc.name: UnmarshallingTest002
420 * @tc.desc: test Unmarshalling function when parcel is nullptr
421 * @tc.type: FUNC
422 * @tc.require: issueIC9GIH
423 * @tc.precon: None
424 * @tc.step:
425     1.Creat a ITypesUtil object and parcel is nullptr
426     2.call Unmarshalling function and check the result
427 * @tc.experct: Unmarshalling failed and return false
428 */
429 HWTEST_F(DataShareCommonTest, UnmarshallingTest002, TestSize.Level0)
430 {
431     LOG_INFO("DataShareCommonTest UnmarshallingTest002::Start");
432     OperationStatement operationStatement;
433     MessageParcel parcel;
434     auto result = ITypesUtil::Unmarshalling(operationStatement, parcel);
435     EXPECT_FALSE(result);
436     LOG_INFO("DataShareCommonTest UnmarshallingTest002::End");
437 }
438 
439 /**
440 * @tc.name: UnmarshallingTest003
441 * @tc.desc: test Unmarshalling function when parcel is nullptr
442 * @tc.type: FUNC
443 * @tc.require: issueIC9GIH
444 * @tc.precon: None
445 * @tc.step:
446     1.Creat a ITypesUtil object and parcel is nullptr
447     2.call Unmarshalling function and check the result
448 * @tc.experct: Unmarshalling failed and return false
449 */
450 HWTEST_F(DataShareCommonTest, UnmarshallingTest003, TestSize.Level0)
451 {
452     LOG_INFO("DataShareCommonTest UnmarshallingTest003::Start");
453     ExecResult execResult;
454     MessageParcel parcel;
455     auto result = ITypesUtil::Unmarshalling(execResult, parcel);
456     EXPECT_FALSE(result);
457     LOG_INFO("DataShareCommonTest UnmarshallingTest003::End");
458 }
459 
460 /**
461 * @tc.name: UnmarshallingTest004
462 * @tc.desc: test Unmarshalling function when parcel is nullptr
463 * @tc.type: FUNC
464 * @tc.require: issueIC9GIH
465 * @tc.precon: None
466 * @tc.step:
467     1.Creat a ITypesUtil object and parcel is nullptr
468     2.call Unmarshalling function and check the result
469 * @tc.experct: Unmarshalling failed and return false
470 */
471 HWTEST_F(DataShareCommonTest, UnmarshallingTest004, TestSize.Level0)
472 {
473     LOG_INFO("DataShareCommonTest UnmarshallingTest004::Start");
474     ExecResultSet execResultSet;
475     MessageParcel parcel;
476     auto result = ITypesUtil::Unmarshalling(execResultSet, parcel);
477     EXPECT_FALSE(result);
478     LOG_INFO("DataShareCommonTest UnmarshallingTest004::End");
479 }
480 
481 /**
482 * @tc.name: MarshallingTest001
483 * @tc.desc: test Marshalling function when parcel is nullptr
484 * @tc.type: FUNC
485 * @tc.require: issueIC9GIH
486 * @tc.precon: None
487 * @tc.step:
488     1.Creat a ITypesUtil object and parcel is nullptr
489     2.call Marshalling function and check the result
490 * @tc.experct: Marshalling success and return ture
491 */
492 HWTEST_F(DataShareCommonTest, MarshallingTest001, TestSize.Level0)
493 {
494     LOG_INFO("DataShareCommonTest MarshallingTest001::Start");
495     ITypesUtil::RdbChangeNode changeNode;
496     MessageParcel parcel;
497     auto result = ITypesUtil::Marshalling(changeNode, parcel);
498     EXPECT_TRUE(result);
499     LOG_INFO("DataShareCommonTest MarshallingTest001::End");
500 }
501 
502 /**
503 * @tc.name: MarshallingTest002
504 * @tc.desc: test Marshalling function when sharedBlock_ is nullptr
505 * @tc.type: FUNC
506 * @tc.require: issueIC9GIH
507 * @tc.precon: None
508 * @tc.step:
509     1.Creat a DataShareResultSet object
510     2.call Marshalling function when sharedBlock_ is nullptr and check the result
511 * @tc.experct: Marshalling failed and return false
512 */
513 HWTEST_F(DataShareCommonTest, MarshallingTest002, TestSize.Level0)
514 {
515     LOG_INFO("DataShareCommonTest MarshallingTest002::Start");
516     DataShareResultSet dataShareResultSet;
517     MessageParcel parcel;
518     auto result = dataShareResultSet.Marshalling(parcel);
519     EXPECT_FALSE(result);
520     LOG_INFO("DataShareCommonTest MarshallingTest002::End");
521 }
522 
523 /**
524 * @tc.name: GoToTest001
525 * @tc.desc: test GoTo function when GoToRow return E_ERROR
526 * @tc.type: FUNC
527 * @tc.require: issueIC9GIH
528 * @tc.precon: None
529 * @tc.step:
530     1.Creat a MockDataShareAbsResultSet object
531     2.call GoTo function when GoToRow return E_ERROR and check the result
532 * @tc.experct: GoTo failed and return E_ERROR
533 */
534 HWTEST_F(DataShareCommonTest, GoToTest001, TestSize.Level0)
535 {
536     LOG_INFO("DataShareCommonTest GoToTest001::Start");
537     MockDataShareAbsResultSet mockResultSet;
538     int offset = 1;
539     EXPECT_CALL(mockResultSet, GoToRow(testing::_))
540         .WillOnce(testing::Return(E_ERROR));
541     auto result = mockResultSet.GoTo(offset);
542     EXPECT_EQ(result, E_ERROR);
543     LOG_INFO("DataShareCommonTest GoToTest001::End");
544 }
545 
546 /**
547 * @tc.name: GoToTest002
548 * @tc.desc: test GoTo function
549 * @tc.type: FUNC
550 * @tc.require: issueIC9GIH
551 * @tc.precon: None
552 * @tc.step:
553     1.Creat a MockDataShareAbsResultSet object
554     2.call GoTo function and check the result
555 * @tc.experct: GoTo success and return E_OK
556 */
557 HWTEST_F(DataShareCommonTest, GoToTest002, TestSize.Level0)
558 {
559     LOG_INFO("DataShareCommonTest GoToTest002::Start");
560     DataShareAbsResultSet dataShareAbsResultSet;
561     int offset = 1;
562     auto result = dataShareAbsResultSet.GoTo(offset);
563     EXPECT_EQ(result, E_OK);
564     LOG_INFO("DataShareCommonTest GoToTest002::End");
565 }
566 
567 /**
568 * @tc.name: IsEndedTest001
569 * @tc.desc: test IsEnded function when GetRowCount return E_ERROR
570 * @tc.type: FUNC
571 * @tc.require: issueIC9GIH
572 * @tc.precon: None
573 * @tc.step:
574     1.Creat a MockDataShareAbsResultSet object
575     2.call IsEnded function when GetRowCount return E_ERROR and check the result
576 * @tc.experct: IsEnded failed and return E_ERROR
577 */
578 HWTEST_F(DataShareCommonTest, IsEndedTest001, TestSize.Level0)
579 {
580     LOG_INFO("DataShareCommonTest IsEndedTest001::Start");
581     MockDataShareAbsResultSet mockResultSet;
582     EXPECT_CALL(mockResultSet, GetRowCount(testing::_))
583         .WillOnce(testing::Return(E_ERROR));
584     bool test = true;
585     auto result = mockResultSet.IsEnded(test);
586     EXPECT_EQ(result, E_ERROR);
587     LOG_INFO("DataShareCommonTest IsEndedTest001::End");
588 }
589 
590 /**
591 * @tc.name: IsEndedTest002
592 * @tc.desc: test IsEnded function
593 * @tc.type: FUNC
594 * @tc.require: issueIC9GIH
595 * @tc.precon: None
596 * @tc.step:
597     1.Creat a MockDataShareAbsResultSet object
598     2.call IsEnded function and check the result
599 * @tc.experct: IsEnded success and return E_OK
600 */
601 HWTEST_F(DataShareCommonTest, IsEndedTest002, TestSize.Level0)
602 {
603     LOG_INFO("DataShareCommonTest IsEndedTest002::Start");
604     DataShareAbsResultSet dataShareAbsResultSet;
605     bool test = true;
606     auto result = dataShareAbsResultSet.IsEnded(test);
607     EXPECT_EQ(result, E_OK);
608     LOG_INFO("DataShareCommonTest IsEndedTest002::End");
609 }
610 
611 /**
612 * @tc.name: GetColumnCountTest001
613 * @tc.desc: test GetColumnCount function when GetAllColumnNames return E_ERROR
614 * @tc.type: FUNC
615 * @tc.require: issueIC9GIH
616 * @tc.precon: None
617 * @tc.step:
618     1.Creat a MockDataShareAbsResultSet2 object
619     2.call GetColumnCount function when GetAllColumnNames return E_ERROR and check the result
620 * @tc.experct: GetColumnCount failed and return E_ERROR
621 */
622 HWTEST_F(DataShareCommonTest, GetColumnCountTest001, TestSize.Level0)
623 {
624     LOG_INFO("DataShareCommonTest GetColumnCountTest001::Start");
625     MockDataShareAbsResultSet2 mockResultSet;
626     int offset = -1;
627     mockResultSet.count_ = -1;
628     EXPECT_CALL(mockResultSet, GetAllColumnNames(testing::_))
629         .WillOnce(testing::Return(E_ERROR));
630     auto result = mockResultSet.GetColumnCount(offset);
631     EXPECT_EQ(result, E_ERROR);
632     LOG_INFO("DataShareCommonTest GetColumnCountTest001::End");
633 }
634 
635 /**
636 * @tc.name: GetColumnName001
637 * @tc.desc: test GetColumnName function when GetColumnCount return E_ERROR
638 * @tc.type: FUNC
639 * @tc.require: issueIC9GIH
640 * @tc.precon: None
641 * @tc.step:
642     1.Creat a MockDataShareAbsResultSet object
643     2.call GetColumnName function when GetColumnCount return E_ERROR and check the result
644 * @tc.experct: GetColumnName failed and return E_ERROR
645 */
646 HWTEST_F(DataShareCommonTest, GetColumnName001, TestSize.Level0)
647 {
648     LOG_INFO("DataShareCommonTest GetColumnName001::Start");
649     MockDataShareAbsResultSet mockResultSet;
650     int columnIndex = 1;
651     std::string columnName = "test";
652     EXPECT_CALL(mockResultSet, GetColumnCount(testing::_))
653         .WillOnce(testing::Return(E_ERROR));
654     auto result = mockResultSet.GetColumnName(columnIndex, columnName);
655     EXPECT_EQ(result, E_ERROR);
656     LOG_INFO("DataShareCommonTest GetColumnName001::End");
657 }
658 
659 /**
660 * @tc.name: GetColumnName002
661 * @tc.desc: test GetColumnName function when columnIndex >= 0
662 * @tc.type: FUNC
663 * @tc.require: issueIC9GIH
664 * @tc.precon: None
665 * @tc.step:
666     1.Creat a MockDataShareAbsResultSet object
667     2.call GetColumnName function when columnIndex >= 0 and check the result
668 * @tc.experct: GetColumnName failed and return E_INVALID_COLUMN_INDEX
669 */
670 HWTEST_F(DataShareCommonTest, GetColumnName002, TestSize.Level0)
671 {
672     LOG_INFO("DataShareCommonTest MarshallingTest002::Start");
673     DataShareAbsResultSet dataShareAbsResultSet;
674     int columnIndex = 1;
675     std::string columnName = "test";
676     auto result = dataShareAbsResultSet.GetColumnName(columnIndex, columnName);
677     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
678     LOG_INFO("DataShareCommonTest MarshallingTest002::End");
679 }
680 
681 /**
682 * @tc.name: GetColumnName003
683 * @tc.desc: test GetColumnName function when columnIndex < 0
684 * @tc.type: FUNC
685 * @tc.require: issueIC9GIH
686 * @tc.precon: None
687 * @tc.step:
688     1.Creat a MockDataShareAbsResultSet object
689     2.call GetColumnName function when columnIndex < 0 and check the result
690 * @tc.experct: GetColumnName failed and return E_INVALID_COLUMN_INDEX
691 */
692 HWTEST_F(DataShareCommonTest, GetColumnName003, TestSize.Level0)
693 {
694     LOG_INFO("DataShareCommonTest MarshallingTest002::Start");
695     DataShareAbsResultSet dataShareAbsResultSet;
696     int columnIndex = -1;
697     std::string columnName = "test";
698     auto result = dataShareAbsResultSet.GetColumnName(columnIndex, columnName);
699     EXPECT_EQ(result, E_INVALID_COLUMN_INDEX);
700     LOG_INFO("DataShareCommonTest MarshallingTest002::End");
701 }
702 
703 /**
704 * @tc.name: RegisterClientDeathObserver001
705 * @tc.desc: test RegisterClientDeathObserver function when observer = nullptr
706 * @tc.type: FUNC
707 * @tc.require: issueIC9GIH
708 * @tc.precon: None
709 * @tc.step:
710     1.Creat a MockDataShareAbsResultSet object when observer = nullptr
711     2.call RegisterClientDeathObserver function and check the result
712 * @tc.experct: RegisterClientDeathObserver failed and return -1
713 */
714 HWTEST_F(DataShareCommonTest, RegisterClientDeathObserver001, TestSize.Level0)
715 {
716     LOG_INFO("DataShareCommonTest RegisterClientDeathObserver001::Start");
717     sptr<IRemoteObject> observer = nullptr;
718     std::string appId = "testAppid";
719     DataShareKvServiceProxy dataShareKvServiceProxy(observer);
720     auto result = dataShareKvServiceProxy.RegisterClientDeathObserver(appId, observer);
721     EXPECT_EQ(result, -1);
722     LOG_INFO("DataShareCommonTest RegisterClientDeathObserver001::End");
723 }
724 } // namespace DataShare
725 } // namespace OHOS