1 /*
2 * Copyright (c) 2021 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 "db_constant.h"
19 #include "distributeddb_storage_single_ver_natural_store_testcase.h"
20
21 using namespace testing::ext;
22 using namespace DistributedDB;
23 using namespace DistributedDBUnitTest;
24 using namespace std;
25
26 namespace {
27 DistributedDB::KvStoreConfig g_config;
28 std::string g_testDir;
29 const std::string MEM_URL = "file:31?mode=memory&cache=shared";
30 DistributedDB::SQLiteSingleVerNaturalStore *g_store = nullptr;
31 DistributedDB::SQLiteSingleVerNaturalStoreConnection *g_connection = nullptr;
32 }
33
34 class DistributedDBStorageMemorySingleVerNaturalStoreTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void DistributedDBStorageMemorySingleVerNaturalStoreTest::SetUpTestCase(void)
43 {
44 DistributedDBToolsUnitTest::TestDirInit(g_testDir);
45 LOGD("Test dir is %s", g_testDir.c_str());
46 DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir + "/TestGeneralNB/" + DBConstant::SINGLE_SUB_DIR);
47 }
48
TearDownTestCase(void)49 void DistributedDBStorageMemorySingleVerNaturalStoreTest::TearDownTestCase(void) {}
50
SetUp(void)51 void DistributedDBStorageMemorySingleVerNaturalStoreTest::SetUp(void)
52 {
53 DistributedDBToolsUnitTest::PrintTestCaseInfo();
54 KvDBProperties property;
55 property.SetStringProp(KvDBProperties::DATA_DIR, g_testDir);
56 property.SetStringProp(KvDBProperties::STORE_ID, "TestGeneralNB");
57 property.SetStringProp(KvDBProperties::IDENTIFIER_DIR, "31");
58 property.SetBoolProp(KvDBProperties::MEMORY_MODE, true);
59 property.SetIntProp(KvDBProperties::DATABASE_TYPE, KvDBProperties::SINGLE_VER_TYPE_SQLITE);
60 g_store = new (std::nothrow) SQLiteSingleVerNaturalStore;
61 ASSERT_NE(g_store, nullptr);
62 ASSERT_EQ(g_store->Open(property), E_OK);
63
64 int erroCode = E_OK;
65 g_connection = static_cast<SQLiteSingleVerNaturalStoreConnection *>(g_store->GetDBConnection(erroCode));
66 ASSERT_NE(g_connection, nullptr);
67 g_store->DecObjRef(g_store);
68 EXPECT_EQ(erroCode, E_OK);
69 }
70
TearDown(void)71 void DistributedDBStorageMemorySingleVerNaturalStoreTest::TearDown(void)
72 {
73 if (g_connection != nullptr) {
74 g_connection->Close();
75 }
76
77 g_store = nullptr;
78 DistributedDBToolsUnitTest::RemoveTestDbFiles(g_testDir + "/TestGeneralNB/" + DBConstant::SINGLE_SUB_DIR);
79 }
80
81 /**
82 * @tc.name: GetSyncData001
83 * @tc.desc: To test the function of querying the data in the time stamp range in the database.
84 * @tc.type: FUNC
85 * @tc.require: AR000CRAKO
86 * @tc.author: wangbingquan
87 */
88 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData001, TestSize.Level1)
89 {
90 /**
91 * @tc.steps:step1. Obtain the data within the time stamp range
92 * through the GetSyncData(A, C) interface of the NaturalStore, where A<B<C.
93 * @tc.expected: step1. GetSyncData The number of output parameter
94 * in the output parameter OK, dataItems is 1.
95 */
96 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData001(g_store, g_connection);
97 }
98
99 /**
100 * @tc.name: GetSyncData002
101 * @tc.desc: Test the function that the database does not query the data in the time stamp range.
102 * @tc.type: FUNC
103 * @tc.require: AR000CCPOM
104 * @tc.author: wangbingquan
105 */
106 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData002, TestSize.Level1)
107 {
108 /**
109 * @tc.steps:step1. Obtain the data within the time stamp range
110 * through the GetSyncData(A, B) interface of the NaturalStore,
111 * where A<B<C and interference data processing are added.
112 * @tc.expected: step1. GetSyncData The number of output parameters
113 * in the output parameter E_NOT_FOUND,dataItems is 0.
114 */
115 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData002(g_store, g_connection);
116 }
117
118 /**
119 * @tc.name: GetSyncData003
120 * @tc.desc: To test the function of querying data when the timestamp range
121 * in the data obtaining interface is invalid.
122 * @tc.type: FUNC
123 * @tc.require: AR000CCPOM
124 * @tc.author: wangbingquan
125 */
126 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData003, TestSize.Level1)
127 {
128 /**
129 * @tc.steps:step1. Obtain the data within the time stamp range
130 * through the GetSyncData(A, B) interface of the NaturalStore, where A>B
131 * @tc.expected: step1. The value of GetSyncData is E_INVALID_ARG.
132 */
133 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData003(g_store, g_connection);
134 }
135
136 /**
137 * @tc.name: GetSyncData004
138 * @tc.desc: To the test database Subcon reading, a large number of data records exist in the time stamp range.
139 * @tc.type: FUNC
140 * @tc.require: AR000CCPOM
141 * @tc.author: wangbingquan
142 */
143 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData004, TestSize.Level1)
144 {
145 /**
146 * @tc.steps:step1. Obtain the data within the time stamp range
147 * through the GetSyncData(A, B) interface of the NaturalStore.
148 * @tc.expected: step1. Return E_GET_UNFINISHED.
149 */
150 /**
151 * @tc.steps:step2. Continue to obtain data through the GetSyncDataNext() interface
152 * of the NaturalStore until the E_GET_FINISHED message is returned.
153 * @tc.expected: step2. When the GetSyncDataNext returns E_GET_FINISHED,
154 * the total number of obtained data is the number of inserted data and the data is consistent.
155 */
156 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData004(g_store, g_connection);
157 }
158
159 /**
160 * @tc.name: GetSyncData005
161 * @tc.desc: In the test database, if a large number of data records exist
162 * in the time stamp range, a packet is read successfully.
163 * @tc.type: FUNC
164 * @tc.require: AR000CCPOM
165 * @tc.author: wangbingquan
166 */
167 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData005, TestSize.Level1)
168 {
169 /**
170 * @tc.steps:step1. Obtain the data within the time stamp range
171 * through the GetSyncData(A, B) interface of the NaturalStore.
172 * @tc.expected: step1. The total size of all data in OK, dataItems is 99K.
173 */
174 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData005(g_store, g_connection);
175 }
176
177 /**
178 * @tc.name: GetSyncData006
179 * @tc.desc: To test the function of reading data when the time stamp range in the database
180 * is greater than the value of blockSize.
181 * @tc.type: FUNC
182 * @tc.require: AR000CCPOM
183 * @tc.author: wangbingquan
184 */
185 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetSyncData006, TestSize.Level1)
186 {
187 /**
188 * @tc.steps:step1. Use the GetSyncData(A, B) interface of the NaturalStore
189 * and set blockSize to 50 kb to obtain the data within the time stamp range.
190 * @tc.expected: step1. The system returns E_GET_FINISHED. The size of the obtained data is 1 kb.
191 */
192 DistributedDBStorageSingleVerNaturalStoreTestCase::GetSyncData006(g_store, g_connection);
193 }
194
195 /**
196 * @tc.name: PutSyncData001
197 * @tc.desc: To test the function of synchronizing the new data of the remote device that synchronizes the database.
198 * @tc.type: FUNC
199 * @tc.require: AR000CCPOM
200 * @tc.author: wangbingquan
201 */
202 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, PutSyncData001, TestSize.Level1)
203 {
204 /**
205 * @tc.steps:step1/2. Set Ioption to synchronous data and insert a (key1, value1) data record by put interface.
206 */
207 /**
208 * @tc.steps:step3. Insert a (key1, value2!=value1, timestamp, false) data record
209 * through the PutSyncData interface. The value of timestamp is less than or equal
210 * to the value of timestamp. For Compare the timestamp to determine whether to synchronization data.
211 * @tc.expected: step3. Return OK.
212 */
213 /**
214 * @tc.steps:step4. The Ioption is set to synchronize data
215 * through the Get interface to obtain the value data of the key1.
216 * @tc.expected: step4. Return OK.The obtained value is value1.
217 */
218 /**
219 * @tc.steps:step5. Insert a (key1, value3!=value1, timestamp, false) data record
220 * through the PutSyncData interface of the NaturalStore. The value of timestamp
221 * is greater than that of timestamp inserted in 2.
222 * @tc.expected: step5. Return OK.
223 */
224 /**
225 * @tc.steps:step6. The Ioption is set to synchronize data through the Get interface
226 * to obtain the value data of the key1.
227 * @tc.expected: step6. Return OK.
228 */
229 /**
230 * @tc.steps:step7. Insert a (key2, value4) data record through the PutSyncData interface.
231 * @tc.expected: step7. Return OK.
232 */
233 /**
234 * @tc.steps:step8. The Ioption is set to synchronize data
235 * through the Get interface to obtain the value data of the key2.
236 * @tc.expected: step8. Returns OK, and the obtained data is value4.
237 */
238 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData001(g_store, g_connection);
239 }
240
241 /**
242 * @tc.name: PutSyncData002
243 * @tc.desc: To test the function of synchronizing data from the remote device
244 * to the local device after the data is deleted from the remote device.
245 * @tc.type: FUNC
246 * @tc.require: AR000CCPOM
247 * @tc.author: wangbingquan
248 */
249 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, PutSyncData002, TestSize.Level1)
250 {
251 /**
252 * @tc.steps:step1/2. Set Ioption to synchronous data and insert a (key1, value1) data record by put interface.
253 */
254 /**
255 * @tc.steps:step3. Insert a (key1, value2!=value1, timestamp, false) data record
256 * through the PutSyncData interface. The value of timestamp is less than or equal
257 * to the value of timestamp. For Compare the timestamp to determine whether delete data.
258 * @tc.expected: step3. Return OK.
259 */
260 /**
261 * @tc.steps:step4. The Ioption is set to synchronize data
262 * through the Get interface to obtain the value data of the key1.
263 * @tc.expected: step4. Return OK.The obtained value is value1.
264 */
265 /**
266 * @tc.steps:step5. Insert a (key1, value3!=value1, timestamp, false) data record
267 * through the PutSyncData interfac. The value of timestamp
268 * is greater than that of timestamp inserted in step2.
269 * @tc.expected: step5. Return OK.
270 */
271 /**
272 * @tc.steps:step6. The Ioption is set to synchronize data through the Get interface
273 * to obtain the value data of the key1.
274 * @tc.expected: step6. Return E_NOT_FOUND.
275 */
276 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData002(g_store, g_connection);
277 }
278
279 /**
280 * @tc.name: PutSyncData003
281 * @tc.desc: To test the function of synchronizing the mixed data of the added
282 * and deleted data from the remote device to the local device.
283 * @tc.type: FUNC
284 * @tc.require: AR000CCPOM
285 * @tc.author: wangbingquan
286 */
287 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, PutSyncData003, TestSize.Level1)
288 {
289 /**
290 * @tc.steps:step1. Insert a data record (key1,value1 is not null) and (key2, value2 is not null)
291 * through the PutSyncData interface.
292 * @tc.expected: step1. Return OK.
293 */
294 /**
295 * @tc.steps:step2. Set Ioption as the synchronization data to obtain the data of key1 and key2.
296 * @tc.expected: step2. The Get interface returns OK. The value of key1 is value1,
297 * and the value of key2 is value2.
298 */
299 /**
300 * @tc.steps:step3. Insert a (key3, value3) and delete the data of the (key1, value1).
301 * @tc.expected: step3. The PutSyncData returns OK.
302 */
303 /**
304 * @tc.steps:step4. Set Ioption to the synchronization data and obtain the data of key1, key2, and key3.
305 * @tc.expected: step4. Get key1 returns E_NOT_FOUND,Get key2.
306 * The value of OK,value is value2, the value of Get key3 is OK,
307 * and the value of value is value3.
308 */
309 DistributedDBStorageSingleVerNaturalStoreTestCase::PutSyncData003(g_store, g_connection);
310 }
311
312 /**
313 * @tc.name: PutMetaData001
314 * @tc.desc: Test metadata insertion and modification.
315 * @tc.type: FUNC
316 * @tc.require: AR000CCPOM
317 * @tc.author: wangbingquan
318 */
319 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, PutMetaData001, TestSize.Level1)
320 {
321 /**
322 * @tc.steps:step1. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
323 * @tc.expected: step1. Return OK.
324 */
325 /**
326 * @tc.steps:step2. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
327 * @tc.expected: step2. The obtained value is the same as the value of value1.
328 */
329 /**
330 * @tc.steps:step3. The key value is key1, the value is not empty,
331 * and the value of value2 is different from the value of value1 through the PutMetaData interface.
332 * @tc.expected: step3. Return OK.
333 */
334 /**
335 * @tc.steps:step4. Run the GetMetaData command to obtain the value of key1
336 * and check whether the value is the same as the value of value2.
337 * @tc.expected: step4. The obtained value is the same as the value of value2.
338 */
339 /**
340 * @tc.steps:step5. Use PutMetaData to insert a record whose key is empty and value is not empty.
341 * @tc.expected: step5. Return E_INVALID_ARGS.
342 */
343 /**
344 * @tc.steps:step6. Use PutMetaData in NaturalStore to insert data whose key2(!=key1)
345 * is not empty and value is empty.
346 * @tc.expected: step6. Return OK.
347 */
348 /**
349 * @tc.steps:step7. Obtain the value of key2 and check whether the value is empty.
350 * @tc.expected: step7. The obtained value is empty.
351 */
352 /**
353 * @tc.steps:step8. Insert the data whose key size is 1024 and value size is 4Mb
354 * through PutMetaData of NaturalStore.
355 * @tc.expected: step8. Return OK.
356 */
357 /**
358 * @tc.steps:step9/10. Insert data items whose key size is greater than 1 kb
359 * or value size greater than 4Mb through PutMetaData of NaturalStore.
360 * @tc.expected: step9/10. Return E_INVALID_ARGS.
361 */
362 DistributedDBStorageSingleVerNaturalStoreTestCase::PutMetaData001(g_store, g_connection);
363 }
364
365 /**
366 * @tc.name: GetMetaData001
367 * @tc.desc: To test the function of reading the metadata of a key in the database.
368 * @tc.type: FUNC
369 * @tc.require: AR000CCPOM
370 * @tc.author: wangbingquan
371 */
372 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetMetaData001, TestSize.Level1)
373 {
374 /**
375 * @tc.steps:step1. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
376 * @tc.expected: step1. Return OK.
377 */
378 /**
379 * @tc.steps:step2. Run the PutMetaData command to insert a non-empty key1 non-empty value1 data record.
380 * @tc.expected: step2. The obtained value is the same as the value of value1.
381 */
382 /**
383 * @tc.steps:step3. The key value is key1, the value is not empty,
384 * and the value of value2 is different from the value of value1 through the PutMetaData interface.
385 * @tc.expected: step3. Return OK.
386 */
387 /**
388 * @tc.steps:step4. Run the GetMetaData command to obtain the value of key1
389 * and check whether the value is the same as the value of value2.
390 * @tc.expected: step4. The obtained value is the same as the value of value2.
391 */
392 /**
393 * @tc.steps:step5. Use PutMetaData to insert a record whose key is empty and value is not empty.
394 * @tc.expected: step5. Return E_INVALID_ARGS.
395 */
396 /**
397 * @tc.steps:step6. Use PutMetaData in NaturalStore to insert data whose key2(!=key1)
398 * is not empty and value is empty.
399 * @tc.expected: step6. Return OK.
400 */
401 /**
402 * @tc.steps:step7. Obtain the value of key2 and check whether the value is empty.
403 * @tc.expected: step7. The obtained value is empty.
404 */
405 /**
406 * @tc.steps:step8. Insert the data whose key size is 1024 and value size is 4Mb
407 * through PutMetaData of NaturalStore.
408 * @tc.expected: step8. Return OK.
409 */
410 /**
411 * @tc.steps:step9/10. Insert data items whose key size is greater than 1 kb
412 * or value size greater than 4Mb through PutMetaData of NaturalStore.
413 * @tc.expected: step9/10. Return E_INVALID_ARGS.
414 */
415 DistributedDBStorageSingleVerNaturalStoreTestCase::GetMetaData001(g_store, g_connection);
416 }
417
418 /**
419 * @tc.name: GetCurrentMaxTimestamp001
420 * @tc.desc: To test the function of obtaining the maximum timestamp when a record exists in the database.
421 * @tc.type: FUNC
422 * @tc.require: AR000CCPOM
423 * @tc.author: wangbingquan
424 */
425 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetCurrentMaxTimestamp001, TestSize.Level1)
426 {
427 /**
428 * @tc.steps:step1/2. Insert a data record into the synchronization database.
429 */
430 /**
431 * @tc.steps:step3. The current maximum timestamp is A.
432 */
433 /**
434 * @tc.steps:step4. Insert a data record into the synchronization database.
435 */
436 /**
437 * @tc.steps:step5. Obtain the maximum timestamp B and check whether B>=A exists.
438 * @tc.expected: step5. The obtained timestamp is B>=A.
439 */
440 DistributedDBStorageSingleVerNaturalStoreTestCase::GetCurrentMaxTimestamp001(g_store, g_connection);
441 }
442
443 /**
444 * @tc.name: GetCurrentMaxTimestamp002
445 * @tc.desc: Obtain the maximum timestamp when no record exists in the test record library.
446 * @tc.type: FUNC
447 * @tc.require: AR000CCPOM
448 * @tc.author: wangbingquan
449 */
450 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, GetCurrentMaxTimestamp002, TestSize.Level1)
451 {
452 /**
453 * @tc.steps:step1. Obtains the maximum timestamp in the current database record.
454 * @tc.expected: step1. Return timestamp is 0.
455 */
456 DistributedDBStorageSingleVerNaturalStoreTestCase::GetCurrentMaxTimestamp002(g_store);
457 }
458
459 /**
460 * @tc.name: LocalDatabaseOperate001
461 * @tc.desc: Test the function of inserting data in the local database of the NaturalStore.
462 * @tc.type: FUNC
463 * @tc.require: AR000CCPOM
464 * @tc.author: wangbingquan
465 */
466 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, LocalDatabaseOperate001, TestSize.Level1)
467 {
468 /**
469 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
470 * @tc.expected: step1/2. Return OK.
471 */
472 /**
473 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
474 * Check whether the value is the same as the value of value1.
475 * @tc.expected: step3. The obtained value and value2 are the same.
476 */
477 /**
478 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
479 * The value cannot be empty. value2(!=value1)
480 * @tc.expected: step4. Return OK.
481 */
482 /**
483 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
484 * and check whether the value is the same as the value of value2.
485 * @tc.expected: step5. The obtained value and value2 are the same.
486 */
487 /**
488 * @tc.steps: step6. The Ioption parameter is set to the local data.
489 * The data record whose key is empty and value is not empty is inserted.
490 * @tc.expected: step6. Return E_INVALID_DATA.
491 */
492 /**
493 * @tc.steps: step7. Set Ioption to the local data, insert data
494 * whose key2(!=key1) is not empty, and value is empty.
495 * @tc.expected: step7. Return OK.
496 */
497 /**
498 * @tc.steps: step8. Set option to local data, obtain the value of key2,
499 * and check whether the value is empty.
500 * @tc.expected: step8. Return OK, value is empty.
501 */
502 /**
503 * @tc.steps: step9. Ioption Set the local data.
504 * Insert the data whose key size is 1024 and value size is 4Mb.
505 * @tc.expected: step9. Return OK.
506 */
507 /**
508 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
509 * whose value is greater than 4Mb or key is bigger than 1Kb
510 * @tc.expected: step10/11. Return E_INVALID_ARGS.
511 */
512 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate001(g_store, g_connection);
513 }
514
515 /**
516 * @tc.name: LocalDatabaseOperate002
517 * @tc.desc: Test the function of deleting data from the local database of the NaturalStore.
518 * @tc.type: FUNC
519 * @tc.require: AR000CCPOM
520 * @tc.author: wangbingquan
521 */
522 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, LocalDatabaseOperate002, TestSize.Level1)
523 {
524 /**
525 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
526 * @tc.expected: step1/2. Return OK.
527 */
528 /**
529 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
530 * Check whether the value is the same as the value of value1.
531 * @tc.expected: step3. The obtained value and value2 are the same.
532 */
533 /**
534 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
535 * The value cannot be empty. value2(!=value1)
536 * @tc.expected: step4. Return OK.
537 */
538 /**
539 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
540 * and check whether the value is the same as the value of value2.
541 * @tc.expected: step5. The obtained value and value2 are the same.
542 */
543 /**
544 * @tc.steps: step6. The Ioption parameter is set to the local data.
545 * The data record whose key is empty and value is not empty is inserted.
546 * @tc.expected: step6. Return E_INVALID_DATA.
547 */
548 /**
549 * @tc.steps: step7. Set Ioption to the local data, insert data
550 * whose key2(!=key1) is not empty, and value is empty.
551 * @tc.expected: step7. Return OK.
552 */
553 /**
554 * @tc.steps: step8. Set option to local data, obtain the value of key2,
555 * and check whether the value is empty.
556 * @tc.expected: step8. Return OK, value is empty.
557 */
558 /**
559 * @tc.steps: step9. Ioption Set the local data.
560 * Insert the data whose key size is 1024 and value size is 4Mb.
561 * @tc.expected: step9. Return OK.
562 */
563 /**
564 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
565 * whose value is greater than 4Mb or key is bigger than 1Kb
566 * @tc.expected: step10/11. Return E_INVALID_ARGS.
567 */
568 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate002(g_store, g_connection);
569 }
570
571 /**
572 * @tc.name: LocalDatabaseOperate003
573 * @tc.desc: To test the function of reading data from the local database of the NaturalStore.
574 * @tc.type: FUNC
575 * @tc.require: AR000CCPOM
576 * @tc.author: wangbingquan
577 */
578 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, LocalDatabaseOperate003, TestSize.Level1)
579 {
580 /**
581 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
582 * @tc.expected: step1/2. Return OK.
583 */
584 /**
585 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
586 * Check whether the value is the same as the value of value1.
587 * @tc.expected: step3. The obtained value and value2 are the same.
588 */
589 /**
590 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
591 * The value cannot be empty. value2(!=value1)
592 * @tc.expected: step4. Return OK.
593 */
594 /**
595 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
596 * and check whether the value is the same as the value of value2.
597 * @tc.expected: step5. The obtained value and value2 are the same.
598 */
599 /**
600 * @tc.steps: step6. The Ioption parameter is set to the local data.
601 * The data record whose key is empty and value is not empty is inserted.
602 * @tc.expected: step6. Return E_INVALID_DATA.
603 */
604 /**
605 * @tc.steps: step7. Set Ioption to the local data, insert data
606 * whose key2(!=key1) is not empty, and value is empty.
607 * @tc.expected: step7. Return OK.
608 */
609 /**
610 * @tc.steps: step8. Set option to local data, obtain the value of key2,
611 * and check whether the value is empty.
612 * @tc.expected: step8. Return OK, value is empty.
613 */
614 /**
615 * @tc.steps: step9. Ioption Set the local data.
616 * Insert the data whose key size is 1024 and value size is 4Mb.
617 * @tc.expected: step9. Return OK.
618 */
619 /**
620 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
621 * whose value is greater than 4Mb or key is bigger than 1Kb
622 * @tc.expected: step10/11. Return E_INVALID_ARGS.
623 */
624 DistributedDBStorageSingleVerNaturalStoreTestCase::LocalDatabaseOperate003(g_store, g_connection);
625 }
626
627 /**
628 * @tc.name: SyncDatabaseOperate001
629 * @tc.desc: To test the function of inserting data of the local device in the synchronization database.
630 * @tc.type: FUNC
631 * @tc.require: AR000CCPOM
632 * @tc.author: wangbingquan
633 */
634 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate001, TestSize.Level1)
635 {
636 /**
637 * @tc.steps: step1/2. Set Ioption to the local data and insert a record of key1 and value1.
638 * @tc.expected: step1/2. Return OK.
639 */
640 /**
641 * @tc.steps: step3. Set Ioption to the local data and obtain the value of key1.
642 * Check whether the value is the same as the value of value1.
643 * @tc.expected: step3. The obtained value and value2 are the same.
644 */
645 /**
646 * @tc.steps: step4. Ioption Set this parameter to the local data. Insert key1.
647 * The value cannot be empty. value2(!=value1)
648 * @tc.expected: step4. Return OK.
649 */
650 /**
651 * @tc.steps: step5. Set Ioption to the local data, GetMetaData to obtain the value of key1,
652 * and check whether the value is the same as the value of value2.
653 * @tc.expected: step5. The obtained value and value2 are the same.
654 */
655 /**
656 * @tc.steps: step6. The Ioption parameter is set to the local data.
657 * The data record whose key is empty and value is not empty is inserted.
658 * @tc.expected: step6. Return E_INVALID_DATA.
659 */
660 /**
661 * @tc.steps: step7. Set Ioption to the local data, insert data
662 * whose key2(!=key1) is not empty, and value is empty.
663 * @tc.expected: step7. Return OK.
664 */
665 /**
666 * @tc.steps: step8. Set option to local data, obtain the value of key2,
667 * and check whether the value is empty.
668 * @tc.expected: step8. Return OK, value is empty.
669 */
670 /**
671 * @tc.steps: step9. Ioption Set the local data.
672 * Insert the data whose key size is 1024 and value size is 4Mb.
673 * @tc.expected: step9. Return OK.
674 */
675 /**
676 * @tc.steps: step10/11. Set Ioption to the local data and insert data items
677 * whose value is greater than 4Mb or key is bigger than 1Kb
678 * @tc.expected: step10/11. Return E_INVALID_ARGS.
679 */
680 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate001(g_store, g_connection);
681 }
682
683 /**
684 * @tc.name: SyncDatabaseOperate002
685 * @tc.desc: test the put operation after data synced from other devices.
686 * @tc.type: FUNC
687 * @tc.require: AR000CCPOM
688 * @tc.author: wangbingquan
689 */
690 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate002, TestSize.Level1)
691 {
692 /**
693 * @tc.steps: step1/2. Add a remote synchronization data record. (key1, value1).
694 */
695 /**
696 * @tc.steps: step3. Ioption is set to synchronous data. Obtains the value data of the key1.
697 * @tc.expected: step3. Return OK. The value is the same as the value of value1.
698 */
699 /**
700 * @tc.steps: step4. Ioption Set the data to be synchronized and insert the data of key1,value2.
701 * @tc.expected: step4. Return OK.
702 */
703 /**
704 * @tc.steps: step3. Ioption is set to synchronous data. Obtains the value data of the key1.
705 * @tc.expected: step3. Return OK. The value is the same as the value of value2.
706 */
707 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate002(g_store, g_connection);
708 }
709
710 /**
711 * @tc.name: SyncDatabaseOperate003
712 * @tc.desc: test the delete operation in sync database.
713 * @tc.type: FUNC
714 * @tc.require: AR000CCPOM
715 * @tc.author: wangbingquan
716 */
717 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate003, TestSize.Level1)
718 {
719 /**
720 * @tc.steps: step2. Set Ioption to the local data and delete the data whose key is key1 (empty).
721 * @tc.expected: step2. Return E_INVALID_ARGS.
722 */
723 /**
724 * @tc.steps: step3. Set Ioption to the local data, insert non-null key1, and non-null value1 data.
725 * @tc.expected: step3. Return E_OK.
726 */
727 /**
728 * @tc.steps: step4. Set Ioption to the local data, obtain the value of key1,
729 * and check whether the value is the same as that of value1.
730 * @tc.expected: step4. Return E_OK. The obtained value is the same as the value of value1.
731 */
732 /**
733 * @tc.steps: step5. Set Ioption to the local data and delete the data whose key is key1.
734 * @tc.expected: step5. Return E_OK.
735 */
736 /**
737 * @tc.steps: step5. Set Ioption to the local data and obtain the value of Key1.
738 * @tc.expected: step5. Return E_NOT_FOUND.
739 */
740 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate003(g_store, g_connection);
741 }
742
743 /**
744 * @tc.name: SyncDatabaseOperate004
745 * @tc.desc: test the delete for the data from other devices in sync database.
746 * @tc.type: FUNC
747 * @tc.require: AR000CCPOM
748 * @tc.author: wangbingquan
749 */
750 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate004, TestSize.Level1)
751 {
752 /**
753 * @tc.steps: step2. The Ioption parameter is set to synchronize data to obtain the value data of the key1.
754 * @tc.expected: step2. Return OK. The value is the same as the value of value1.
755 */
756 /**
757 * @tc.steps: step3. The Ioption parameter is set to synchronize data, and the key1 data is deleted.
758 * @tc.expected: step3. Return OK.
759 */
760 /**
761 * @tc.steps: step4. The Ioption parameter is set to synchronize data to obtain the value data of the key1.
762 * @tc.expected: step4. Return E_NOT_FOUND.
763 */
764 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate004(g_store, g_connection);
765 }
766
767 /**
768 * @tc.name: SyncDatabaseOperate005
769 * @tc.desc: test the reading for sync database.
770 * @tc.type: FUNC
771 * @tc.require: AR000CCPOM
772 * @tc.author: wangbingquan
773 */
774 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate005, TestSize.Level1)
775 {
776 /**
777 * @tc.steps: step2. Set Ioption to the local data and delete the data whose key is key1 (empty).
778 * @tc.expected: step2. Return E_INVALID_ARGS.
779 */
780 /**
781 * @tc.steps: step3. Set Ioption to the local data, insert non-null key1, and non-null value1 data.
782 * @tc.expected: step3. Return E_OK.
783 */
784 /**
785 * @tc.steps: step4. Set Ioption to the local data, obtain the value of key1,
786 * and check whether the value is the same as that of value1.
787 * @tc.expected: step4. Return E_OK. The obtained value is the same as the value of value1.
788 */
789 /**
790 * @tc.steps: step5. Set Ioption to the local data and obtain the value data of Key1.
791 * Check whether the value is the same as the value of value2.
792 * @tc.expected: step4. Return E_OK, and the value is the same as the value of value2.
793 */
794 /**
795 * @tc.steps: step5. The Ioption is set to the local.
796 * The data of the key1 and value2(!=value1) is inserted.
797 * @tc.expected: step4. Return E_OK.
798 */
799 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate005(g_store, g_connection);
800 }
801
802 /**
803 * @tc.name: SyncDatabaseOperate006
804 * @tc.desc: test the get entries for sync database
805 * @tc.type: FUNC
806 * @tc.require: AR000CCPOM
807 * @tc.author: wangbingquan
808 */
809 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, SyncDatabaseOperate006, TestSize.Level1)
810 {
811 /**
812 * @tc.steps: step2/3/4. Set Ioption to synchronous data.
813 * Insert the data of key=keyPrefix + 'a', value1.
814 * Insert the data of key=keyPrefix + 'c', value2.
815 * Insert the data of key length=keyPrefix length - 1, value3.
816 * @tc.expected: step2/3/4. Return E_NOT_FOUND.
817 */
818 /**
819 * @tc.steps: step5. Obtain all data whose prefixKey is keyPrefix.
820 * @tc.expected: step5. Return OK. The number of obtained data records is 2.
821 */
822 /**
823 * @tc.steps: step6. Obtain all data whose prefixKey is empty.
824 * @tc.expected: step6. Return OK. The number of obtained data records is 3.
825 */
826 /**
827 * @tc.steps: step7. Obtain all data whose prefixKey is keyPrefix.
828 * @tc.expected: step7. Return E_NOT_SUPPORT.
829 */
830 DistributedDBStorageSingleVerNaturalStoreTestCase::SyncDatabaseOperate006(g_store, g_connection);
831 }
832
833 /**
834 * @tc.name: ClearRemoteData001
835 * @tc.desc: test the clear data synced from the remote by device.
836 * @tc.type: FUNC
837 * @tc.require: AR000CIFDA AR000CQS3T
838 * @tc.author: wangbingquan
839 */
840 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, ClearRemoteData001, TestSize.Level1)
841 {
842 /**
843 * @tc.steps: step1. New data is inserted to the B end of the device. [keyB, valueB].
844 */
845 /**
846 * @tc.steps: step2. The device pulls the data of the device B, and the device inserts the [keyA, valueA].
847 */
848 /**
849 * @tc.steps: step3. The device obtains the data of keyA and valueB.
850 * @tc.expected: step3. Obtain [keyA, valueA] and [keyB, valueB].
851 */
852 /**
853 * @tc.steps: step4.Invoke the interface for clearing the synchronization data of the B device.
854 */
855 /**
856 * @tc.steps: step5. The device obtains the data of keyA and valueB.
857 * @tc.expected: step5. The value of [keyA, valueA] is obtained,
858 * and the value of NOT_FOUND is obtained by querying keyB.
859 */
860 DistributedDBStorageSingleVerNaturalStoreTestCase::ClearRemoteData001(g_store, g_connection);
861 }
862
863 /**
864 * @tc.name: DeleteUserKeyValue001
865 * @tc.desc: When a user deletes a data record, the system clears the user record.
866 * @tc.type: FUNC
867 * @tc.require: AR000CKRTC AR000CQE0D
868 * @tc.author: sunpeng
869 */
870 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue001, TestSize.Level1)
871 {
872 /**
873 * @tc.steps: step1. delete K1.
874 * @tc.expected: step1. delete K1 successfully.
875 */
876 /**
877 * @tc.steps: step2. Real query by sqlite3.
878 * @tc.expected: step2. Find KEY_1, not find K2.
879 */
880 DistributedDBStorageSingleVerNaturalStoreTestCase::MemoryDbDeleteUserKeyValue001(g_store, g_connection, MEM_URL);
881 }
882
883 /**
884 * @tc.name: DeleteUserKeyValue002
885 * @tc.desc: After the synchronization library data is deleted locally, add the same key data locally.
886 * @tc.type: FUNC
887 * @tc.require: AR000CKRTC AR000CQE0D
888 * @tc.author: sunpeng
889 */
890 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue002, TestSize.Level1)
891 {
892 /**
893 * @tc.steps: step1. Delete key1 data via Delete interface.
894 * @tc.expected: step1. Delete successfully.
895 */
896 /**
897 * @tc.steps: step2. New data from key1, value3 via Put interface.
898 * @tc.expected: step2. New data from key1, value3 via Put interface successfully.
899 */
900 /**
901 * @tc.steps: step3. Query key1 data via Get interface.
902 * @tc.expected: step3. Query key1 data via Get interface successfully, get value3 by key1.
903 */
904 /**
905 * @tc.steps: step4. Query key1 real data by sqlite3.
906 * @tc.expected: step4. Two records were found.
907 */
908 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue002(g_store, g_connection, MEM_URL);
909 }
910
911 /**
912 * @tc.name: DeleteUserKeyValue003
913 * @tc.desc: After the synchronization database data is deleted locally, the same key data is added from the remote end.
914 * @tc.type: FUNC
915 * @tc.require: AR000CKRTC AR000CQE0D
916 * @tc.author: sunpeng
917 */
918 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue003, TestSize.Level1)
919 {
920 /**
921 * @tc.steps: step1. Delete data by key1.
922 * @tc.expected: step1. Delete successfully.
923 */
924 /**
925 * @tc.steps: step2. Get data by key1.
926 * @tc.expected: step1. Key1 not exist in database.
927 */
928 /**
929 * @tc.steps: step3. Get a new data from remote device B , key1, value3,
930 * with a smaller timestamp than the current timestamp.
931 */
932 /**
933 * @tc.steps: step4. Get data by key1.
934 * @tc.expected: step4. Key1 not exist in database.
935 */
936 /**
937 * @tc.steps: step5. Get a new data from remote device C , key1, value4,
938 * and the timestamp is larger than the current timestamp.
939 */
940 /**
941 * @tc.steps: step6. Get data by key1.
942 * @tc.expected: step6. Key1 not exist in database.
943 */
944 /**
945 * @tc.steps: step7. Get real data by key1.
946 * @tc.expected: step7. Get 1 record.
947 */
948 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue003(g_store, g_connection, MEM_URL);
949 }
950
951 /**
952 * @tc.name: DeleteUserKeyValue004
953 * @tc.desc: Changes in key after remote delete data syncs to local
954 * @tc.type: FUNC
955 * @tc.require: AR000CKRTC AR000CQE0D
956 * @tc.author: sunpeng
957 */
958 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue004, TestSize.Level1)
959 {
960 /**
961 * @tc.steps: step1 2 3. Synchronize data to another device B; delete key1 data from device B;
962 * pull the action of key1 to local.
963 */
964 /**
965 * @tc.steps: step4. Close database.
966 */
967 /**
968 * @tc.steps: step5 6. Get real data by key1;and get the number of records.
969 * @tc.expected: step5 6. Not exist key1 real data in database;Get 1 record.
970 */
971 DistributedDBStorageSingleVerNaturalStoreTestCase::MemoryDbDeleteUserKeyValue004(g_store, g_connection, MEM_URL);
972 }
973
974 /**
975 * @tc.name: DeleteUserKeyValue005
976 * @tc.desc: New unified key data locally after remote delete data syncs to local
977 * @tc.type: FUNC
978 * @tc.require: AR000CKRTC AR000CQE0D
979 * @tc.author: sunpeng
980 */
981 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue005, TestSize.Level1)
982 {
983 /**
984 * @tc.steps: step1 2 3. Synchronize data to another device B; delete key1 data from device B;
985 * pull the action of key1 to local.
986 */
987 /**
988 * @tc.steps: step4. Put K1 V1 to database.
989 * @tc.expected: step4. Put successfully.
990 */
991 /**
992 * @tc.steps: step5. Close database.
993 */
994 /**
995 * @tc.steps: step6 7. Get real data by key1;and get the number of records.
996 * @tc.expected: step6 7. Not exist key1 real data in database;Get 2 record.
997 */
998 DistributedDBStorageSingleVerNaturalStoreTestCase::MemoryDbDeleteUserKeyValue005(g_store, g_connection, MEM_URL);
999 }
1000
1001 /**
1002 * @tc.name: DeleteUserKeyValue006
1003 * @tc.desc: After the remote delete data is synced to the local,
1004 * the same key data is added from the remote other devices
1005 * @tc.type: FUNC
1006 * @tc.require: AR000CKRTC AR000CQE0D
1007 * @tc.author: sunpeng
1008 */
1009 HWTEST_F(DistributedDBStorageMemorySingleVerNaturalStoreTest, DeleteUserKeyValue006, TestSize.Level1)
1010 {
1011 /**
1012 * @tc.steps: step1. Remote device B sync deletes data key1 and pushes to local.
1013 */
1014 /**
1015 * @tc.steps: step2. Get key1 from database.
1016 * @tc.expected: step2. Not exist key1.
1017 */
1018 /**
1019 * @tc.steps: step3. Remote device C syncs new data (key1, value2),
1020 * timestamp is less than delete timestamp, to local.
1021 */
1022 /**
1023 * @tc.steps: step4. Get key1 from database.
1024 * @tc.expected: step4. Not exist key1.
1025 */
1026 /**
1027 * @tc.steps: step5. Remote device C syncs new data (key1, value2),
1028 * timestamp is bigger than delete timestamp, to local.
1029 */
1030 /**
1031 * @tc.steps: step6. Get key1 from database.
1032 * @tc.expected: step6. Exist key1.
1033 */
1034 /**
1035 * @tc.steps: step7. Get real data from database.
1036 * @tc.expected: step7. Get 1 record.
1037 */
1038 DistributedDBStorageSingleVerNaturalStoreTestCase::DeleteUserKeyValue006(g_store, g_connection, MEM_URL);
1039 }
1040
1041