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 std::string SUB_USER_1 = "subUser1"; 45 const std::string SUB_USER_2 = "subUser2"; 46 47 const int NUM_LENGTH = 10; 48 const int LETTER_LENGTH = 52; 49 const uint8_t KEY_NUM[NUM_LENGTH] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 50 const uint8_t VALUE_LETTER[LETTER_LENGTH] = { 51 'A', 'B', 'C', 'D', 'E', 'F', 'G', 52 'H', 'I', 'J', 'L', 'M', 'L', 'N', 53 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 54 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 55 'c', 'd', 'e', 'f', 'g', 'h', 'i', 56 'j', 'l', 'm', 'l', 'n', 'o', 'p', 57 'q', 'r', 's', 't', 'u', 'v', 'w', 58 'x', 'y', 'z' 59 }; 60 61 const DistributedDB::Key KEY_1 = {'1'}; 62 const DistributedDB::Value VALUE_1 = {'a'}; 63 const DistributedDB::Key KEY_2 = {'2'}; 64 const DistributedDB::Value VALUE_2 = {'b'}; 65 const DistributedDB::Key KEY_3 = {'3'}; 66 const DistributedDB::Value VALUE_3 = {'c'}; 67 const DistributedDB::Key KEY_4 = {'4'}; 68 const DistributedDB::Value VALUE_4 = {'d'}; 69 const DistributedDB::Key KEY_5 = {'5'}; 70 const DistributedDB::Value VALUE_5 = {'e'}; 71 const DistributedDB::Key KEY_6 = {'6'}; 72 const DistributedDB::Value VALUE_6 = {'f'}; 73 const DistributedDB::Key KEY_7 = {'7'}; 74 const DistributedDB::Value VALUE_7 = {'g'}; 75 76 const DistributedDB::Key NULL_KEY_1; 77 const DistributedDB::Value NULL_VALUE_1; 78 79 const DistributedDB::Entry ENTRY_1 = {KEY_1, VALUE_1}; 80 const DistributedDB::Entry ENTRY_2 = {KEY_2, VALUE_2}; 81 const DistributedDB::Entry NULL_ENTRY_1 = {NULL_KEY_1, VALUE_1}; 82 const DistributedDB::Entry NULL_ENTRY_2 = {KEY_1, NULL_VALUE_1}; 83 84 const DistributedDB::Entry ENTRY_3 = {KEY_3, VALUE_3}; 85 const DistributedDB::Entry ENTRY_4 = {KEY_4, VALUE_4}; 86 87 const DistributedDB::Entry KV_ENTRY_1 = {KEY_1, VALUE_1}; 88 const DistributedDB::Entry KV_ENTRY_2 = {KEY_2, VALUE_2}; 89 const DistributedDB::Entry KV_ENTRY_3 = {KEY_3, VALUE_3}; 90 const DistributedDB::Entry KV_ENTRY_4 = {KEY_4, VALUE_4}; 91 92 const std::vector<DistributedDB::Entry> ENTRY_VECTOR = {ENTRY_1, ENTRY_2}; 93 94 const int DEFAULT_NB_KEY_VALUE_SIZE = 10; 95 96 // generate a key, has keyCount chars, from KEY_NUM[startPosition], return keyTest 97 void GenerateKey(int keyCount, int startPosition, DistributedDB::Key &keyTest); 98 99 // generate a value, has valueCount chars, from VALUE_LETTER[startPosition], return valueTest 100 void GenerateValue(int valueCount, int startPosition, DistributedDB::Value &valueTest); 101 102 /* 103 * generate an entry, entry.key and entry.value have valueCount chars, 104 * from KEY_NUM[startPosition] and VALUE_LETTER[startPosition], return entryTest 105 */ 106 void GenerateEntry(int entryCount, int startPosition, DistributedDB::Entry &entryTest); 107 108 /* 109 * generate a vector<entry>, vector.size() is entryVectorCount, entry.key and entry.value have valueCount chars, 110 * from KEY_NUM[startPosition] and VALUE_LETTER[startPosition], return entrysTest 111 */ 112 void GenerateEntryVector(int entryVectorCount, int entryCount, std::vector<DistributedDB::Entry> &entrysTest); 113 114 void GenerateRecords(int recordNum, std::vector<DistributedDB::Entry> &entries, std::vector<DistributedDB::Key> &keys, 115 int keySize = DEFAULT_NB_KEY_VALUE_SIZE, int valSize = DEFAULT_NB_KEY_VALUE_SIZE); 116 } // namespace DistributedDBUnitTest 117 118 #endif // DISTRIBUTEDDB_DATA_GENERATE_UNIT_H 119