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 #ifndef DISTRIBUTEDDB_DATA_GENERATE_UNIT_H 17 #define DISTRIBUTEDDB_DATA_GENERATE_UNIT_H 18 19 #include <string> 20 #include <vector> 21 #include "distributeddb_tools_unit_test.h" 22 #include "store_types.h" 23 24 namespace DistributedDBUnitTest { 25 // define some variables to init a KvStoreDelegateManager object. 26 const std::string APP_ID = "app0"; 27 const std::string SCHEMA_APP_ID = "app1"; 28 const std::string USER_ID = "user0"; 29 30 const std::string STORE_ID_LOCAL = "distributed_local_db_test"; 31 const std::string STORE_ID_SYNC = "distributed_sync_db_test"; 32 const std::string STORE_ID_1 = "distributed_db_test1"; 33 const std::string STORE_ID_2 = "distributed_db_test2"; 34 const std::string STORE_ID_3 = "distributed_db_test3"; 35 const std::string STORE_ID_4 = "distributed_db_test4"; 36 const std::string STORE_ID_5 = "distributed_db_test5"; 37 const std::string STORE_ID_6 = "distributed_db_test6"; 38 const std::string STORE_ID_7 = "distributed_db_test7"; 39 const std::string STORE_ID_8 = "distributed_db_test8"; 40 41 constexpr int32_t INSTANCE_ID_1 = 1; 42 constexpr int32_t INSTANCE_ID_2 = 2; 43 44 const int NUM_LENGTH = 10; 45 const int LETTER_LENGTH = 52; 46 const uint8_t KEY_NUM[NUM_LENGTH] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 47 const uint8_t VALUE_LETTER[LETTER_LENGTH] = { 48 'A', 'B', 'C', 'D', 'E', 'F', 'G', 49 'H', 'I', 'J', 'L', 'M', 'L', 'N', 50 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 51 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 52 'c', 'd', 'e', 'f', 'g', 'h', 'i', 53 'j', 'l', 'm', 'l', 'n', 'o', 'p', 54 'q', 'r', 's', 't', 'u', 'v', 'w', 55 'x', 'y', 'z' 56 }; 57 58 const DistributedDB::Key KEY_1 = {'1'}; 59 const DistributedDB::Value VALUE_1 = {'a'}; 60 const DistributedDB::Key KEY_2 = {'2'}; 61 const DistributedDB::Value VALUE_2 = {'b'}; 62 const DistributedDB::Key KEY_3 = {'3'}; 63 const DistributedDB::Value VALUE_3 = {'c'}; 64 const DistributedDB::Key KEY_4 = {'4'}; 65 const DistributedDB::Value VALUE_4 = {'d'}; 66 const DistributedDB::Key KEY_5 = {'5'}; 67 const DistributedDB::Value VALUE_5 = {'e'}; 68 const DistributedDB::Key KEY_6 = {'6'}; 69 const DistributedDB::Value VALUE_6 = {'f'}; 70 const DistributedDB::Key KEY_7 = {'7'}; 71 const DistributedDB::Value VALUE_7 = {'g'}; 72 73 const DistributedDB::Key NULL_KEY_1; 74 const DistributedDB::Value NULL_VALUE_1; 75 76 const DistributedDB::Entry ENTRY_1 = {KEY_1, VALUE_1}; 77 const DistributedDB::Entry ENTRY_2 = {KEY_2, VALUE_2}; 78 const DistributedDB::Entry NULL_ENTRY_1 = {NULL_KEY_1, VALUE_1}; 79 const DistributedDB::Entry NULL_ENTRY_2 = {KEY_1, NULL_VALUE_1}; 80 81 const DistributedDB::Entry ENTRY_3 = {KEY_3, VALUE_3}; 82 const DistributedDB::Entry ENTRY_4 = {KEY_4, VALUE_4}; 83 84 const DistributedDB::Entry KV_ENTRY_1 = {KEY_1, VALUE_1}; 85 const DistributedDB::Entry KV_ENTRY_2 = {KEY_2, VALUE_2}; 86 const DistributedDB::Entry KV_ENTRY_3 = {KEY_3, VALUE_3}; 87 const DistributedDB::Entry KV_ENTRY_4 = {KEY_4, VALUE_4}; 88 89 const std::vector<DistributedDB::Entry> ENTRY_VECTOR = {ENTRY_1, ENTRY_2}; 90 91 const int DEFAULT_NB_KEY_VALUE_SIZE = 10; 92 93 // generate a key, has keyCount chars, from KEY_NUM[startPosition], return keyTest 94 void GenerateKey(int keyCount, int startPosition, DistributedDB::Key &keyTest); 95 96 // generate a value, has valueCount chars, from VALUE_LETTER[startPosition], return valueTest 97 void GenerateValue(int valueCount, int startPosition, DistributedDB::Value &valueTest); 98 99 /* 100 * generate an entry, entry.key and entry.value have valueCount chars, 101 * from KEY_NUM[startPosition] and VALUE_LETTER[startPosition], return entryTest 102 */ 103 void GenerateEntry(int entryCount, int startPosition, DistributedDB::Entry &entryTest); 104 105 /* 106 * generate a vector<entry>, vector.size() is entryVectorCount, entry.key and entry.value have valueCount chars, 107 * from KEY_NUM[startPosition] and VALUE_LETTER[startPosition], return entrysTest 108 */ 109 void GenerateEntryVector(int entryVectorCount, int entryCount, std::vector<DistributedDB::Entry> &entrysTest); 110 111 void GenerateRecords(int recordNum, std::vector<DistributedDB::Entry> &entries, std::vector<DistributedDB::Key> &keys, 112 int keySize = DEFAULT_NB_KEY_VALUE_SIZE, int valSize = DEFAULT_NB_KEY_VALUE_SIZE); 113 } // namespace DistributedDBUnitTest 114 115 #endif // DISTRIBUTEDDB_DATA_GENERATE_UNIT_H 116