From 99318693a8538e9b4f5a19d25ee6e530f7758586 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Mon, 16 Jun 2025 15:34:09 +0800 Subject: [PATCH] update Signed-off-by: z30053788 Change-Id: Id3ca0ab0d190cb96855e46762b9fe14a499ccb66 --- .../mock_abs_shared_result_set.cpp | 6 + .../notification_rdb_data_mgr_test.cpp | 192 ++++++++++++++++++ .../os_account_manager_helper_test.cpp | 25 +++ 3 files changed, 223 insertions(+) diff --git a/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_abs_shared_result_set.cpp b/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_abs_shared_result_set.cpp index a52cb4242..43fdb92e7 100755 --- a/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_abs_shared_result_set.cpp +++ b/services/ans/test/unittest/notification_rdb_data_mgr_test/mock_abs_shared_result_set.cpp @@ -19,6 +19,7 @@ namespace { bool g_mockHasBlockRet = true; bool g_mockGetStringRet = true; + bool g_mockGetUserTableName = true; } void MockHasBlock(bool mockRet) @@ -31,6 +32,11 @@ void MockGetString(bool mockRet) g_mockGetStringRet = mockRet; } +void MockGetUserTableName(bool mockRet) +{ + g_mockGetUserTableName = mockRet; +} + namespace OHOS { namespace NativeRdb { bool AbsSharedResultSet::HasBlock() diff --git a/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp b/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp index 6ed1cc8dc..b07f6d8c2 100755 --- a/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp +++ b/services/ans/test/unittest/notification_rdb_data_mgr_test/notification_rdb_data_mgr_test.cpp @@ -34,6 +34,7 @@ namespace { extern void MockHasBlock(bool mockRet); extern void MockGoToFirstRow(bool mockRet); extern void MockGetString(bool mockRet); +extern void MockGetUserTableName(bool mockRet); using namespace testing::ext; using namespace OHOS::NativeRdb; @@ -757,5 +758,196 @@ HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02600 g_mockExecuteSql = false; ASSERT_EQ(notificationDataMgr->DropUserTable(-1), NativeRdb::E_ERROR); } + + +/** + * @tc.name : OnUpgrade_Test_001 + * @tc.number : + * @tc.desc : Test that OnUpgrade function returns E_OK when called + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, OnUpgrade_Test_001, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr rdbStoreData_ = + std::make_unique(notificationRdbConfig); + int32_t oldVersion = 1; + int32_t newVersion = 2; + auto rdbStore = std::make_shared(); + int32_t result = rdbStoreData_->OnUpgrade(*rdbStore, oldVersion, newVersion); + + EXPECT_EQ(result, NativeRdb::E_OK); +} + +/** + * @tc.name : OnDowngrade_Test_001 + * @tc.number : + * @tc.desc : Test that OnDowngrade function returns E_OK when called + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, OnDowngrade_Test_001, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr rdbStoreData_ = + std::make_unique(notificationRdbConfig); + int32_t currentVersion = 1; + int32_t targetVersion = 2; + auto rdbStore = std::make_shared(); + int32_t result = rdbStoreData_->OnDowngrade(*rdbStore, currentVersion, targetVersion); + + EXPECT_EQ(result, NativeRdb::E_OK); +} + +/** + * @tc.name : onCorruption_Test_001 + * @tc.number : + * @tc.desc : Test that onCorruption function returns E_OK when called + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, onCorruption_Test_001, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr rdbStoreData_ = + std::make_unique(notificationRdbConfig); + std::string databaseFile = "test_file"; + int32_t result = rdbStoreData_->onCorruption(databaseFile); + + EXPECT_EQ(result, NativeRdb::E_OK); +} + +/** + * @tc.name : InsertData_Test_001 + * @tc.number : + * @tc.desc : test InsertData + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, InsertData_Test_001, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = nullptr; + std::string key = ""; + std::string value = ""; + MockGetUserTableName(false); + ASSERT_NE(notificationDataMgr->InsertData(key, value, -1), NativeRdb::E_OK); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_001 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_ERROR when rdbStore_ is null. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_001, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = nullptr; + + std::unordered_map values; + int32_t userId = 1; + std::string key = "testKey"; + + // Call the function and verify the result + int32_t result = notificationDataMgr->QueryDataContainsWithKey(key, values, userId); + EXPECT_EQ(result, NativeRdb::E_ERROR); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_002 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_ERROR when rdbStore_ is null. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_002, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = std::make_shared(); + + std::unordered_map values; + int32_t userId = 1; + std::string key = "testKey"; + + // Call the function and verify the result + int32_t result = notificationDataMgr->QueryDataContainsWithKey(key, values, userId); + EXPECT_EQ(result, NativeRdb::E_OK); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_003 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_ERROR when the result set is null. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_003, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = std::make_shared(); + + std::unordered_map values; + std::string tableName = "testTable"; + std::string key = "testKey"; + g_mockQueryRet = true; + + int32_t result = notificationDataMgr->QueryDataContainsWithKey(tableName, key, values); + EXPECT_EQ(result, NativeRdb::E_ERROR); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_004 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_EMPTY_VALUES_BUCKET when GoToFirstRow fails. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_004, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = std::make_shared(); + + std::unordered_map values; + std::string tableName = "testTable"; + std::string key = "testKey"; + g_mockQueryRet = false; + MockGoToFirstRow(false); + + int32_t result = notificationDataMgr->QueryDataContainsWithKey(tableName, key, values); + EXPECT_EQ(result, NativeRdb::E_EMPTY_VALUES_BUCKET); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_005 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_EMPTY_VALUES_BUCKET. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_005, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = std::make_shared(); + + std::unordered_map values; + std::string tableName = "testTable"; + std::string key = "testKey"; + + int32_t result = notificationDataMgr->QueryDataContainsWithKey(tableName, key, values); + EXPECT_EQ(result, NativeRdb::E_EMPTY_VALUES_BUCKET); +} + +/** + * @tc.name : QueryDataContainsWithKey_Test_006 + * @tc.number : + * @tc.desc : Test case to verify that the function returns E_ERROR. + */ +HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, QueryDataContainsWithKey_Test_006, Function | SmallTest | Level1) +{ + NotificationRdbConfig notificationRdbConfig; + std::unique_ptr notificationDataMgr = + std::make_unique(notificationRdbConfig); + notificationDataMgr->rdbStore_ = std::make_shared(); + + int32_t result = notificationDataMgr->RestoreForMasterSlaver(); + EXPECT_EQ(result, NativeRdb::E_ERROR); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/os_account_manager_helper_test.cpp b/services/ans/test/unittest/os_account_manager_helper_test.cpp index a13607524..dbdcdc02e 100644 --- a/services/ans/test/unittest/os_account_manager_helper_test.cpp +++ b/services/ans/test/unittest/os_account_manager_helper_test.cpp @@ -23,6 +23,7 @@ using namespace testing::ext; namespace OHOS { namespace Notification { +constexpr int32_t ERR_ACCOUNT_COMMON_PERMISSION_DENIED = 0x400008; class OsAccountManagerHelperTest : public testing::Test { public: static void SetUpTestSuite() {}; @@ -130,5 +131,29 @@ HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0400, Function | SmallTest int32_t userId = 10736; ASSERT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId)); } + +/** + * @tc.number : GetAllOsAccount_001 + * @tc.name : GetAllOsAccount_001 + * @tc.desc : test GetAllOsAccount function. + */ +HWTEST_F(OsAccountManagerHelperTest, GetAllOsAccount_001, Function | SmallTest | Level1) +{ + std::vector userIds; + ASSERT_EQ(OsAccountManagerHelper::GetInstance().GetAllOsAccount(userIds), + ERR_ACCOUNT_COMMON_PERMISSION_DENIED); +} + +/** + * @tc.number : GetOsAccountPrivateStatus_Test_001 + * @tc.name : GetOsAccountPrivateStatus_Test_001 + * @tc.desc : test GetAllOsAccount function. + */ +HWTEST_F(OsAccountManagerHelperTest, GetOsAccountPrivateStatus_Test_001, Function | SmallTest | Level1) +{ + bool isPrivate = false; + ASSERT_EQ(OsAccountManagerHelper::GetInstance().GetOsAccountPrivateStatus(isPrivate), + ERR_ACCOUNT_COMMON_PERMISSION_DENIED); +} } } \ No newline at end of file -- Gitee