From 5dd8c1be132a99520895c5b00695940c7c660f0b Mon Sep 17 00:00:00 2001 From: liaoyonghuang Date: Fri, 27 Jun 2025 11:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=BC=82=E5=B8=B8=E5=88=86?= =?UTF-8?q?=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoyonghuang --- frameworks/libs/distributeddb/test/BUILD.gn | 16 ++++--- .../common/tokenizer/sqlite_adapter_test.cpp | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/frameworks/libs/distributeddb/test/BUILD.gn b/frameworks/libs/distributeddb/test/BUILD.gn index a1ee1ac14c9..ffab5b0e52f 100644 --- a/frameworks/libs/distributeddb/test/BUILD.gn +++ b/frameworks/libs/distributeddb/test/BUILD.gn @@ -898,6 +898,7 @@ config("tokenizer_config_unittest") { visibility = [ ":*" ] include_dirs = [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/include", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/sqlite_adapter/include", ] defines = [ @@ -911,18 +912,15 @@ config("tokenizer_config_unittest") { } ohos_unittest("tokenizer_test") { - branch_protector_ret = "pac_ret" - - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - module_out_path = module_output_path sources = [ "unittest/common/tokenizer/sqlite_adapter_test.cpp" ] - sources += [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp" ] + sources += [ + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/sqlite_adapter/src/tokenizer_sqlite.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/sqlite_adapter/src/tokenizer_api_mgr.cpp", + "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/sqlite_adapter/src/tokenizer_api.cpp" + ] configs = [ ":tokenizer_config_unittest" ] cflags_cc = [] diff --git a/frameworks/libs/distributeddb/test/unittest/common/tokenizer/sqlite_adapter_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/tokenizer/sqlite_adapter_test.cpp index ea5dbd4acaf..8f59d165cd6 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/tokenizer/sqlite_adapter_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/tokenizer/sqlite_adapter_test.cpp @@ -25,6 +25,7 @@ #else #include "sqlite3sym.h" #endif +#include "tokenizer_sqlite.h" using namespace std; using namespace testing::ext; @@ -346,4 +347,45 @@ HWTEST_F(SqliteAdapterTest, SqliteAdapterTest004, TestSize.Level0) const char *SQLDROP = "DROP TABLE IF EXISTS example;"; SQLTest(SQLDROP); EXPECT_EQ(sqlite3_close(g_sqliteDb), SQLITE_OK); +} + +/** + * @tc.name: SqliteAdapterTest005 + * @tc.desc: Test abnormal branch + * @tc.type: FUNC + * @tc.require: + * @tc.author: liaoyonghuang + */ +HWTEST_F(SqliteAdapterTest, SqliteAdapterTest005, TestSize.Level0) +{ + /** + * @tc.steps: step1. Test duplicate creation + * @tc.expected: step1. OK. + */ + std::vector args = {"cut_mode", "short_words"}; + std::vector cStr; + cStr.reserve(args.size()); + for (const auto &arg : args) { + cStr.push_back(arg.c_str()); + } + Fts5Tokenizer *ppOut1 = nullptr; + EXPECT_EQ(fts5_customtokenizer_xCreate(nullptr, cStr.data(), args.size(), &ppOut1), SQLITE_OK); + Fts5Tokenizer *ppOut2 = nullptr; + EXPECT_EQ(fts5_customtokenizer_xCreate(nullptr, cStr.data(), args.size(), &ppOut2), SQLITE_OK); + fts5_customtokenizer_xDelete(ppOut1); + fts5_customtokenizer_xDelete(ppOut2); + /** + * @tc.steps: step2. Test abnormal tokenizer + * @tc.expected: step2. OK. + */ + XTokenFn xToken = [](void *, int, const char *, int, int, int)-> int { + return 0; + }; + const int expectRet = -3000; // -3000 is GRD_INVALID_ARGS + EXPECT_EQ(fts5_customtokenizer_xTokenize(nullptr, nullptr, 0, nullptr, 0, xToken), expectRet); + /** + * @tc.steps: step3. Test abnormal tokenizer init + * @tc.expected: step3. OK. + */ + EXPECT_FALSE(sqlite3_customtokenizer_init(nullptr, nullptr, nullptr) == SQLITE_OK); } \ No newline at end of file -- Gitee