• 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 <gtest/gtest.h>
17 
18 #include <string>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include "common.h"
22 #include "relational_store.h"
23 #include "oh_value_object.h"
24 #include "relational_store_error_code.h"
25 
26 using namespace testing::ext;
27 using namespace OHOS::NativeRdb;
28 
29 class RdbNativePredicatesTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32     static void TearDownTestCase(void);
33     void SetUp();
34     void TearDown();
InitRdbConfig()35     static void InitRdbConfig()
36     {
37         config_.dataBaseDir = RDB_TEST_PATH;
38         config_.storeName = "rdb_predicates_test.db";
39         config_.bundleName = "";
40         config_.moduleName = "";
41         config_.securityLevel = OH_Rdb_SecurityLevel::S1;
42         config_.isEncrypt = false;
43         config_.selfSize = sizeof(OH_Rdb_Config);
44     }
45     static OH_Rdb_Config config_;
46 };
47 
48 OH_Rdb_Store *predicatesTestRdbStore_;
49 OH_Rdb_Config RdbNativePredicatesTest::config_ = {0};
SetUpTestCase(void)50 void RdbNativePredicatesTest::SetUpTestCase(void)
51 {
52     InitRdbConfig();
53     mkdir(config_.dataBaseDir, 0770);
54     int errCode = 0;
55     char table[] = "test";
56     predicatesTestRdbStore_ = OH_Rdb_GetOrOpen(&config_, &errCode);
57     EXPECT_NE(predicatesTestRdbStore_, NULL);
58 
59     char createTableSql[] = "CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, data1 TEXT, data2 INTEGER, "
60                             "data3 FLOAT, data4 BLOB, data5 TEXT);";
61     errCode = OH_Rdb_Execute(predicatesTestRdbStore_, createTableSql);
62 
63     OH_VBucket *valueBucket = OH_Rdb_CreateValuesBucket();
64     valueBucket->putInt64(valueBucket, "id", 1);
65     valueBucket->putText(valueBucket, "data1", "zhangSan");
66     valueBucket->putInt64(valueBucket, "data2", 12800);
67     valueBucket->putReal(valueBucket, "data3", 100.1);
68     uint8_t arr[] = {1, 2, 3, 4, 5};
69     int len = sizeof(arr) / sizeof(arr[0]);
70     valueBucket->putBlob(valueBucket, "data4", arr, len);
71     valueBucket->putText(valueBucket, "data5", "ABCDEFG");
72     errCode = OH_Rdb_Insert(predicatesTestRdbStore_, table, valueBucket);
73     EXPECT_EQ(errCode, 1);
74 
75     valueBucket->clear(valueBucket);
76     valueBucket->putInt64(valueBucket, "id", 2);
77     valueBucket->putText(valueBucket, "data1", "liSi");
78     valueBucket->putInt64(valueBucket, "data2", 13800);
79     valueBucket->putReal(valueBucket, "data3", 200.1);
80     valueBucket->putText(valueBucket, "data5", "ABCDEFGH");
81     errCode = OH_Rdb_Insert(predicatesTestRdbStore_, table, valueBucket);
82     EXPECT_EQ(errCode, 2);
83 
84     valueBucket->clear(valueBucket);
85     valueBucket->putInt64(valueBucket, "id", 3);
86     valueBucket->putText(valueBucket, "data1", "wangWu");
87     valueBucket->putInt64(valueBucket, "data2", 14800);
88     valueBucket->putReal(valueBucket, "data3", 300.1);
89     valueBucket->putText(valueBucket, "data5", "ABCDEFGHI");
90     errCode = OH_Rdb_Insert(predicatesTestRdbStore_, table, valueBucket);
91     EXPECT_EQ(errCode, 3);
92 
93     valueBucket->destroy(valueBucket);
94 }
95 
TearDownTestCase(void)96 void RdbNativePredicatesTest::TearDownTestCase(void)
97 {
98     delete predicatesTestRdbStore_;
99     predicatesTestRdbStore_ = NULL;
100     OH_Rdb_DeleteStore(&config_);
101 }
102 
SetUp(void)103 void RdbNativePredicatesTest::SetUp(void)
104 {
105 }
106 
TearDown(void)107 void RdbNativePredicatesTest::TearDown(void)
108 {
109 }
110 
111 /**
112  * @tc.name: RDB_Native_predicates_test_001
113  * @tc.desc: Normal testCase of Predicates for EqualTo、AndOR、beginWrap and endWrap
114  * @tc.type: FUNC
115  */
116 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_001, TestSize.Level1)
117 {
118     int errCode = 0;
119     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
120     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
121     uint32_t count = 1;
122     const char *data1Value = "zhangSan";
123     valueObject->putText(valueObject, data1Value);
124     predicates->beginWrap(predicates)->equalTo(predicates, "data1", valueObject)->orOperate(predicates);
125     double data3Value = 200.1;
126     valueObject->putDouble(valueObject, &data3Value, count);
127     predicates->equalTo(predicates, "data3", valueObject)->endWrap(predicates);
128 
129     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
130     EXPECT_NE(cursor, NULL);
131     int rowCount = 0;
132     errCode = cursor->getRowCount(cursor, &rowCount);
133     EXPECT_EQ(rowCount, 2);
134 
135     valueObject->destroy(valueObject);
136     predicates->destroy(predicates);
137     cursor->destroy(cursor);
138 }
139 
140 /**
141  * @tc.name: RDB_Native_predicates_test_002
142  * @tc.desc: Normal testCase of Predicates for NotEqualTo
143  * @tc.type: FUNC
144  */
145 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_002, TestSize.Level1)
146 {
147     int errCode = 0;
148     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
149     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
150     const char *data1Value = "zhangSan";
151     valueObject->putText(valueObject, data1Value);
152     predicates->notEqualTo(predicates, "data1", valueObject);
153     EXPECT_EQ(errCode, 0);
154 
155     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
156     EXPECT_NE(cursor, NULL);
157     int rowCount = 0;
158     errCode = cursor->getRowCount(cursor, &rowCount);
159     EXPECT_EQ(rowCount, 2);
160 
161     valueObject->destroy(valueObject);
162     predicates->destroy(predicates);
163     cursor->destroy(cursor);
164 }
165 
166 /**
167  * @tc.name: RDB_Native_predicates_test_003
168  * @tc.desc: Normal testCase of Predicates for GreaterThan
169  * @tc.type: FUNC
170  */
171 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_003, TestSize.Level1)
172 {
173     int errCode = 0;
174     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
175     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
176     const char *data5Value = "ABCDEFG";
177     valueObject->putText(valueObject, data5Value);
178     predicates->greaterThan(predicates, "data5", valueObject);
179 
180     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
181     EXPECT_NE(cursor, NULL);
182     int rowCount = 0;
183     errCode = cursor->getRowCount(cursor, &rowCount);
184     EXPECT_EQ(rowCount, 2);
185 
186     cursor->goToNextRow(cursor);
187 
188     int columnCount = 0;
189     cursor->getColumnCount(cursor, &columnCount);
190     EXPECT_EQ(columnCount, 6);
191 
192     int64_t id;
193     cursor->getInt64(cursor, 0, &id);
194     EXPECT_EQ(id, 2);
195 
196     size_t size = 0;
197     cursor->getSize(cursor, 1, &size);
198     char data1Value[size + 1];
199     cursor->getText(cursor, 1, data1Value, size + 1);
200     EXPECT_EQ(strcmp(data1Value, "liSi"), 0);
201 
202     int64_t data2Value;
203     cursor->getInt64(cursor, 2, &data2Value);
204     EXPECT_EQ(data2Value, 13800);
205 
206     double data3Value;
207     cursor->getReal(cursor, 3, &data3Value);
208     EXPECT_EQ(data3Value, 200.1);
209 
210     bool isNull = false;
211     cursor->isNull(cursor, 4, &isNull);
212     EXPECT_EQ(isNull, true);
213 
214     cursor->getSize(cursor, 5, &size);
215     char data5Value_1[size + 1];
216     cursor->getText(cursor, 5, data5Value_1, size + 1);
217     EXPECT_EQ(strcmp(data5Value_1, "ABCDEFGH"), 0);
218 
219     cursor->goToNextRow(cursor);
220 
221     cursor->getInt64(cursor, 0, &id);
222     EXPECT_EQ(id, 3);
223 
224     cursor->getSize(cursor, 1, &size);
225     char data1Value_1[size + 1];
226     cursor->getText(cursor, 1, data1Value_1, size + 1);
227     EXPECT_EQ(strcmp(data1Value_1, "wangWu"), 0);
228 
229     cursor->getInt64(cursor, 2, &data2Value);
230     EXPECT_EQ(data2Value, 14800);
231 
232     cursor->getReal(cursor, 3, &data3Value);
233     EXPECT_EQ(data3Value, 300.1);
234 
235     cursor->isNull(cursor, 4, &isNull);
236     EXPECT_EQ(isNull, true);
237 
238     cursor->getSize(cursor, 5, &size);
239     char data5Value_2[size + 1];
240     cursor->getText(cursor, 5, data5Value_2, size + 1);
241     EXPECT_EQ(strcmp(data5Value_2, "ABCDEFGHI"), 0);
242 
243     valueObject->destroy(valueObject);
244     predicates->destroy(predicates);
245     cursor->destroy(cursor);
246 }
247 
248 /**
249  * @tc.name: RDB_Native_predicates_test_004
250  * @tc.desc: Normal testCase of Predicates for GreaterThanOrEqualTo
251  * @tc.type: FUNC
252  */
253 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_004, TestSize.Level1)
254 {
255     int errCode = 0;
256     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
257     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
258     const char *data5Value = "ABCDEFG";
259     valueObject->putText(valueObject, data5Value);
260     predicates->greaterThanOrEqualTo(predicates, "data5", valueObject);
261 
262     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
263     EXPECT_NE(cursor, NULL);
264     int rowCount = 0;
265     errCode = cursor->getRowCount(cursor, &rowCount);
266     EXPECT_EQ(rowCount, 3);
267 
268     valueObject->destroy(valueObject);
269     predicates->destroy(predicates);
270     cursor->destroy(cursor);
271 }
272 
273 /**
274  * @tc.name: RDB_Native_predicates_test_005
275  * @tc.desc: Normal testCase of Predicates for LessThan
276  * @tc.type: FUNC
277  */
278 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_005, TestSize.Level1)
279 {
280     int errCode = 0;
281     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
282     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
283     const char *data5Value = "ABCDEFG";
284     valueObject->putText(valueObject, data5Value);
285     predicates->lessThan(predicates, "data5", valueObject);
286 
287     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
288     EXPECT_NE(cursor, NULL);
289     int rowCount = 0;
290     errCode = cursor->getRowCount(cursor, &rowCount);
291     EXPECT_EQ(rowCount, 0);
292 
293     valueObject->destroy(valueObject);
294     predicates->destroy(predicates);
295     cursor->destroy(cursor);
296 }
297 
298 /**
299  * @tc.name: RDB_Native_predicates_test_006
300  * @tc.desc: Normal testCase of Predicates for LessThanOrEqualTo
301  * @tc.type: FUNC
302  */
303 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_006, TestSize.Level1)
304 {
305     int errCode = 0;
306     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
307     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
308     const char *data5Value = "ABCDEFG";
309     valueObject->putText(valueObject, data5Value);
310     predicates->lessThanOrEqualTo(predicates, "data5", valueObject);
311 
312     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
313     EXPECT_NE(cursor, NULL);
314     int rowCount = 0;
315     errCode = cursor->getRowCount(cursor, &rowCount);
316     EXPECT_EQ(rowCount, 1);
317 
318     valueObject->destroy(valueObject);
319     predicates->destroy(predicates);
320     cursor->destroy(cursor);
321 }
322 
323 /**
324  * @tc.name: RDB_Native_predicates_test_007
325  * @tc.desc: Normal testCase of Predicates for IsNull.
326  * @tc.type: FUNC
327  */
328 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_007, TestSize.Level1)
329 {
330     int errCode = 0;
331     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
332     predicates->isNull(predicates, "data4");
333 
334     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
335     EXPECT_NE(cursor, NULL);
336     int rowCount = 0;
337     errCode = cursor->getRowCount(cursor, &rowCount);
338     EXPECT_EQ(rowCount, 2);
339 
340     predicates->destroy(predicates);
341     cursor->destroy(cursor);
342 }
343 
344 /**
345  * @tc.name: RDB_Native_predicates_test_008
346  * @tc.desc: Normal testCase of Predicates for IsNull.
347  * @tc.type: FUNC
348  */
349 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_008, TestSize.Level1)
350 {
351     int errCode = 0;
352     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
353     predicates->isNotNull(predicates, "data4");
354 
355     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
356     EXPECT_NE(cursor, NULL);
357     int rowCount = 0;
358     errCode = cursor->getRowCount(cursor, &rowCount);
359     EXPECT_EQ(rowCount, 1);
360 
361     predicates->destroy(predicates);
362     cursor->destroy(cursor);
363 }
364 
365 /**
366  * @tc.name: RDB_Native_predicates_test_009
367  * @tc.desc: Normal testCase of Predicates for Between
368  * @tc.type: FUNC
369  */
370 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_009, TestSize.Level1)
371 {
372     int errCode = 0;
373     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
374     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
375     int64_t data2Value[] = {12000, 13000};
376     uint32_t len = sizeof(data2Value) / sizeof(data2Value[0]);
377     valueObject->putInt64(valueObject, data2Value, len);
378     predicates->between(predicates, "data2", valueObject);
379     double data3Value[] = {0.1, 101.1};
380     len = sizeof(data3Value) / sizeof(data3Value[0]);
381     valueObject->putDouble(valueObject, data3Value, len);
382     predicates->between(predicates, "data3", valueObject);
383 
384     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
385     EXPECT_NE(cursor, NULL);
386     int rowCount = 0;
387     errCode = cursor->getRowCount(cursor, &rowCount);
388     EXPECT_EQ(rowCount, 1);
389 
390     valueObject->destroy(valueObject);
391     predicates->destroy(predicates);
392     cursor->destroy(cursor);
393 }
394 
395 /**
396  * @tc.name: RDB_Native_predicates_test_010
397  * @tc.desc: Normal testCase of Predicates for NotBetween
398  * @tc.type: FUNC
399  */
400 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_010, TestSize.Level1)
401 {
402     int errCode = 0;
403     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
404     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
405     int64_t data2Value[] = {12000, 13000};
406     int len = sizeof(data2Value) / sizeof(data2Value[0]);
407     valueObject->putInt64(valueObject, data2Value, len);
408     predicates->notBetween(predicates, "data2", valueObject);
409 
410     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
411     EXPECT_NE(cursor, NULL);
412     int rowCount = 0;
413     errCode = cursor->getRowCount(cursor, &rowCount);
414     EXPECT_EQ(rowCount, 2);
415 
416     valueObject->destroy(valueObject);
417     predicates->destroy(predicates);
418     cursor->destroy(cursor);
419 }
420 
421 /**
422  * @tc.name: RDB_Native_predicates_test_011
423  * @tc.desc: Normal testCase of Predicates for OrderBy、Limit、Offset.
424  * @tc.type: FUNC
425  */
426 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_011, TestSize.Level1)
427 {
428     int errCode = 0;
429     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
430     predicates->orderBy(predicates, "data2", OH_OrderType::ASC);
431     predicates->limit(predicates, 1);
432     predicates->offset(predicates, 1);
433     predicates->distinct(predicates);
434 
435     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
436     EXPECT_NE(cursor, NULL);
437     int rowCount = 0;
438     errCode = cursor->getRowCount(cursor, &rowCount);
439     EXPECT_EQ(rowCount, 1);
440 
441     errCode = cursor->goToNextRow(cursor);
442     int columnIndex;
443     cursor->getColumnIndex(cursor, "data2", &columnIndex);
444     EXPECT_EQ(columnIndex, 2);
445     int64_t longValue;
446     cursor->getInt64(cursor, columnIndex, &longValue);
447     EXPECT_EQ(longValue, 13800);
448 
449     predicates->destroy(predicates);
450     cursor->destroy(cursor);
451 }
452 
453 /**
454  * @tc.name: RDB_Native_predicates_test_012
455  * @tc.desc: Normal testCase of Predicates for In.
456  * @tc.type: FUNC
457  */
458 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_012, TestSize.Level1)
459 {
460     int errCode = 0;
461     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
462     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
463     const char *data1Value[] = {"zhangSan", "liSi"};
464     int len = sizeof(data1Value) / sizeof(data1Value[0]);
465     valueObject->putTexts(valueObject, data1Value, len);
466     predicates->in(predicates, "data1", valueObject);
467 
468     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
469     EXPECT_NE(cursor, NULL);
470     int rowCount = 0;
471     errCode = cursor->getRowCount(cursor, &rowCount);
472     EXPECT_EQ(rowCount, 2);
473 
474     valueObject->destroy(valueObject);
475     predicates->destroy(predicates);
476     cursor->destroy(cursor);
477 }
478 
479 /**
480  * @tc.name: RDB_Native_predicates_test_013
481  * @tc.desc: Normal testCase of Predicates for NotIn.
482  * @tc.type: FUNC
483  */
484 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_013, TestSize.Level1)
485 {
486     int errCode = 0;
487     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
488     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
489     const char *data1Value[] = {"zhangSan", "liSi"};
490     int len = sizeof(data1Value) / sizeof(data1Value[0]);
491     valueObject->putTexts(valueObject, data1Value, len);
492     predicates->notIn(predicates, "data1", valueObject);
493 
494     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
495     EXPECT_NE(cursor, NULL);
496     int rowCount = 0;
497     errCode = cursor->getRowCount(cursor, &rowCount);
498     EXPECT_EQ(rowCount, 1);
499 
500     valueObject->destroy(valueObject);
501     predicates->destroy(predicates);
502     cursor->destroy(cursor);
503 }
504 
505 /**
506  * @tc.name: RDB_Native_predicates_test_014
507  * @tc.desc: Normal testCase of Predicates for Like.
508  * @tc.type: FUNC
509  */
510 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_014, TestSize.Level1)
511 {
512     int errCode = 0;
513     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
514     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
515     const char *data5Value = "ABCD%";
516     valueObject->putText(valueObject, data5Value);
517     predicates->like(predicates, "data5", valueObject);
518     const char *data2Value = "%800";
519     valueObject->putText(valueObject, data2Value);
520     predicates->like(predicates, "data2", valueObject);
521 
522     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
523     EXPECT_NE(cursor, NULL);
524     int rowCount = 0;
525     errCode = cursor->getRowCount(cursor, &rowCount);
526     EXPECT_EQ(rowCount, 3);
527 
528     valueObject->destroy(valueObject);
529     predicates->destroy(predicates);
530     cursor->destroy(cursor);
531 }
532 
533 /**
534  * @tc.name: RDB_Native_predicates_test_015
535  * @tc.desc: Normal testCase of Predicates for GroupBy.
536  * @tc.type: FUNC
537  */
538 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_015, TestSize.Level1)
539 {
540     int errCode = 0;
541     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
542     const char *columnNames[] = {"data1", "data2"};
543     int len = sizeof(columnNames) / sizeof(columnNames[0]);
544     predicates->groupBy(predicates, columnNames, len);
545 
546     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
547     EXPECT_NE(cursor, NULL);
548     int rowCount = 0;
549     errCode = cursor->getRowCount(cursor, &rowCount);
550     EXPECT_EQ(rowCount, 3);
551 
552     predicates->destroy(predicates);
553     cursor->destroy(cursor);
554 }
555 
556 /**
557  * @tc.name: RDB_Native_predicates_test_016
558  * @tc.desc: Normal testCase of Predicates for And.
559  * @tc.type: FUNC
560  */
561 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_016, TestSize.Level1)
562 {
563     int errCode = 0;
564     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
565     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
566     const char *data1Value = "zhangSan";
567     valueObject->putText(valueObject, data1Value);
568     predicates->equalTo(predicates, "data1", valueObject);
569     predicates->andOperate(predicates);
570     double data3Value = 100.1;
571     valueObject->putDouble(valueObject, &data3Value, 1);
572     predicates->equalTo(predicates, "data3", valueObject);
573 
574     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
575     EXPECT_NE(cursor, NULL);
576     int rowCount = 0;
577     errCode = cursor->getRowCount(cursor, &rowCount);
578     EXPECT_EQ(rowCount, 1);
579 
580     valueObject->destroy(valueObject);
581     predicates->destroy(predicates);
582     errCode = cursor->destroy(cursor);
583 }
584 
585 /**
586  * @tc.name: RDB_Native_predicates_test_017
587  * @tc.desc: Normal testCase of Predicates for Clear.
588  * @tc.type: FUNC
589  */
590 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_017, TestSize.Level1)
591 {
592     int errCode = 0;
593     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
594     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
595     const char *data1Value = "zhangSan";
596     valueObject->putText(valueObject, data1Value);
597     predicates->equalTo(predicates, "data1", valueObject);
598 
599     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
600     EXPECT_NE(cursor, NULL);
601     int rowCount = 0;
602     errCode = cursor->getRowCount(cursor, &rowCount);
603     EXPECT_EQ(rowCount, 1);
604     errCode = cursor->destroy(cursor);
605 
606     predicates->clear(predicates);
607     predicates->notEqualTo(predicates, "data1", valueObject);
608     cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
609     EXPECT_NE(cursor, NULL);
610     errCode = cursor->getRowCount(cursor, &rowCount);
611     EXPECT_EQ(rowCount, 2);
612 
613     valueObject->destroy(valueObject);
614     predicates->destroy(predicates);
615     cursor->destroy(cursor);
616 }
617 /**
618  * @tc.name: RDB_Native_predicates_test_018
619  * @tc.desc: Normal testCase of Predicates for table name is NULL.
620  * @tc.type: FUNC
621  */
622 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_018, TestSize.Level1)
623 {
624     char *table = NULL;
625     OH_Predicates *predicates = OH_Rdb_CreatePredicates(table);
626     EXPECT_EQ(predicates, NULL);
627 
628     OH_Cursor *cursor = OH_Rdb_Query(predicatesTestRdbStore_, predicates, NULL, 0);
629     EXPECT_EQ(cursor, NULL);
630 }
631 
632 /**
633  * @tc.name: RDB_Native_predicates_test_019
634  * @tc.desc: Normal testCase of Predicates for anomalous branch.
635  * @tc.type: FUNC
636  */
637 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_019, TestSize.Level1)
638 {
639     OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
640     EXPECT_NE(predicates, NULL);
641 
642     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
643     const char *data1Value = "zhangSan";
644     valueObject->putText(valueObject, data1Value);
645     predicates->equalTo(nullptr, "data1", valueObject);
646     predicates->equalTo(predicates, nullptr, valueObject);
647     predicates->equalTo(predicates, "data1", nullptr);
648     predicates->notEqualTo(nullptr, "data1", valueObject);
649     predicates->notEqualTo(predicates, nullptr, valueObject);
650     predicates->notEqualTo(predicates, "data1", nullptr);
651 
652     predicates->beginWrap(nullptr);
653     predicates->endWrap(nullptr);
654 
655     predicates->orOperate(nullptr);
656     predicates->andOperate(nullptr);
657 
658     predicates->isNull(nullptr, "data4");
659     predicates->isNull(predicates, nullptr);
660     predicates->isNotNull(nullptr, "data4");
661     predicates->isNotNull(predicates, nullptr);
662 
663     const char *data5ValueLike = "ABCD%";
664     valueObject->putText(valueObject, data5ValueLike);
665     predicates->like(nullptr, "data5", valueObject);
666     predicates->like(predicates, nullptr, valueObject);
667     predicates->like(predicates, "data5", nullptr);
668 
669     int64_t data2Value[] = {12000, 13000};
670     uint32_t len = sizeof(data2Value) / sizeof(data2Value[0]);
671     valueObject->putInt64(valueObject, data2Value, len);
672     predicates->between(nullptr, "data2", valueObject);
673     predicates->between(predicates, nullptr, valueObject);
674     predicates->between(predicates, "data2", nullptr);
675     predicates->notBetween(nullptr, "data2", valueObject);
676     predicates->notBetween(predicates, nullptr, valueObject);
677     predicates->notBetween(predicates, "data2", nullptr);
678     int64_t data2Value_1[] = {12000};
679     len = sizeof(data2Value_1) / sizeof(data2Value_1[0]);
680     valueObject->putInt64(valueObject, data2Value_1, len);
681     predicates->between(predicates, "data2", valueObject);
682     predicates->notBetween(predicates, "data2", valueObject);
683 
684     const char *data5Value = "ABCDEFG";
685     valueObject->putText(valueObject, data5Value);
686     predicates->greaterThan(nullptr, "data5", valueObject);
687     predicates->greaterThan(predicates, nullptr, valueObject);
688     predicates->greaterThan(predicates, "data5", nullptr);
689     predicates->lessThan(nullptr, "data5", valueObject);
690     predicates->lessThan(predicates, nullptr, valueObject);
691     predicates->lessThan(predicates, "data5", nullptr);
692     predicates->greaterThanOrEqualTo(nullptr, "data5", valueObject);
693     predicates->greaterThanOrEqualTo(predicates, nullptr, valueObject);
694     predicates->greaterThanOrEqualTo(predicates, "data5", nullptr);
695     predicates->lessThanOrEqualTo(nullptr, "data5", valueObject);
696     predicates->lessThanOrEqualTo(predicates, nullptr, valueObject);
697     predicates->lessThanOrEqualTo(predicates, "data5", nullptr);
698 
699     predicates->orderBy(nullptr, "data2", OH_OrderType::ASC);
700     predicates->orderBy(predicates, nullptr, OH_OrderType::ASC);
701 
702     predicates->distinct(nullptr);
703     predicates->limit(nullptr, 1);
704     predicates->offset(nullptr, 1);
705 
706     const char *columnNames[] = {"data1", "data2"};
707     len = sizeof(columnNames) / sizeof(columnNames[0]);
708     predicates->groupBy(nullptr, columnNames, len);
709     predicates->groupBy(predicates, nullptr, len);
710     predicates->groupBy(predicates, columnNames, 0);
711 
712     const char *data1ValueIn[] = {"zhangSan", "liSi"};
713     len = sizeof(data1ValueIn) / sizeof(data1ValueIn[0]);
714     valueObject->putTexts(valueObject, data1ValueIn, len);
715     predicates->in(nullptr, "data1", valueObject);
716     predicates->in(predicates, nullptr, valueObject);
717     predicates->in(predicates, "data1", nullptr);
718     predicates->notIn(nullptr, "data1", valueObject);
719     predicates->notIn(predicates, nullptr, valueObject);
720     predicates->notIn(predicates, "data1", nullptr);
721 
722     predicates->clear(nullptr);
723     int errCode = predicates->destroy(nullptr);
724     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
725     valueObject->destroy(valueObject);
726     predicates->destroy(predicates);
727 }
728 
729 /**
730  * @tc.name: RDB_Native_predicates_test_020
731  * @tc.desc: Normal testCase of RelationalPredicatesObjects for anomalous branch.
732  * @tc.type: FUNC
733  */
734 HWTEST_F(RdbNativePredicatesTest, RDB_Native_predicates_test_020, TestSize.Level1)
735 {
736     OH_VObject *valueObject = OH_Rdb_CreateValueObject();
737     int64_t data2Value[] = {12000, 13000};
738     uint32_t len = sizeof(data2Value) / sizeof(data2Value[0]);
739     int errCode = valueObject->putInt64(nullptr, data2Value, len);
740     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
741     errCode = valueObject->putInt64(valueObject, nullptr, len);
742     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
743     errCode = valueObject->putInt64(valueObject, data2Value, 0);
744     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
745 
746     uint32_t count = 1;
747     double data3Value = 200.1;
748     errCode = valueObject->putDouble(nullptr, &data3Value, count);
749     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
750     errCode = valueObject->putDouble(valueObject, nullptr, count);
751     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
752     errCode = valueObject->putDouble(valueObject, &data3Value, 0);
753     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
754 
755     const char *data1Value = "zhangSan";
756     valueObject->putText(nullptr, data1Value);
757     valueObject->putText(valueObject, nullptr);
758 
759     const char *data1ValueTexts[] = {"zhangSan", "liSi"};
760     len = sizeof(data1ValueTexts) / sizeof(data1ValueTexts[0]);
761     errCode = valueObject->putTexts(nullptr, data1ValueTexts, len);
762     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
763     errCode = valueObject->putTexts(valueObject, nullptr, len);
764     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
765     errCode = valueObject->putTexts(valueObject, data1ValueTexts, 0);
766     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
767 
768     errCode = valueObject->destroy(nullptr);
769     EXPECT_EQ(errCode, OH_Rdb_ErrCode::RDB_E_INVALID_ARGS);
770     valueObject->destroy(valueObject);
771 }