diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h index 201000ec174fd7e152e778fb2a0ce8080f4bd372..1a8cf9148604026b804cb6ba1aebb832257f5e72 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_base/grd_type_export.h @@ -21,7 +21,7 @@ extern "C" { #endif // __cplusplus #ifndef _WIN32 - #define DOC_API __attribute__ ((visibility ("default"))) +#define DOC_API __attribute__((visibility("default"))) #endif typedef struct GRD_DB GRD_DB; @@ -29,17 +29,19 @@ typedef struct GRD_DB GRD_DB; /** * @brief Open database config */ -#define GRD_DB_OPEN_ONLY 0x00 -#define GRD_DB_OPEN_CREATE 0x01 -#define GRD_DB_OPEN_CHECK_FOR_ABNORMAL 0x02 // check data in database if close abnormally last time, - // if data is corrupted, rebuild the database -#define GRD_DB_OPEN_CHECK 0x04// check data in database when open database, if data is corrupted, rebuild the database. +#define GRD_DB_OPEN_ONLY 0x00 +#define GRD_DB_OPEN_CREATE 0x01 +#define GRD_DB_OPEN_CHECK_FOR_ABNORMAL \ + 0x02 // check data in database if close abnormally last time, \ + // if data is corrupted, rebuild the database +#define GRD_DB_OPEN_CHECK \ + 0x04 // check data in database when open database, if data is corrupted, rebuild the database. /** * @brief Close database config */ -#define GRD_DB_CLOSE 0x00 -#define GRD_DB_CLOSE_IGNORE_ERROR 0x01 +#define GRD_DB_CLOSE 0x00 +#define GRD_DB_CLOSE_IGNORE_ERROR 0x01 /** * @brief flush database config @@ -47,7 +49,7 @@ typedef struct GRD_DB GRD_DB; #define GRD_DB_FLUSH_ASYNC 0x00 #define GRD_DB_FLUSH_SYNC 0x01 -#define GRD_DOC_ID_DISPLAY 0x01 +#define GRD_DOC_ID_DISPLAY 0x01 typedef struct Query { const char *filter; const char *projection; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h index b4df9c6bc12093464b005beb1f3e3009a195c6b7..9d217a1e48c1356ab8ce1b605dd6a4d125c799d6 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/include/grd_document/grd_document_api.h @@ -16,8 +16,8 @@ #ifndef GRD_DOCUMENT_API_H #define GRD_DOCUMENT_API_H -#include "grd_base/grd_type_export.h" #include "grd_base/grd_resultset_api.h" +#include "grd_base/grd_type_export.h" #ifdef __cplusplus extern "C" { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/collection_option.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/collection_option.h index 727592400325ca7e56f8980a1befde71dbad0b04..42bd55db5ed8e7081c15b9af994fcb05f30d2904 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/collection_option.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/collection_option.h @@ -29,6 +29,7 @@ public: bool operator==(const CollectionOption &targetOption) const; bool operator!=(const CollectionOption &targetOption) const; + private: std::string option_ = "{}"; uint32_t maxDoc_ = UINT32_MAX; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/db_config.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/db_config.h index c04116f2a8931a7b6ee4aa2722d5c042f500503d..ec7d8f448fce6e558bd6069d4cc0db12abe444d2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/db_config.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/db_config.h @@ -38,7 +38,7 @@ private: int32_t pageSize_ = 4; // 4: default page size k uint32_t redoFlushByTrx_ = 0; uint32_t redoPubBufSize_ = 1024; // 1024: default 1024k buff size - int32_t maxConnNum_ = 100; // 100: default max conn + int32_t maxConnNum_ = 100; // 100: default max conn uint32_t bufferPoolSize_ = 1024; // 100: default 1024k pool size uint32_t crcCheckEnable_ = 1; }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h index 02197027a27783bec712d17597567ac8feb9c743..6f88630c7eeee11a5353afdc15ddbe583a02d13c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h @@ -17,9 +17,10 @@ #define JSON_COMMON_H #include -#include -#include #include +#include +#include + #include "json_object.h" namespace DocumentDB { @@ -28,25 +29,25 @@ public: JsonCommon() = default; ~JsonCommon(); - static ValueObject GetValueByFiled(JsonObject &node, const std::string& filed); - static ValueObject GetValueByFiled(JsonObject &node, const std::string& filed, bool &isFiledExist); + static ValueObject GetValueByFiled(JsonObject &node, const std::string &filed); + static ValueObject GetValueByFiled(JsonObject &node, const std::string &filed, bool &isFiledExist); static bool CheckJsonField(JsonObject &node); static bool CheckProjectionField(JsonObject &node); static int ParseNode(JsonObject &Node, std::vector singlePath, - std::vector> &resultPath, bool isFirstFloor); + std::vector> &resultPath, bool isFirstFloor); static std::vector> ParsePath(const JsonObject &node, int &errCode); - static std::vector GetLeafValue(const JsonObject &node); + static std::vector GetLeafValue(const JsonObject &node); static bool isValueEqual(const ValueObject &srcValue, const ValueObject &targetValue); static int Append(const JsonObject &src, const JsonObject &add, bool isReplace); static bool IsJsonNodeMatch(const JsonObject &src, const JsonObject &target, int &errCode); + private: static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); + int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); static bool CheckNode(JsonObject &Node, std::set filedSet, bool &errFlag); - static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, - bool &errFlag, bool isFirstFloor); + static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, bool &errFlag, bool isFirstFloor); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); }; -} // DocumentDB +} // namespace DocumentDB #endif // JSON_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp index 82f32c29b99ba27d98422737bc50c3cead4038c9..c15c3895805cba030760984dad5477b7c88ccedd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp @@ -15,8 +15,8 @@ #include "collection_option.h" -#include #include +#include #include "doc_errno.h" #include "json_object.h" @@ -43,7 +43,7 @@ bool CheckConfigSupport(const JsonObject &config, int &errCode) } return true; } -} +} // namespace CollectionOption CollectionOption::ReadOption(const std::string &optStr, int &errCode) { if (optStr.empty()) { @@ -66,7 +66,7 @@ CollectionOption CollectionOption::ReadOption(const std::string &optStr, int &er return {}; } - static const JsonFieldPath maxDocField = {OPT_MAX_DOC}; + static const JsonFieldPath maxDocField = { OPT_MAX_DOC }; if (!collOpt.IsFieldExists(maxDocField)) { return {}; } @@ -114,4 +114,4 @@ bool CollectionOption::operator!=(const CollectionOption &targetOption) const { return !(*this == targetOption); } -} \ No newline at end of file +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp index b60de5b19c912b46c8e0e1c58ef4737f8345cb8a..9af67794d15bf84cdb255b186d47021152bebf86 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp @@ -20,8 +20,8 @@ #include "doc_errno.h" #include "doc_limit.h" -#include "log_print.h" #include "json_object.h" +#include "log_print.h" namespace DocumentDB { namespace { @@ -39,18 +39,12 @@ const std::string DB_CONFIG_MAX_CONN_NUM = "maxconnnum"; const std::string DB_CONFIG_BUFFER_POOL_SIZE = "bufferpoolsize"; const std::string DB_CONFIG_CRC_CHECK_ENABLE = "crccheckenable"; -const std::vector DB_CONFIG = { - DB_CONFIG_PAGESIZE, - DB_CONFIG_REDO_FLUSH_BY_TRX, - DB_CONFIG_REDO_PUB_BUFF_SIZE, - DB_CONFIG_MAX_CONN_NUM, - DB_CONFIG_BUFFER_POOL_SIZE, - DB_CONFIG_CRC_CHECK_ENABLE -}; +const std::vector DB_CONFIG = { DB_CONFIG_PAGESIZE, DB_CONFIG_REDO_FLUSH_BY_TRX, + DB_CONFIG_REDO_PUB_BUFF_SIZE, DB_CONFIG_MAX_CONN_NUM, DB_CONFIG_BUFFER_POOL_SIZE, DB_CONFIG_CRC_CHECK_ENABLE }; bool CheckPageSizeConfig(const JsonObject &config, int32_t &pageSize, int &errCode) { - static const JsonFieldPath pageSizeField = {DB_CONFIG_PAGESIZE}; + static const JsonFieldPath pageSizeField = { DB_CONFIG_PAGESIZE }; if (!config.IsFieldExists(pageSizeField)) { return true; } @@ -62,7 +56,7 @@ bool CheckPageSizeConfig(const JsonObject &config, int32_t &pageSize, int &errCo return false; } - static const std::vector pageSizeValid = {4, 8, 16, 32, 64}; + static const std::vector pageSizeValid = { 4, 8, 16, 32, 64 }; if (std::find(pageSizeValid.begin(), pageSizeValid.end(), configValue.GetIntValue()) == pageSizeValid.end()) { GLOGE("Check DB config failed, invalid pageSize value."); errCode = -E_INVALID_CONFIG_VALUE; @@ -75,7 +69,7 @@ bool CheckPageSizeConfig(const JsonObject &config, int32_t &pageSize, int &errCo bool CheckRedoFlushConfig(const JsonObject &config, uint32_t &redoFlush, int &errCode) { - static const JsonFieldPath redoFlushField = {DB_CONFIG_REDO_FLUSH_BY_TRX}; + static const JsonFieldPath redoFlushField = { DB_CONFIG_REDO_FLUSH_BY_TRX }; if (!config.IsFieldExists(redoFlushField)) { return true; } @@ -99,7 +93,7 @@ bool CheckRedoFlushConfig(const JsonObject &config, uint32_t &redoFlush, int &er bool CheckRedoBufSizeConfig(const JsonObject &config, uint32_t &redoBufSize, int &errCode) { - static const JsonFieldPath redoBufSizeField = {DB_CONFIG_REDO_PUB_BUFF_SIZE}; + static const JsonFieldPath redoBufSizeField = { DB_CONFIG_REDO_PUB_BUFF_SIZE }; if (!config.IsFieldExists(redoBufSizeField)) { return true; } @@ -123,7 +117,7 @@ bool CheckRedoBufSizeConfig(const JsonObject &config, uint32_t &redoBufSize, int bool CheckMaxConnNumConfig(const JsonObject &config, int32_t &maxConnNum, int &errCode) { - static const JsonFieldPath maxConnNumField = {DB_CONFIG_MAX_CONN_NUM}; + static const JsonFieldPath maxConnNumField = { DB_CONFIG_MAX_CONN_NUM }; if (!config.IsFieldExists(maxConnNumField)) { return true; } @@ -145,10 +139,9 @@ bool CheckMaxConnNumConfig(const JsonObject &config, int32_t &maxConnNum, int &e return true; } -bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint32_t &redoBufSize, - int &errCode) +bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint32_t &redoBufSize, int &errCode) { - static const JsonFieldPath bufferPoolSizeField = {DB_CONFIG_BUFFER_POOL_SIZE}; + static const JsonFieldPath bufferPoolSizeField = { DB_CONFIG_BUFFER_POOL_SIZE }; if (!config.IsFieldExists(bufferPoolSizeField)) { return true; } @@ -173,7 +166,7 @@ bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint3 bool CheckCrcCheckEnableConfig(const JsonObject &config, uint32_t &crcCheckEnable, int &errCode) { - static const JsonFieldPath crcCheckEnableField = {DB_CONFIG_CRC_CHECK_ENABLE}; + static const JsonFieldPath crcCheckEnableField = { DB_CONFIG_CRC_CHECK_ENABLE }; if (!config.IsFieldExists(crcCheckEnableField)) { return true; } @@ -209,7 +202,7 @@ bool CheckConfigSupport(const JsonObject &config, int &errCode) } return true; } -} +} // namespace DBConfig DBConfig::ReadConfig(const std::string &confStr, int &errCode) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 96834acd397a304e94e2e4eb1aabe7ec309ba08d..0d0a438ca2a3055ce6933859c54a6fe3da9406d2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -12,15 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "json_common.h" + #include #include + #include "doc_errno.h" #include "log_print.h" #include "securec.h" -#include "json_common.h" namespace DocumentDB { -ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string& filed) +ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string &filed) { while (!node.IsNull()) { if (node.GetItemFiled() == filed) { @@ -36,7 +38,7 @@ ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string& fil return ValueObject(); } -ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string& filed, bool &isFiledExist) +ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string &filed, bool &isFiledExist) { while (!node.IsNull()) { if (node.GetItemFiled() == filed) { @@ -71,7 +73,7 @@ void JsonCommon::CheckLeafNode(const JsonObject &node, std::vector } } -std::vector JsonCommon::GetLeafValue(const JsonObject &node) +std::vector JsonCommon::GetLeafValue(const JsonObject &node) { std::vector leafValue; if (node.IsNull()) { @@ -133,8 +135,7 @@ bool JsonCommon::CheckJsonField(JsonObject &jsonObj) return CheckNode(jsonObj, filedSet, errFlag); } -bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set filedSet, - bool &errFlag, bool isFirstFloor) +bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set filedSet, bool &errFlag, bool isFirstFloor) { if (!errFlag) { return false; @@ -155,7 +156,7 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fil } for (size_t i = 0; i < fieldName.size(); i++) { if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || - (isFirstFloor && '.' == fieldName[i]))) { + (isFirstFloor && '.' == fieldName[i]))) { errFlag = false; return false; } @@ -280,7 +281,7 @@ JsonFieldPath ExpendPathForField(const JsonFieldPath &path, bool &isCollapse) } void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, - std::function AppendFoo) + std::function AppendFoo) { JsonObject child = obj.GetChild(); while (!child.IsNull()) { @@ -295,7 +296,7 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, } void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, - std::function MatchFoo) + std::function MatchFoo) { JsonObject child = obj.GetChild(); while (!child.IsNull()) { @@ -349,8 +350,8 @@ bool AddSpliteFiled(const JsonObject &src, const JsonObject &item, const JsonFie externErrCode = -E_DATA_CONFLICT; return false; } - (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) : - errCode = hitItem.AddItemToObject(abandonPath[i]); + (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) + : errCode = hitItem.AddItemToObject(abandonPath[i]); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); newHitPath.emplace_back(abandonPath[i]); hitItem = hitItem.FindItem(newHitPath, errCode); @@ -371,8 +372,8 @@ bool AddSpliteFiled(const JsonObject &src, const JsonObject &item, const JsonFie externErrCode = -E_DATA_CONFLICT; return false; } - (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) : - errCode = hitItem.AddItemToObject(abandonPath[i]); + (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) + : errCode = hitItem.AddItemToObject(abandonPath[i]); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); newHitPath.emplace_back(abandonPath[i]); hitItem = hitItem.FindItem(newHitPath, errCode); @@ -382,7 +383,7 @@ bool AddSpliteFiled(const JsonObject &src, const JsonObject &item, const JsonFie } bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, const JsonObject &father, - const JsonObject &item, int &externErrCode) + const JsonObject &item, int &externErrCode) { int errCode = 0; JsonFieldPath granPaPath = fatherPath; @@ -423,7 +424,7 @@ bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, co } bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const JsonObject &father, - const JsonObject &item, int &externErrCode) + const JsonObject &item, int &externErrCode) { int errCode = 0; JsonFieldPath fatherPath = itemPath; @@ -470,74 +471,75 @@ bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const } return true; } -} +} // namespace int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isReplace) { int externErrCode = E_OK; bool isAddedFlag = false; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace, &isAddedFlag](const JsonFieldPath &path, - const JsonObject &father, const JsonObject &item) { - bool isCollapse = false; - JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); - JsonFieldPath fatherPath = itemPath; - fatherPath.pop_back(); - int errCode = E_OK; - if (src.IsFieldExists(itemPath)) { - JsonObject srcItem = src.FindItem(itemPath, errCode); - if (errCode != E_OK) { - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - GLOGE("Find item in source json object failed. %d", errCode); - return false; - } - bool ret = JsonNodeReplace (src, itemPath, father, item, externErrCode); - if (!ret) { - return false; - } - isAddedFlag = true; - return false; - } else { - if (isReplace) { - GLOGE("path not exist, replace failed"); - externErrCode = -E_NO_DATA; - return false; - } - JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); - std::string lastFieldName = itemPath.back(); - if (srcFatherItem.IsNull()) { + [&src, &externErrCode, &isReplace, &isAddedFlag](const JsonFieldPath &path, const JsonObject &father, + const JsonObject &item) { + bool isCollapse = false; + JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); + JsonFieldPath fatherPath = itemPath; + fatherPath.pop_back(); + int errCode = E_OK; + if (src.IsFieldExists(itemPath)) { + JsonObject srcItem = src.FindItem(itemPath, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find item in source json object failed. %d", errCode); + return false; + } + bool ret = JsonNodeReplace(src, itemPath, father, item, externErrCode); + if (!ret) { + return false; + } isAddedFlag = true; - AddSpliteFiled(src, item, itemPath, externErrCode); return false; - } - if (errCode == E_OK) { - if (isCollapse && (!IsNumber(itemPath.back()) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { - errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); - if (errCode != E_OK) { - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - GLOGE("Add item to object failed. %d", errCode); - return false; - } + } else { + if (isReplace) { + GLOGE("path not exist, replace failed"); + externErrCode = -E_NO_DATA; + return false; + } + JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); + std::string lastFieldName = itemPath.back(); + if (srcFatherItem.IsNull()) { isAddedFlag = true; + AddSpliteFiled(src, item, itemPath, externErrCode); return false; } - if (!isCollapse) { - bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); - if (!ret) { - GLOGE("replace faild"); + if (errCode == E_OK) { + if (isCollapse && + (!IsNumber(itemPath.back()) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { + errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Add item to object failed. %d", errCode); + return false; + } + isAddedFlag = true; return false; } - isAddedFlag = true; - return false; // Different node types, overwrite directly, skip child node + if (!isCollapse) { + bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); + if (!ret) { + GLOGE("replace faild"); + return false; + } + isAddedFlag = true; + return false; // Different node types, overwrite directly, skip child node + } } + if (!isAddedFlag) { + GLOGE("Add nothing because data conflict"); + externErrCode = -E_DATA_CONFLICT; + } + return false; // Source path not exist, overwrite directly, skip child node } - if (!isAddedFlag) { - GLOGE("Add nothing because data conflict"); - externErrCode = -E_DATA_CONFLICT; - } - return false; // Source path not exist, overwrite directly, skip child node - } - }); + }); return externErrCode; } @@ -565,8 +567,8 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i bool isMatch = false; int errCode = 0; while (!srcChild.IsNull()) { - if (srcChild.GetType() == JsonObject::Type::JSON_OBJECT && target.GetType() == - JsonObject::Type::JSON_OBJECT && (IsJsonNodeMatch(srcChild, target, errCode))) { + if (srcChild.GetType() == JsonObject::Type::JSON_OBJECT && target.GetType() == JsonObject::Type::JSON_OBJECT && + (IsJsonNodeMatch(srcChild, target, errCode))) { isMatch = true; isAlreadyMatched = 1; break; @@ -577,7 +579,7 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i } bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) + int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) { int errCode; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); @@ -640,8 +642,7 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target { errCode = E_OK; int isMatchFlag = true; - JsonObjectIterator(target, {}, - [&src, &isMatchFlag, &errCode](JsonFieldPath &path, const JsonObject &item) { + JsonObjectIterator(target, {}, [&src, &isMatchFlag, &errCode](JsonFieldPath &path, const JsonObject &item) { int isAlreadyMatched = 0; bool isCollapse = false; if (isMatchFlag == false) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp index 10fd0fffb8ed44bd2d8ca63ee51291932e5107a4..e6df873ce61cda1ede9ce0a8eeaa805b22af6d1b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/log_print.cpp @@ -14,8 +14,9 @@ */ #include -#include "securec.h" + #include "hilog/log.h" +#include "securec.h" namespace DocumentDB { namespace { @@ -57,7 +58,7 @@ void PreparePrivateLog(const char *format, std::string &outStrFormat) outStrFormat.replace(pos, PRIVATE_TAG.size(), ".3s"); } } -} +} // namespace void Logger::Log(Level level, const std::string &tag, const char *func, int line, const char *format, ...) { @@ -79,4 +80,4 @@ void Logger::Log(Level level, const std::string &tag, const char *func, int line PrintLog(level, tag, msg); } -} +} // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp index 31786a74dc86d85b77434dd791b98619996af373..1af7c1fff99233f48205a3e6f0433fd85bd8a67a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/os_api.cpp @@ -13,9 +13,10 @@ * limitations under the License. */ #include "os_api.h" + +#include #include #include -#include #include "doc_errno.h" #include "log_print.h" @@ -23,7 +24,7 @@ namespace DocumentDB { namespace { - const int ACCESS_MODE_EXISTENCE = 0; +const int ACCESS_MODE_EXISTENCE = 0; } namespace OSAPI { bool CheckPermission(const std::string &filePath) @@ -49,17 +50,17 @@ int GetRealPath(const std::string &inOriPath, std::string &outRealPath) return -E_OUT_OF_MEMORY; } if (memset_s(realPath, MAX_PATH_LENGTH + 1, 0, MAX_PATH_LENGTH + 1) != EOK) { - delete []realPath; + delete[] realPath; return -E_SECUREC_ERROR; } if (realpath(inOriPath.c_str(), realPath) == nullptr) { GLOGE("[OS_API] Realpath error:%d.", errno); - delete []realPath; + delete[] realPath; return -E_SYSTEM_API_FAIL; } outRealPath = std::string(realPath); - delete []realPath; + delete[] realPath; return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp index fff6188d208afaffc01ac49fdfbc9177ae11acc1..fa6e5f7605f3141a774abf438e1baac899c3bd54 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/base/grd_db_api.cpp @@ -18,8 +18,8 @@ #include "doc_errno.h" #include "document_store_manager.h" #include "grd_base/grd_error.h" -#include "log_print.h" #include "grd_type_inner.h" +#include "log_print.h" using namespace DocumentDB; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index bc88d8796229b67f6ac181a742216337556c5a26..285036fc4ba7d7e609305b3cefbd1ec2604efcc2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "document_check.h" + #include #include #include "doc_errno.h" #include "log_print.h" #include "securec.h" -#include "document_check.h" namespace DocumentDB { namespace { @@ -46,7 +47,7 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi } return true; } -} +} // namespace bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::string &lowerCaseName, int &errCode) { @@ -248,14 +249,14 @@ bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector JSON_DEEP_MAX) { return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h index 46c9f7f3f25ea5541c3c5f241fb99ef8b1ac4d9b..d094ed42adbc655d6892dd77b6bb5197e33a8574 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h @@ -18,6 +18,7 @@ #include #include + #include "json_common.h" namespace DocumentDB { @@ -42,5 +43,5 @@ using Key = std::vector; using Value = std::vector; constexpr const char *COLL_PREFIX = "GRD_COLL_"; -} // DocumentDB +} // namespace DocumentDB #endif // DOCUMENT_CHECK_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp index 216facd921e9b3111f9c9b9584cfa3f718495c28..be6b65eadc8fc40e9e28b109945de676016f3b49 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp @@ -14,9 +14,10 @@ */ #include "grd_document/grd_document_api.h" + #include "grd_base/grd_error.h" -#include "grd_type_inner.h" #include "grd_resultset_inner.h" +#include "grd_type_inner.h" #include "log_print.h" using namespace DocumentDB; @@ -104,18 +105,16 @@ int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, un return errCode; } -int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, - GRD_ResultSet **resultSet) +int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, GRD_ResultSet **resultSet) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || resultSet == nullptr || - query.filter == nullptr - || query.projection == nullptr) { + query.filter == nullptr || query.projection == nullptr) { return GRD_INVALID_ARGS; } if (db->store_->IsCollectionOpening(collectionName)) { return GRD_RESOURCE_BUSY; } - GRD_ResultSet *grdResultSet = new (std::nothrow)GRD_ResultSet(); + GRD_ResultSet *grdResultSet = new (std::nothrow) GRD_ResultSet(); if (grdResultSet == nullptr) { GLOGE("Memory allocation failed!"); return -E_FAILED_MEMORY_ALLOCATE; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp index 686f2846a37edd24e8b16242707bed1aeb52837b..b54cc345bede563dab590b9c798ecb93aa5bd5ac 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_resultset_api.cpp @@ -12,14 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "grd_base/grd_resultset_api.h" + #include -#include "grd_base/grd_error.h" #include "doc_errno.h" #include "grd_base/grd_error.h" #include "grd_resultset_inner.h" #include "log_print.h" -#include "grd_base/grd_resultset_api.h" using namespace DocumentDB; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h index 9c5576697e75459ba868b99cd39c7823b34fc15f..f4a546821718fdc4de84120c60675f5da2b5b7f5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h @@ -16,7 +16,6 @@ #ifndef GRD_FORMAT_CONFIG_H #define GRD_FORMAT_CONFIG_H - #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_type_inner.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_type_inner.h index 6366370136761013c6cbeaa4dd65214df36cfcf6..f26f6ac4897e2a80b7f347844a775f78208346a4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_type_inner.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_type_inner.h @@ -16,8 +16,8 @@ #ifndef GRD_TYPE_INNER_H #define GRD_TYPE_INNER_H -#include "document_store.h" #include "doc_errno.h" +#include "document_store.h" #include "grd_base/grd_error.h" typedef struct GRD_DB { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h index 194af3d3b1770fa445bf11e5456da3b083f8a998..bae5a5938b23e75693be378b9853869ed37d3882 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h @@ -17,6 +17,7 @@ #define COLLECTION_H #include + #include "document_check.h" #include "kv_store_executor.h" @@ -24,8 +25,8 @@ namespace DocumentDB { class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); - Collection(const Collection &a) {}; - Collection() {}; + Collection(const Collection &a){}; + Collection(){}; ~Collection(); int PutDocument(const Key &key, const Value &document); @@ -36,6 +37,7 @@ public: int UpsertDocument(const std::string &id, const std::string &document, bool isReplace = true); bool FindDocument(); int UpdateDocument(const std::string &id, const std::string &document, bool isReplace = false); + private: std::string name_; KvStoreExecutor *executor_ = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h index 24eea19a707955af8eb2ca86a05c4393f3dc0e20..0db886c0542cb6472263cf2f9b6c6b686d176822 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h @@ -40,5 +40,5 @@ constexpr int E_RESOURCE_BUSY = E_BASE + 50; constexpr int E_FAILED_MEMORY_ALLOCATE = E_BASE + 51; int TrasnferDocErr(int err); -} // DocumentDB +} // namespace DocumentDB #endif // DOC_ERRNO_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h index 7f1da94fbee6d5d9bcb974fa70cdc1c3ece06535..5f20864b781a94d337318d0c4f0e0db89347020a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h @@ -16,12 +16,12 @@ #ifndef DOCUMENT_STORE_H #define DOCUMENT_STORE_H -#include #include #include +#include -#include "kv_store_executor.h" #include "collection.h" +#include "kv_store_executor.h" struct GRD_ResultSet; namespace DocumentDB { @@ -34,20 +34,21 @@ public: int DropCollection(const std::string &name, int flags); int UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, int flags); - int UpsertDocument(const std::string &collection, const std::string &filter, - const std::string &document, int flags); + int UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, + int flags); int InsertDocument(const std::string &collection, const std::string &document, int flag); int DeleteDocument(const std::string &collection, const std::string &filter, int flag); - int FindDocument(const std::string &collection, const std::string &filter, - const std::string &projection, int flags, GRD_ResultSet *grdResultSet); + int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, + int flags, GRD_ResultSet *grdResultSet); KvStoreExecutor *GetExecutor(int errCode); bool IsCollectionOpening(const std::string collection); int EraseCollection(const std::string collectionName); + private: int GetViewType(JsonObject &jsonObj, bool &viewType); std::mutex dbMutex_; KvStoreExecutor *executor_ = nullptr; - std::map collections_; + std::map collections_; }; -} // DocumentDB +} // namespace DocumentDB #endif // DOCUMENT_STORE_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h index 7004316297c97f6d592863672b892e29d6c9a8f8..193118f47cc34fedc937023fd85aa57ef4586381 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store_manager.h @@ -17,6 +17,7 @@ #define DOCUMENT_STORE_MANAGER_H #include + #include "document_store.h" namespace DocumentDB { @@ -31,5 +32,5 @@ private: static bool CheckDBPath(const std::string &path, std::string &canonicalPath, std::string &dbName, int &errCode); static bool CheckDBConfig(const std::string &config, int &errCode); }; -} // DocumentDB +} // namespace DocumentDB #endif // DOCUMENT_STORE_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/projection_tree.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/projection_tree.h index 8ffcc18c6c525e4f75674af6717516c8780145bf..a2763707fd702d2bd018f235836419fd3d2df129 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/projection_tree.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/projection_tree.h @@ -16,15 +16,16 @@ #define PROJECTION_TREE_H #include -#include #include +#include + #include "doc_errno.h" #include "json_common.h" #include "log_print.h" namespace DocumentDB { struct ProjectionNode { - std::unordered_map SonNode; + std::unordered_map SonNode; bool isDeepest; int Deep; int ViewType; @@ -34,7 +35,7 @@ struct ProjectionNode { isDeepest = true; } int DeleteProjectionNode(); - ~ProjectionNode () + ~ProjectionNode() { DeleteProjectionNode(); } @@ -46,8 +47,9 @@ public: int ParseTree(std::vector> &path); bool SearchTree(std::vector &singlePath, int &index); + private: ProjectionNode node_; }; -} // DocumentDB +} // namespace DocumentDB #endif // PROJECTION_TREE_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h index e2dca6e9b6e35cda6a5d932d8dfd4e6fd6d78902..289eec22a8d81e7a2d637ebdc525053654836f7e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h @@ -17,14 +17,15 @@ #define RESULTSET_H #include -#include "grd_base/grd_type_export.h" -#include "projection_tree.h" -#include "vector" + #include "doc_errno.h" -#include "json_object.h" -#include "securec.h" #include "document_check.h" #include "document_store.h" +#include "grd_base/grd_type_export.h" +#include "json_object.h" +#include "projection_tree.h" +#include "securec.h" +#include "vector" namespace DocumentDB { class ResultSet { @@ -33,16 +34,17 @@ public: ~ResultSet(); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId); + std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); int GetNext(); int GetValue(char **value); int GetKey(std::string &key); int EraseCollection(); + private: int CutJsonBranch(std::string &jsonData); int CheckCutNode(JsonObject *node, std::vector singleCutPath, - std::vector> &allCutPath); + std::vector> &allCutPath); DocumentStore *store_ = nullptr; std::string collectionName_; ValueObject key_; @@ -56,5 +58,5 @@ private: int index_ = 0; std::vector> matchDatas_; }; -} // DocumentDB +} // namespace DocumentDB #endif // RESULTSET_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set_common.h index e32b7b5e9df3f6c3fa1dcb36fb3a4d7cac3c484d..52779d443ff8a54a84d6c5fc0262c879a546005e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set_common.h @@ -17,17 +17,17 @@ #define RESULTSET_COMMON_H #include -#include "grd_base/grd_type_export.h" -#include "vector" + #include "doc_errno.h" +#include "grd_base/grd_type_export.h" #include "result_set.h" +#include "vector" namespace DocumentDB { class ValueObject; int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, std::vector> &path, bool ifShowId, bool viewType, ResultSet &resultSet, bool &isOnlyId); -int InitResultSet(DocumentStore *store, const std::string collectionName, - const std::string &filter, ResultSet &resultSet); -} // DocumentDB +int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, + ResultSet &resultSet); +} // namespace DocumentDB #endif //RESULTSET_COMMON_H - diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp index 6d22b01066f169e18d5bfbe60b5d0d9bef4e1c2b..ab098f736a871e9a63c63883f9062c560144ba5d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp @@ -17,8 +17,8 @@ #include -#include "document_check.h" #include "doc_errno.h" +#include "document_check.h" #include "log_print.h" namespace DocumentDB { @@ -135,7 +135,7 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen GLOGE("document's length is too long"); return -E_OVER_LIMIT; } - valSet = {valStr.begin(), valStr.end()}; + valSet = { valStr.begin(), valStr.end() }; } } return executor_->PutData(name_, keyId, valSet); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp index c15cc0c11b403629b5ffd3a97dd0935ae6468485..6dc3712998845d0efaaecd06bc6914f8fda11815 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp @@ -14,6 +14,7 @@ */ #include "doc_errno.h" + #include "grd_base/grd_error.h" namespace DocumentDB { @@ -79,4 +80,4 @@ int TrasnferDocErr(int err) return GetErrorCategory(outErr); } -} \ No newline at end of file +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 0638c2477916638a4a147ad4d14fcf92e739233b..210316d84bd4920decaeb127408fd9f8110c97fe 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -14,13 +14,14 @@ */ #include "document_store.h" + #include "collection_option.h" -#include "document_check.h" #include "doc_errno.h" +#include "document_check.h" #include "grd_base/grd_type_export.h" +#include "grd_resultset_inner.h" #include "log_print.h" #include "result_set_common.h" -#include "grd_resultset_inner.h" namespace DocumentDB { const int COLLECTION_LENS_MAX = 512 * 1024; @@ -29,9 +30,7 @@ const int JSON_DEEP_MAX = 4; constexpr const char *KEY_ID = "_id"; const bool caseSensitive = true; -DocumentStore::DocumentStore(KvStoreExecutor *executor) : executor_(executor) -{ -} +DocumentStore::DocumentStore(KvStoreExecutor *executor) : executor_(executor) {} DocumentStore::~DocumentStore() { @@ -194,8 +193,8 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri return errCode; } -int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, - int flags) +int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, + const std::string &document, int flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -231,7 +230,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri std::vector> filterAllPath; filterAllPath = JsonCommon::ParsePath(filterObj, errCode); if (errCode != E_OK) { - return errCode; + return errCode; } bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); @@ -341,7 +340,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri std::vector> filterAllPath; filterAllPath = JsonCommon::ParsePath(filterObj, errCode); if (errCode != E_OK) { - return errCode; + return errCode; } bool isOnlyId = true; errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); @@ -372,8 +371,8 @@ KvStoreExecutor *DocumentStore::GetExecutor(int errCode) { return executor_; } -int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, - int flags, GRD_ResultSet *grdResultSet) +int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, + const std::string &projection, int flags, GRD_ResultSet *grdResultSet) { if (flags != 0 && flags != GRD_DOC_ID_DISPLAY) { GLOGE("FindDocument flag is illegal"); @@ -397,7 +396,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string std::vector> filterAllPath; filterAllPath = JsonCommon::ParsePath(filterObj, errCode); if (errCode != E_OK) { - return errCode; + return errCode; } bool isOnlyId = true; errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); @@ -449,10 +448,11 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return ret; } -bool DocumentStore::IsCollectionOpening(const std::string collection) { +bool DocumentStore::IsCollectionOpening(const std::string collection) +{ if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); - return true; + return true; } return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp index c9f2dd0761783bb05244ec67833131d4d86cf737..40c6c541deb19adf027a23e328bd7c1ab6d7e457 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store_manager.cpp @@ -13,13 +13,14 @@ * limitations under the License. */ +#include "document_store_manager.h" + #include "db_config.h" #include "doc_errno.h" #include "grd_base/grd_type_export.h" +#include "kv_store_manager.h" #include "log_print.h" #include "os_api.h" -#include "kv_store_manager.h" -#include "document_store_manager.h" namespace DocumentDB { namespace { @@ -42,7 +43,7 @@ bool CheckDBCreate(unsigned int flags, const std::string &path) } return true; } -} +} // namespace int DocumentStoreManager::GetDocumentStore(const std::string &path, const std::string &config, unsigned int flags, DocumentStore *&store) @@ -139,4 +140,4 @@ bool DocumentStoreManager::CheckDBConfig(const std::string &config, int &errCode { return true; } -} // DocumentDB \ No newline at end of file +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/projection_tree.cpp index ca2abd109b464057682e619779001cc2faaecda7..6a67e29c660ed081eeca10e962da3964fd7e7df2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/projection_tree.cpp @@ -12,17 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include "projection_tree.h" +#include + namespace DocumentDB { const int JSON_DEEP_MAX = 4; -ProjectionTree::ProjectionTree() { -} +ProjectionTree::ProjectionTree() {} -ProjectionTree::~ProjectionTree() { -} +ProjectionTree::~ProjectionTree() {} int ProjectionTree::ParseTree(std::vector> &path) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp index b4a568291e66a4c828577afc9df0bde55b64941b..72d5e23b8d3a8f620b1b78957b152c422a77f3a7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp @@ -13,17 +13,14 @@ * limitations under the License. */ #include "result_set.h" + #include "log_print.h" namespace DocumentDB { constexpr const char *KEY_ID = "_id"; -ResultSet::ResultSet() -{ -} -ResultSet::~ResultSet() -{ -} +ResultSet::ResultSet() {} +ResultSet::~ResultSet() {} int ResultSet::EraseCollection() { if (store_ != nullptr) { @@ -32,10 +29,10 @@ int ResultSet::EraseCollection() return E_OK; } int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId) + std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId) { isOnlyId_ = isOnlyId; - store_ = store; + store_ = store; collectionName_ = collectionName; filter_ = filter; projectionPath_ = path; @@ -51,7 +48,7 @@ int ResultSet::Init(DocumentStore *store, const std::string collectionName, cons int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter) { ifFiled_ = true; - store_ = store; + store_ = store; collectionName_ = collectionName; filter_ = filter; return E_OK; @@ -80,7 +77,7 @@ int ResultSet::GetNext() errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); - return -E_NO_DATA; + return -E_NO_DATA; } std::string jsonData(document.begin(), document.end()); CutJsonBranch(jsonData); @@ -106,7 +103,7 @@ int ResultSet::GetNext() } matchDatas_ = values; } - } else if (index_ == 0) { + } else if (index_ == 0) { int errCode = 0; auto coll = Collection(collectionName_, store_->GetExecutor(errCode)); std::vector> values; @@ -130,13 +127,13 @@ int ResultSet::GetNext() return E_OK; } -int ResultSet::GetValue(char **value) +int ResultSet::GetValue(char **value) { if (index_ == 0 || (index_ > matchDatas_.size())) { GLOGE("The value vector in resultSet is empty"); return -E_NO_DATA; } - auto jsonData = matchDatas_[index_ - 1].second; + auto jsonData = matchDatas_[index_ - 1].second; char *jsonstr = new char[jsonData.size() + 1]; if (jsonstr == nullptr) { GLOGE("Memory allocation failed!"); @@ -158,12 +155,12 @@ int ResultSet::GetKey(std::string &key) GLOGE("The value vector in resultSet is empty"); return -E_NO_DATA; } - key = matchDatas_[index_ - 1].first; + key = matchDatas_[index_ - 1].first; return E_OK; } int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePath, - std::vector> &allCutPath) + std::vector> &allCutPath) { if (node == nullptr) { GLOGE("No node to cut"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set_common.cpp index b3942c830ca89a294dea290811100e594b804a86..c34c4a803836e3beb4284d6e85597f3367843d26 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set_common.cpp @@ -13,11 +13,13 @@ * limitations under the License. */ +#include "result_set_common.h" + #include #include + #include "doc_errno.h" #include "grd_base/grd_error.h" -#include "result_set_common.h" namespace DocumentDB { class ValueObject; @@ -27,10 +29,9 @@ int InitResultSet(DocumentStore *store, const std::string collectionName, const return resultSet.Init(store, collectionName, filter, path, ifShowId, viewType, isOnlyId); } -int InitResultSet(DocumentStore *store, const std::string collectionName, - const std::string &filter, ResultSet &resultSet) +int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, + ResultSet &resultSet) { return resultSet.Init(store, collectionName, filter); } -} // DocumentDB - +} // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index bde5710410ec74d947292b2c887770b2250b738d..f205698408e267f17f8c5eac22a09131f2dcf9e4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -18,8 +18,8 @@ #include #include -#include #include +#include #include "cJSON.h" @@ -43,7 +43,7 @@ public: int64_t GetIntValue() const; double GetDoubleValue() const; std::string GetStringValue() const; - bool operator==(const ValueObject& other) const; + bool operator==(const ValueObject &other) const; private: ValueType valueType = ValueType::VALUE_NULL; @@ -61,7 +61,7 @@ using JsonFieldPath = std::vector; class JsonObject { public: static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = false); - ~JsonObject (); + ~JsonObject(); std::string Print() const; @@ -81,7 +81,7 @@ public: void ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode); void SetItemValue(const ValueObject &value) const; int InsertItemObject(int which, const JsonObject &newItem); - + std::string GetItemFiled() const; std::string GetItemFiled(int &errCode) const; @@ -113,6 +113,5 @@ private: bool isOwner_ = false; bool caseSensitive_ = false; }; -} // DocumentDB +} // namespace DocumentDB #endif // JSON_OBJECT_H - diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h index 2f3bc84d168d0d8da8691dc17b19fea8b0238b8a..1051abe25c817ef17b0170d212ed32b2d72d381a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h @@ -17,6 +17,7 @@ #define KV_STORE_EXECUTOR_H #include + #include "document_check.h" namespace DocumentDB { @@ -38,5 +39,5 @@ public: virtual int SetCollectionOption(const std::string &name, const std::string &option) = 0; virtual int CleanCollectionOption(const std::string &name) = 0; }; -} // DocumentDB +} // namespace DocumentDB #endif // KV_STORE_EXECUTOR_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_manager.h index c1df107236329fd3961755f57886aca64e9a8e14..2a84cf89c1339d9c5015a942bbdf9b16d4a634f2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_manager.h @@ -26,5 +26,5 @@ class KvStoreManager { public: static int GetKvStore(const std::string &path, const DBConfig &config, KvStoreExecutor *&executor); }; -} // DocumentDB +} // namespace DocumentDB #endif // KV_STORE_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index 1c883fd544af0572066525fbe992c8e8a42d2321..fe6106e2ad1bad69309526b2b9d34adea0e932be 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -14,7 +14,9 @@ */ #include "json_object.h" + #include + #include "doc_errno.h" #include "log_print.h" @@ -30,7 +32,7 @@ bool IsNumber(const std::string &str) return std::isdigit(c); }); } -} +} // namespace ValueObject::ValueObject(bool val) { @@ -81,7 +83,7 @@ std::string ValueObject::GetStringValue() const return stringValue; } -bool ValueObject::operator==(const ValueObject& other) const +bool ValueObject::operator==(const ValueObject &other) const { if (this->GetValueType() != other.GetValueType()) { return false; @@ -167,7 +169,6 @@ int JsonObject::GetDeep(cJSON *cjson) return depth; } - int JsonObject::CheckNumber(cJSON *item, int &errCode) { if (item != NULL && cJSON_IsNumber(item)) { @@ -321,7 +322,7 @@ int JsonObject::AddItemToObject(const std::string &fieldName, const JsonObject & } if (IsNumber(fieldName) && n <= std::stoi(fieldName)) { GLOGE("Add item object to array over size."); - return -E_NO_DATA; + return -E_NO_DATA; } } if (cjson_->type != cJSON_Object) { @@ -386,7 +387,7 @@ ValueObject JsonObject::GetItemValue() const void JsonObject::ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode) { if (!newItem.IsNull() || !this->IsNull()) { - if (this->GetType() == JsonObject::Type::JSON_OBJECT) { + if (this->GetType() == JsonObject::Type::JSON_OBJECT) { if (!(this->GetObjectItem(filedName.c_str(), errCode).IsNull())) { cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); cJSON_ReplaceItemInObjectCaseSensitive(this->cjson_, filedName.c_str(), copyItem); @@ -497,7 +498,6 @@ cJSON *GetChild(cJSON *cjson, const std::string &field, bool caseSens) return nullptr; } - cJSON *GetChildPowerMode(cJSON *cjson, const std::string &field, bool caseSens) { if (cjson->type == cJSON_Object) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/kv_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/kv_store_manager.cpp index bea868485ede0e7044a40f54427354d1b6a57617..40fe20e54948d6c4d2f8868a39aab5dda5adefd9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/kv_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/kv_store_manager.cpp @@ -13,11 +13,12 @@ * limitations under the License. */ +#include "kv_store_manager.h" + #include "doc_errno.h" #include "log_print.h" #include "sqlite_store_executor_impl.h" #include "sqlite_utils.h" -#include "kv_store_manager.h" namespace DocumentDB { int KvStoreManager::GetKvStore(const std::string &path, const DBConfig &config, KvStoreExecutor *&executor) @@ -66,4 +67,4 @@ END: sqliteExecutor = nullptr; return errCode; } -} \ No newline at end of file +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp index ff2b47ed9c1fbc3bc205bc0c32143afbc54d863b..149c921f92ae64e99832f40597a13e3280ed513f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -13,11 +13,12 @@ * limitations under the License. */ -#include "document_check.h" +#include "sqlite_store_executor_impl.h" + #include "doc_errno.h" +#include "document_check.h" #include "log_print.h" #include "sqlite_utils.h" -#include "sqlite_store_executor_impl.h" namespace DocumentDB { int SqliteStoreExecutor::CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db) @@ -53,9 +54,7 @@ END: return errCode; } -SqliteStoreExecutor::SqliteStoreExecutor(sqlite3 *handle) : dbHandle_(handle) -{ -} +SqliteStoreExecutor::SqliteStoreExecutor(sqlite3 *handle) : dbHandle_(handle) {} SqliteStoreExecutor::~SqliteStoreExecutor() { @@ -66,7 +65,7 @@ SqliteStoreExecutor::~SqliteStoreExecutor() int SqliteStoreExecutor::GetDBConfig(std::string &config) { std::string dbConfigKeyStr = "DB_CONFIG"; - Key dbConfigKey = {dbConfigKeyStr.begin(), dbConfigKeyStr.end()}; + Key dbConfigKey = { dbConfigKeyStr.begin(), dbConfigKeyStr.end() }; Value dbConfigVal; int errCode = GetData("grd_meta", dbConfigKey, dbConfigVal); config.assign(dbConfigVal.begin(), dbConfigVal.end()); @@ -76,8 +75,8 @@ int SqliteStoreExecutor::GetDBConfig(std::string &config) int SqliteStoreExecutor::SetDBConfig(const std::string &config) { std::string dbConfigKeyStr = "DB_CONFIG"; - Key dbConfigKey = {dbConfigKeyStr.begin(), dbConfigKeyStr.end()}; - Value dbConfigVal = {config.begin(), config.end()}; + Key dbConfigKey = { dbConfigKeyStr.begin(), dbConfigKeyStr.end() }; + Value dbConfigVal = { config.begin(), config.end() }; return PutData("grd_meta", dbConfigKey, dbConfigVal); } @@ -87,11 +86,14 @@ int SqliteStoreExecutor::PutData(const std::string &collName, const Key &key, co return -E_ERROR; } std::string sql = "INSERT OR REPLACE INTO '" + collName + "' VALUES (?,?);"; - int errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [key, value](sqlite3_stmt *stmt) { - SQLiteUtils::BindBlobToStatement(stmt, 1, key); - SQLiteUtils::BindBlobToStatement(stmt, 2, value); - return E_OK; - }, nullptr); + int errCode = SQLiteUtils::ExecSql( + dbHandle_, sql, + [key, value](sqlite3_stmt *stmt) { + SQLiteUtils::BindBlobToStatement(stmt, 1, key); + SQLiteUtils::BindBlobToStatement(stmt, 2, value); + return E_OK; + }, + nullptr); if (errCode != SQLITE_OK) { GLOGE("[sqlite executor] Put data failed. err=%d", errCode); if (errCode == -E_ERROR) { @@ -111,14 +113,17 @@ int SqliteStoreExecutor::GetData(const std::string &collName, const Key &key, Va } int innerErrorCode = -E_NOT_FOUND; std::string sql = "SELECT value FROM '" + collName + "' WHERE key=?;"; - int errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [key](sqlite3_stmt *stmt) { - SQLiteUtils::BindBlobToStatement(stmt, 1, key); - return E_OK; - }, [&value, &innerErrorCode](sqlite3_stmt *stmt) { - SQLiteUtils::GetColumnBlobValue(stmt, 0, value); - innerErrorCode = E_OK; - return E_OK; - }); + int errCode = SQLiteUtils::ExecSql( + dbHandle_, sql, + [key](sqlite3_stmt *stmt) { + SQLiteUtils::BindBlobToStatement(stmt, 1, key); + return E_OK; + }, + [&value, &innerErrorCode](sqlite3_stmt *stmt) { + SQLiteUtils::GetColumnBlobValue(stmt, 0, value); + innerErrorCode = E_OK; + return E_OK; + }); if (errCode != SQLITE_OK) { GLOGE("[sqlite executor] Get data failed. err=%d", errCode); return errCode; @@ -127,7 +132,7 @@ int SqliteStoreExecutor::GetData(const std::string &collName, const Key &key, Va } int SqliteStoreExecutor::GetFilededData(const std::string &collName, const JsonObject &filterObj, - std::vector> &values) const + std::vector> &values) const { if (dbHandle_ == nullptr) { GLOGE("Invalid db handle."); @@ -138,26 +143,29 @@ int SqliteStoreExecutor::GetFilededData(const std::string &collName, const JsonO bool isFindMatch = false; int innerErrorCode = -E_NOT_FOUND; std::string sql = "SELECT key, value FROM '" + collName + "';"; - int errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [](sqlite3_stmt *stmt) { - return E_OK; - }, [&keyResult, &innerErrorCode, &valueResult, &filterObj, &values, &isFindMatch](sqlite3_stmt *stmt) { - SQLiteUtils::GetColumnBlobValue(stmt, 0, keyResult); - SQLiteUtils::GetColumnBlobValue(stmt, 1, valueResult); - std::string keyStr(keyResult.begin(), keyResult.end()); - std::string valueStr(valueResult.begin(), valueResult.end()); - int externErrCode; - JsonObject srcObj = JsonObject::Parse(valueStr, externErrCode, true); - if (externErrCode != E_OK) { - GLOGE("srcObj Parsed faild"); - return externErrCode; - } - if (JsonCommon::IsJsonNodeMatch(srcObj, filterObj, externErrCode)) { - isFindMatch = true; - values.emplace_back(std::pair(keyStr, valueStr)); - } - innerErrorCode = E_OK; - return E_OK; - }); + int errCode = SQLiteUtils::ExecSql( + dbHandle_, sql, + [](sqlite3_stmt *stmt) { + return E_OK; + }, + [&keyResult, &innerErrorCode, &valueResult, &filterObj, &values, &isFindMatch](sqlite3_stmt *stmt) { + SQLiteUtils::GetColumnBlobValue(stmt, 0, keyResult); + SQLiteUtils::GetColumnBlobValue(stmt, 1, valueResult); + std::string keyStr(keyResult.begin(), keyResult.end()); + std::string valueStr(valueResult.begin(), valueResult.end()); + int externErrCode; + JsonObject srcObj = JsonObject::Parse(valueStr, externErrCode, true); + if (externErrCode != E_OK) { + GLOGE("srcObj Parsed faild"); + return externErrCode; + } + if (JsonCommon::IsJsonNodeMatch(srcObj, filterObj, externErrCode)) { + isFindMatch = true; + values.emplace_back(std::pair(keyStr, valueStr)); + } + innerErrorCode = E_OK; + return E_OK; + }); if (errCode != SQLITE_OK) { GLOGE("[sqlite executor] Get data failed. err=%d", errCode); return errCode; @@ -180,10 +188,13 @@ int SqliteStoreExecutor::DelData(const std::string &collName, const Key &key) return -E_NO_DATA; } std::string sql = "DELETE FROM '" + collName + "' WHERE key=?;"; - errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [key](sqlite3_stmt *stmt) { - SQLiteUtils::BindBlobToStatement(stmt, 1, key); - return E_OK; - }, nullptr); + errCode = SQLiteUtils::ExecSql( + dbHandle_, sql, + [key](sqlite3_stmt *stmt) { + SQLiteUtils::BindBlobToStatement(stmt, 1, key); + return E_OK; + }, + nullptr); if (errCode != SQLITE_OK) { GLOGE("[sqlite executor] Delete data failed. err=%d", errCode); if (errCode == -E_ERROR) { @@ -254,13 +265,16 @@ bool SqliteStoreExecutor::IsCollectionExists(const std::string &name, int &errCo bool isExists = false; std::string sql = "SELECT tbl_name FROM sqlite_master WHERE tbl_name=?;"; - errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [name](sqlite3_stmt *stmt) { - SQLiteUtils::BindTextToStatement(stmt, 1, name); - return E_OK; - }, [&isExists](sqlite3_stmt *stmt) { - isExists = true; - return E_OK; - }); + errCode = SQLiteUtils::ExecSql( + dbHandle_, sql, + [name](sqlite3_stmt *stmt) { + SQLiteUtils::BindTextToStatement(stmt, 1, name); + return E_OK; + }, + [&isExists](sqlite3_stmt *stmt) { + isExists = true; + return E_OK; + }); if (errCode != E_OK) { GLOGE("Check collection exist failed. %d", errCode); } @@ -270,7 +284,7 @@ bool SqliteStoreExecutor::IsCollectionExists(const std::string &name, int &errCo int SqliteStoreExecutor::GetCollectionOption(const std::string &name, std::string &option) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; - Key collOptKey = {collOptKeyStr.begin(), collOptKeyStr.end()}; + Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; Value collOptVal; int errCode = GetData("grd_meta", collOptKey, collOptVal); option.assign(collOptVal.begin(), collOptVal.end()); @@ -280,15 +294,15 @@ int SqliteStoreExecutor::GetCollectionOption(const std::string &name, std::strin int SqliteStoreExecutor::SetCollectionOption(const std::string &name, const std::string &option) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; - Key collOptKey = {collOptKeyStr.begin(), collOptKeyStr.end()}; - Value collOptVal = {option.begin(), option.end()}; + Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; + Value collOptVal = { option.begin(), option.end() }; return PutData("grd_meta", collOptKey, collOptVal); } int SqliteStoreExecutor::CleanCollectionOption(const std::string &name) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; - Key collOptKey = {collOptKeyStr.begin(), collOptKeyStr.end()}; + Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; return DelData("grd_meta", collOptKey); } -} // DocumentDB \ No newline at end of file +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h index 2e0164bfd952d984049884bc61216e4fe2a55851..dfef5998ba365875dca0d1967747938ccd9dbc62 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h @@ -17,9 +17,9 @@ #define SQLITE_STORE_EXECUTOR_IMPL_H #include "db_config.h" +#include "json_common.h" #include "kv_store_executor.h" #include "sqlite3.h" -#include "json_common.h" namespace DocumentDB { class SqliteStoreExecutor : public KvStoreExecutor { @@ -49,5 +49,5 @@ public: private: sqlite3 *dbHandle_ = nullptr; }; -} // DocumentDB +} // namespace DocumentDB #endif // SQLITE_STORE_EXECUTOR_IMPL_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.cpp index bb86791fb5bb5cd26f979678665af805c1b057d3..5ae0777bb6b2da52bb9ff634d20ff89f388c5e94 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.cpp @@ -15,13 +15,14 @@ #include "sqlite_utils.h" #include + #include "doc_errno.h" #include "log_print.h" namespace DocumentDB { const int MAX_BLOB_READ_SIZE = 5 * 1024 * 1024; // 5M limit const int MAX_TEXT_READ_SIZE = 5 * 1024 * 1024; // 5M limit -const int BUSY_TIMEOUT_MS = 3000; // 3000ms for sqlite busy timeout. +const int BUSY_TIMEOUT_MS = 3000; // 3000ms for sqlite busy timeout. const std::string BEGIN_SQL = "BEGIN TRANSACTION"; const std::string BEGIN_IMMEDIATE_SQL = "BEGIN IMMEDIATE TRANSACTION"; const std::string COMMIT_SQL = "COMMIT TRANSACTION"; @@ -44,7 +45,7 @@ int MapSqliteError(int errCode) std::mutex g_logConfigMutex; bool g_configLog = false; -} +} // namespace void SQLiteUtils::SqliteLogCallback(void *data, int err, const char *msg) { @@ -154,8 +155,8 @@ int SQLiteUtils::BindBlobToStatement(sqlite3_stmt *statement, int index, const s if (value.empty()) { errCode = sqlite3_bind_zeroblob(statement, index, -1); // -1 for zero-length blob. } else { - errCode = sqlite3_bind_blob(statement, index, static_cast(value.data()), - value.size(), SQLITE_TRANSIENT); + errCode = sqlite3_bind_blob(statement, index, static_cast(value.data()), value.size(), + SQLITE_TRANSIENT); } if (errCode != SQLITE_OK) { @@ -174,7 +175,7 @@ int SQLiteUtils::GetColumnBlobValue(sqlite3_stmt *statement, int index, std::vec if (keySize < 0 || keySize > MAX_BLOB_READ_SIZE) { GLOGW("[SQLiteUtils][Column blob] size over limit:%d", keySize); value.resize(MAX_BLOB_READ_SIZE + 1); // Reset value size to invalid - return E_OK; // Return OK for continue get data, but value is invalid + return E_OK; // Return OK for continue get data, but value is invalid } auto keyRead = static_cast(sqlite3_column_blob(statement, index)); @@ -213,7 +214,7 @@ int SQLiteUtils::GetColumnTextValue(sqlite3_stmt *statement, int index, std::str if (valSize < 0 || valSize > MAX_TEXT_READ_SIZE) { GLOGW("[SQLiteUtils][Column text] size over limit:%d", valSize); value.resize(MAX_TEXT_READ_SIZE + 1); // Reset value size to invalid - return E_OK; // Return OK for continue get data, but value is invalid + return E_OK; // Return OK for continue get data, but value is invalid } const unsigned char *val = sqlite3_column_text(statement, index); @@ -261,8 +262,8 @@ int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql) return MapSqliteError(errCode); } -int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::function &bindCallback, - const std::function &resultCallback) +int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::function &bindCallback, + const std::function &resultCallback) { if (db == nullptr || sql.empty()) { return -E_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.h index 597a576ee4e695d9411095adffe27eacc641e939..3567163c6387ef2022c2400ddc60a279027e72e1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_utils.h @@ -47,8 +47,8 @@ public: static int RollbackTransaction(sqlite3 *db); static int ExecSql(sqlite3 *db, const std::string &sql); - static int ExecSql(sqlite3 *db, const std::string &sql, const std::function &bindCallback, - const std::function &resultCallback); + static int ExecSql(sqlite3 *db, const std::string &sql, const std::function &bindCallback, + const std::function &resultCallback); private: static void SqliteLogCallback(void *data, int err, const char *msg); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp index 15e790c846866f0fc06dd6d09c25eeff7062a4c9..a943af5aeb77dcd75f47960a6888b2fa442f72c2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp @@ -17,10 +17,10 @@ #include "doc_errno.h" #include "documentdb_test_utils.h" -#include "log_print.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" #include "grd_document/grd_document_api.h" +#include "log_print.h" #include "sqlite_utils.h" using namespace DocumentDB; @@ -35,17 +35,11 @@ public: void TearDown(); }; -void DocumentDBApiTest::SetUpTestCase(void) -{ -} +void DocumentDBApiTest::SetUpTestCase(void) {} -void DocumentDBApiTest::TearDownTestCase(void) -{ -} +void DocumentDBApiTest::TearDownTestCase(void) {} -void DocumentDBApiTest::SetUp(void) -{ -} +void DocumentDBApiTest::SetUp(void) {} void DocumentDBApiTest::TearDown(void) { @@ -119,11 +113,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBPathTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::vector invalidPath = { - nullptr, - "", - "/a/b/c/" - }; + std::vector invalidPath = { nullptr, "", "/a/b/c/" }; for (auto path : invalidPath) { GLOGD("OpenDBPathTest001: open db with path: %s", path); int status = GRD_DBOpen(path, nullptr, GRD_DB_OPEN_CREATE, &db); @@ -156,7 +146,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBPathTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; const int MAX_JSON_LEN = 512 * 1024; std::string configStr = std::string(MAX_JSON_LEN, 'a'); int status = GRD_DBOpen(path.c_str(), configStr.c_str(), GRD_DB_OPEN_CREATE, &db); @@ -173,7 +163,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigTest002, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "{aa}", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_INVALID_FORMAT); } @@ -188,7 +178,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigTest003, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), R""({"notSupport":123})"", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_INVALID_ARGS); } @@ -203,7 +193,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigTest003, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; std::vector configList = { R""({"maxConnNum":0})"", @@ -231,7 +221,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest002, TestSize.Level1) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; for (int i = 16; i <= 1024; i++) { std::string config = "{\"maxConnNum\":" + std::to_string(i) + "}"; @@ -257,7 +247,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest002, TestSize.Level1) HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest003, TestSize.Level1) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; std::string config = R""({"maxConnNum":16})""; int status = GRD_DBOpen(path.c_str(), config.c_str(), GRD_DB_OPEN_CREATE, &db); @@ -283,7 +273,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest003, TestSize.Level1) */ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest004, TestSize.Level1) { - std::string path= "./document.db"; + std::string path = "./document.db"; int maxCnt = 16; std::string config = "{\"maxConnNum\":" + std::to_string(maxCnt) + "}"; @@ -321,7 +311,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest004, TestSize.Level1) HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; std::vector configList = { R""({"pageSize":0})"", @@ -358,7 +348,7 @@ int GetDBPageSize(const std::string &path) sqlite3_close_v2(db); return pageSize; } -} +} // namespace /** * @tc.name: OpenDBConfigPageSizeTest002 @@ -370,9 +360,9 @@ int GetDBPageSize(const std::string &path) HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest002, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; - for (int size : {4, 8, 16, 32, 64}) { + for (int size : { 4, 8, 16, 32, 64 }) { std::string config = "{\"pageSize\":" + std::to_string(size) + "}"; int status = GRD_DBOpen(path.c_str(), config.c_str(), GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); @@ -396,7 +386,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest003, TestSize.Level1) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; std::string config = R""({"pageSize":4})""; int status = GRD_DBOpen(path.c_str(), config.c_str(), GRD_DB_OPEN_CREATE, &db); @@ -423,9 +413,9 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest003, TestSize.Level1) HWTEST_F(DocumentDBApiTest, OpenDBConfigRedoFlushTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; - for (int flush : {0, 1}) { + for (int flush : { 0, 1 }) { std::string config = "{\"redoFlushByTrx\":" + std::to_string(flush) + "}"; int status = GRD_DBOpen(path.c_str(), config.c_str(), GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); @@ -448,7 +438,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigRedoFlushTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBConfigRedoFlushTest002, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; std::string config = R""({"redoFlushByTrx":3})""; int status = GRD_DBOpen(path.c_str(), config.c_str(), GRD_DB_OPEN_CREATE, &db); @@ -465,14 +455,9 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigRedoFlushTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBFlagTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; - std::vector invaldFlag = { - GRD_DB_OPEN_CHECK_FOR_ABNORMAL | GRD_DB_OPEN_CHECK, - GRD_DB_OPEN_CREATE | GRD_DB_OPEN_CHECK_FOR_ABNORMAL | GRD_DB_OPEN_CHECK, - 0x08, - 0xffff, - UINT32_MAX - }; + std::string path = "./document.db"; + std::vector invaldFlag = { GRD_DB_OPEN_CHECK_FOR_ABNORMAL | GRD_DB_OPEN_CHECK, + GRD_DB_OPEN_CREATE | GRD_DB_OPEN_CHECK_FOR_ABNORMAL | GRD_DB_OPEN_CHECK, 0x08, 0xffff, UINT32_MAX }; for (unsigned int flag : invaldFlag) { GLOGD("OpenDBFlagTest001: open doc db with flag %u", flag); int status = GRD_DBOpen(path.c_str(), "", flag, &db); @@ -490,7 +475,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBFlagTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, OpenDBFlagTest002, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "", GRD_DB_OPEN_ONLY, &db); EXPECT_EQ(status, GRD_INVALID_ARGS); @@ -553,7 +538,7 @@ HWTEST_F(DocumentDBApiTest, CloseDBTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, CloseDBFlagTest001, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); ASSERT_NE(db, nullptr); @@ -575,7 +560,7 @@ HWTEST_F(DocumentDBApiTest, CloseDBFlagTest001, TestSize.Level0) HWTEST_F(DocumentDBApiTest, CloseDBFlagTest002, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); ASSERT_NE(db, nullptr); @@ -599,17 +584,12 @@ HWTEST_F(DocumentDBApiTest, CloseDBFlagTest002, TestSize.Level0) HWTEST_F(DocumentDBApiTest, CloseDBFlagTest003, TestSize.Level0) { GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); ASSERT_NE(db, nullptr); - std::vector invaldFlag = { - 0x02, - 0x03, - 0xffff, - UINT32_MAX - }; + std::vector invaldFlag = { 0x02, 0x03, 0xffff, UINT32_MAX }; for (unsigned int flag : invaldFlag) { GLOGD("CloseDBFlagTest003: close doc db with flag %u", flag); status = GRD_DBClose(db, flag); @@ -636,14 +616,14 @@ HWTEST_F(DocumentDBApiTest, FlushDBTest001, TestSize.Level0) EXPECT_EQ(GRD_Flush(nullptr, GRD_DB_FLUSH_SYNC), GRD_INVALID_ARGS); GRD_DB *db = nullptr; - std::string path= "./document.db"; + std::string path = "./document.db"; int status = GRD_DBOpen(path.c_str(), "", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); ASSERT_NE(db, nullptr); EXPECT_EQ(GRD_Flush(db, GRD_DB_FLUSH_ASYNC), GRD_OK); EXPECT_EQ(GRD_Flush(db, GRD_DB_FLUSH_SYNC), GRD_OK); - std::vector invalidFlags = {2, 4, 8, 512, 1024, UINT32_MAX}; + std::vector invalidFlags = { 2, 4, 8, 512, 1024, UINT32_MAX }; for (auto flags : invalidFlags) { EXPECT_EQ(GRD_Flush(db, flags), GRD_INVALID_ARGS); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp index 63b72d43685e6c81eaa88f5d050686704fe60819..df17a4c90d5014547a27335dea0a126468dd2f69 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp @@ -17,10 +17,10 @@ #include "doc_errno.h" #include "documentdb_test_utils.h" -#include "log_print.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" #include "grd_document/grd_document_api.h" +#include "log_print.h" #include "sqlite_utils.h" using namespace DocumentDB; @@ -30,7 +30,7 @@ using namespace DocumentDBUnitTest; namespace { std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; -} +} // namespace class DocumentDBCollectionTest : public testing::Test { public: @@ -40,13 +40,9 @@ public: void TearDown(); }; -void DocumentDBCollectionTest::SetUpTestCase(void) -{ -} +void DocumentDBCollectionTest::SetUpTestCase(void) {} -void DocumentDBCollectionTest::TearDownTestCase(void) -{ -} +void DocumentDBCollectionTest::TearDownTestCase(void) {} void DocumentDBCollectionTest::SetUp(void) { @@ -103,12 +99,7 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest002, TestSize.Level0) EXPECT_EQ(GRD_DropCollection(g_db, it, 0), GRD_INVALID_ARGS); } - std::vector invalidNameFormat = { - "GRD_123", - "grd_123", - "GM_SYS_123", - "gm_sys_123" - }; + std::vector invalidNameFormat = { "GRD_123", "grd_123", "GM_SYS_123", "gm_sys_123" }; for (auto *it : invalidNameFormat) { GLOGD("CollectionTest002: create collection with name: %s", it); @@ -127,15 +118,8 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest002, TestSize.Level0) HWTEST_F(DocumentDBCollectionTest, CollectionTest003, TestSize.Level0) { string overLenName(MAX_COLLECTION_LEN - 1, 'a'); - std::vector validName = { - "123", - "&^%@", - "中文字符", - "sqlite_master", - "NULL", - "SELECT", - overLenName.c_str() - }; + std::vector validName = { "123", "&^%@", "中文字符", "sqlite_master", "NULL", "SELECT", + overLenName.c_str() }; for (auto *it : validName) { GLOGD("CollectionTest003: create collection with name: %s", it); @@ -213,7 +197,7 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest006, TestSize.Level0) */ HWTEST_F(DocumentDBCollectionTest, CollectionTest007, TestSize.Level0) { - for (int flag : std::vector {2, 4, 8, 1024, UINT32_MAX}) { + for (int flag : std::vector{ 2, 4, 8, 1024, UINT32_MAX }) { EXPECT_EQ(GRD_CreateCollection(g_db, "student", "", flag), GRD_INVALID_ARGS); EXPECT_EQ(GRD_DropCollection(g_db, "student", flag), GRD_INVALID_ARGS); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 8207d6d591da99994494450cf132c6f9e5db7f9e..17ff76b7b25f45d3f8ba2514a7fa7aeb6cac76fc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -17,10 +17,10 @@ #include "doc_errno.h" #include "documentdb_test_utils.h" -#include "log_print.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" #include "grd_document/grd_document_api.h" +#include "log_print.h" #include "sqlite_utils.h" using namespace DocumentDB; @@ -31,7 +31,7 @@ namespace { std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; const char *g_coll = "student"; -} +} // namespace class DocumentDBDataTest : public testing::Test { public: @@ -41,13 +41,9 @@ public: void TearDown(); }; -void DocumentDBDataTest::SetUpTestCase(void) -{ -} +void DocumentDBDataTest::SetUpTestCase(void) {} -void DocumentDBDataTest::TearDownTestCase(void) -{ -} +void DocumentDBDataTest::TearDownTestCase(void) {} void DocumentDBDataTest::SetUp(void) { @@ -109,12 +105,12 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest003, TestSize.Level0) { std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; std::vector> invalidName = { - {nullptr, GRD_INVALID_ARGS}, - {"", GRD_INVALID_ARGS}, - {"GRD_123", GRD_INVALID_FORMAT}, - {"grd_123", GRD_INVALID_FORMAT}, - {"GM_SYS_123", GRD_INVALID_FORMAT}, - {"gm_sys_123", GRD_INVALID_FORMAT}, + { nullptr, GRD_INVALID_ARGS }, + { "", GRD_INVALID_ARGS }, + { "GRD_123", GRD_INVALID_FORMAT }, + { "grd_123", GRD_INVALID_FORMAT }, + { "GM_SYS_123", GRD_INVALID_FORMAT }, + { "gm_sys_123", GRD_INVALID_FORMAT }, }; for (auto it : invalidName) { GLOGD("UpsertDataTest003: upsert data with collectionname: %s", it.first); @@ -122,14 +118,9 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest003, TestSize.Level0) } } -HWTEST_F(DocumentDBDataTest, UpsertDataTest004, TestSize.Level0) -{ -} - -HWTEST_F(DocumentDBDataTest, UpsertDataTest005, TestSize.Level0) -{ +HWTEST_F(DocumentDBDataTest, UpsertDataTest004, TestSize.Level0) {} -} +HWTEST_F(DocumentDBDataTest, UpsertDataTest005, TestSize.Level0) {} /** * @tc.name: UpsertDataTest006 @@ -143,7 +134,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest006, TestSize.Level0) std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - for (auto flags : std::vector {2, 4, 8, 64, 1024, UINT32_MAX}) { + for (auto flags : std::vector{ 2, 4, 8, 64, 1024, UINT32_MAX }) { EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), document.c_str(), flags), GRD_INVALID_ARGS); } } @@ -219,12 +210,12 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest003, TestSize.Level0) std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; std::vector> invalidName = { - {nullptr, GRD_INVALID_ARGS}, - {"", GRD_INVALID_ARGS}, - {"GRD_123", GRD_INVALID_FORMAT}, - {"grd_123", GRD_INVALID_FORMAT}, - {"GM_SYS_123", GRD_INVALID_FORMAT}, - {"gm_sys_123", GRD_INVALID_FORMAT}, + { nullptr, GRD_INVALID_ARGS }, + { "", GRD_INVALID_ARGS }, + { "GRD_123", GRD_INVALID_FORMAT }, + { "grd_123", GRD_INVALID_FORMAT }, + { "GM_SYS_123", GRD_INVALID_FORMAT }, + { "gm_sys_123", GRD_INVALID_FORMAT }, }; for (auto it : invalidName) { GLOGD("UpdateDataTest003: update data with collectionname: %s", it.first); @@ -239,9 +230,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest003, TestSize.Level0) * @tc.require: * @tc.author: lianhuix */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) -{ -} +HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) {} /** * @tc.name: UpdateDataTest005 @@ -250,9 +239,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) * @tc.require: * @tc.author: lianhuix */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) -{ -} +HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) {} /** * @tc.name: UpdateDataTest006 @@ -265,7 +252,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - std::vector invalidFlags = {2, 4, 8, 1024, UINT32_MAX}; + std::vector invalidFlags = { 2, 4, 8, 1024, UINT32_MAX }; for (auto flag : invalidFlags) { GLOGD("UpdateDataTest006: update data with flag: %u", flag); EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), document.c_str(), flag), GRD_INVALID_ARGS); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp index 8558a0ef473c48930328c339b13db6c22ac7a52f..74898556793de5838f24b807d48b5affc9f26496 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp @@ -16,12 +16,12 @@ #include #include "grd_base/grd_db_api.h" -#include "grd_document/grd_document_api.h" #include "grd_base/grd_error.h" +#include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" -#include "grd_type_inner.h" +#include "grd_document/grd_document_api.h" #include "grd_resultset_inner.h" -#include "grd_base/grd_resultset_api.h" +#include "grd_type_inner.h" using namespace testing::ext; namespace { @@ -30,7 +30,7 @@ constexpr const char *NULL_JSON_STR = "{}"; const int MAX_COLLECTION_LENS = 511; std::string path = "./document.db"; GRD_DB *g_db = nullptr; -} +} // namespace class DocumentDeleteApiTest : public testing::Test { public: @@ -64,8 +64,7 @@ void DocumentDeleteApiTest::SetUp(void) * @tc.steps:step2. Insert many document in order to delete * @tc.expected: step2. GRD_OK */ - const char *document1 = - "{ \ + const char *document1 = "{ \ \"_id\" : \"1\", \ \"name\": \"xiaoming\", \ \"address\": \"beijing\", \ @@ -73,8 +72,7 @@ void DocumentDeleteApiTest::SetUp(void) \"friend\" : {\"name\" : \"David\", \"sex\" : \"female\", \"age\" : 90}, \ \"subject\": [\"math\", \"English\", \"music\", {\"info\" : \"exam\"}] \ }"; - const char *document2 = - "{ \ + const char *document2 = "{ \ \"_id\" : \"2\", \ \"name\": \"ori\", \ \"address\": \"beijing\", \ @@ -82,8 +80,7 @@ void DocumentDeleteApiTest::SetUp(void) \"friend\" : {\"name\" : \"David\", \"sex\" : \"female\", \"age\" : 90}, \ \"subject\": [\"math\", \"English\", \"music\"] \ }"; - const char *document3 = - "{ \ + const char *document3 = "{ \ \"_id\" : \"3\", \ \"name\": \"David\", \ \"address\": \"beijing\", \ @@ -248,7 +245,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest006, TestSize.Level1) */ const char *filter = "{\"_id\" : \"1\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_DeleteDoc(g_db, COLLECTION_NAME, filter, 0), 1); /** @@ -278,7 +275,6 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest007, TestSize.Level1) EXPECT_EQ(GRD_DeleteDoc(g_db, collectionName2.c_str(), filter, 0), GRD_OVER_LIMIT); } - /** * @tc.name: DocumentDelete008 * @tc.desc: Test delete with invalid NULL input for all parameters. @@ -314,8 +310,8 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest010, TestSize.Level1) * @tc.steps:step1. Test delete document when filter _id is int and string. * @tc.expected: step1. GRD_INVALID_ARGS */ - std::vector filterVec = {R"({"_id" : 1})", R"({"_id":[1, 2]})", - R"({"_id" : {"t1" : 1}})", R"({"_id":null})", R"({"_id":true})", R"({"_id" : 1.333})", R"({"_id" : -2.0})"}; + std::vector filterVec = { R"({"_id" : 1})", R"({"_id":[1, 2]})", R"({"_id" : {"t1" : 1}})", + R"({"_id":null})", R"({"_id":true})", R"({"_id" : 1.333})", R"({"_id" : -2.0})" }; for (const auto &item : filterVec) { EXPECT_EQ(GRD_DeleteDoc(g_db, COLLECTION_NAME, item.c_str(), 0), GRD_INVALID_ARGS); } @@ -325,7 +321,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest010, TestSize.Level1) /** * @tc.name: DocumentDelete011 - * @tc.desc: + * @tc.desc: * @tc.type: FUNC * @tc.require: * @tc.author: mazhao @@ -339,7 +335,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest011, TestSize.Level1) const char *filter = "{\"_id\" : \"1\"}"; const char *filter2 = "{\"subject.info\" : \"exam\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_DeleteDoc(g_db, COLLECTION_NAME, filter2, 0), 1); /** @@ -352,7 +348,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest011, TestSize.Level1) /** * @tc.name: DocumentDelete012 - * @tc.desc: + * @tc.desc: * @tc.type: FUNC * @tc.require: * @tc.author: mazhao @@ -366,7 +362,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest012, TestSize.Level1) const char *filter = "{\"_id\" : \"1\"}"; const char *filter2 = "{\"subject.info\" : \"exam\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_DeleteDoc(g_db, COLLECTION_NAME, filter2, 0), 1); /** @@ -376,5 +372,3 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest012, TestSize.Level1) EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } - - diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp index 4d5ea66348bebe0f5f230f50489bf3f8f74e733d..3691ff168c6049fc611fd1662713284f90557390 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp @@ -15,16 +15,16 @@ #include +#include "doc_errno.h" +#include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" -#include "grd_document/grd_document_api.h" #include "grd_base/grd_error.h" +#include "grd_base/grd_resultset_api.h" #include "grd_base/grd_type_export.h" +#include "grd_document/grd_document_api.h" +#include "grd_resultset_inner.h" #include "grd_type_inner.h" -#include "grd_base/grd_resultset_api.h" -#include "doc_errno.h" #include "log_print.h" -#include "documentdb_test_utils.h" -#include "grd_resultset_inner.h" using namespace testing::ext; namespace { @@ -61,7 +61,8 @@ static const char *g_document13 = "{\"_id\" : \"13\", \"name\":\"doc13\",\"item\ {\"school\":\"AB\", \"age\" : 15}}"; static const char *g_document14 = "{\"_id\" : \"14\", \"name\":\"doc14\",\"item\" : true,\"personInfo\":\ [{\"school\":\"B\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 85}]}"; -static const char *g_document15 = "{\"_id\" : \"15\", \"name\":\"doc15\",\"personInfo\":[{\"school\":\"C\", \"age\" : 5}]}"; +static const char *g_document15 = "{\"_id\" : \"15\", \"name\":\"doc15\",\"personInfo\":[{\"school\":\"C\", \"age\" : " + "5}]}"; static const char *g_document16 = "{\"_id\" : \"16\", \"name\":\"doc16\", \"nested1\":{\"nested2\":{\"nested3\":\ {\"nested4\":\"ABC\", \"field2\":\"CCC\"}}}}"; static const char *g_document17 = "{\"_id\" : \"17\", \"name\":\"doc17\",\"personInfo\":\"oh,ok\"}"; @@ -71,11 +72,14 @@ static const char *g_document19 = "{\"_id\" : \"19\", \"name\":\"doc19\",\"ITEM\ {\"school\":\"AB\", \"age\":15}}"; static const char *g_document20 = "{\"_id\" : \"20\", \"name\":\"doc20\",\"ITEM\" : true,\"personInfo\":\ [{\"SCHOOL\":\"B\", \"AGE\":15}, {\"SCHOOL\":\"C\", \"AGE\":35}]}"; -static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, {\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; -static std::vectorg_data = {g_document1, g_document2, g_document3, g_document4, g_document5, g_document6, g_document7, - g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23}; - -static void InsertData(GRD_DB *g_db, const char *collectionName) +static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : " + "true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, " + "{\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; +static std::vector g_data = { g_document1, g_document2, g_document3, g_document4, g_document5, + g_document6, g_document7, g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, + g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23 }; + +static void InsertData(GRD_DB *g_db, const char *collectionName) { for (const auto &item : g_data) { EXPECT_EQ(GRD_InsertDoc(g_db, collectionName, item, 0), GRD_OK); @@ -91,7 +95,7 @@ static void CompareValue(const char *value, const char *targetValue) EXPECT_EQ(errCode, E_OK); EXPECT_EQ(valueObj.Print(), targetValueObj.Print()); } -} +} // namespace class DocumentFindApiTest : public testing::Test { public: @@ -121,10 +125,7 @@ void DocumentFindApiTest::SetUp(void) InsertData(g_db, "student"); } -void DocumentFindApiTest::TearDown(void) -{ -} - +void DocumentFindApiTest::TearDown(void) {} /** * @tc.name: DocumentFindApiTest001 @@ -141,7 +142,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest001, TestSize.Level1) */ const char *filter = "{\"_id\" : \"6\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = NULL; @@ -172,9 +173,9 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest002, TestSize.Level1) */ const char *filter = "{\"_id\" : \"6\", \"name\":\"doc6\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); - /** + /** * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. * @tc.expected: step2. GRD_GetValue return GRD_INVALID_ARGS and GRD_Next return GRD_INVALID_ARGS. */ @@ -200,9 +201,9 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest004, TestSize.Level1) */ const char *filter = "{\"name\":\"doc6\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); - + /** * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. * @tc.expected: step2. GRD_GetValue return GRD_INVALID_ARGS and GRD_Next return GRD_INVALID_ARGS. @@ -229,7 +230,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest004, TestSize.Level1) // */ // GRD_ResultSet *resultSet1 = nullptr; // const char *filter1 = "{\"_id\" : \"1\", \"info\" : 1}"; -// Query query1 = {filter1, "{}"}; +// Query query1 = {filter1, "{}"}; // EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query1, 1, &resultSet1), GRD_OK); // EXPECT_EQ(GRD_FreeResultSet(resultSet1), GRD_OK); @@ -239,7 +240,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest004, TestSize.Level1) // */ // GRD_ResultSet *resultSet2 = nullptr; // const char *filter2 = "{\"_id\" : \"1\", \"_id\" : \"2\"}"; -// Query query2 = {filter2, "{}"}; +// Query query2 = {filter2, "{}"}; // EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query2, 1, &resultSet2), GRD_INVALID_ARGS); // EXPECT_EQ(GRD_FreeResultSet(resultSet1), GRD_OK); @@ -295,7 +296,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet1 = nullptr; const char *filter1 = "{\"_id\" : \"valstring\"}"; - Query query1 = {filter1, "{}"}; + Query query1 = { filter1, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query1, 1, &resultSet1), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet1), GRD_OK); @@ -305,7 +306,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet2 = nullptr; const char *filter2 = "{\"_id\" : 1}"; - Query query2 = {filter2, "{}"}; + Query query2 = { filter2, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query2, 1, &resultSet2), GRD_INVALID_ARGS); /** @@ -314,7 +315,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet3 = nullptr; const char *filter3 = "{\"_id\" : [\"2\", 1]}"; - Query query3 = {filter3, "{}"}; + Query query3 = { filter3, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query3, 1, &resultSet3), GRD_INVALID_ARGS); /** @@ -323,7 +324,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet4 = nullptr; const char *filter4 = "{\"_id\" : {\"info_val\" : \"1\"}}"; - Query query4 = {filter4, "{}"}; + Query query4 = { filter4, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query4, 1, &resultSet4), GRD_INVALID_ARGS); /** @@ -332,7 +333,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet5 = nullptr; const char *filter5 = "{\"_id\" : true}"; - Query query5 = {filter5, "{}"}; + Query query5 = { filter5, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query5, 1, &resultSet5), GRD_INVALID_ARGS); /** @@ -341,7 +342,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) */ GRD_ResultSet *resultSet6 = nullptr; const char *filter6 = "{\"_id\" : null}"; - Query query6 = {filter6, "{}"}; + Query query6 = { filter6, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query6, 1, &resultSet6), GRD_INVALID_ARGS); } @@ -358,7 +359,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest016, TestSize.Level1) const char *colName2 = "GM_SYS_sysfff"; GRD_ResultSet *resultSet = NULL; const char *filter = "{\"_id\" : \"1\"}"; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, colName1, query, 1, &resultSet), GRD_INVALID_FORMAT); EXPECT_EQ(GRD_FindDoc(g_db, colName2, query, 1, &resultSet), GRD_INVALID_FORMAT); } @@ -402,7 +403,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest019, TestSize.Level1) { const char *filter = "{\"_id\" : \"100\"}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); char *value = NULL; @@ -426,7 +427,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest023, TestSize.Level1) const char *filter = "{\"_id\" : \"6\"}"; GRD_ResultSet *resultSet = nullptr; GRD_ResultSet *resultSet2 = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet2), GRD_RESOURCE_BUSY); @@ -463,8 +464,8 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest024, TestSize.Level1) const char *filter = "{\"_id\" : \"6\"}"; GRD_ResultSet *resultSet = nullptr; GRD_ResultSet *resultSet2 = nullptr; - Query query = {filter, "{}"}; - const char* collectionName = "DocumentFindApiTest024"; + Query query = { filter, "{}" }; + const char *collectionName = "DocumentFindApiTest024"; EXPECT_EQ(GRD_CreateCollection(g_db, collectionName, "", 0), GRD_OK); InsertData(g_db, collectionName); EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); @@ -511,7 +512,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest025, TestSize.Level1) const char *projectionInfo = "{\"name\": true, \"nested1.nested2.nested3.nested4\":true}"; const char *targetDocument = "{\"name\":\"doc16\", \"nested1\":{\"nested2\":{\"nested3\":\ {\"nested4\":\"ABC\"}}}}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -531,7 +532,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest025, TestSize.Level1) * @tc.expected: step3. succeed to get the record. */ projectionInfo = "{\"name\": true, \"nested1\":{\"nested2\":{\"nested3\":{\"nested4\":true}}}}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -550,7 +551,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest025, TestSize.Level1) */ projectionInfo = "{\"name\": 0, \"nested1.nested2.nested3.nested4\":0}"; targetDocument = "{\"nested1\":{\"nested2\":{\"nested3\":{\"field2\":\"CCC\"}}}}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -576,7 +577,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest026, TestSize.Level1) const char *filter = "{\"_id\" : \"16\"}"; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"name\": true, \"nested1.nested2.nested3.nested4.nested5\":true}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; //EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); // EXPECT_EQ(GRD_Next(resultSet), GRD_INVALID_ARGS); // char *value = nullptr; @@ -608,7 +609,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest027, TestSize.Level1) const char *projectionInfo = "{\"name\": true, \"other_Info\":true, \"non_exist_field\":true}"; const char *targetDocument = "{\"name\": \"doc7\", \"other_Info\":[{\"school\":\"BX\", \"age\":15},\ {\"school\":\"C\", \"age\":35}]}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -616,14 +617,14 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest027, TestSize.Level1) CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - + /** * @tc.steps: step2. Create filter to match g_document7, _id flag is 0. * Create projection to display name, other _info and existing field with space. * @tc.expected: step2. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\": true, \"other_Info\":true, \" item \":true}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -632,7 +633,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest027, TestSize.Level1) * @tc.expected: step3. Match the g_document7 and display name, other_Info. */ projectionInfo = "{\"name\": true, \"other_Info\":true, \"ITEM\": true}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; resultSet = nullptr; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); @@ -660,7 +661,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest028, TestSize.Level1) GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"name\": true, \"other_Info.non_exist_field\":true}"; const char *targetDocument = "{\"name\": \"doc7\"}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -668,14 +669,14 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest028, TestSize.Level1) CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - + /** * @tc.steps: step2. Create filter to match g_document7, _id flag is 0. * Create projection to display name, other _info and existing field with space. * @tc.expected: step2. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\": true, \"other_Info\":{\"non_exist_field\":true}}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; resultSet = nullptr; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); @@ -690,7 +691,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest028, TestSize.Level1) * @tc.expected: step3. Match the g_document7 and display name, other_Info. */ projectionInfo = "{\"name\": true, \"other_Info.0\": true}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; resultSet = nullptr; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_INVALID_ARGS); @@ -713,7 +714,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest029, TestSize.Level1) const char *filter = "{\"_id\" : \"4\"}"; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"personInfo\": true, \"personInfo.grade\": true}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); } @@ -735,7 +736,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) const char *projectionInfo = "{\"non_exist_field\":true}"; int flag = 0; const char *targetDocument = "{}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -743,7 +744,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - + /** * @tc.steps: step2. Create filter to match g_document7, _id flag is 1. * @tc.expected: step2. Match g_document7, and return a json with _id. @@ -751,7 +752,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) resultSet = nullptr; flag = 1; targetDocument = "{\"_id\": \"7\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); value = NULL; @@ -779,7 +780,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) const char *projectionInfo = "{\"name\":true, \"item\":true}"; int flag = 0; const char *targetDocument = "{\"name\":\"doc7\", \"item\":\"fruit\"}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -787,7 +788,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - + /** * @tc.steps: step2. Create filter to match g_document7, _id flag is 1. * @tc.expected: step2. Match g_document7, and return a json with _id. @@ -796,7 +797,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) flag = 1; projectionInfo = "{\"name\": 1, \"item\": 1}"; targetDocument = "{\"_id\":\"7\", \"name\":\"doc7\", \"item\":\"fruit\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); value = NULL; @@ -824,7 +825,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) const char *projectionInfo = "{\"name\":true, \"item\":true}"; int flag = 0; const char *targetDocument = "{\"name\":\"doc7\", \"item\":\"fruit\"}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -840,7 +841,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) flag = 1; projectionInfo = "{\"name\": 1, \"item\": 1}"; targetDocument = "{\"_id\":\"7\", \"name\":\"doc7\", \"item\":\"fruit\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); value = NULL; @@ -856,7 +857,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) flag = 1; projectionInfo = "{\"name\": 10, \"item\": 10}"; targetDocument = "{\"_id\":\"7\", \"name\":\"doc7\", \"item\":\"fruit\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); value = NULL; @@ -883,8 +884,10 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"name\":false, \"item\":false}"; int flag = 0; - const char *targetDocument = "{\"other_Info\":[{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}";; - Query query = {filter, projectionInfo}; + const char *targetDocument = "{\"other_Info\":[{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : " + "35}]}"; + ; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -899,8 +902,10 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) resultSet = nullptr; flag = 1; projectionInfo = "{\"name\": 0, \"item\": 0}"; - targetDocument = "{\"_id\": \"7\", \"other_Info\":[{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}";; - query = {filter, projectionInfo}; + targetDocument = "{\"_id\": \"7\", \"other_Info\":[{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" " + ": 35}]}"; + ; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); value = NULL; @@ -929,7 +934,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) \"personInfo.shool1\": 1, \"personInfo.age1\": 1}"; int flag = 0; const char *targetDocument = "{\"name\":\"doc4\"}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -944,8 +949,9 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) */ projectionInfo = "{\"name\": false, \"personInfo.grade1\": false, \ \"personInfo.shool1\": false, \"personInfo.age1\": false}"; - const char *targetDocument2 = "{\"item\":\"paper\",\"personInfo\":{\"grade\" : 1, \"school\":\"A\", \"age\" : 18}}"; - query = {filter, projectionInfo}; + const char *targetDocument2 = "{\"item\":\"paper\",\"personInfo\":{\"grade\" : 1, \"school\":\"A\", \"age\" : " + "18}}"; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -959,7 +965,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) */ projectionInfo = "{\"name\": 1, \"personInfo.school\": 1, \"personInfo.age\": 1}"; const char *targetDocument3 = "{\"name\":\"doc4\", \"personInfo\": {\"school\":\"A\", \"age\" : 18}}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -973,7 +979,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) */ projectionInfo = "{\"name\": 1, \"personInfo.school\": 1, \"personInfo.age1\": 1}"; const char *targetDocument4 = "{\"name\":\"doc4\", \"personInfo\": {\"school\":\"A\"}}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -998,7 +1004,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest035, TestSize.Level1) const char *filter = "{\"_id\" : \"17\"}"; GRD_ResultSet *resultSet = nullptr; int flag = 0; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, GRD_DOC_ID_DISPLAY, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -1030,7 +1036,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest036, TestSize.Level1) const char *filter = "{\"_id\" : \"17\"}"; GRD_ResultSet *resultSet = nullptr; int flag = 0; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, "", query, 0, &resultSet), GRD_INVALID_ARGS); EXPECT_EQ(GRD_FindDoc(g_db, NULL, query, 0, &resultSet), GRD_INVALID_ARGS); } @@ -1051,7 +1057,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) const char *filter = "{\"_id\" : \"4\"}"; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"name\":1, \"personInfo\":0, \"item\":1}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -1059,7 +1065,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step2. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":2, \"personInfo\":0, \"item\":2}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -1067,7 +1073,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step3. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":true, \"personInfo\":0, \"item\":true}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -1075,7 +1081,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step4. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":\"\", \"personInfo\":0, \"item\":\"\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -1083,7 +1089,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step5. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":1, \"item\":false"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); /** @@ -1091,7 +1097,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step6. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":-1.123, \"item\":false"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); /** @@ -1099,7 +1105,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) * @tc.expected: step7. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":true, \"item\":false"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); } @@ -1121,7 +1127,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest038, TestSize.Level1) const char *projectionInfo = "{\"name\":false, \"personInfo\": 0, \"item\":0}"; int flag = 0; const char *targetDocument = "{}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -1135,7 +1141,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest038, TestSize.Level1) * @tc.expected: step2. Match g_document6, Return json with _id. */ targetDocument = "{\"_id\": \"6\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -1159,11 +1165,12 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest039, TestSize.Level1) */ const char *filter = "{\"_id\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; - const char *projectionInfo = "{\"name\":true, \"personInfo.age\": \"\", \"item\":1, \"color\":10, \"nonExist\" : -100}"; + const char *projectionInfo = "{\"name\":true, \"personInfo.age\": \"\", \"item\":1, \"color\":10, \"nonExist\" : " + "-100}"; const char *targetDocument = "{\"name\":\"doc18\", \"item\":\"mobile phone\", \"personInfo\":\ {\"age\":66}, \"color\":\"blue\"}"; int flag = 0; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); char *value = nullptr; @@ -1178,7 +1185,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest039, TestSize.Level1) */ targetDocument = "{\"_id\" : \"18\", \"name\":\"doc18\",\"item\" : \"mobile phone\",\"personInfo\":\ {\"age\":66}, \"color\":\"blue\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); @@ -1204,7 +1211,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest040, TestSize.Level1) GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{\"personInfo\":[true, 1]}"; int flag = 1; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_INVALID_ARGS); /** @@ -1212,7 +1219,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest040, TestSize.Level1) * @tc.expected: step2. Match the g_document18 and return GRD_INVALID_ARGS. */ projectionInfo = "{\"personInfo\":null}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_INVALID_ARGS); /** @@ -1220,7 +1227,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest040, TestSize.Level1) * @tc.expected: step3. Match the g_document18 and return GRD_INVALID_ARGS. */ projectionInfo = "{\"personInfo\":\"invalid string.\"}"; - query = {filter, projectionInfo}; + query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_INVALID_ARGS); } @@ -1239,9 +1246,10 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest042, TestSize.Level1) */ const char *filter = "{\"_iD\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; - const char *projectionInfo = "{\"Name\":true, \"personInfo.age\": \"\", \"item\":1, \"COLOR\":10, \"nonExist\" : -100}"; + const char *projectionInfo = "{\"Name\":true, \"personInfo.age\": \"\", \"item\":1, \"COLOR\":10, \"nonExist\" : " + "-100}"; int flag = 0; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, flag, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); @@ -1249,10 +1257,10 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest042, TestSize.Level1) * @tc.steps: step2. Test field with upper projection. * @tc.expected: step2. Match g_document18, Return json with item, personInfo.age, color and _id. */ - const char *filter1 = "{\"_id\" : \"18\"}"; - const char* targetDocument = "{\"_id\" : \"18\", \"item\" : \"mobile phone\",\"personInfo\":\ + const char *filter1 = "{\"_id\" : \"18\"}"; + const char *targetDocument = "{\"_id\" : \"18\", \"item\" : \"mobile phone\",\"personInfo\":\ {\"age\":66}}"; - query = {filter1, projectionInfo}; + query = { filter1, projectionInfo }; char *value = nullptr; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); @@ -1283,7 +1291,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest044, TestSize.Level1) const char *targetDocument = "{\"_id\" : \"18\", \"name\":\"doc18\", \"personInfo\":\ {\"school\":\"DD\"}, \"color\":\"blue\"}"; int flag = 0; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; char *value = nullptr; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); @@ -1310,7 +1318,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest045, TestSize.Level1) const char *filter = "{\"_id\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; int flag = 0; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; string collectionName1(MAX_COLLECTION_NAME, 'a'); ASSERT_EQ(GRD_CreateCollection(g_db, collectionName1.c_str(), "", 0), GRD_OK); EXPECT_EQ(GRD_FindDoc(g_db, collectionName1.c_str(), query, 1, &resultSet), GRD_OK); @@ -1338,7 +1346,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest052, TestSize.Level1) const char *filter = "{\"_id\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; int flag = 0; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; string collectionName1(MAX_COLLECTION_NAME, 'a'); ASSERT_EQ(GRD_CreateCollection(g_db, collectionName1.c_str(), "", 0), GRD_OK); EXPECT_EQ(GRD_FindDoc(g_db, collectionName1.c_str(), query, 1, &resultSet), GRD_OK); @@ -1366,7 +1374,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest053, TestSize.Level1) const char *filter = "{\"_id\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 3, &resultSet), GRD_INVALID_ARGS); /** @@ -1398,7 +1406,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest054, TestSize.Level1) const char *filter = "{\"_id\" : \"18\"}"; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{}"; - Query query = {filter, projectionInfo}; + Query query = { filter, projectionInfo }; EXPECT_EQ(GRD_FindDoc(nullptr, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** @@ -1411,7 +1419,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest054, TestSize.Level1) * @tc.steps: step1. Test with query that has two nullptr data. * @tc.expected: step1. Return GRD_INVALID_ARGS. */ - query = {nullptr, nullptr}; + query = { nullptr, nullptr }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); } @@ -1428,7 +1436,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest055, TestSize.Level1) * @tc.steps:step1.Find doc, but filter' _id value lens is larger than MAX_ID_LENS * @tc.expected:step1.GRD_OVER_LIMIT. */ - string document1 = "{\"_id\" : "; + string document1 = "{\"_id\" : "; string document2 = "\""; string document4 = "\""; string document5 = "}"; @@ -1436,7 +1444,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest055, TestSize.Level1) string filter = document1 + document2 + document_midlle + document4 + document5; GRD_ResultSet *resultSet = nullptr; const char *projectionInfo = "{}"; - Query query = {filter.c_str(), projectionInfo}; + Query query = { filter.c_str(), projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OVER_LIMIT); /** @@ -1445,9 +1453,9 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest055, TestSize.Level1) */ string document_midlle2(MAX_ID_LENS, 'k'); filter = document1 + document2 + document_midlle2 + document4 + document5; - query = {filter.c_str(), projectionInfo}; + query = { filter.c_str(), projectionInfo }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); - EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } /** @@ -1465,7 +1473,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) */ const char *filter = "{\"personInfo\" : {\"school\":\"B\"}}"; GRD_ResultSet *resultSet = nullptr; - Query query = {filter, "{}"}; + Query query = { filter, "{}" }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); @@ -1481,7 +1489,6 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } - /** * @tc.name: DocumentFindApiTest056 * @tc.desc: Test findDoc with no _id. @@ -1498,7 +1505,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest057, TestSize.Level1) const char *filter = "{\"personInfo\" : {\"school\":\"B\"}}"; GRD_ResultSet *resultSet = nullptr; const char *projection = "{\"version\": 1}"; - Query query = {filter, projection}; + Query query = { filter, projection }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp index 0dd1a43c116b3e434aec86f3d6fb6fa5de414420..fc489a730f41189eb0fda753f64441eff93def90 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp @@ -16,8 +16,8 @@ #include #include "grd_base/grd_db_api.h" -#include "grd_document/grd_document_api.h" #include "grd_base/grd_error.h" +#include "grd_document/grd_document_api.h" using namespace testing::ext; namespace { @@ -32,33 +32,33 @@ const int MAX_ID_LENS = 899; static void TestInsertDocIntoCertainColl(const char *collectionName, const char *projection, int expectedResult) { - /** * @tc.steps: step1. Create Collection + /** * @tc.steps: step1. Create Collection * @tc.expected: step1. GRD_OK */ - EXPECT_EQ(GRD_CreateCollection(g_db, collectionName, "", 0), expectedResult); - /** + EXPECT_EQ(GRD_CreateCollection(g_db, collectionName, "", 0), expectedResult); + /** * @tc.steps: step2. Insert projection into colloction. * @tc.expected: step2. GRD_OK */ - EXPECT_EQ(GRD_InsertDoc(g_db, collectionName, projection, 0), expectedResult); - /** + EXPECT_EQ(GRD_InsertDoc(g_db, collectionName, projection, 0), expectedResult); + /** * @tc.steps: step3. Call GRD_DroCollection to drop the collection. * @tc.expected: step3. GRD_OK */ - EXPECT_EQ(GRD_DropCollection(g_db, collectionName, 0), expectedResult); + EXPECT_EQ(GRD_DropCollection(g_db, collectionName, 0), expectedResult); } -const char* SetRandomDocument(int i) +const char *SetRandomDocument(int i) { - string document1 = "{\"_id\" : "; + string document1 = "{\"_id\" : "; string document2 = "\""; - string document3 = {'2','6'}; + string document3 = { '2', '6' }; string document4 = "\""; string document5 = ", \"name\" : \"Ori\"}"; string document = document1 + document2 + document3 + document4 + document5; return document.c_str(); } -} +} // namespace class DocumentInsertApiTest : public testing::Test { public: @@ -82,14 +82,9 @@ void DocumentInsertApiTest::TearDownTestCase(void) remove(path.c_str()); } -void DocumentInsertApiTest::SetUp(void) -{ -} - -void DocumentInsertApiTest::TearDown(void) -{ -} +void DocumentInsertApiTest::SetUp(void) {} +void DocumentInsertApiTest::TearDown(void) {} /** * @tc.name: DocumentInsertApiTest001 @@ -104,7 +99,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest001, TestSize.Level1) * @tc.steps:step1.Insert document into collection which dose not exist * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"1\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"1\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, NO_EXIST_COLLECTION_NAME, document1, 0), GRD_INVALID_ARGS); } @@ -121,35 +116,34 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest002, TestSize.Level1) * @tc.steps:step1.Insert a document whose _id is integer * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : 2, \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : 2, \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_INVALID_ARGS); /** * @tc.steps:step2.Insert a document whose _id is bool * @tc.expected:step2.GRD_INVALID_ARGS */ - const char *document2 = "{\"_id\" : true, \"name\" : \"Chuan\"}"; + const char *document2 = "{\"_id\" : true, \"name\" : \"Chuan\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_INVALID_ARGS); /** * @tc.steps:step2.Insert a document whose _id is NULL * @tc.expected:step2.GRD_INVALID_ARGS */ - const char *document3 = "{\"_id\" : null, \"name\" : \"Chuan\"}"; + const char *document3 = "{\"_id\" : null, \"name\" : \"Chuan\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document3, 0), GRD_INVALID_ARGS); /** * @tc.steps:step2.Insert a document whose _id is ARRAY * @tc.expected:step2.GRD_INVALID_ARGS */ - const char *document4 = "{\"_id\" : [\"2\"], \"name\" : \"Chuan\"}"; + const char *document4 = "{\"_id\" : [\"2\"], \"name\" : \"Chuan\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document4, 0), GRD_INVALID_ARGS); /** * @tc.steps:step2.Insert a document whose _id is OBJECT * @tc.expected:step2.GRD_INVALID_ARGS */ - const char *document5 = "{\"_id\" : {\"val\" : \"2\"}, \"name\" : \"Chuan\"}"; + const char *document5 = "{\"_id\" : {\"val\" : \"2\"}, \"name\" : \"Chuan\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document5, 0), GRD_INVALID_ARGS); } - /** * @tc.name: DocumentInsertApiTest003 * @tc.desc: Insert a document whose _id has appeared before @@ -163,7 +157,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest003, TestSize.Level1) * @tc.steps:step1.Insert a document whose _id is string * @tc.expected:step1.GRD_OK */ - const char *document1 = "{\"_id\" : \"3\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"3\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); /** @@ -187,7 +181,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest004, TestSize.Level1) * @tc.steps:step1.step1.parameter db is NULL * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"4\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"4\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(NULL, RIGHT_COLLECTION_NAME, document1, 0), GRD_INVALID_ARGS); } @@ -204,13 +198,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest005, TestSize.Level1) * @tc.steps:step1.Parameter collectionName is NULL * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"5\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"5\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, NULL, document1, 0), GRD_INVALID_ARGS); /** * @tc.steps:step2.Parameter collectionName is empty string * @tc.expected:step2.GRD_INVALID_ARGS */ - const char *document2 = "{\"_id\" : \"5\", \"name\" : \"Chuang\"}"; + const char *document2 = "{\"_id\" : \"5\", \"name\" : \"Chuang\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, "", document2, 0), GRD_INVALID_ARGS); } @@ -227,7 +221,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest006, TestSize.Level1) * @tc.steps:step1.parameter flags is not zero * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"6\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"6\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 1), GRD_INVALID_ARGS); } @@ -244,7 +238,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest007, TestSize.Level1) * @tc.steps:step1.parameter flags is int_max * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"7\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"7\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, INT_MAX), GRD_INVALID_ARGS); } @@ -261,7 +255,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest008, TestSize.Level1) * @tc.steps:step1.parameter flags is int_min * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"_id\" : \"8\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"8\", \"name\" : \"Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, INT_MIN), GRD_INVALID_ARGS); } @@ -283,9 +277,9 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest009, TestSize.Level1) * @tc.steps:step2.parameter collectionName is larger than max_collectionName_lens; * @tc.expected:step2.GRD_OVER_LIMIT */ - const char *document1 = "{\"_id\" : \"9\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"9\", \"name\" : \"Ori\"}"; std::string collectionName2(MAX_COLLECTION_LENS + 1, 'a'); - EXPECT_EQ(GRD_InsertDoc(g_db, collectionName2.c_str(), document1, 0), GRD_OVER_LIMIT); + EXPECT_EQ(GRD_InsertDoc(g_db, collectionName2.c_str(), document1, 0), GRD_OVER_LIMIT); } /** @@ -302,7 +296,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest010, TestSize.Level1) * @tc.expected:step1.GRD_OK */ const char *collectionName = "collction@!#"; - const char *document1 = "{\"_id\" : \"10\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"10\", \"name\" : \"Ori\"}"; TestInsertDocIntoCertainColl(collectionName, document1, GRD_OK); } @@ -320,7 +314,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest011, TestSize.Level1) * @tc.expected:step1.GRD_OK */ string collectionName(257, 'k'); - const char *document1 = "{\"_id\" : \"10\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"10\", \"name\" : \"Ori\"}"; TestInsertDocIntoCertainColl(collectionName.c_str(), document1, GRD_OK); } @@ -337,7 +331,8 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest014, TestSize.Level1) * @tc.steps:step1.document's JSON depth is larger than 4, which is 5. * @tc.expected:step1.GRD_INVALID_ARGS */ - const char *document1 = "{\"level1\" : {\"level2\" : {\"level3\" : {\"level4\": {\"level5\" : 1}}, \"level3_2\" : \"level3_2_val\"\ + const char *document1 = + "{\"level1\" : {\"level2\" : {\"level3\" : {\"level4\": {\"level5\" : 1}}, \"level3_2\" : \"level3_2_val\"\ }},\"_id\":\"14\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_INVALID_ARGS); /** @@ -352,7 +347,8 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest014, TestSize.Level1) * @tc.steps:step1.document's JSON depth is 4 * @tc.expected:step1.GRD_OK */ - const char *document3 = "{\"level1\" : {\"level2\" : {\"level3\" : { \"level4\" : \"level5_1val\"}, \"level3_2\" : \"level3_2_val\"\ + const char *document3 = + "{\"level1\" : {\"level2\" : {\"level3\" : { \"level4\" : \"level5_1val\"}, \"level3_2\" : \"level3_2_val\"\ }},\"_id\":\"14\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document3, 0), GRD_OK); } @@ -397,7 +393,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest016, TestSize.Level1) * @tc.steps:step1.document JSON string contains irregular char. * @tc.expected:step1.GRD_OK */ - const char *document1 = "{\"_id\" : \"16\", \"name\" : \"!@#Ori\"}"; + const char *document1 = "{\"_id\" : \"16\", \"name\" : \"!@#Ori\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); } @@ -449,7 +445,8 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest019, TestSize.Level1) * @tc.steps:step1.Insert a normal documents which _id is in the end of the string * @tc.expected:step1.GRD_OK. */ - const char *document1 = "{\"name\" : \"Jack\", \"age\" : 18, \"friend\" : {\"name\" : \" lucy\"}, \"_id\" : \"19\"}"; + const char *document1 = "{\"name\" : \"Jack\", \"age\" : 18, \"friend\" : {\"name\" : \" lucy\"}, \"_id\" : " + "\"19\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); } @@ -468,7 +465,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest022, TestSize.Level1) */ string collectionName = string(256, 'k'); string collectionName1(MAX_COLLECTION_LENS, 'a'); - const char *document1 = "{\"_id\" : \"22\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"22\", \"name\" : \"Ori\"}"; TestInsertDocIntoCertainColl(collectionName.c_str(), document1, GRD_OK); } @@ -488,7 +485,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest023, TestSize.Level1) * @tc.expected:step1.GRD_OK. */ string collectionName = "Aads_sd__23Asb_"; - const char *document1 = "{\"_id\" : \"23\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"23\", \"name\" : \"Ori\"}"; TestInsertDocIntoCertainColl(collectionName.c_str(), document1, GRD_OK); } @@ -507,7 +504,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step1.GRD_INVALID_FORMAT. */ string collectionName = "GRD_collectionName"; - const char *document1 = "{\"_id\" : \"24\", \"name\" : \"Ori\"}"; + const char *document1 = "{\"_id\" : \"24\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document1, 0), GRD_INVALID_FORMAT); @@ -516,7 +513,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step2.GRD_INVALID_FORMAT. */ collectionName = "GM_SYS__collectionName"; - const char *document2 = "{\"_id\" : \"24_2\", \"name\" : \"Ori\"}"; + const char *document2 = "{\"_id\" : \"24_2\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document2, 0), GRD_INVALID_FORMAT); @@ -525,7 +522,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step3.GRD_INVALID_FORMAT. */ collectionName = "grd_collectionName"; - const char *document3 = "{\"_id\" : \"24_3\", \"name\" : \"Ori\"}"; + const char *document3 = "{\"_id\" : \"24_3\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document3, 0), GRD_INVALID_FORMAT); @@ -534,7 +531,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step4.GRD_INVALID_FORMAT. */ collectionName = "gm_sys_collectionName"; - const char *document4 = "{\"_id\" : \"24_4\", \"name\" : \"Ori\"}"; + const char *document4 = "{\"_id\" : \"24_4\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document4, 0), GRD_INVALID_FORMAT); @@ -543,7 +540,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step5.GRD_INVALID_FORMAT. */ collectionName = "gM_sYs_collectionName"; - const char *document5 = "{\"_id\" : \"24_5\", \"name\" : \"Ori\"}"; + const char *document5 = "{\"_id\" : \"24_5\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document5, 0), GRD_INVALID_FORMAT); @@ -552,7 +549,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step6.GRD_INVALID_FORMAT. */ collectionName = "gRd_collectionName"; - const char *document6 = "{\"_id\" : \"24_6\", \"name\" : \"Ori\"}"; + const char *document6 = "{\"_id\" : \"24_6\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document6, 0), GRD_INVALID_FORMAT); @@ -561,7 +558,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) * @tc.expected:step7.GRD_INVALID_FORMAT. */ collectionName = "gRd@collectionName"; - const char *document7 = "{\"_id\" : \"24_7\", \"name\" : \"Ori\"}"; + const char *document7 = "{\"_id\" : \"24_7\", \"name\" : \"Ori\"}"; GRD_CreateCollection(g_db, collectionName.c_str(), "", 0); EXPECT_EQ(GRD_InsertDoc(g_db, collectionName.c_str(), document7, 0), GRD_OK); } @@ -586,21 +583,24 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest025, TestSize.Level1) * @tc.steps:step2.documents JSON depth is exactly 4. * @tc.expected:step2.GRD_OK. */ - const char *document2 = "{\"_id\" : \"25_1\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ + const char *document2 = + "{\"_id\" : \"25_1\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ \"age\" : 18, \"sex\" : \"男\"}, { \"newName1\" : [\"qw\", \"dr\", 0, \"ab\"] }]}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_OK); /** * @tc.steps:step3.documents JSON depth is exactly 4, but the last field in array contains leading number * @tc.expected:step3.GRD_INVALID_ARGS. */ - const char *document3 = "{\"_id\" : \"25_2\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ + const char *document3 = + "{\"_id\" : \"25_2\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ \"age\" : 18, \"sex\" : \"男\"}, [\"qw\", \"dr\", 0, \"ab\", {\"0ab\" : null}]]}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document3, 0), GRD_INVALID_ARGS); /** * @tc.steps:step4.documents JSON depth is exactly 5. * @tc.expected:step4.GRD_INVALID_ARGS. */ - const char *document4 = "{\"_id\" : \"25_3\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ + const char *document4 = + "{\"_id\" : \"25_3\", \"class_name\" : \"计算机科学一班\", \"signed_info\" : true, \"student_info\" : [{\"name\":\"张三\", \ \"age\" : 18, \"sex\" : \"男\"}, { \"newName1\" : [\"qw\", \"dr\", 0, \"ab\", {\"level5\" : 1}] }]}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document4, 0), GRD_INVALID_ARGS); } @@ -618,14 +618,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest, TestSize.Level1) * @tc.steps:step1.Insert 100 normal documents continuously * @tc.expected:step1.GRD_OK. */ - string document1 = "{\"_id\" : "; + string document1 = "{\"_id\" : "; string document2 = "\""; string document4 = "\""; string document5 = ", \"name\" : \"Ori\"}"; for (int i = 0; i < 5; i++) { - string document_midlle = "26" + std::to_string(i); - string document = document1 + document2 + document_midlle + document4 + document5; - EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document.c_str(), 0), GRD_OK); + string document_midlle = "26" + std::to_string(i); + string document = document1 + document2 + document_midlle + document4 + document5; + EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document.c_str(), 0), GRD_OK); } } @@ -716,7 +716,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest038, TestSize.Level1) */ const char *document5 = R"({"_id" : "38_4", "t1" : [1, 2, -1.79769313486231570E+308]})"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document5, 0), GRD_OK); - /** + /** * @tc.steps:step6.Insert document with maxium double value * @tc.expected:step6.GRD_INVALID_ARGS. */ @@ -737,7 +737,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest039, TestSize.Level1) * @tc.steps:step1.Insert a filter which _id value's lens is larger than MAX_ID_LENS. * @tc.expected:step1.GRD_OVER_LIMIT. */ - string document1 = "{\"_id\" : "; + string document1 = "{\"_id\" : "; string document2 = "\""; string document4 = "\""; string document5 = ", \"name\" : \"Ori\"}"; @@ -763,13 +763,12 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest039, TestSize.Level1) */ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest040, TestSize.Level1) { - const char *filter ="{\"_id\" : \"1\"}"; + const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"objectInfo.child.child.level.extra\" : {\"hasChild\" : true}}"; const char *updata2 = "{\"objectInfo.child.child\" : {\"child\":{\"child\":null}}}"; EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata2, 0), GRD_INVALID_ARGS); } - /** * @tc.name: DocumentUpdataApiTest041 * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS @@ -779,7 +778,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest040, TestSize.Level1) */ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest041, TestSize.Level1) { - const char *filter ="{\"_id\" : \"1\"}"; + const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"_id\" : \"6\"}"; EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata1, 0), GRD_INVALID_ARGS); } @@ -793,7 +792,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest041, TestSize.Level1) */ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest042, TestSize.Level1) { - const char *filter ="{\"_id\" : \"1\"}"; + const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"age$\" : \"21\"}"; const char *updata2 = "{\"bonus..traffic\" : 100}"; const char *updata3 = "{\"0item\" : 100}"; @@ -813,7 +812,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest042, TestSize.Level1) */ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest043, TestSize.Level1) { - const char *filter ="{\"_id\" : \"1\"}"; + const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"age\" : 21}"; const char *updata2 = "{\"bonus..traffic\" : 100}"; EXPECT_EQ(GRD_UpdateDoc(g_db, NULL, filter, updata1, 0), GRD_INVALID_ARGS); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_test_utils.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_test_utils.h index a513875ef87a922f39132229a2e9e620f2bda17c..b1dc3f516b59db00e5cd2cf3643e631ecece1eb8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_test_utils.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_test_utils.h @@ -17,7 +17,6 @@ #define DOCUMENTDB_TEST_UTILS_H #include - namespace DocumentDBUnitTest { class DocumentDBTestUtils { public: diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.h index a513875ef87a922f39132229a2e9e620f2bda17c..b1dc3f516b59db00e5cd2cf3643e631ecece1eb8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/common/documentdb_test_utils.h @@ -17,7 +17,6 @@ #define DOCUMENTDB_TEST_UTILS_H #include - namespace DocumentDBUnitTest { class DocumentDBTestUtils { public: diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp index f83891b930b58721faab36cde66731c5a974a9cd..e2c64b68511dea9606129b4c57082bc0605d0a34 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -16,8 +16,8 @@ #include #include -#include "documentdb_test_utils.h" #include "doc_errno.h" +#include "documentdb_test_utils.h" #include "json_common.h" #include "log_print.h" @@ -33,21 +33,13 @@ public: void TearDown(); }; -void DocumentDBJsonCommonTest::SetUpTestCase(void) -{ -} +void DocumentDBJsonCommonTest::SetUpTestCase(void) {} -void DocumentDBJsonCommonTest::TearDownTestCase(void) -{ -} +void DocumentDBJsonCommonTest::TearDownTestCase(void) {} -void DocumentDBJsonCommonTest::SetUp(void) -{ -} +void DocumentDBJsonCommonTest::SetUp(void) {} -void DocumentDBJsonCommonTest::TearDown(void) -{ -} +void DocumentDBJsonCommonTest::TearDown(void) {} /** * @tc.name: OpenDBTest001 @@ -59,7 +51,8 @@ void DocumentDBJsonCommonTest::TearDown(void) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) { std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; - std::string updateDoc = R""({"name":"Xue","case":{"field1":1,"field2":"string","field3":[1,2,3]},"age":28,"addr":{"city":"shenzhen","postal":518000}})""; + std::string updateDoc = + R""({"name":"Xue","case":{"field1":1,"field2":"string","field3":[1,2,3]},"age":28,"addr":{"city":"shenzhen","postal":518000}})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -70,11 +63,11 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"case", "field1"}, errCode); + JsonObject itemCase = src.FindItem({ "case", "field1" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 1); - JsonObject itemName = src.FindItem({"name"}, errCode); + JsonObject itemName = src.FindItem({ "name" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Xue"); } @@ -93,20 +86,21 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"grade"}, errCode); + JsonObject itemCase = src.FindItem({ "grade" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 99); // 99: grade - JsonObject itemName = src.FindItem({"name", "1"}, errCode); + JsonObject itemName = src.FindItem({ "name", "1" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); } - HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) { - std::string document = R""({"name":["Tmn","BB","Alice"],"age":[1,2,3],"addr":[{"city":"shanghai","postal":200001},{"city":"wuhan","postal":430000}]})""; - std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"age":18,"addr":[{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; + std::string document = + R""({"name":["Tmn","BB","Alice"],"age":[1,2,3],"addr":[{"city":"shanghai","postal":200001},{"city":"wuhan","postal":430000}]})""; + std::string updateDoc = + R""({"name":["Xue","Neco","Lip"],"age":18,"addr":[{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -116,11 +110,11 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"addr", "1", "city"}, errCode); + JsonObject itemCase = src.FindItem({ "addr", "1", "city" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "beijing"); // 99: grade - JsonObject itemName = src.FindItem({"name", "1"}, errCode); + JsonObject itemName = src.FindItem({ "name", "1" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); } @@ -128,7 +122,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.5":"GG"})"";; + std::string updateDoc = R""({"name.5":"GG"})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -142,7 +137,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.2":"GG"})"";; + std::string updateDoc = R""({"name.2":"GG"})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -153,7 +149,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "2"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "2" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); } @@ -172,7 +168,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "midle.AA"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "midle.AA" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); } @@ -191,7 +187,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "first", "0" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "LL"); } @@ -210,12 +206,11 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest008, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "first", "0" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XXX"); } - HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest009, TestSize.Level0) { std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; @@ -230,7 +225,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest009, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "first"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "first" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XX"); } @@ -249,7 +244,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest010, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "first", "XX"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "first", "XX" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "AA"); } @@ -272,7 +267,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest011, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest012, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.first":"GG"})"";; + std::string updateDoc = R""({"name.first":"GG"})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -286,7 +282,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest012, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name":{"first":"GG"}})"";; + std::string updateDoc = R""({"name":{"first":"GG"}})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -300,7 +297,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) { std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.0":"GG"})"";; + std::string updateDoc = R""({"name.0":"GG"})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -314,7 +312,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) { std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.first":["GG","MM"]})"";; + std::string updateDoc = R""({"name.first":["GG","MM"]})""; + ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -324,7 +323,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); + JsonObject itemCase = src.FindItem({ "name", "first", "0" }, errCode); EXPECT_EQ(errCode, E_OK); EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); } @@ -350,8 +349,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest001, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest002, TestSize.Level0) { - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"instock": {"warehouse":"A", "qty":5}})"";; + std::string document = + R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"instock": {"warehouse":"A", "qty":5}})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -361,8 +362,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest002, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest003, TestSize.Level0) { - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": "GG"})"";; + std::string document = + R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item": "GG"})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -372,8 +375,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest003, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest004, TestSize.Level0) { - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": "GG"})"";; + std::string document = + R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item": "GG"})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -383,8 +388,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest004, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest005, TestSize.Level0) { - std::string document = R""({"item": ["GG", "AA"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": ["GG", "AA"]})"";; + std::string document = + R""({"item": ["GG", "AA"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item": ["GG", "AA"]})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -394,8 +401,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest005, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest006, TestSize.Level0) { - std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item.0": "GG"})"";; + std::string document = + R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item.0": "GG"})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -405,8 +414,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest006, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest007, TestSize.Level0) { - std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": ["GG", {"gender":"girl"}]})"";; + std::string document = + R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item": ["GG", {"gender":"girl"}]})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -416,8 +427,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest007, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest008, TestSize.Level0) { - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": {"gender":"girl"}})"";; + std::string document = + R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; + std::string filter = R""({"item": {"gender":"girl"}})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -427,9 +440,11 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest008, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest009, TestSize.Level0) { - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"qty" : 16, "warehouse":"A"}, + std::string document = + R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"qty" : 16, "warehouse":"A"}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"instock.warehouse": "A"})"";; + std::string filter = R""({"instock.warehouse": "A"})""; + ; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); @@ -439,7 +454,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest009, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest010, TestSize.Level0) { - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A"}, + std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A"}, {"warehouse":"C", "qty":15}]})""; std::string filter = R""({"instock.warehouse": "C"})""; int errCode = E_OK; @@ -451,7 +466,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest010, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest011, TestSize.Level0) { - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; + std::string document = + R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; std::string filter = R""({"instock" : {"warehose" : "A", "qty" : 5}})""; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); @@ -462,7 +478,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest011, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest012, TestSize.Level0) { - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; + std::string document = + R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; std::string filter = R""({"instock" : {"warehose" : "A", "bad" : "2" ,"qty" : 5}})""; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); @@ -473,7 +490,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest012, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest013, TestSize.Level0) { - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; + std::string document = + R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; std::string filter = R""({"instock.qty" : 15})""; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); @@ -484,7 +502,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest013, TestSize.Leve HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest014, TestSize.Level0) { - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; + std::string document = + R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; std::string filter = R""({"instock.1.qty" : 15})""; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp index fa16a27a019fc874f28bff8beef2a4bc71208ffa..b9ce2849469a1cf45ef3192f7673a2a97ce06641 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp @@ -14,8 +14,9 @@ */ #include -#include "documentdb_test_utils.h" + #include "doc_errno.h" +#include "documentdb_test_utils.h" #include "json_object.h" using namespace DocumentDB; @@ -30,21 +31,13 @@ public: void TearDown(); }; -void DocumentDBJsonObjectTest::SetUpTestCase(void) -{ -} +void DocumentDBJsonObjectTest::SetUpTestCase(void) {} -void DocumentDBJsonObjectTest::TearDownTestCase(void) -{ -} +void DocumentDBJsonObjectTest::TearDownTestCase(void) {} -void DocumentDBJsonObjectTest::SetUp(void) -{ -} +void DocumentDBJsonObjectTest::SetUp(void) {} -void DocumentDBJsonObjectTest::TearDown(void) -{ -} +void DocumentDBJsonObjectTest::TearDown(void) {} /** * @tc.name: OpenDBTest001 @@ -61,7 +54,7 @@ HWTEST_F(DocumentDBJsonObjectTest, JsonObjectTest001, TestSize.Level0) JsonObject conf = JsonObject::Parse(config, ret); EXPECT_EQ(ret, E_OK); - ValueObject obj = conf.GetObjectByPath({"b", "c"}, ret); + ValueObject obj = conf.GetObjectByPath({ "b", "c" }, ret); EXPECT_EQ(obj.GetValueType(), ValueObject::ValueType::VALUE_NUMBER); EXPECT_EQ(obj.GetIntValue(), 234);