diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/CMakeLists.txt b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/CMakeLists.txt index 7686fe996a158d7464e5bf20047a648492d73239..4d7754bdf2e95ade26a51662bbbd4144a80ad346 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/CMakeLists.txt +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/CMakeLists.txt @@ -160,6 +160,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/src/interface ${PROJECT_SOURCE_DIR}/src/interface/include ${PROJECT_SOURCE_DIR}/src/interface/src + ${PROJECT_SOURCE_DIR}/src/executor/include ) set(DISTRIBUTEDDB_PATH ${PROJECT_SOURCE_DIR}/third_party/distributeddatamgr_kv_store/frameworks/libs/distributeddb/) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/include/grd_document/grd_document_api.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/include/grd_document/grd_document_api.h index 09f1719c9dc5b7123b1c56c9c43f3e1492793644..fc062be4497d52feca315a8142c6a48c157b72ac 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/include/grd_document/grd_document_api.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/include/grd_document/grd_document_api.h @@ -16,8 +16,8 @@ #ifndef GRD_DOCUMENT_API_H #define GRD_DOCUMENT_API_H -#include "grd_type_export.h" -#include "grd_resultset_api.h" +#include "grd_base/grd_type_export.h" +#include "grd_base/grd_resultset_api.h" #ifdef __cplusplus extern "C" { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/doc_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/doc_common.h index a4919b67f803d95adf6ad4b521e9011ea0d2d532..f6c0f55c917f58d9bd42afa6f18bffff8608f491 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/doc_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/doc_common.h @@ -18,9 +18,31 @@ #include #include +#include "json_obect.h" namespace DocumentDB { +struct ResultValue { + enum class ValueType { + VALUE_INT, + VALUE_TRUE, + VALUE_FALSE, + VALUE_STRING, + VALUE_OBJECT, + VALUE_ARRAY + }; + int ResultValue_int; + std::string ResultValue_string; + ValueType ResultValue_type; + JsonObject *jsonObject; +} using Key = std::vector; using Value = std::vector; + +int GetJsonDeep(const std::string &jsonStr, int &jsonDeep); +int CheckColletionNameFormat(JsonObject *collectionName); +int CheckDBFormat(GRD_DB *DB); +int CheckfilterFormat(JsonObject *filter); + + } // DocumentDB #endif // DOC_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h new file mode 100644 index 0000000000000000000000000000000000000000..90cb580ddd6017fd2e1a6436e06659196f292c3c --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/include/json_common.h @@ -0,0 +1,40 @@ +/* +* 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 json_COMMON_H +#define json_COMMON_H + +#include +#include +#include "json_obect.h" + + +namespace DocumentDB { +class JsonCommon { +public: + JsonCommon() = default; + ~JsonCommon() = default; + + std::string GetValue(JsonObect *jsonObect, std::vector path); + + int DeleteJsonData(JsonObect *jsonObect, std::vector path); + + std::vector GetJsonBrotherField(JsonObect *jsonObect, std::vector path); + + std::pair FindItem (JsonObect *jsonObect, std::vector path);//pair.first is JsonObect_root + + std::vector> ParsePath(JsonObect *jsonObect); +} // DocumentDB +#endif // json_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/json_operator.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp similarity index 100% rename from services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/json_operator.h rename to services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/common/src/json_common.cpp diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/grd_document_api.cpp index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e2702e762436431eeca9c4578fabf9274d981e1e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/grd_document_api.cpp @@ -0,0 +1,56 @@ + +#include "grd_base/grd_db_api.h" +#include "grd_base/grd_error.h" +#include "document_store_manager.h" +#include "document_store.h" +#include "doc_errno.h" +#include "grd_document/grd_document_api.h" + +using namespace DocumentDB; + +typedef struct GRD_DB { + DocumentStore *store_ = nullptr; +} GRD_DB; + +int GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, unsigned int flags) +{ + return GRD_OK; +} + +int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flags) +{ + return GRD_OK; +} + +int GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, unsigned int flags) +{ + auto store = db->store_; + std::string str1 = collectionName; + std::string str2 = document; + Key key(str1.c_str(), str1.c_str() + str1.size()); + Value value(str2.c_str(), str2.c_str() + str2.size()); + if (store->PutData(key, value) != E_OK) { + return GRD_FIELD_NOT_FOUND; + } + return GRD_OK;; +} + +int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned int flags, GRD_ResultSet **resultSet) +{ + return GRD_OK; +} + +int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, unsigned int flags) +{ + return GRD_OK; +} + +int GRD_UpSertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, unsigned int flags) +{ + return GRD_OK; +} + +int GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, unsigned int flags) +{ + return GRD_OK; +} diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/projectionTree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/projectionTree.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2653bb6b6d0f5b3ed2d79d8a44ae8257b693041f --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/document/projectionTree.cpp @@ -0,0 +1,65 @@ +/* +* 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 +#include "projectionTree.h" +#include "log_print.h" + +using namespace DocumentDB; + +int ProjectionTree::ParseTree(std::vector> &path) { + ProjectionNode *node = root_; + if (node == NULL) { + GLOGX("root_ is null"); + return 0; + } + for (int i = 0; i < path.size(); i++) { + node = root_; + for (int j = 0; j < path[i].size(); j++) { + if (node->SonNode[path[i][j]] != nullptr) { + node = node->SonNode[path[i][j]]; + if (j < path[i].size() - 1 && node->isDeepest == true) { + GLOGX("projection format is wrong"); + return 0; + } + if (j == path[i].size() - 1 && node->isDeepest == false) { + GLOGX("projection format is wrong"); + return 0; + } + } + else { + auto tempNode = new ProjectionNode; + tempNode->Deep = node->Deep + 1; + node->isDeepest = false; + node->SonNode[path[i][j]] = tempNode; + node = node->SonNode[path[i][j]]; + } + } + } + return 0; +} + +bool ProjectionTree::SerchTree(std::vector &onePath) { + ProjectionNode *node = root_; + for (int i = 0; i < onePath.size(); i++) { + if (node->SonNode[onePath[i]]) { + node = node->SonNode[onePath[i]]; + } + else { + return false; + } + } + return true; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/include/projectionTree.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/include/projectionTree.h new file mode 100644 index 0000000000000000000000000000000000000000..4b891b44f73b7c2487bdd3845dcfbe170d967766 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/executor/include/projectionTree.h @@ -0,0 +1,52 @@ +/* +* 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 PROJECTION_TREE_H +#define PROJECTION_TREE_H + +#include +#include +#include + +namespace DocumentDB { +struct ProjectionNode { + std::unordered_map SonNode; + bool isDeepest; + int Deep; + ProjectionNode() { + Deep = 1; + isDeepest = true; + } +}; + +class ProjectionTree { +public: + ProjectionTree() = default; + + ~ProjectionTree() = default; + + void Init() { + root_ = new ProjectionNode(); + } + + int ParseTree(std::vector> &path); + + bool SerchTree(std::vector &onePath); + +private: + ProjectionNode *root_; +}; +} // DocumentDB +#endif // PROJECTION_TREE_H diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/include/document_store.h index 52bb3c29f2d6abe42a75e543e3cc9b12474b7a5b..d9ba96791d2f5a09876deee4d9aa2fb85f3817d4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/include/document_store.h @@ -23,6 +23,7 @@ class DocumentStore { public: DocumentStore(KvStoreExecutor *); ~DocumentStore(); + int PutData(const Key &key, const Value &value); private: KvStoreExecutor *executor_ = nullptr; }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp index ac9e5ad43483b6f03703aa807cd984ca4d5f3ff6..c5b1ff9ab240d1b3c00f0a6bc7d412c4a19e295e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp @@ -24,4 +24,9 @@ DocumentStore::~DocumentStore() { delete executor_; } + +int DocumentStore::PutData(const Key &key, const Value &value) +{ + executor_->PutData(key, value); +} } // DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h new file mode 100644 index 0000000000000000000000000000000000000000..3d3163e5d1005ce7fbfed3ef5bf359b56f32a060 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/json_object.h @@ -0,0 +1,45 @@ +/* +* 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 JSON_OBJECT_H +#define JSON_OBJECT_H + +#include "doc_common.h" + +namespace DocumentDB { +class JsonObect { +public: + JsonObect () = default; + virtual ~JsonObect() = default; + + virtual int Init() = 0; + + virtual int Print() = 0; + + virtual int GetItemObject() = 0; + + virtual int GetItemArray() = 0; + + virtual int GetArraySize() = 0; + + virtual int GetItemValue() = 0; + + virtual int DelectItemFromObect() = 0; + + JsonObect *next = nullptr; + JsonObect *child = nullptr; +}; +} // DocumentDB +#endif // JSON_OBJECT_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/kv_store_manager.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/kv_store_manager.h index 6c82e98367bd306349b2e4622d68e72d636475bb..a2a8baeb530c82725ff16cc8221e44a9657b4401 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/kv_store_manager.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/include/kv_store_manager.h @@ -24,6 +24,7 @@ namespace DocumentDB { class KvStoreManager { public: static int GetKvStore(const std::string &path, KvStoreExecutor *&executor); + static int InsertKvStore(); }; } // DocumentDB #endif // KV_STORE_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h new file mode 100644 index 0000000000000000000000000000000000000000..8064c40002e098fad16a3e87fbded30c0b3720a5 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/cjson_object.h @@ -0,0 +1,47 @@ +/* +* 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 CJSON_OBJECT_H +#define CJSON_OBJECT_H + +#include "json_object.h" +#include "cJSON.h" +#include "doc_common.h" + +namespace DocumentDB { +class cJsonObject : public cJsonObject { +public: + cJsonObject(); + virtual ~cJsonObject() override; + + int Parse() override; + + int Print() override; + + int GetItemObject() override; + + int GetItemArray() override; + + int GetArraySize() override; + + int GetItemValue() override; + + int DelectItemFromObect() override; + +private: + cJSON *cjson_; +}; +} // DocumentDB +#endif // SQLITE_STORE_EXECUTOR_IMPL_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/json_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/kv_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/kv_store_manager.cpp index d4c91bcdec586ea8ad1067e4043041dc475d07b7..dbc8e278806b1a81a2971cd9edffd8cc7030082d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/kv_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/kv_store_manager.cpp @@ -41,7 +41,6 @@ int KvStoreManager::GetKvStore(const std::string &path, KvStoreExecutor *&execut if (db == nullptr) { return -E_ERROR; } - executor = new (std::nothrow) SqliteStoreExecutor(db); return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp index 78f763138d89e2c0cd0ebd870cf58bbc310479ba..68580312979112bbd639aab7cd07eae9bbe1034a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -12,7 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "securec.h" #include "doc_errno.h" +#include "log_print.h" #include "sqlite_store_executor_impl.h" namespace DocumentDB { @@ -28,6 +30,35 @@ SqliteStoreExecutor::~SqliteStoreExecutor() int SqliteStoreExecutor::PutData(const Key &key, const Value &value) { + sqlite3 *db = dbHandle_; + int rc; + const std::string sql_creat = "CREATE TABLE JSON(" \ + "id varchar(255)," \ + "json varchar(255) );"; + char *errMsg = nullptr; + rc = sqlite3_exec(db, sql_creat.c_str(), 0, 0, &errMsg); + if( rc != SQLITE_OK ){ + return E_ERROR; + } + int rc_2; + std::string sql_key(key.begin(), key.end()); + sql_key.insert(0, "\'"); + sql_key.push_back('\''); + std::string sql_value(value.begin(), value.end()); + sql_value.insert(0, "\'"); + sql_value.push_back('\''); + const std::string sql_insert_head = "INSERT INTO JSON VALUES ("; + const std::string sql_insert_middle_key = sql_key; + const std::string sql_insert_middle_dot = ","; + const std::string sql_insert_middle_value = sql_value; + const std::string sql_insert_tail = ");"; + const std::string sql_insert = sql_insert_head + sql_insert_middle_key + sql_insert_middle_dot + sql_insert_middle_value + sql_insert_tail; + char *errMsg_2 = nullptr; + rc_2 = sqlite3_exec(db, sql_insert.c_str(), 0, 0, &errMsg_2); + if( rc_2 != SQLITE_OK ){ + return E_ERROR; + } + sqlite3_close(db); return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_insert_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6c864a72279ffd782e40a560b2616cd3ee0accec --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_insert_test.cpp @@ -0,0 +1,66 @@ +/* +* 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 + +#include "grd_base/grd_db_api.h" +#include "grd_document/grd_document_api.h" +#include "grd_base/grd_error.h" +using namespace testing::ext; + +std::string path = "./document.db"; +GRD_DB *g_db = nullptr; + +class DocumentInsertApiTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DocumentInsertApiTest::SetUpTestCase(void) +{ + GRD_DBOpen(path.c_str(), nullptr, 0, &g_db); + EXPECT_NE(g_db, nullptr); +} + +void DocumentInsertApiTest::TearDownTestCase(void) +{ +} + +void DocumentInsertApiTest::SetUp(void) +{ +} + +void DocumentInsertApiTest::TearDown(void) +{ +} + + +/** + * @tc.name: OpenDBTest001 + * @tc.desc: Test Insert document db + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ + +HWTEST_F(DocumentInsertApiTest, InsertDBTest001, TestSize.Level1) +{ + const char *key = "id"; + const char *document = "{\"id\":\"1\"}"; + EXPECT_EQ(GRD_InsertDoc(g_db, key, document, 0), GRD_OK); +} \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/doucumentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/doucumentdb_api_test.cpp index ea2b198f1a56920f56a10eb21841423926f8eaed..d3ba2596ee350a3c45b1051a189015053cefec6d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/doucumentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/doucumentdb_api_test.cpp @@ -18,6 +18,7 @@ #include "log_print.h" #include "grd_base/grd_db_api.h" #include "grd_base/grd_error.h" +#include "grd_document/grd_document_api.h" using namespace DocumentDB; using namespace testing::ext; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/json_Adator/jsonInfo_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/json_Adator/jsonInfo_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8aa6304f963ac32ab77e116a8802d390dffed754 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/json_Adator/jsonInfo_test.cpp @@ -0,0 +1,93 @@ +/* +* 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 + +#include "grd_base/grd_db_api.h" +#include "jsonInfo.h" + +using namespace testing::ext; + +namespace { + const int MAX_DEPTH_FOR_TEST = 10; + const int STRING1_DEPTH = 12; + const int STRING3_DEPTH = 6; + + // nest depth = 12 and valid. + const string JSON_STRING1 = "{\"#14\":[[{\"#11\":{\"#8\":[{\"#5\":[[{\"#2\":[{\"#0\":\"value_\"},\"value_\"]," + "\"#3\":\"value_\"},\"value_\"],\"value_\"],\"#6\":\"value_\"},\"value_\"],\"#9\":\"value_\"}," + "\"#12\":\"value_\"},\"value_\"],\"value_\"],\"#15\":{\"#18\":{\"#16\":\"value_\"},\"#19\":\"value_\"}}"; + + // nest depth = 12 and invalid happens in nest depth = 2. + const string JSON_STRING2 = "{\"#17\":[\"just for mistake pls.[{\"#14\":[[{\"#11\":{\"#8\":{\"#5\":[{\"#2\":" + "{\"#0\":\"value_\"},\"#3\":\"value_\"},\"value_\"],\"#6\":\"value_\"},\"#9\":\"value_\"}," + "\"#12\":\"value_\"},\"value_\"],\"value_\"],\"#15\":\"value_\"},\"value_\"],\"value_\"]," + "\"#18\":{\"#21\":{\"#19\":\"value_\"},\"#22\":\"value_\"}}"; + + // nest depth = 6 and valid. + const string JSON_STRING3 = "{\"#5\":[{\"#2\":[[{\"#0\":\"value_\"},\"value_\"],\"value_\"],\"#3\":\"value_\"}," + "\"value_\"],\"#6\":{\"#7\":\"value_\",\"#8\":\"value_\"}}"; + + // nest depth = 6 and invalid happens in nest depth = 3. + const string JSON_STRING4 = "{\"#6\":[{\"#3\":\"just for mistake pls.[{\"#0\":[\"value_\"],\"#1\":\"value_\"}," + "\"value_\"],\"#4\":\"value_\"},\"value_\"],\"#7\":{\"#8\":\"value_\",\"#9\":\"value_\"}}"; + + // nest depth = 15 and invalid happens in nest depth = 11. + const string JSON_STRING5 = "{\"#35\":[{\"#29\":{\"#23\":{\"#17\":{\"#11\":{\"#8\":[{\"#5\":[{\"#2\":" + "\"just for mistake pls.[[[{\"#0\":\"value_\"},\"value_\"],\"value_\"],\"value_\"],\"#3\":\"value_\"}," + "\"value_\"],\"#6\":\"value_\"},\"value_\"],\"#9\":\"value_\"},\"#12\":{\"#13\":\"value_\"," + "\"#14\":\"value_\"}},\"#18\":{\"#19\":\"value_\",\"#20\":\"value_\"}},\"#24\":{\"#25\":\"value_\"," + "\"#26\":\"value_\"}},\"#30\":{\"#31\":\"value_\",\"#32\":\"value_\"}},\"value_\"],\"#36\":" + "{\"#37\":[\"value_\"],\"#38\":\"value_\"}}"; + + uint32_t g_oriMaxNestDepth = 0; +} + +class jsonInfoTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void jsonInfoTest::SetUpTestCase(void) +{ +} + +void jsonInfoTest::TearDownTestCase(void) +{ +} + +void jsonInfoTest::SetUp(void) +{ +} + +void jsonInfoTest::TearDown(void) +{ +} + + +/** + * @tc.name: GetjsonDeepTest + * @tc.desc: Test get jsons deep lens. + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(jsonInfoTest, GetjsonDeepTest001, TestSize.Level1) +{ + +} \ No newline at end of file