From 60b6dfd33c86aedf34423adf9335aaad9c6a57fd Mon Sep 17 00:00:00 2001 From: lianhuix Date: Thu, 11 May 2023 15:46:59 +0800 Subject: [PATCH] Fix codechecks Signed-off-by: lianhuix --- .../service/data_share/gaussdb_rd/BUILD.gn | 3 +- .../src/common/include/collection_option.h | 1 - .../gaussdb_rd/src/common/include/db_config.h | 6 +- .../src/common/include/db_constant.h | 27 ++ .../gaussdb_rd/src/common/include/log_print.h | 12 +- .../gaussdb_rd/src/common/include/os_api.h | 2 +- .../gaussdb_rd/src/common/src/db_config.cpp | 41 ++- .../gaussdb_rd/src/common/src/db_constant.cpp | 20 ++ .../gaussdb_rd/src/common/src/json_common.cpp | 14 +- .../gaussdb_rd/src/common/src/log_print.cpp | 15 +- .../gaussdb_rd/src/common/src/os_api.cpp | 6 +- .../{document_check.cpp => check_common.cpp} | 8 +- .../{document_check.h => check_common.h} | 8 +- .../executor/document/grd_document_api.cpp | 2 - .../src/interface/include/collection.h | 4 +- .../include/document_store_manager.h | 1 - .../src/interface/include/result_set.h | 2 +- .../src/interface/include/result_set_common.h | 2 +- .../src/interface/src/collection.cpp | 7 +- .../src/interface/src/doc_errno.cpp | 10 +- .../src/interface/src/document_store.cpp | 4 +- .../oh_adapter/include/kv_store_executor.h | 2 +- .../src/oh_adapter/include/kv_store_manager.h | 2 +- .../src/oh_adapter/src/json_object.cpp | 1 - .../src/oh_adapter/src/kv_store_manager.cpp | 4 +- .../src/sqlite_store_executor_impl.cpp | 45 +-- .../src/sqlite_store_executor_impl.h | 7 +- .../gaussdb_rd/test/unittest/BUILD.gn | 14 +- .../api/documentdb_collection_test.cpp | 2 +- .../unittest/api/documentdb_data_test.cpp | 19 +- .../unittest/api/documentdb_delete_test.cpp | 57 +-- .../unittest/api/documentdb_find_test.cpp | 336 ++++++------------ .../unittest/api/documentdb_insert_test.cpp | 146 ++++---- .../documentdb_json_common_test.cpp | 17 +- 34 files changed, 390 insertions(+), 457 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_constant.h create mode 100644 services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_constant.cpp rename services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/{document_check.cpp => check_common.cpp} (98%) rename services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/{document_check.h => check_common.h} (92%) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn index 8282d4b3..021120b4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -49,11 +49,12 @@ ohos_shared_library("gaussdb_rd") { sources = [ "src/common/src/collection_option.cpp", "src/common/src/db_config.cpp", + "src/common/src/db_constant.cpp", "src/common/src/json_common.cpp", "src/common/src/log_print.cpp", "src/common/src/os_api.cpp", "src/executor/base/grd_db_api.cpp", - "src/executor/document/document_check.cpp", + "src/executor/document/check_common.cpp", "src/executor/document/grd_document_api.cpp", "src/executor/document/grd_resultset_api.cpp", "src/interface/src/collection.cpp", diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/collection_option.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/collection_option.h index 42bd55db..8f982807 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/collection_option.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/collection_option.h @@ -16,7 +16,6 @@ #ifndef COLLECTION_OPTION_H #define COLLECTION_OPTION_H -#include #include namespace DocumentDB { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_config.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_config.h index 8e926bc8..faa1cca2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_config.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_config.h @@ -23,7 +23,9 @@ class DBConfig final { public: static DBConfig ReadConfig(const std::string &confStr, int &errCode); + DBConfig() = default; ~DBConfig() = default; + std::string ToString() const; int32_t GetPageSize() const; @@ -34,10 +36,10 @@ public: bool CheckPersistenceEqual(const DBConfig &targetConfig) const; private: - DBConfig() = default; + static DBConfig GetDBConfigFromJsonStr(const std::string &confStr, int &errCode); std::string configStr_ = {}; - int32_t pageSize_ = 4; // 4: default page size k + 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 diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_constant.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_constant.h new file mode 100644 index 00000000..7bafc802 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/db_constant.h @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef DB_CONSTANT_H +#define DB_CONSTANT_H + +#include + +namespace DocumentDB { +class DBConstant final { +public: + static const std::string COLL_PREFIX; // = "GRD_COLL_"; +}; +} // namespace DocumentDB +#endif // DB_CONSTANT_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h index 25918731..8264ffbd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h @@ -21,7 +21,7 @@ namespace DocumentDB { constexpr const char *LOG_TAG_DOC = "GAUSSDB_RD"; -class Logger { +class LogPrint { public: enum class Level { LEVEL_DEBUG, @@ -36,9 +36,9 @@ public: } // namespace DocumentDB #define NO_LOG(...) // No log in normal and release. Used for convenience when deep debugging -#define GLOGD(...) Logger::Log(Logger::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGI(...) Logger::Log(Logger::Level::LEVEL_INFO, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGW(...) Logger::Log(Logger::Level::LEVEL_WARN, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGE(...) Logger::Log(Logger::Level::LEVEL_ERROR, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGF(...) Logger::Log(Logger::Level::LEVEL_FATAL, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGD(...) LogPrint::Log(LogPrint::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGI(...) LogPrint::Log(LogPrint::Level::LEVEL_INFO, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGW(...) LogPrint::Log(LogPrint::Level::LEVEL_WARN, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGE(...) LogPrint::Log(LogPrint::Level::LEVEL_ERROR, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGF(...) LogPrint::Log(LogPrint::Level::LEVEL_FATAL, LOG_TAG_DOC, __VA_ARGS__) #endif // LOG_PRINT_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/os_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/os_api.h index f2c34f16..e735edb9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/os_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/os_api.h @@ -25,7 +25,7 @@ bool CheckPathExistence(const std::string &filePath); int GetRealPath(const std::string &inOriPath, std::string &outRealPath); -void SplitFilePath(const std::string &filePath, std::string &fileDir, std::string &fileName); +void SplitFilePath(const std::string &filePath, std::string &fieldir, std::string &fileName); } // namespace OSAPI } // namespace DocumentDB #endif // OS_API_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp index e800910f..bdd09c68 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp @@ -107,7 +107,7 @@ bool CheckBufferPoolSizeConfig(const JsonObject &config, int32_t pageSize, uint3 { std::function checkFunction = [&pageSize](uint32_t val) { return val >= MIN_BUFFER_POOL_SIZE && val <= MAX_BUFFER_POOL_SIZE && - val >= static_cast(pageSize * 64); + val >= static_cast(pageSize * 64); // 64: pool size should be 64 times larger then pageSize }; return CheckAndGetDBConfig(config, DB_CONFIG_BUFFER_POOL_SIZE, checkFunction, redoBufSize); } @@ -144,24 +144,9 @@ int CheckConfigValid(const JsonObject &config) } } // namespace -DBConfig DBConfig::ReadConfig(const std::string &confStr, int &errCode) +DBConfig DBConfig::GetDBConfigFromJsonStr(const std::string &confStr, int &errCode) { - if (confStr.empty()) { - return {}; - } - - if (confStr.length() + 1 > MAX_DB_CONFIG_LEN) { - GLOGE("Config json string is too long."); - errCode = -E_OVER_LIMIT; - return {}; - } - - std::string lowerCaseConfStr = confStr; - std::transform(lowerCaseConfStr.begin(), lowerCaseConfStr.end(), lowerCaseConfStr.begin(), [](unsigned char c) { - return std::tolower(c); - }); - - JsonObject dbConfig = JsonObject::Parse(lowerCaseConfStr, errCode); + JsonObject dbConfig = JsonObject::Parse(confStr, errCode); if (errCode != E_OK) { GLOGE("Read DB config failed from str. %d", errCode); return {}; @@ -215,6 +200,26 @@ DBConfig DBConfig::ReadConfig(const std::string &confStr, int &errCode) return conf; } +DBConfig DBConfig::ReadConfig(const std::string &confStr, int &errCode) +{ + if (confStr.empty()) { + return {}; + } + + if (confStr.length() + 1 > MAX_DB_CONFIG_LEN) { + GLOGE("Config json string is too long."); + errCode = -E_OVER_LIMIT; + return {}; + } + + std::string lowerCaseConfStr = confStr; + std::transform(lowerCaseConfStr.begin(), lowerCaseConfStr.end(), lowerCaseConfStr.begin(), [](unsigned char c) { + return std::tolower(c); + }); + + return GetDBConfigFromJsonStr(lowerCaseConfStr, errCode); +} + std::string DBConfig::ToString() const { return configStr_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_constant.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_constant.cpp new file mode 100644 index 00000000..cbaef55d --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_constant.cpp @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "db_constant.h" + +namespace DocumentDB { +const std::string DBConstant::COLL_PREFIX = "GRD_COLL_"; +} // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index e9267988..5d961b22 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -14,9 +14,6 @@ */ #include "json_common.h" -#include -#include - #include "doc_errno.h" #include "log_print.h" #include "securec.h" @@ -110,7 +107,7 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, boo return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || '_' == fieldName[i])) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || fieldName[i] == '_')) { errFlag = false; return false; } @@ -166,8 +163,8 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fie return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || - (isFirstFloor && '.' == fieldName[i]))) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || (fieldName[i] == '_') || + (isFirstFloor && fieldName[i] == '.'))) { errCode = -E_INVALID_ARGS; errFlag = false; return false; @@ -710,10 +707,11 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target isMatchFlag = false; return false; } - if (isAlreadyMatched == 0) { //Not match anything + if (isAlreadyMatched == 0) { // Not match anything isMatchFlag = false; } - return false; // Source path not exist, if leaf value is null, isMatchFlag become true, else it will become false. + // Source path not exist, if leaf value is null, isMatchFlag become true, else it will become false. + return false; } }); return isMatchFlag; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp index 246852eb..b23067ef 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp @@ -20,8 +20,7 @@ namespace DocumentDB { namespace { - -void PrintLog(Logger::Level level, const std::string &tag, const std::string &msg) +void PrintLog(LogPrint::Level level, const std::string &tag, const std::string &msg) { if (msg.empty()) { return; @@ -29,19 +28,19 @@ void PrintLog(Logger::Level level, const std::string &tag, const std::string &ms const std::string format = "%{public}s"; OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag.c_str() }; switch (level) { - case Logger::Level::LEVEL_DEBUG: + case LogPrint::Level::LEVEL_DEBUG: (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); break; - case Logger::Level::LEVEL_INFO: + case LogPrint::Level::LEVEL_INFO: (void)OHOS::HiviewDFX::HiLog::Info(label, format.c_str(), msg.c_str()); break; - case Logger::Level::LEVEL_WARN: + case LogPrint::Level::LEVEL_WARN: (void)OHOS::HiviewDFX::HiLog::Warn(label, format.c_str(), msg.c_str()); break; - case Logger::Level::LEVEL_ERROR: + case LogPrint::Level::LEVEL_ERROR: (void)OHOS::HiviewDFX::HiLog::Error(label, format.c_str(), msg.c_str()); break; - case Logger::Level::LEVEL_FATAL: + case LogPrint::Level::LEVEL_FATAL: (void)OHOS::HiviewDFX::HiLog::Fatal(label, format.c_str(), msg.c_str()); break; default: @@ -60,7 +59,7 @@ void PreparePrivateLog(const char *format, std::string &outStrFormat) } } // namespace -void Logger::Log(Level level, const std::string &tag, const char *format, ...) +void LogPrint::Log(Level level, const std::string &tag, const char *format, ...) { static const int maxLogLength = 1024; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/os_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/os_api.cpp index f3e2a983..8374915d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/os_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/os_api.cpp @@ -64,7 +64,7 @@ int GetRealPath(const std::string &inOriPath, std::string &outRealPath) return E_OK; } -void SplitFilePath(const std::string &filePath, std::string &fileDir, std::string &fileName) +void SplitFilePath(const std::string &filePath, std::string &fieldir, std::string &fileName) { if (filePath.empty()) { return; @@ -73,11 +73,11 @@ void SplitFilePath(const std::string &filePath, std::string &fileDir, std::strin auto slashPos = filePath.find_last_of('/'); if (slashPos == std::string::npos) { fileName = filePath; - fileDir = ""; + fieldir = ""; return; } - fileDir = filePath.substr(0, slashPos); + fieldir = filePath.substr(0, slashPos); fileName = filePath.substr(slashPos + 1); } } // namespace OSAPI diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp similarity index 98% rename from services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp rename to services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 4a3c8a4a..f67486e4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "document_check.h" +#include "check_common.h" #include #include @@ -95,7 +95,7 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return -E_INVALID_ARGS; } for (auto oneChar : filterPath[i][j]) { - if (!((isalpha(oneChar)) || (isdigit(oneChar)) || ('_' == oneChar))) { + if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { return -E_INVALID_ARGS; } } @@ -204,7 +204,7 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector #include @@ -38,7 +38,5 @@ public: }; using Key = std::vector; using Value = std::vector; - -constexpr const char *COLL_PREFIX = "GRD_COLL_"; } // namespace DocumentDB -#endif // DOCUMENT_CHECK_H \ No newline at end of file +#endif // CHECK_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp index 5fffa173..9b89a81b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -94,11 +94,9 @@ int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter case GRD_OK: deleteCount = 1; return deleteCount; - break; case GRD_NO_DATA: deleteCount = 0; return deleteCount; - break; default: break; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 2b0a982d..6ae7a99b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -18,15 +18,13 @@ #include -#include "document_check.h" +#include "check_common.h" #include "kv_store_executor.h" namespace DocumentDB { class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); - Collection(const Collection &a){}; - Collection(){}; ~Collection(); int PutDocument(const Key &key, const Value &document); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store_manager.h index 4696beab..f9745fae 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store_manager.h @@ -17,7 +17,6 @@ #define DOCUMENT_STORE_MANAGER_H #include -#include #include #include "document_store.h" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 28187d30..590b6f37 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -19,7 +19,7 @@ #include #include "doc_errno.h" -#include "document_check.h" +#include "check_common.h" #include "document_store.h" #include "grd_base/grd_type_export.h" #include "json_object.h" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index 52779d44..fa2c17c7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -30,4 +30,4 @@ int InitResultSet(DocumentStore *store, const std::string collectionName, const int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, ResultSet &resultSet); } // namespace DocumentDB -#endif //RESULTSET_COMMON_H +#endif // RESULTSET_COMMON_H diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index 651d1ece..972b4dc9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -15,10 +15,9 @@ #include "collection.h" -#include - +#include "check_common.h" +#include "db_constant.h" #include "doc_errno.h" -#include "document_check.h" #include "log_print.h" namespace DocumentDB { @@ -30,7 +29,7 @@ Collection::Collection(const std::string &name, KvStoreExecutor *executor) : exe std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { return std::tolower(c); }); - name_ = COLL_PREFIX + lowerCaseName; + name_ = DBConstant::COLL_PREFIX + lowerCaseName; } Collection::~Collection() diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/doc_errno.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/doc_errno.cpp index 46be82ab..cf205495 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/doc_errno.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/doc_errno.cpp @@ -20,9 +20,9 @@ namespace DocumentDB { int GetErrorCategory(int errCode) { - int categoryCode = errCode % 1000000; - categoryCode /= 1000; - categoryCode *= 1000; + int categoryCode = errCode % 1000000; // 1000000: mod to get last 6 digits + categoryCode /= 1000; // 1000: deviced to remove first 3 digits + categoryCode *= 1000; // 1000: multiply to pad the output return categoryCode; } @@ -74,12 +74,10 @@ int TransferDocErr(int err) case -E_OUT_OF_MEMORY: outErr = GRD_FAILED_MEMORY_ALLOCATE; break; - case -E_INNER_ERROR: - outErr = GRD_INNER_ERR; - break; case -E_INVALID_FILE_FORMAT: outErr = GRD_INVALID_FILE_FORMAT; break; + case -E_INNER_ERROR: default: outErr = GRD_INNER_ERR; break; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index bb3215f3..4b3b7682 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -17,7 +17,7 @@ #include "collection_option.h" #include "doc_errno.h" -#include "document_check.h" +#include "check_common.h" #include "grd_base/grd_type_export.h" #include "grd_resultset_inner.h" #include "log_print.h" @@ -447,10 +447,12 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri Key key(id.begin(), id.end()); return coll.DeleteDocument(key); } + KvStoreExecutor *DocumentStore::GetExecutor(int errCode) { return executor_; } + int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h index 9b6533e0..7dd31d4e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_executor.h @@ -18,7 +18,7 @@ #include -#include "document_check.h" +#include "check_common.h" namespace DocumentDB { class KvStoreExecutor { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h index fc71bbf7..fb492181 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/kv_store_manager.h @@ -18,7 +18,7 @@ #include #include "db_config.h" -#include "document_check.h" +#include "check_common.h" #include "kv_store_executor.h" namespace DocumentDB { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 625d39f5..83abf1c0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -21,7 +21,6 @@ #include "log_print.h" namespace DocumentDB { - namespace { bool IsNumber(const std::string &str) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp index 32e89330..5162ebf4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp @@ -29,13 +29,13 @@ int KvStoreManager::GetKvStore(const std::string &path, const DBConfig &config, } sqlite3 *db = nullptr; - int errCode = SqliteStoreExecutor::CreateDatabase(path, config, db); + int errCode = SqliteStoreExecutorImpl::CreateDatabase(path, config, db); if (errCode != E_OK) { GLOGE("Get kv store failed. %d", errCode); return errCode; } - auto *sqliteExecutor = new (std::nothrow) SqliteStoreExecutor(db); + auto *sqliteExecutor = new (std::nothrow) SqliteStoreExecutorImpl(db); if (sqliteExecutor == nullptr) { sqlite3_close_v2(db); return -E_OUT_OF_MEMORY; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index fbd0fd84..9b463564 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -15,13 +15,14 @@ #include "sqlite_store_executor_impl.h" +#include "check_common.h" +#include "db_constant.h" #include "doc_errno.h" -#include "document_check.h" #include "log_print.h" #include "sqlite_utils.h" namespace DocumentDB { -int SqliteStoreExecutor::CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db) +int SqliteStoreExecutorImpl::CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db) { if (db != nullptr) { return -E_INVALID_ARGS; @@ -60,15 +61,15 @@ END: return errCode; } -SqliteStoreExecutor::SqliteStoreExecutor(sqlite3 *handle) : dbHandle_(handle) {} +SqliteStoreExecutorImpl::SqliteStoreExecutorImpl(sqlite3 *handle) : dbHandle_(handle) {} -SqliteStoreExecutor::~SqliteStoreExecutor() +SqliteStoreExecutorImpl::~SqliteStoreExecutorImpl() { sqlite3_close_v2(dbHandle_); dbHandle_ = nullptr; } -int SqliteStoreExecutor::GetDBConfig(std::string &config) +int SqliteStoreExecutorImpl::GetDBConfig(std::string &config) { std::string dbConfigKeyStr = "DB_CONFIG"; Key dbConfigKey = { dbConfigKeyStr.begin(), dbConfigKeyStr.end() }; @@ -78,7 +79,7 @@ int SqliteStoreExecutor::GetDBConfig(std::string &config) return errCode; } -int SqliteStoreExecutor::SetDBConfig(const std::string &config) +int SqliteStoreExecutorImpl::SetDBConfig(const std::string &config) { std::string dbConfigKeyStr = "DB_CONFIG"; Key dbConfigKey = { dbConfigKeyStr.begin(), dbConfigKeyStr.end() }; @@ -86,22 +87,22 @@ int SqliteStoreExecutor::SetDBConfig(const std::string &config) return PutData("grd_meta", dbConfigKey, dbConfigVal); } -int SqliteStoreExecutor::StartTransaction() +int SqliteStoreExecutorImpl::StartTransaction() { return SQLiteUtils::BeginTransaction(dbHandle_, TransactType::IMMEDIATE); } -int SqliteStoreExecutor::Commit() +int SqliteStoreExecutorImpl::Commit() { return SQLiteUtils::CommitTransaction(dbHandle_); } -int SqliteStoreExecutor:: Rollback() +int SqliteStoreExecutorImpl::Rollback() { return SQLiteUtils::RollbackTransaction(dbHandle_); } -int SqliteStoreExecutor::PutData(const std::string &collName, const Key &key, const Value &value) +int SqliteStoreExecutorImpl::PutData(const std::string &collName, const Key &key, const Value &value) { if (dbHandle_ == nullptr) { return -E_ERROR; @@ -126,7 +127,7 @@ int SqliteStoreExecutor::PutData(const std::string &collName, const Key &key, co return E_OK; } -int SqliteStoreExecutor::InsertData(const std::string &collName, const Key &key, const Value &value) +int SqliteStoreExecutorImpl::InsertData(const std::string &collName, const Key &key, const Value &value) { if (dbHandle_ == nullptr) { return -E_ERROR; @@ -151,7 +152,7 @@ int SqliteStoreExecutor::InsertData(const std::string &collName, const Key &key, return E_OK; } -int SqliteStoreExecutor::GetData(const std::string &collName, const Key &key, Value &value) const +int SqliteStoreExecutorImpl::GetData(const std::string &collName, const Key &key, Value &value) const { if (dbHandle_ == nullptr) { GLOGE("Invalid db handle."); @@ -177,7 +178,7 @@ int SqliteStoreExecutor::GetData(const std::string &collName, const Key &key, Va return innerErrorCode; } -int SqliteStoreExecutor::GetFieldedData(const std::string &collName, const JsonObject &filterObj, +int SqliteStoreExecutorImpl::GetFieldedData(const std::string &collName, const JsonObject &filterObj, std::vector> &values) const { if (dbHandle_ == nullptr) { @@ -222,7 +223,7 @@ int SqliteStoreExecutor::GetFieldedData(const std::string &collName, const JsonO return innerErrorCode; } -int SqliteStoreExecutor::DelData(const std::string &collName, const Key &key) +int SqliteStoreExecutorImpl::DelData(const std::string &collName, const Key &key) { if (dbHandle_ == nullptr) { GLOGE("Invalid db handle."); @@ -251,12 +252,12 @@ int SqliteStoreExecutor::DelData(const std::string &collName, const Key &key) return errCode; } -int SqliteStoreExecutor::CreateCollection(const std::string &name, const std::string &option, bool ignoreExists) +int SqliteStoreExecutorImpl::CreateCollection(const std::string &name, const std::string &option, bool ignoreExists) { if (dbHandle_ == nullptr) { return -E_ERROR; } - std::string collName = COLL_PREFIX + name; + std::string collName = DBConstant::COLL_PREFIX + name; int errCode = E_OK; bool isExists = IsCollectionExists(collName, errCode); if (errCode != E_OK) { @@ -282,13 +283,13 @@ int SqliteStoreExecutor::CreateCollection(const std::string &name, const std::st return E_OK; } -int SqliteStoreExecutor::DropCollection(const std::string &name, bool ignoreNonExists) +int SqliteStoreExecutorImpl::DropCollection(const std::string &name, bool ignoreNonExists) { if (dbHandle_ == nullptr) { return -E_ERROR; } - std::string collName = COLL_PREFIX + name; + std::string collName = DBConstant::COLL_PREFIX + name; if (!ignoreNonExists) { int errCode = E_OK; bool isExists = IsCollectionExists(collName, errCode); @@ -310,7 +311,7 @@ int SqliteStoreExecutor::DropCollection(const std::string &name, bool ignoreNonE return E_OK; } -bool SqliteStoreExecutor::IsCollectionExists(const std::string &name, int &errCode) +bool SqliteStoreExecutorImpl::IsCollectionExists(const std::string &name, int &errCode) { bool isExists = false; std::string sql = "SELECT tbl_name FROM sqlite_master WHERE tbl_name=?;"; @@ -331,7 +332,7 @@ bool SqliteStoreExecutor::IsCollectionExists(const std::string &name, int &errCo return isExists; } -int SqliteStoreExecutor::GetCollectionOption(const std::string &name, std::string &option) +int SqliteStoreExecutorImpl::GetCollectionOption(const std::string &name, std::string &option) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; @@ -341,7 +342,7 @@ int SqliteStoreExecutor::GetCollectionOption(const std::string &name, std::strin return errCode; } -int SqliteStoreExecutor::SetCollectionOption(const std::string &name, const std::string &option) +int SqliteStoreExecutorImpl::SetCollectionOption(const std::string &name, const std::string &option) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; @@ -349,7 +350,7 @@ int SqliteStoreExecutor::SetCollectionOption(const std::string &name, const std: return PutData("grd_meta", collOptKey, collOptVal); } -int SqliteStoreExecutor::CleanCollectionOption(const std::string &name) +int SqliteStoreExecutorImpl::CleanCollectionOption(const std::string &name) { std::string collOptKeyStr = "COLLECTION_OPTION_" + name; Key collOptKey = { collOptKeyStr.begin(), collOptKeyStr.end() }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h index 532d4b91..7b82379e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.h @@ -22,12 +22,13 @@ #include "sqlite3.h" namespace DocumentDB { -class SqliteStoreExecutor : public KvStoreExecutor { +class SqliteStoreExecutorImpl : public KvStoreExecutor { public: static int CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db); - SqliteStoreExecutor(sqlite3 *handle); - ~SqliteStoreExecutor() override; + SqliteStoreExecutorImpl() = default; + explicit SqliteStoreExecutorImpl(sqlite3 *handle); + ~SqliteStoreExecutorImpl() override; int GetDBConfig(std::string &config); int SetDBConfig(const std::string &config); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index 42adb4b9..892ec657 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -51,7 +51,7 @@ ohos_source_set("src_file") { "../../src/common/src/log_print.cpp", "../../src/common/src/os_api.cpp", "../../src/executor/base/grd_db_api.cpp", - "../../src/executor/document/document_check.cpp", + "../../src/executor/document/check_common.cpp", "../../src/executor/document/grd_document_api.cpp", "../../src/executor/document/grd_resultset_api.cpp", "../../src/interface/src/collection.cpp", @@ -139,15 +139,15 @@ documentdb_unittest("DocumentDBJsonObjectTest") { sources = [ "oh_adapter/documentdb_jsonobject_test.cpp" ] } -documentdb_unittest("DocumentInsertApiTest") { +documentdb_unittest("DocumentDBInsertTest") { sources = [ "api/documentdb_insert_test.cpp" ] } -documentdb_unittest("DocumentFindApiTest") { +documentdb_unittest("DocumentDBFindTest") { sources = [ "api/documentdb_find_test.cpp" ] } -documentdb_unittest("DocumentDeleteApiTest") { +documentdb_unittest("DocumentDBDeleteTest") { sources = [ "api/documentdb_delete_test.cpp" ] } @@ -160,11 +160,11 @@ group("unittest") { ":DocumentDBApiTest", ":DocumentDBCollectionTest", ":DocumentDBDataTest", + ":DocumentDBDeleteTest", + ":DocumentDBFindTest", + ":DocumentDBInsertTest", ":DocumentDBJsonCommonTest", ":DocumentDBJsonObjectTest", - ":DocumentDeleteApiTest", - ":DocumentFindApiTest", - ":DocumentInsertApiTest", ] } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp index 43cacdb7..92aedcd5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp @@ -197,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/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index faa10174..57ab47aa 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -15,6 +15,7 @@ #include +#include "cJSON.h" #include "doc_errno.h" #include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" @@ -22,7 +23,6 @@ #include "grd_document/grd_document_api.h" #include "log_print.h" #include "sqlite_utils.h" -#include "cJSON.h" using namespace DocumentDB; using namespace testing::ext; @@ -134,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); } } @@ -150,7 +150,8 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string val = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), + GRD_INVALID_ARGS); } /** @@ -185,7 +186,8 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest010, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpsertDataTest011, TestSize.Level0) { - int result = GRD_UpsertDoc(g_db, g_coll, R"({"_id" : "abcde"})", R"({"t1":{"t22":[1,{"t23":1, "t23":1},3 ,4]}})", 0); + int result = + GRD_UpsertDoc(g_db, g_coll, R"({"_id" : "abcde"})", R"({"t1":{"t22":[1,{"t23":1, "t23":1},3 ,4]}})", 0); ASSERT_EQ(result, GRD_INVALID_FORMAT); } @@ -290,7 +292,8 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpdateDataTest008, TestSize.Level0) { - const char *updateStr = R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; + const char *updateStr = + R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; int result = GRD_UpdateDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); int result2 = GRD_UpsertDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); EXPECT_EQ(result, GRD_INVALID_ARGS); @@ -312,7 +315,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) Query query = { filter.c_str(), projection }; EXPECT_EQ(GRD_FindDoc(g_db, g_coll, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); string valueStr = value; string repectStr = R""({"_id":"1234","field1":1,"field2":2,"FIELD1":[1,true,1.23456789,"hello world!",null]})""; @@ -332,8 +335,8 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest010, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpdateDataTest011, TestSize.Level0) { int result = GRD_OK; - const char *doc = R"({"_id":"007", "field1":{"c_field":{"cc_field":{"ccc_field":1}}}, "field2":2})"; - result = GRD_InsertDoc(g_db,g_coll, doc, 0); + const char *doc = R"({"_id":"007", "field1":{"c_field":{"cc_field":{"ccc_field":1}}}, "field2":2})"; + result = GRD_InsertDoc(g_db, g_coll, doc, 0); cJSON *updata = cJSON_CreateObject(); for (int i = 0; i <= 40000; i++) { string temp = "f" + string(5 - std::to_string(i).size(), '0') + std::to_string(i); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp index a41d3557..8165c73b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_delete_test.cpp @@ -15,6 +15,7 @@ #include +#include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" #include "grd_base/grd_resultset_api.h" @@ -24,14 +25,15 @@ #include "grd_type_inner.h" using namespace testing::ext; +using namespace DocumentDBUnitTest; namespace { constexpr const char *COLLECTION_NAME = "student"; constexpr const char *NULL_JSON_STR = "{}"; const int MAX_COLLECTION_LENS = 511; -std::string path = "./document.db"; +std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; -class DocumentDeleteApiTest : public testing::Test { +class DocumentDBDeleteTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -39,20 +41,19 @@ public: void TearDown(); void InsertDoc(const char *collectionName, const char *document); }; -void DocumentDeleteApiTest::SetUpTestCase(void) +void DocumentDBDeleteTest::SetUpTestCase(void) { - std::string path = "./document.db"; - int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); + int status = GRD_DBOpen(g_path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); EXPECT_EQ(status, GRD_OK); } -void DocumentDeleteApiTest::TearDownTestCase(void) +void DocumentDBDeleteTest::TearDownTestCase(void) { EXPECT_EQ(GRD_DBClose(g_db, 0), GRD_OK); - remove(path.c_str()); + DocumentDBTestUtils::RemoveTestDbFiles(g_path); } -void DocumentDeleteApiTest::SetUp(void) +void DocumentDBDeleteTest::SetUp(void) { /** * @tc.steps:step1. Create Collection @@ -87,12 +88,12 @@ void DocumentDeleteApiTest::SetUp(void) \"friend\" : {\"name\" : \"David\", \"sex\" : \"female\", \"age\" : 90}, \ \"subject\": [\"Sing\", \"Jump\", \"Rap\", \"BasketBall\"] \ }"; - DocumentDeleteApiTest::InsertDoc(COLLECTION_NAME, document1); - DocumentDeleteApiTest::InsertDoc(COLLECTION_NAME, document2); - DocumentDeleteApiTest::InsertDoc(COLLECTION_NAME, document3); + DocumentDBDeleteTest::InsertDoc(COLLECTION_NAME, document1); + DocumentDBDeleteTest::InsertDoc(COLLECTION_NAME, document2); + DocumentDBDeleteTest::InsertDoc(COLLECTION_NAME, document3); } -void DocumentDeleteApiTest::TearDown(void) +void DocumentDBDeleteTest::TearDown(void) { /** * @tc.steps:step1. Call GRD_DropCollection to drop the collection @@ -121,7 +122,7 @@ static void ChkDeleteResWithFilter(const char *filter) EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } -void DocumentDeleteApiTest::InsertDoc(const char *collectionName, const char *document) +void DocumentDBDeleteTest::InsertDoc(const char *collectionName, const char *document) { EXPECT_EQ(GRD_InsertDoc(g_db, collectionName, document, 0), GRD_OK); } @@ -133,7 +134,7 @@ void DocumentDeleteApiTest::InsertDoc(const char *collectionName, const char *do * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest001, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest001, TestSize.Level1) { /** * @tc.steps:step1. Delete all the document @@ -149,7 +150,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest001, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest002, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest002, TestSize.Level1) { /** * @tc.steps:step1. Delete with filter which has no _id @@ -166,7 +167,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest002, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest003, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest003, TestSize.Level1) { /** * @tc.steps:step1. Delete with filter which has more than one fields. @@ -183,7 +184,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest003, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest004, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest004, TestSize.Level1) { /** * @tc.steps:step1. Test delete with un-zero flags @@ -195,14 +196,14 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest004, TestSize.Level1) * @tc.steps:step2. Test delete with NULL collection name * @tc.expected: step2. GRD_INVALID_ARGS */ - // const char *filter2 = "{\"_id\" : \"1\"}"; - // EXPECT_EQ(GRD_DeleteDoc(g_db, NULL, filter2, 0), GRD_INVALID_ARGS); + const char *filter2 = "{\"_id\" : \"1\"}"; + EXPECT_EQ(GRD_DeleteDoc(g_db, NULL, filter2, 0), GRD_INVALID_ARGS); /** * @tc.steps:step3. Test delete with empty collection name * @tc.expected: step3. GRD_INVALID_ARGS */ - // const char *filter1 = "{\"_id\" : \"1\"}"; - // EXPECT_EQ(GRD_DeleteDoc(g_db, "", filter1, 1), GRD_INVALID_ARGS); + const char *filter3 = "{\"_id\" : \"1\"}"; + EXPECT_EQ(GRD_DeleteDoc(g_db, "", filter3, 1), GRD_INVALID_ARGS); } /** @@ -213,7 +214,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest004, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest005, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest005, TestSize.Level1) { /** * @tc.step1: Test delete with same collection name @@ -236,7 +237,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest005, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest006, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest006, TestSize.Level1) { /** * @tc.step1: Create filter with _id and get the record according to filter condition. @@ -262,7 +263,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest006, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest007, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest007, TestSize.Level1) { const char *filter = "{\"_id\" : \"1\"}"; string collectionName1(MAX_COLLECTION_LENS, 'a'); @@ -281,7 +282,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest007, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest008, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest008, TestSize.Level1) { /** * @tc.steps:step1. Delete with filter which has more than one fields. @@ -303,7 +304,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest008, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest010, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest010, TestSize.Level1) { /** * @tc.steps:step1. Test delete document when filter _id is int and string. @@ -325,7 +326,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest010, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest011, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest011, TestSize.Level1) { /** * @tc.step1: Create filter with _id and get the record according to filter condition. @@ -352,7 +353,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest011, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentDeleteApiTest, DeleteDBTest012, TestSize.Level1) +HWTEST_F(DocumentDBDeleteTest, DeleteDBTest012, TestSize.Level1) { /** * @tc.step1: Create filter with _id and get the record according to filter condition. diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 285a5fbd..3fa8c92d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include #include +#include +#include #include "doc_errno.h" #include "documentdb_test_utils.h" @@ -28,8 +29,10 @@ #include "log_print.h" using namespace testing::ext; +using namespace DocumentDBUnitTest; + namespace { -std::string path = "./document.db"; +std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; constexpr const char *COLLECTION_NAME = "student"; const int MAX_COLLECTION_NAME = 511; @@ -46,7 +49,7 @@ static const char *g_document4 = "{\"_id\" : \"4\", \"name\":\"doc4\",\"item\":\ static const char *g_document5 = "{\"_id\" : \"5\", \"name\":\"doc5\",\"item\":\"journal\",\"personInfo\":\ [{\"sex\" : \"woma\", \"school\" : \"B\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document6 = "{\"_id\" : \"6\", \"name\":\"doc6\",\"item\":false,\"personInfo\":\ - [{\"school\":\"B\", \"teacher\" : \"mike\",\"age\" : 15}, {\"school\":\"C\", \"teacher\" : \"moon\",\"age\" : 20}]}"; + [{\"school\":\"B\", \"teacher\" : \"mike\",\"age\" : 15}, {\"school\":\"C\", \"teacher\" : \"moon\",\"age\":20}]}"; static const char *g_document7 = "{\"_id\" : \"7\", \"name\":\"doc7\",\"item\":\"fruit\",\"other_Info\":\ [{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document8 = "{\"_id\" : \"8\", \"name\":\"doc8\",\"item\":true,\"personInfo\":\ @@ -94,7 +97,7 @@ static void CompareValue(const char *value, const char *targetValue) EXPECT_EQ(valueObj.Print(), targetValueObj.Print()); } -class DocumentFindApiTest : public testing::Test { +class DocumentDBFindTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -102,38 +105,37 @@ public: void TearDown(); void InsertDoc(const char *collectionName, const char *document); }; -void DocumentFindApiTest::SetUpTestCase(void) +void DocumentDBFindTest::SetUpTestCase(void) { - std::string path = "./document.db"; - int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); + int status = GRD_DBOpen(g_path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); EXPECT_EQ(status, GRD_OK); EXPECT_EQ(GRD_CreateCollection(g_db, COLLECTION_NAME, "", 0), GRD_OK); EXPECT_NE(g_db, nullptr); } -void DocumentFindApiTest::TearDownTestCase(void) +void DocumentDBFindTest::TearDownTestCase(void) { EXPECT_EQ(GRD_DBClose(g_db, 0), GRD_OK); - remove(path.c_str()); + DocumentDBTestUtils::RemoveTestDbFiles(g_path); } -void DocumentFindApiTest::SetUp(void) +void DocumentDBFindTest::SetUp(void) { EXPECT_EQ(GRD_DropCollection(g_db, COLLECTION_NAME, 0), GRD_OK); EXPECT_EQ(GRD_CreateCollection(g_db, COLLECTION_NAME, "", 0), GRD_OK); InsertData(g_db, "student"); } -void DocumentFindApiTest::TearDown(void) {} +void DocumentDBFindTest::TearDown(void) {} /** - * @tc.name: DocumentFindApiTest001 + * @tc.name: DocumentDBFindTest001 * @tc.desc: Test Insert document db * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest001, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest001, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -144,7 +146,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest001, TestSize.Level1) 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; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, g_document6); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -158,17 +160,18 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest001, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest002 + * @tc.name: DocumentDBFindTest002 * @tc.desc: Test filter with multiple fields and _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest002, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest002, TestSize.Level1) { /** * @tc.steps: step1. Create filter with multiple and _id. and get the record according to filter condition. - * @tc.expected: step1. Failed to get the record, the result is GRD_INVALID_ARGS, GRD_GetValue return GRD_NOT_AVAILABLE and GRD_Next return GRD_NO_DATA. + * @tc.expected: step1. Failed to get the record, the result is GRD_INVALID_ARGS, + * GRD_GetValue return GRD_NOT_AVAILABLE and GRD_Next return GRD_NO_DATA. */ const char *filter = "{\"_id\" : \"6\", \"name\":\"doc6\"}"; GRD_ResultSet *resultSet = nullptr; @@ -179,20 +182,20 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest002, TestSize.Level1) * @tc.expected: step2. GRD_GetValue return GRD_INVALID_ARGS and GRD_Next return GRD_INVALID_ARGS. */ EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } /** - * @tc.name: DocumentFindApiTest004 + * @tc.name: DocumentDBFindTest004 * @tc.desc: test filter with string filter without _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest004, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest004, TestSize.Level1) { /** * @tc.steps: step1. Create filter without _id and get the record according to filter condition. @@ -207,87 +210,21 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest004, TestSize.Level1) * @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. */ - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } -// /** -// * @tc.name: DocumentFindApiTest005 -// * @tc.desc: test filter field with other word. -// * @tc.type: FUNC -// * @tc.require: -// * @tc.author: mazhao -// */ -// HWTEST_F(DocumentFindApiTest, DocumentFindApiTest005, TestSize.Level1) -// { -// /** -// * @tc.steps: step1. Create filter with _id and number -// * @tc.expected: step1. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet1 = nullptr; -// const char *filter1 = "{\"_id\" : \"1\", \"info\" : 1}"; -// Query query1 = {filter1, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query1, 1, &resultSet1), GRD_OK); -// EXPECT_EQ(GRD_FreeResultSet(resultSet1), GRD_OK); - -// /** -// * @tc.steps: step2. Create filter with two _id -// * @tc.expected: step2. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet2 = nullptr; -// const char *filter2 = "{\"_id\" : \"1\", \"_id\" : \"2\"}"; -// Query query2 = {filter2, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query2, 1, &resultSet2), GRD_INVALID_ARGS); -// EXPECT_EQ(GRD_FreeResultSet(resultSet1), GRD_OK); - -// /** -// * @tc.steps: step3. Create filter with array and _id -// * @tc.expected: step3. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet3 = nullptr; -// const char *filter3 = "{\"_id\" : \"1\", \"info\" : [\"2\", 1]}"; -// Query query3 = {filter3, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query3, 1, &resultSet3), GRD_OK); - -// /** -// * @tc.steps: step4. Create filter with object and _id -// * @tc.expected: step4. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet4 = nullptr; -// const char *filter4 = "{\"_id\" : \"1\", \"info\" : {\"info_val\" : \"1\"}}"; -// Query query4 = {filter4, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query4, 1, &resultSet4), GRD_OK); - -// /** -// * @tc.steps: step5. Create filter with bool and _id -// * @tc.expected: step5. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet5 = nullptr; -// const char *filter5 = "{\"_id\" : \"1\", \"info\" : true}"; -// Query query5 = {filter5, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query5, 1, &resultSet5), GRD_OK); - -// /** -// * @tc.steps: step6. Create filter with null and _id -// * @tc.expected: step6. Failed to get the record, the result is GRD_INVALID_ARGS, -// */ -// GRD_ResultSet *resultSet6 = nullptr; -// const char *filter6 = "{\"_id\" : \"1\", \"info\" : null}"; -// Query query6 = {filter6, "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query6, 1, &resultSet6), GRD_OK); -// } - /** - * @tc.name: DocumentFindApiTest006 + * @tc.name: DocumentDBFindTest006 * @tc.desc: test filter field with id which has different type of value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest006, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id which value is string @@ -346,78 +283,50 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest006, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest016 + * @tc.name: DocumentDBFindTest016 * @tc.desc: Test filter with collection Name is invalid. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest016, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest016, TestSize.Level1) { const char *colName1 = "grd_type"; const char *colName2 = "GM_SYS_sysfff"; - GRD_ResultSet *resultSet = NULL; + GRD_ResultSet *resultSet = nullptr; const char *filter = "{\"_id\" : \"1\"}"; 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); } -// /** -// * @tc.name: DocumentFindApiTest017 -// * @tc.desc: Test filter field with large filter -// * @tc.type: FUNC -// * @tc.require: -// * @tc.author: mazhao -// */ -// HWTEST_F(DocumentFindApiTest, DocumentFindApiTest017, TestSize.Level1) -// { -// GRD_ResultSet *resultSet = nullptr; -// string documentPart1 = "{\"_id\" : \"18\", \"item\" :\" "; -// string documentPart2 = "\" }"; -// string jsonVal = string(512 * 1024 - documentPart1.size() - documentPart2.size() - 1, 'k'); -// string document = documentPart1 + jsonVal + documentPart2; -// string jsonVal1 = string(512 * 1024 - documentPart1.size() - documentPart2.size(), 'k'); -// string document1 = documentPart1 + jsonVal1 + documentPart2; - -// Query query = {document.c_str(), "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); -// EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); -// char *value = NULL; -// EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); -// EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - -// query = {document1.c_str(), "{}"}; -// EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OVER_LIMIT); -// } - /** - * @tc.name: DocumentFindApiTest019 + * @tc.name: DocumentDBFindTest019 * @tc.desc: Test filter field with no result * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest019, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest019, TestSize.Level1) { const char *filter = "{\"_id\" : \"100\"}"; GRD_ResultSet *resultSet = nullptr; 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; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } /** - * @tc.name: DocumentFindApiTest023 + * @tc.name: DocumentDBFindTest023 * @tc.desc: Test filter field with double find. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest023, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest023, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -431,7 +340,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest023, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet2), GRD_RESOURCE_BUSY); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, g_document6); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -452,32 +361,32 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest023, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest024 + * @tc.name: DocumentDBFindTest024 * @tc.desc: Test filter field with multi collections * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest024, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest024, TestSize.Level1) { const char *filter = "{\"_id\" : \"6\"}"; GRD_ResultSet *resultSet = nullptr; GRD_ResultSet *resultSet2 = nullptr; Query query = { filter, "{}" }; - const char *collectionName = "DocumentFindApiTest024"; + const char *collectionName = "DocumentDBFindTest024"; 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); EXPECT_EQ(GRD_FindDoc(g_db, collectionName, query, 1, &resultSet2), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, g_document6); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_Next(resultSet2), GRD_OK); - char *value2 = NULL; + char *value2 = nullptr; EXPECT_EQ(GRD_GetValue(resultSet2, &value2), GRD_OK); CompareValue(value2, g_document6); EXPECT_EQ(GRD_FreeValue(value2), GRD_OK); @@ -493,13 +402,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest024, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest025 + * @tc.name: DocumentDBFindTest025 * @tc.desc: Test nested projection, with viewType equals to 1. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest025, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest025, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document16, _id flag is 0. @@ -558,27 +467,15 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest025, TestSize.Level1) EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } -#include -/** - * @tc.name: DocumentFindApiTest026 - * @tc.desc: Test nested projection, with _id flag equals to 1. Projection is 5 level. - * @tc.type: FUNC - * @tc.require: - * @tc.author: mazhao - */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest026, TestSize.Level1) -{ - -} /** - * @tc.name: DocumentFindApiTest027 + * @tc.name: DocumentDBFindTest027 * @tc.desc: Test projection with invalid field, _id field equals to 1. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest027, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest027, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -625,13 +522,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest027, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest028 + * @tc.name: DocumentDBFindTest028 * @tc.desc: Test projection with invalid field in Array,_id field equals to 1. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest028, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest028, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -679,13 +576,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest028, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest029 + * @tc.name: DocumentDBFindTest029 * @tc.desc: Test projection with path conflict._id field equals to 0. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest029, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest029, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document4, _id flag is 0. @@ -700,13 +597,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest029, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest030 + * @tc.name: DocumentDBFindTest030 * @tc.desc: Test _id flag and field.None exist field. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest030, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -736,7 +633,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) 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; + value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -744,13 +641,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest030, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest031 + * @tc.name: DocumentDBFindTest031 * @tc.desc: Test _id flag and field.Exist field with 1 value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest031, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -781,7 +678,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) 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; + value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -789,13 +686,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest031, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest032 + * @tc.name: DocumentDBFindTest032 * @tc.desc: Test _id flag and field.Exist field with 1 value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest032, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -825,7 +722,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) 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; + value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -841,7 +738,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) 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; + value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -849,13 +746,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest032, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest033 + * @tc.name: DocumentDBFindTest033 * @tc.desc: Test _id flag and field.Exist field with 0 value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest033, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document7, _id flag is 0. @@ -867,7 +764,6 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) int flag = 0; 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); @@ -885,11 +781,10 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) projectionInfo = "{\"name\": 0, \"item\": 0}"; 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; + value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, targetDocument); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -897,13 +792,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest033, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest034 + * @tc.name: DocumentDBFindTest034 * @tc.desc: Test projection with nonexist field in nested structure. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest034, TestSize.Level1) { /** * @tc.steps: step1. Create filter to match g_document4, _id flag is 0. @@ -970,13 +865,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest034, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest035 + * @tc.name: DocumentDBFindTest035 * @tc.desc: test filter with id string filter * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest035, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest035, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -1001,13 +896,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest035, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest036 + * @tc.name: DocumentDBFindTest036 * @tc.desc: Test with invalid collectionName. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest036, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest036, TestSize.Level1) { /** * @tc.steps: step1. Test with invalid collectionName. @@ -1017,20 +912,20 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest036, TestSize.Level1) GRD_ResultSet *resultSet = nullptr; 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); + EXPECT_EQ(GRD_FindDoc(g_db, nullptr, query, 0, &resultSet), GRD_INVALID_ARGS); } /** - * @tc.name: DocumentFindApiTest037 + * @tc.name: DocumentDBFindTest037 * @tc.desc: Test field with different value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest037, TestSize.Level1) { /** - * @tc.steps: step1. Test filed with different value.some are 1, other are 0. + * @tc.steps: step1. Test field with different value.some are 1, other are 0. * @tc.expected: step1. Return GRD_INVALID_ARGS. */ const char *filter = "{\"_id\" : \"4\"}"; @@ -1040,7 +935,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** - * @tc.steps: step2. Test filed with different value.some are 2, other are 0. + * @tc.steps: step2. Test field with different value.some are 2, other are 0. * @tc.expected: step2. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":2, \"personInfo\":0, \"item\":2}"; @@ -1048,7 +943,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** - * @tc.steps: step3. Test filed with different value.some are 0, other are true. + * @tc.steps: step3. Test field with different value.some are 0, other are true. * @tc.expected: step3. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":true, \"personInfo\":0, \"item\":true}"; @@ -1056,7 +951,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** - * @tc.steps: step4. Test filed with different value.some are 0, other are "". + * @tc.steps: step4. Test field with different value.some are 0, other are "". * @tc.expected: step4. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":\"\", \"personInfo\":0, \"item\":\"\"}"; @@ -1064,7 +959,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); /** - * @tc.steps: step5. Test filed with different value.some are 1, other are false. + * @tc.steps: step5. Test field with different value.some are 1, other are false. * @tc.expected: step5. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":1, \"item\":false"; @@ -1072,7 +967,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); /** - * @tc.steps: step6. Test filed with different value.some are -1.123, other are false. + * @tc.steps: step6. Test field with different value.some are -1.123, other are false. * @tc.expected: step6. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":-1.123, \"item\":false"; @@ -1080,7 +975,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); /** - * @tc.steps: step7. Test filed with different value.some are true, other are false. + * @tc.steps: step7. Test field with different value.some are true, other are false. * @tc.expected: step7. Return GRD_INVALID_ARGS. */ projectionInfo = "{\"name\":false, \"personInfo\":true, \"item\":false"; @@ -1089,13 +984,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest037, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest038 + * @tc.name: DocumentDBFindTest038 * @tc.desc: Test field with false value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest038, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest038, TestSize.Level1) { /** * @tc.steps: step1. Test field with different false value. Some are false, other are 0. flag is 0. @@ -1130,13 +1025,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest038, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest039 + * @tc.name: DocumentDBFindTest039 * @tc.desc: Test field with true value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest039, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest039, TestSize.Level1) { /** * @tc.steps: step1. Test field with different true value. Some are true, other are 1. flag is 0. @@ -1174,13 +1069,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest039, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest040 + * @tc.name: DocumentDBFindTest040 * @tc.desc: Test field with invalid value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest040, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest040, TestSize.Level1) { /** * @tc.steps: step1. Test field with invalid value.Value is array. @@ -1211,13 +1106,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest040, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest042 + * @tc.name: DocumentDBFindTest042 * @tc.desc: Test field with no existed uppercase filter * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest042, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest042, TestSize.Level1) { /** * @tc.steps: step1. Test field with no existed uppercase filter. @@ -1251,13 +1146,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest042, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest044 + * @tc.name: DocumentDBFindTest044 * @tc.desc: Test field with uppercase projection * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest044, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest044, TestSize.Level1) { /** * @tc.steps: step1. Test with false uppercase projection @@ -1281,13 +1176,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest044, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest045 + * @tc.name: DocumentDBFindTest045 * @tc.desc: Test field with too long collectionName * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest045, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest045, TestSize.Level1) { /** * @tc.steps: step1. Test with false uppercase projection @@ -1308,13 +1203,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest045, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest052 + * @tc.name: DocumentDBFindTest052 * @tc.desc: Test field when id string len is large than max * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest052, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest052, TestSize.Level1) { /** * @tc.steps: step1. Test with false uppercase projection @@ -1335,13 +1230,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest052, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest053 + * @tc.name: DocumentDBFindTest053 * @tc.desc: Test with invalid flags * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest053, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest053, TestSize.Level1) { /** * @tc.steps: step1. Test with invalid flags which is 3. @@ -1367,13 +1262,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest053, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest054 + * @tc.name: DocumentDBFindTest054 * @tc.desc: Test with null g_db and resultSet, filter. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest054, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest054, TestSize.Level1) { /** * @tc.steps: step1. Test with null g_db. @@ -1400,13 +1295,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest054, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest055 + * @tc.name: DocumentDBFindTest055 * @tc.desc: Find doc, but filter' _id value lens is larger than MAX_ID_LENS * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest055, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest055, TestSize.Level1) { /** * @tc.steps:step1.Find doc, but filter' _id value lens is larger than MAX_ID_LENS @@ -1435,13 +1330,13 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest055, TestSize.Level1) } /** - * @tc.name: DocumentFindApiTest056 + * @tc.name: DocumentDBFindTest056 * @tc.desc: Test findDoc with no _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest056, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -1453,7 +1348,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) 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); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, g_document5); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); @@ -1461,18 +1356,17 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. * @tc.expected: step2. Cannot get next record, return GRD_NO_DATA. */ - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } /** - * @tc.name: DocumentFindApiTest056 + * @tc.name: DocumentDBFindTest056 * @tc.desc: Test findDoc with no _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest057, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest057, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -1485,27 +1379,25 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest057, TestSize.Level1) 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); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - //CompareValue(value, g_document6); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); /** * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. * @tc.expected: step2. Cannot get next record, return GRD_NO_DATA. */ - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } /** - * @tc.name: DocumentFindApiTest058 + * @tc.name: DocumentDBFindTest058 * @tc.desc: Test findDoc with no _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest058, TestSize.Level1) {} +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest058, TestSize.Level1) {} -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest059, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest059, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. @@ -1518,7 +1410,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest059, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_INVALID_FORMAT); } -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest060, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest060, TestSize.Level1) { const char *filter = "{}"; GRD_ResultSet *resultSet = nullptr; @@ -1527,12 +1419,12 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest060, TestSize.Level1) EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_INVALID_ARGS); } -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest061, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest061, TestSize.Level1) { - const char *document064 = "{\"_id\" : \"64\", \"a\":1, \"doc64\" : 2}"; - const char *document063 = "{\"_id\" : \"63\", \"a\":1, \"doc63\" : 2}"; - const char *document062 = "{\"_id\" : \"62\", \"a\":1, \"doc62\" : 2}"; - const char *document061 = "{\"_id\" : \"61\", \"a\":1, \"doc61\" : 2}"; + const char *document064 = "{\"_id\" : \"64\", \"a\":1, \"doc64\" : 2}"; + const char *document063 = "{\"_id\" : \"63\", \"a\":1, \"doc63\" : 2}"; + const char *document062 = "{\"_id\" : \"62\", \"a\":1, \"doc62\" : 2}"; + const char *document061 = "{\"_id\" : \"61\", \"a\":1, \"doc61\" : 2}"; EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document064, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document063, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document062, 0), GRD_OK); @@ -1543,7 +1435,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest061, TestSize.Level1) Query query = { filter, projection }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; + char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, document061); @@ -1562,7 +1454,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest061, TestSize.Level1) EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest062, TestSize.Level1) +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest062, TestSize.Level1) { const char *filter = R"({"abc123_.":1})"; GRD_ResultSet *resultSet = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp index 91cb510c..4dc404b8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp @@ -13,16 +13,19 @@ * limitations under the License. */ -#include #include +#include +#include "documentdb_test_utils.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" #include "grd_document/grd_document_api.h" using namespace testing::ext; +using namespace DocumentDBUnitTest; + namespace { -std::string path = "./document.db"; +std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; const char *RIGHT_COLLECTION_NAME = "student"; const char *NO_EXIST_COLLECTION_NAME = "no_exisit"; @@ -48,40 +51,40 @@ static void TestInsertDocIntoCertainColl(const char *collectionName, const char EXPECT_EQ(GRD_DropCollection(g_db, collectionName, 0), expectedResult); } -class DocumentInsertApiTest : public testing::Test { +class DocumentDBInsertTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); }; -void DocumentInsertApiTest::SetUpTestCase(void) + +void DocumentDBInsertTest::SetUpTestCase(void) { - std::string path = "./document.db"; - int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); + int status = GRD_DBOpen(g_path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db); EXPECT_EQ(status, GRD_OK); EXPECT_EQ(GRD_CreateCollection(g_db, "student", "", 0), GRD_OK); EXPECT_NE(g_db, nullptr); } -void DocumentInsertApiTest::TearDownTestCase(void) +void DocumentDBInsertTest::TearDownTestCase(void) { EXPECT_EQ(GRD_DBClose(g_db, 0), GRD_OK); - remove(path.c_str()); + DocumentDBTestUtils::RemoveTestDbFiles(g_path); } -void DocumentInsertApiTest::SetUp(void) {} +void DocumentDBInsertTest::SetUp(void) {} -void DocumentInsertApiTest::TearDown(void) {} +void DocumentDBInsertTest::TearDown(void) {} /** - * @tc.name: DocumentInsertApiTest001 + * @tc.name: DocumentDBInsertTest001 * @tc.desc: Insert documents into collection which dose not exist * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest001, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest001, TestSize.Level1) { /** * @tc.steps:step1.Insert document into collection which dose not exist @@ -92,13 +95,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest001, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest002 + * @tc.name: DocumentDBInsertTest002 * @tc.desc: Insert documents into collection which _id is not string * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest002, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest002, TestSize.Level1) { /** * @tc.steps:step1.Insert a document whose _id is integer @@ -133,13 +136,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest002, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest003 + * @tc.name: DocumentDBInsertTest003 * @tc.desc: Insert a document whose _id has appeared before * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest003, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest003, TestSize.Level1) { /** * @tc.steps:step1.Insert a document whose _id is string @@ -152,18 +155,18 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest003, TestSize.Level1) * @tc.steps:step2.Insert a document whose _id has appeared before * @tc.expected:step2.GRD_DATA_CONFLICT */ - // const char *document2 = "{\"_id\" : \"3\", \"name\" : \"Chuan\"}"; - // EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_DATA_CONFLICT); + const char *document2 = "{\"_id\" : \"3\", \"name\" : \"Chuan\"}"; + EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_DATA_CONFLICT); } /** - * @tc.name: DocumentInsertApiTest004 + * @tc.name: DocumentDBInsertTest004 * @tc.desc: Test Insert with null parameter. parameter db is NULL * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest004, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest004, TestSize.Level1) { /** * @tc.steps:step1.step1.parameter db is NULL @@ -174,13 +177,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest004, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest005 + * @tc.name: DocumentDBInsertTest005 * @tc.desc: Test insert with null parameter. parameter collectionName is NULL. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest005, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest005, TestSize.Level1) { /** * @tc.steps:step1.Parameter collectionName is NULL @@ -197,13 +200,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest005, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest006 + * @tc.name: DocumentDBInsertTest006 * @tc.desc: parameter flags is not zero * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest006, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest006, TestSize.Level1) { /** * @tc.steps:step1.parameter flags is not zero @@ -214,13 +217,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest006, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest007 + * @tc.name: DocumentDBInsertTest007 * @tc.desc: parameter flags is INT_MAX * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest007, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest007, TestSize.Level1) { /** * @tc.steps:step1.parameter flags is int_max @@ -231,13 +234,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest007, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest008 + * @tc.name: DocumentDBInsertTest008 * @tc.desc: parameter flags is int_min * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest008, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest008, TestSize.Level1) { /** * @tc.steps:step1.parameter flags is int_min @@ -248,13 +251,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest008, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest009 + * @tc.name: DocumentDBInsertTest009 * @tc.desc: parameter collectionName and document is NULL or invalid * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest009, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest009, TestSize.Level1) { /** * @tc.steps:step1.parameter collectionName and document is NULL; @@ -271,13 +274,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest009, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest010 + * @tc.name: DocumentDBInsertTest010 * @tc.desc: parameter collectionName contains irregular charactor * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest010, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest010, TestSize.Level1) { /** * @tc.steps:step1.Create Collection whose parameter collectionName contains irregular charactor @@ -289,13 +292,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest010, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest011 + * @tc.name: DocumentDBInsertTest011 * @tc.desc: parameter collectionName is longer than 256 charactors * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest011, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest011, TestSize.Level1) { /** * @tc.steps:step1.Create Collection whose parameter collectionName contains irregular charactor @@ -307,13 +310,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest011, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest014 + * @tc.name: DocumentDBInsertTest014 * @tc.desc: Inserted document's JSON depth is larger than 4, which is 5. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest014, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest014, TestSize.Level1) { /** * @tc.steps:step1.document's JSON depth is larger than 4, which is 5. @@ -339,13 +342,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest014, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest015 + * @tc.name: DocumentDBInsertTest015 * @tc.desc: Inserted document with all kinds of size * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest015, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest015, TestSize.Level1) { /** * @tc.steps:step1.document's JSON is bigger than 512k - 1 @@ -355,7 +358,6 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest015, TestSize.Level1) string documentPart2 = "\" }"; string jsonVal = string(512 * 1024 - documentPart1.size() - documentPart2.size(), 'k'); string document = documentPart1 + jsonVal + documentPart2; - //EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document.c_str(), 0), GRD_OVER_LIMIT); /** * @tc.steps:step2.Insert document's JSON is a large data but lower than 512k - 1 * @tc.expected:step2.GRD_OK @@ -366,13 +368,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest015, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest016 + * @tc.name: DocumentDBInsertTest016 * @tc.desc: document JSON string contains irregular char * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest016, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest016, TestSize.Level1) { /** * @tc.steps:step1.document JSON string contains irregular char. @@ -383,13 +385,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest016, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest017 + * @tc.name: DocumentDBInsertTest017 * @tc.desc: document JSON string contains invalid value type such as BLOB type * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest017, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest017, TestSize.Level1) { /** * @tc.steps:step1.document JSON string contains invalid value type such as BLOB type. @@ -401,13 +403,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest017, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest018 + * @tc.name: DocumentDBInsertTest018 * @tc.desc: The Inserted document is not JSON format * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest018, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest018, TestSize.Level1) { /** * @tc.steps:step1.The Inserted document is not JSON format @@ -418,31 +420,31 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest018, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest019 + * @tc.name: DocumentDBInsertTest019 * @tc.desc: Insert a normal documents * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest019, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest019, 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\"}"; + "\"19\"}"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); } /** - * @tc.name: DocumentInsertApiTest022 + * @tc.name: DocumentDBInsertTest022 * @tc.desc: parameter collectionName is equal to 256 charactors * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest022, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest022, TestSize.Level1) { /** * @tc.steps:step1.parameter collectionName is equal to 256 charactors @@ -455,14 +457,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest022, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest023 + * @tc.name: DocumentDBInsertTest023 * @tc.desc: parameter collectionName contains upper & lower case charactors, * numbers and underline * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest023, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest023, TestSize.Level1) { /** * @tc.steps:step1.parameter collectionName contains upper & lower case charactors, @@ -475,14 +477,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest023, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest024 + * @tc.name: DocumentDBInsertTest024 * @tc.desc: parameter collectionName's head is GRD_ or GM_SYS_ * numbers and underline * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest024, TestSize.Level1) { /** * @tc.steps:step1.parameter collectionName's head is GRD_ @@ -549,13 +551,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest024, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest025 + * @tc.name: DocumentDBInsertTest025 * @tc.desc: Insert document whose depth is 4, which is allowed * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest025, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest025, TestSize.Level1) { /** * @tc.steps:step1.documents JSON depth is 4, which is allowed. @@ -591,13 +593,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest025, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest026 + * @tc.name: DocumentDBInsertTest026 * @tc.desc: Insert 100 normal documents continuously * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest, TestSize.Level1) { /** * @tc.steps:step1.Insert 100 normal documents continuously @@ -615,14 +617,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest035 + * @tc.name: DocumentDBInsertTest035 * @tc.desc: Insert a document whose value contains * upper &lower case charactors, numbers and underline. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest035, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest035, TestSize.Level1) { /** * @tc.steps:step1.Insert a document whose value contains @@ -642,14 +644,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest035, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest036 + * @tc.name: DocumentDBInsertTest036 * @tc.desc: Insert a document whose value contains * string, number, bool, null, array and object type * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest036, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest036, TestSize.Level1) { /** * @tc.steps:step1.Insert a document whose value contains @@ -662,14 +664,14 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest036, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest038 + * @tc.name: DocumentDBInsertTest038 * @tc.desc: Insert document whose value is over the range of double * string, number, bool, null, array and object type * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest038, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest038, TestSize.Level1) { /** * @tc.steps:step1.Insert document whose value is over the range of double @@ -710,13 +712,13 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest038, TestSize.Level1) } /** - * @tc.name: DocumentInsertApiTest039 + * @tc.name: DocumentDBInsertTest039 * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest039, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest039, TestSize.Level1) { /** * @tc.steps:step1.Insert a filter which _id value's lens is larger than MAX_ID_LENS. @@ -746,7 +748,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest039, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest040, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest040, TestSize.Level1) { const char *filter = "{\"_id\" : \"1\"}"; const char *updata2 = "{\"objectInfo.child.child\" : {\"child\":{\"child\":null}}}"; @@ -760,7 +762,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest040, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest041, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest041, TestSize.Level1) { const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"_id\" : \"6\"}"; @@ -774,7 +776,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest041, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest042, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest042, TestSize.Level1) { const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"age$\" : \"21\"}"; @@ -794,7 +796,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest042, TestSize.Level1) * @tc.require: * @tc.author: mazhao */ -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest043, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest043, TestSize.Level1) { const char *filter = "{\"_id\" : \"1\"}"; const char *updata1 = "{\"age\" : 21}"; @@ -805,7 +807,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest043, TestSize.Level1) EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, NULL, 0), GRD_INVALID_ARGS); } -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest044, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest044, TestSize.Level1) { const char *document1 = R""({"_id":"0123", "num":"num"})""; const char *document2 = R""({"_id":"0123", "NUM":"No.45"})""; @@ -813,7 +815,7 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest044, TestSize.Level1) EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_DATA_CONFLICT); } -HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest045, TestSize.Level1) +HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest045, TestSize.Level1) { const char *document1 = R""({"_id":"0123", "num.":"num"})""; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_INVALID_ARGS); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index db98eee0..aca10555 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -45,8 +45,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); @@ -117,7 +117,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; std::string updateDoc = R""({"name.5":"GG"})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -132,7 +131,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; std::string updateDoc = R""({"name.2":"GG"})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -262,7 +260,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest012, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; std::string updateDoc = R""({"name.first":"GG"})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -277,7 +274,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) { std::string document = R""({"name":["Tmn","BB","Alice"]})""; std::string updateDoc = R""({"name":{"first":"GG"}})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -292,7 +288,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) { std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; std::string updateDoc = R""({"name.0":"GG"})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -307,7 +302,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) { std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; std::string updateDoc = R""({"name.first":["GG","MM"]})""; - ; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -346,7 +340,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest002, TestSize.Leve 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); @@ -359,7 +352,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest003, TestSize.Leve 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,7 +364,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest004, TestSize.Leve 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); @@ -626,8 +617,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest024, TestSize.Leve EXPECT_EQ(errCode, E_OK); auto path = JsonCommon::ParsePath(srcObj, errCode); for (auto singlePath : path) { - for (auto filedName : singlePath) { - GLOGE("filedName is =========>%s", filedName.c_str()); + for (auto fieldName : singlePath) { + GLOGE("fieldName is =========>%s", fieldName.c_str()); } GLOGE("///////////////////////////"); } -- Gitee