diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 35c6d13e6fe87ad844afa8bb4889f4c15b0104d0..a748a9c9e07155d8aaa37c9d3d1e428b06e181db 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/reminder_request_calendar_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_timer_test.cpp", + "${frameworks_module_ans_path}/test/unittest/reminder_store_test.cpp", ] configs = [ "//commonlibrary/c_utils/base:utils_config" ] diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index d418b10ea510121282a12d3b6cc616d90074638b..9d12b7e4e47ebcd3df2972cfd35b4fade60a0170 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -837,5 +837,168 @@ HWTEST_F(ReminderRequestTest, SetReminderTimeInMilli_00001, Function | SmallTest rrc->SetReminderTimeInMilli(reminderTimeInMilli); EXPECT_EQ(rrc->GetReminderTimeInMilli(), reminderTimeInMilli); } + +/** + * @tc.name: SetRingDuration_00001 + * @tc.desc: Test SetRingDuration parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, SetRingDuration_00001, Function | SmallTest | Level1) +{ + uint64_t ringDurationInSeconds = 0; + auto rrc = std::make_shared(); + rrc->SetRingDuration(ringDurationInSeconds); + EXPECT_EQ(rrc->GetRingDuration(), 1); +} + +/** + * @tc.name: SetRingDuration_00002 + * @tc.desc: Test SetRingDuration parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, SetRingDuration_00002, Function | SmallTest | Level1) +{ + uint64_t ringDurationInSeconds = 10; + auto rrc = std::make_shared(); + rrc->SetRingDuration(ringDurationInSeconds); + EXPECT_EQ(rrc->GetRingDuration(), ringDurationInSeconds); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool result = false; + Parcel parcel; + auto rrc = std::make_shared(); + if (nullptr == rrc->Unmarshalling(parcel)) { + result = true; + } + EXPECT_EQ(true, result); +} + +/** + * @tc.name: InitNotificationRequest_00001 + * @tc.desc: Test InitNotificationRequest parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, InitNotificationRequest_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); +} + +/** + * @tc.name: InitNotificationRequest_00002 + * @tc.desc: Test InitNotificationRequest parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, InitNotificationRequest_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->SetNotificationId(100); + EXPECT_EQ(rrc->InitNotificationRequest(), true); +} + +/** + * @tc.name: IsAlerting_00001 + * @tc.desc: Test IsAlerting parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, IsAlerting_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->IsAlerting(), false); +} + +/** + * @tc.name: GetButtonInfo_00001 + * @tc.desc: Test GetButtonInfo parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, GetButtonInfo_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->GetButtonInfo(), ""); +} + +/** + * @tc.name: GetShowTime_00001 + * @tc.desc: Test GetShowTime parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, GetShowTime_00001, Function | SmallTest | Level1) +{ + uint64_t showTime = 8 * 60 * 1000; + auto rrc = std::make_shared(); + std::string ret = "00:08"; + EXPECT_EQ(rrc->GetShowTime(showTime), ret); +} + +/** + * @tc.name: GetShowTime_00002 + * @tc.desc: Test GetShowTime parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, GetShowTime_00002, Function | SmallTest | Level1) +{ + uint64_t showTime = 8 * 60 * 1000; + ReminderRequest reminder = ReminderRequest(ReminderRequest::ReminderType::TIMER); + auto rrc = std::make_shared(); + std::string ret = "00:08"; + EXPECT_EQ(rrc->GetShowTime(showTime), ret); +} + +/** + * @tc.name: CreateWantAgent_00001 + * @tc.desc: Test CreateWantAgent parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, CreateWantAgent_00001, Function | SmallTest | Level1) +{ + AppExecFwk::ElementName element; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->CreateWantAgent(element), nullptr); +} + +/** + * @tc.name: GetUid_00001 + * @tc.desc: Test GetUid parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, GetUid_00001, Function | SmallTest | Level1) +{ + int32_t userId = 1; + std::string bundleName = "bundleName"; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->GetUid(userId, bundleName), -1); +} + +/** + * @tc.name: GetUserId_00001 + * @tc.desc: Test GetUserId parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderRequestTest, GetUserId_00001, Function | SmallTest | Level1) +{ + int32_t uid = 1; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->GetUserId(uid), 0); +} } } diff --git a/frameworks/ans/test/unittest/reminder_store_test.cpp b/frameworks/ans/test/unittest/reminder_store_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a684d4fd6b83b29ec700b151e61f3c6971a11fd4 --- /dev/null +++ b/frameworks/ans/test/unittest/reminder_store_test.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminder_helper.h" +#include "notification_preferences.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +namespace { + constexpr int32_t NON_SYSTEM_APP_UID = 1000; + const std::string TEST_DEFUALT_BUNDLE = "bundleName"; + const int32_t STATE_FAIL = -1; +} +class ReminderStoreTest : public testing::Test { +public: + static void SetUpTestCase() + { + ReminderHelper::CancelAllReminders(); + } + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() + { + ReminderHelper::CancelAllReminders(); + } + static sptr bundleOption_; +}; + +sptr ReminderStoreTest::bundleOption_ = + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + +/** + * @tc.name: Init_00001 + * @tc.desc: Test Init parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Init_00001, Function | SmallTest | Level1) +{ + ReminderStore reminderStore; + int32_t ret = reminderStore.Init(); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: InitData_00001 + * @tc.desc: Test InitData parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, InitData_00001, Function | SmallTest | Level1) +{ + ReminderStore reminderStore; + int32_t ret = reminderStore.InitData(); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Delete_00001 + * @tc.desc: Test Delete parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Delete_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 1; + ReminderStore reminderStore; + int32_t ret = reminderStore.Delete(reminderId); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Delete_00002 + * @tc.desc: Test Delete parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Delete_00002, Function | SmallTest | Level1) +{ + std::string pkg = "pkg"; + int32_t userId = 1; + ReminderStore reminderStore; + int32_t ret = reminderStore.Delete(pkg, userId); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Delete_00003 + * @tc.desc: Test Delete parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Delete_00003, Function | SmallTest | Level1) +{ + std::string deleteCondition = "deleteCondition"; + ReminderStore reminderStore; + int32_t ret = reminderStore.Delete(deleteCondition); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Insert_00001 + * @tc.desc: Test Insert parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Insert_00001, Function | SmallTest | Level1) +{ + sptr reminder = nullptr; + ReminderStore reminderStore; + int64_t ret = reminderStore.Insert(reminder, bundleOption_); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Update_00001 + * @tc.desc: Test Update parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Update_00001, Function | SmallTest | Level1) +{ + sptr reminder = nullptr; + ReminderStore reminderStore; + int64_t ret = reminderStore.Update(reminder, bundleOption_); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: Query_00001 + * @tc.desc: Test Query parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, Query_00001, Function | SmallTest | Level1) +{ + std::string queryCondition = "queryCondition"; + std::string name = "it"; + ReminderStore reminderStore; + reminderStore.GetColumnIndex(name); + std::shared_ptr ret = reminderStore.Query(queryCondition); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.name: GetMaxId_00001 + * @tc.desc: Test GetMaxId parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, GetMaxId_00001, Function | SmallTest | Level1) +{ + ReminderStore reminderStore; + int32_t ret = reminderStore.GetMaxId(); + EXPECT_EQ(ret, STATE_FAIL); +} + +/** + * @tc.name: GetAllValidReminders_00001 + * @tc.desc: Test GetAllValidReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, GetAllValidReminders_00001, Function | SmallTest | Level1) +{ + ReminderStore reminderStore; + std::vector> ret = reminderStore.GetAllValidReminders(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.name: GetReminders_00001 + * @tc.desc: Test GetReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5VB6V + */ +HWTEST_F(ReminderStoreTest, GetReminders_00001, Function | SmallTest | Level1) +{ + std::string queryCondition = "queryCondition"; + ReminderStore reminderStore; + std::vector> ret = reminderStore.GetReminders(queryCondition); + EXPECT_EQ(ret.size(), 0); +} +} +} \ No newline at end of file