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