diff --git a/bundle.json b/bundle.json index 47ec4cac15db8662119cab675c75fda064e9350f..29f7ae753297fef7b2eaf22a7133e985636c8e01 100644 --- a/bundle.json +++ b/bundle.json @@ -105,6 +105,7 @@ "//base/notification/distributed_notification_service/services/test/moduletest:moduletest", "//base/notification/distributed_notification_service/frameworks/test/moduletest:moduletest", "//base/notification/distributed_notification_service/frameworks/ans/test/unittest:unittest", + "//base/notification/distributed_notification_service/frameworks/core/test/unittest:unittest", "//base/notification/distributed_notification_service/test:systemtest", "//base/notification/distributed_notification_service/tools:unittest", "//base/notification/distributed_notification_service/test/bechmarktest:benchmarktest", diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index f368a78c2bd30ce8abe634d18203b604ae0fc67c..af1ca979bb1893ae67e3fd8a42a0d366f37faa0b 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -486,7 +486,7 @@ void Notification::SetSourceType(NotificationConstant::SourceType sourceType) std::string Notification::Dump() const { std::string vibrationStyle = ""; - for (auto &style : vibrationStyle_) { + for (const auto &style : vibrationStyle_) { vibrationStyle += std::to_string(style); vibrationStyle += ", "; } diff --git a/frameworks/ans/src/notification_distributed_options.cpp b/frameworks/ans/src/notification_distributed_options.cpp index dbfb26a275de63819df7b2262afed6180f288f69..4f6349f67d05349babd396c986141bc467475f0f 100644 --- a/frameworks/ans/src/notification_distributed_options.cpp +++ b/frameworks/ans/src/notification_distributed_options.cpp @@ -56,13 +56,13 @@ std::vector NotificationDistributedOptions::GetDevicesSupportOperat std::string NotificationDistributedOptions::Dump() { std::string devicesSupportDisplay = ""; - for (auto &device : devicesSupportDisplay_) { + for (const auto &device : devicesSupportDisplay_) { devicesSupportDisplay += device; devicesSupportDisplay += ", "; } std::string devicesSupportOperate = ""; - for (auto &device : devicesSupportOperate_) { + for (const auto &device : devicesSupportOperate_) { devicesSupportOperate += device; devicesSupportOperate += ", "; } diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index ec6963f02244d732372d493faed76b07d923160a..1f8fb171066cc695f99f9068cf7e750a817030b2 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -154,11 +154,6 @@ ErrCode NotificationHelper::IsAllowedNotifySelf(bool &allowed) return DelayedSingleton::GetInstance()->IsAllowedNotifySelf(allowed); } -ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId) -{ - return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId); -} - ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId, bool &popFlag) { return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId, popFlag); diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 3a0baca5d00cb36570767f655b697870b351be62..c9e5e05259ae3342f3d249ffb5bc199c4cd122fc 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -32,9 +32,25 @@ ohos_unittest("ans_reminder_unit_test") { sources = [ "${frameworks_module_ans_path}/test/unittest/ans_log_test.cpp", "${frameworks_module_ans_path}/test/unittest/enabled_notification_callback_data_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_bundle_option_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_content_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_conversational_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_conversational_message_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_do_not_disturb_date_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_flags_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_helper_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_long_text_content_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_media_content_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_multiline_content_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_picture_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_request_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_sorting_map_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_sorting_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_subscribe_info_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_template_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_user_input_test.cpp", + "${frameworks_module_ans_path}/test/unittest/reminder_helper_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_alarm_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_calendar_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da271a3f6bbcbbd20cd73d66db03ac9d4073b5d4 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp @@ -0,0 +1,135 @@ +/* + * 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 "notification_bundle_option.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationBundleOptionTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetBundleName_00001 + * @tc.desc: Test SetBundleName parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, SetBundleName_00001, Function | SmallTest | Level1) +{ + std::string bundleName = "BundleName"; + std::string bundleName1 = "BundleName1"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + rrc->SetBundleName(bundleName1); + EXPECT_EQ(rrc->GetBundleName(), bundleName1); +} + +/** + * @tc.name: SetUid_00001 + * @tc.desc: Test SetUid parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, SetUid_00001, Function | SmallTest | Level1) +{ + std::string bundleName = "BundleName"; + int32_t uid = 10; + int32_t uid1 = 20; + auto rrc = std::make_shared(bundleName, uid); + rrc->SetUid(uid1); + EXPECT_EQ(rrc->GetUid(), uid1); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, Dump_00001, Function | SmallTest | Level1) +{ + std::string bundleName = "BundleName"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + std::string ret = "NotificationBundleOption{ bundleName = BundleName, uid = 10 }"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + std::string bundleName = "BundleName"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::string bundleName = "BundleName"; + int32_t uid = 10; + std::shared_ptr result = + std::make_shared(bundleName, uid); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationBundleOptionTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + std::string bundleName = "BundleName"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_conversational_content_test.cpp b/frameworks/ans/test/unittest/notification_conversational_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c91fb36054e232c8ff92ebb0897492c4637f617 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_conversational_content_test.cpp @@ -0,0 +1,100 @@ +/* + * 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 "notification_conversational_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationConversationalContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationConversationalContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + MessageUser messageUser; + nlohmann::json jsonObject; + auto rrc = std::make_shared(messageUser); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationConversationalContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + MessageUser messageUser; + Parcel parcel; + auto rrc = std::make_shared(messageUser); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationConversationalContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + MessageUser messageUser; + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(messageUser); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationConversationalContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + MessageUser messageUser; + Parcel parcel; + auto rrc = std::make_shared(messageUser); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_do_not_disturb_date_test.cpp b/frameworks/ans/test/unittest/notification_do_not_disturb_date_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c254f89eba2ef7060a607eef79bf7668010f6044 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_do_not_disturb_date_test.cpp @@ -0,0 +1,158 @@ +/* + * 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 "notification_do_not_disturb_date.h" +#undef private +#undef protected + +#include "notification_constant.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationDoNotDisturbDateTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetDoNotDisturbType_00001 + * @tc.desc: Test SetDoNotDisturbType parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, SetDoNotDisturbType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + rrc->SetDoNotDisturbType(doNotDisturbType); + EXPECT_EQ(rrc->GetDoNotDisturbType(), doNotDisturbType); +} + +/** + * @tc.name: SetBeginDate_00001 + * @tc.desc: Test SetBeginDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, SetBeginDate_00001, Function | SmallTest | Level1) +{ + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t beginDate1 = 20; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + rrc->SetBeginDate(beginDate1); + EXPECT_EQ(rrc->GetBeginDate(), beginDate1); +} + +/** + * @tc.name: SetEndDate_00001 + * @tc.desc: Test SetEndDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, SetEndDate_00001, Function | SmallTest | Level1) +{ + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate1 = 20; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + rrc->SetEndDate(endDate1); + EXPECT_EQ(rrc->GetEndDate(), endDate1); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, Dump_00001, Function | SmallTest | Level1) +{ + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + std::string ret = "NotificationDoNotDisturbDate{ doNotDisturbType = 1, beginDate = 10, endDate = 10 }"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate = 10; + std::shared_ptr result = + std::make_shared(doNotDisturbType, beginDate, endDate); + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationDoNotDisturbDateTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + NotificationConstant::DoNotDisturbType doNotDisturbType = NotificationConstant::DoNotDisturbType::ONCE; + int64_t beginDate = 10; + int64_t endDate = 10; + auto rrc = std::make_shared(doNotDisturbType, beginDate, endDate); + EXPECT_EQ(rrc->ReadFromParcel(parcel), true); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_flags_test.cpp b/frameworks/ans/test/unittest/notification_flags_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..165ee044e2c794958d6ac8efe95c7571f1857031 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_flags_test.cpp @@ -0,0 +1,137 @@ +/* + * 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 "notification_flags.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationFlagsTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetSoundEnabled_00001 + * @tc.desc: Test SetSoundEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, SetSoundEnabled_00001, Function | SmallTest | Level1) +{ + NotificationConstant::FlagStatus sound =NotificationConstant::FlagStatus(1); + auto rrc = std::make_shared(); + rrc->SetSoundEnabled(sound); + EXPECT_EQ(rrc->IsSoundEnabled(), sound); +} + +/** + * @tc.name: SetVibrationEnabled_00001 + * @tc.desc: Test SetVibrationEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, SetVibrationEnabled_00001, Function | SmallTest | Level1) +{ + NotificationConstant::FlagStatus vibrationEnabled =NotificationConstant::FlagStatus(1); + auto rrc = std::make_shared(); + rrc->SetVibrationEnabled(vibrationEnabled); + EXPECT_EQ(rrc->IsVibrationEnabled(), vibrationEnabled); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string ret = "soundEnabled = 0, vibrationEnabled = 0"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationFlagsTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), true); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5dda006cbb89eed0ba24773afe29f73e47ee6297 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -0,0 +1,1055 @@ +/* + * 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 + +#include "notification_bundle_option.h" +#include "notification_do_not_disturb_date.h" +#include "enabled_notification_callback_data.h" +#include "notification_request.h" +#include "notification_slot.h" +#include "notification_sorting_map.h" +#include "notification_subscriber.h" +#include "ans_inner_errors.h" +#include "errors.h" +#include "notification_helper.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationHelperTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: AddNotificationSlot_00001 + * @tc.desc: Test AddNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, AddNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationSlot slot; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.AddNotificationSlot(slot); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: AddSlotByType_00001 + * @tc.desc: Test AddSlotByType parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, AddSlotByType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.AddSlotByType(slotType); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: AddNotificationSlots_00001 + * @tc.desc: Test AddNotificationSlots parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, AddNotificationSlots_00001, Function | SmallTest | Level1) +{ + std::vector slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.AddNotificationSlots(slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveNotificationSlot_00001 + * @tc.desc: Test RemoveNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotificationSlot(slotType); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveAllSlots_00001 + * @tc.desc: Test RemoveAllSlots parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveAllSlots_00001, Function | SmallTest | Level1) +{ + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveAllSlots(); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetNotificationSlot_00001 + * @tc.desc: Test GetNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + sptr slot = nullptr; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationSlot(slotType, slot); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetNotificationSlots_00001 + * @tc.desc: Test GetNotificationSlots parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationSlots_00001, Function | SmallTest | Level1) +{ + std::vector> slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationSlots(slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetNotificationSlotNumAsBundle_00001 + * @tc.desc: Test GetNotificationSlotNumAsBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationSlotNumAsBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + uint64_t num = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: PublishNotification_00001 + * @tc.desc: Test PublishNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishNotification_00001, Function | SmallTest | Level1) +{ + NotificationRequest request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishNotification(request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: PublishNotification_00002 + * @tc.desc: Test PublishNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishNotification_00002, Function | SmallTest | Level1) +{ + NotificationRequest request; + std::string deviceId = "DeviceId"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishNotification(request, deviceId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: PublishNotification_00003 + * @tc.desc: Test PublishNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishNotification_00003, Function | SmallTest | Level1) +{ + std::string label = "Label"; + NotificationRequest request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishNotification(label, request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: CancelNotification_00001 + * @tc.desc: Test CancelNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelNotification_00001, Function | SmallTest | Level1) +{ + int32_t notificationId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelNotification(notificationId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelNotification_00002 + * @tc.desc: Test CancelNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelNotification_00002, Function | SmallTest | Level1) +{ + std::string label = "Label"; + int32_t notificationId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelNotification(label, notificationId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelAllNotifications_00001 + * @tc.desc: Test CancelAllNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelAllNotifications_00001, Function | SmallTest | Level1) +{ + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelAllNotifications(); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelAsBundle_00001 + * @tc.desc: Test CancelAsBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelAsBundle_00001, Function | SmallTest | Level1) +{ + int32_t notificationId = 10; + std::string representativeBundle = "RepresentativeBundle"; + int32_t userId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_UID); +} + +/** + * @tc.name: GetActiveNotificationNums_00001 + * @tc.desc: Test GetActiveNotificationNums parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetActiveNotificationNums_00001, Function | SmallTest | Level1) +{ + uint64_t num = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetActiveNotificationNums(num); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetActiveNotifications_00001 + * @tc.desc: Test GetActiveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetActiveNotifications_00001, Function | SmallTest | Level1) +{ + std::vector> request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetActiveNotifications(request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetCurrentAppSorting_00001 + * @tc.desc: Test GetCurrentAppSorting parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetCurrentAppSorting_00001, Function | SmallTest | Level1) +{ + sptr sortingMap = nullptr; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: SetNotificationAgent_00001 + * @tc.desc: Test SetNotificationAgent parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationAgent_00001, Function | SmallTest | Level1) +{ + std::string agent = "Agent"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationAgent(agent); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: GetNotificationAgent_00001 + * @tc.desc: Test GetNotificationAgent parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationAgent_00001, Function | SmallTest | Level1) +{ + std::string agent = "Agent"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationAgent(agent); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: CanPublishNotificationAsBundle_00001 + * @tc.desc: Test CanPublishNotificationAsBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CanPublishNotificationAsBundle_00001, Function | SmallTest | Level1) +{ + std::string representativeBundle = "RepresentativeBundle"; + bool canPublish = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CanPublishNotificationAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: PublishNotificationAsBundle_00001 + * @tc.desc: Test PublishNotificationAsBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishNotificationAsBundle_00001, Function | SmallTest | Level1) +{ + std::string representativeBundle = "RepresentativeBundle"; + NotificationRequest request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishNotificationAsBundle(representativeBundle, request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetNotificationBadgeNum_00001 + * @tc.desc: Test SetNotificationBadgeNum parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationBadgeNum_00001, Function | SmallTest | Level1) +{ + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationBadgeNum(); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: SetNotificationBadgeNum_00002 + * @tc.desc: Test SetNotificationBadgeNum parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationBadgeNum_00002, Function | SmallTest | Level1) +{ + int32_t num = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationBadgeNum(num); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: IsAllowedNotify_00001 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00001, Function | SmallTest | Level1) +{ + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(allowed); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsAllowedNotifySelf_00001 + * @tc.desc: Test IsAllowedNotifySelf parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotifySelf_00001, Function | SmallTest | Level1) +{ + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotifySelf(allowed); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RequestEnableNotification_00001 + * @tc.desc: Test RequestEnableNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + NotificationHelper notificationHelper; + bool needPop = true; + ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, needPop); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: AreNotificationsSuspended_00001 + * @tc.desc: Test AreNotificationsSuspended parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, AreNotificationsSuspended_00001, Function | SmallTest | Level1) +{ + bool suspended = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.AreNotificationsSuspended(suspended); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HasNotificationPolicyAccessPermission_00001 + * @tc.desc: Test HasNotificationPolicyAccessPermission parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, HasNotificationPolicyAccessPermission_00001, Function | SmallTest | Level1) +{ + bool hasPermission = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.HasNotificationPolicyAccessPermission(hasPermission); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetBundleImportance_00001 + * @tc.desc: Test GetBundleImportance parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetBundleImportance_00001, Function | SmallTest | Level1) +{ + NotificationSlot::NotificationLevel importance = NotificationSlot::NotificationLevel::LEVEL_NONE; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetBundleImportance(importance); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveNotification_00001 + * @tc.desc: Test RemoveNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotification_00001, Function | SmallTest | Level1) +{ + std::string key = "Key"; + int32_t removeReason = 2; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotification(key, removeReason); + EXPECT_EQ(ret, (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); +} + +/** + * @tc.name: RemoveNotification_00002 + * @tc.desc: Test RemoveNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotification_00002, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + int32_t notificationId = 10; + std::string label = "Label"; + int32_t removeReason = 2; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotification(bundleOption, notificationId, label, removeReason); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveAllNotifications_00001 + * @tc.desc: Test RemoveAllNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveAllNotifications_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveAllNotifications(bundleOption); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveNotificationsByBundle_00001 + * @tc.desc: Test RemoveNotificationsByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotificationsByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotificationsByBundle(bundleOption); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveNotifications_00001 + * @tc.desc: Test RemoveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotifications_00001, Function | SmallTest | Level1) +{ + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotifications(); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetNotificationSlotsForBundle_00001 + * @tc.desc: Test GetNotificationSlotsForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationSlotsForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::vector> slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationSlotsForBundle(bundleOption, slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: UpdateNotificationSlots_00001 + * @tc.desc: Test UpdateNotificationSlots parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, UpdateNotificationSlots_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::vector> slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.UpdateNotificationSlots(bundleOption, slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetAllActiveNotifications_00001 + * @tc.desc: Test GetAllActiveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetAllActiveNotifications_00001, Function | SmallTest | Level1) +{ + std::vector> notification; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetAllActiveNotifications(notification); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetAllActiveNotifications_00002 + * @tc.desc: Test GetAllActiveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetAllActiveNotifications_00002, Function | SmallTest | Level1) +{ + std::vector key; + std::vector> notification; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetAllActiveNotifications(key, notification); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: IsAllowedNotify_00002 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00002, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(bundleOption, allowed); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetNotificationsEnabledForAllBundles_00001 + * @tc.desc: Test SetNotificationsEnabledForAllBundles parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationsEnabledForAllBundles_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationsEnabledForAllBundles(deviceId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetShowBadgeEnabledForBundle_00001 + * @tc.desc: Test SetShowBadgeEnabledForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetShowBadgeEnabledForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetShowBadgeEnabledForBundle_00001 + * @tc.desc: Test GetShowBadgeEnabledForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetShowBadgeEnabledForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetShowBadgeEnabled_00001 + * @tc.desc: Test GetShowBadgeEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetShowBadgeEnabled_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetShowBadgeEnabled(enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelGroup_00001 + * @tc.desc: Test CancelGroup parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelGroup_00001, Function | SmallTest | Level1) +{ + std::string groupName = "GroupName"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelGroup(groupName); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveGroupByBundle_00001 + * @tc.desc: Test RemoveGroupByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveGroupByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::string groupName = "GroupName"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveGroupByBundle(bundleOption, groupName); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetDoNotDisturbDate_00001 + * @tc.desc: Test SetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetDoNotDisturbDate_00001, Function | SmallTest | Level1) +{ + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetDoNotDisturbDate_00001 + * @tc.desc: Test GetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetDoNotDisturbDate_00001, Function | SmallTest | Level1) +{ + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: DoesSupportDoNotDisturbMode_00001 + * @tc.desc: Test DoesSupportDoNotDisturbMode parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, DoesSupportDoNotDisturbMode_00001, Function | SmallTest | Level1) +{ + bool doesSupport = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsDistributedEnabled_00001 + * @tc.desc: Test IsDistributedEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsDistributedEnabled_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsDistributedEnabled(enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: EnableDistributed_00001 + * @tc.desc: Test EnableDistributed parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributed_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributed(enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: EnableDistributedByBundle_00001 + * @tc.desc: Test EnableDistributedByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributedByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributedByBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: EnableDistributedSelf_00001 + * @tc.desc: Test EnableDistributedSelf parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributedSelf_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributedSelf(enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: IsDistributedEnableByBundle_00001 + * @tc.desc: Test IsDistributedEnableByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsDistributedEnableByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetDeviceRemindType_00001 + * @tc.desc: Test GetDeviceRemindType parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetDeviceRemindType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetDeviceRemindType(remindType); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: PublishContinuousTaskNotification_00001 + * @tc.desc: Test PublishContinuousTaskNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishContinuousTaskNotification_00001, Function | SmallTest | Level1) +{ + NotificationRequest request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishContinuousTaskNotification(request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: CancelContinuousTaskNotification_00001 + * @tc.desc: Test CancelContinuousTaskNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelContinuousTaskNotification_00001, Function | SmallTest | Level1) +{ + std::string label = "label"; + int32_t notificationId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelContinuousTaskNotification(label, notificationId); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsSupportTemplate_00001 + * @tc.desc: Test IsSupportTemplate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsSupportTemplate_00001, Function | SmallTest | Level1) +{ + std::string templateName = "TemplateName"; + bool support = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsSupportTemplate(templateName, support); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsAllowedNotify_00003 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00003, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(userId, allowed); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetNotificationsEnabledForAllBundles_00002 + * @tc.desc: Test SetNotificationsEnabledForAllBundles parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationsEnabledForAllBundles_00002, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationsEnabledForAllBundles(userId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsSupportTemplate_00002 + * @tc.desc: Test IsSupportTemplate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsSupportTemplate_00002, Function | SmallTest | Level1) +{ + std::string templateName = "TemplateName"; + bool support = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsSupportTemplate(templateName, support); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsAllowedNotify_00004 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00004, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(userId, allowed); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetNotificationsEnabledForAllBundles_00003 + * @tc.desc: Test SetNotificationsEnabledForAllBundles parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationsEnabledForAllBundles_00003, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationsEnabledForAllBundles(userId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: RemoveNotifications_00002 + * @tc.desc: Test RemoveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotifications_00002, Function | SmallTest | Level1) +{ + int32_t userId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotifications(userId); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetDoNotDisturbDate_00002 + * @tc.desc: Test SetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetDoNotDisturbDate_00002, Function | SmallTest | Level1) +{ + int32_t userId = 10; + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetDoNotDisturbDate_00002 + * @tc.desc: Test GetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetDoNotDisturbDate_00002, Function | SmallTest | Level1) +{ + int32_t userId = 10; + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetDoNotDisturbDate(userId, doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetEnabledForBundleSlot_00001 + * @tc.desc: Test SetEnabledForBundleSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetEnabledForBundleSlot_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetEnabledForBundleSlot_00001 + * @tc.desc: Test GetEnabledForBundleSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetEnabledForBundleSlot_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetEnabledForBundleSlot(bundleOption, slotType, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetSyncNotificationEnabledWithoutApp_00001 + * @tc.desc: Test SetSyncNotificationEnabledWithoutApp parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetSyncNotificationEnabledWithoutApp_00001, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetSyncNotificationEnabledWithoutApp_00001 + * @tc.desc: Test GetSyncNotificationEnabledWithoutApp parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetSyncNotificationEnabledWithoutApp_00001, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_long_text_content_test.cpp b/frameworks/ans/test/unittest/notification_long_text_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d4285a781420e623add588e9ffc12845612f1655 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_long_text_content_test.cpp @@ -0,0 +1,110 @@ +/* + * 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 "notification_long_text_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationLongTextContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetLongText_00001 + * @tc.desc: Test SetLongText parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLongTextContentTest, SetLongText_00001, Function | SmallTest | Level1) +{ + std::string longText = ""; + auto rrc = std::make_shared(); + rrc->SetLongText(longText); + EXPECT_EQ(rrc->GetLongText(), longText); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLongTextContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLongTextContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLongTextContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLongTextContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_media_content_test.cpp b/frameworks/ans/test/unittest/notification_media_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3929d6b1404a0ce0c880a7998d54789a5825a9b8 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_media_content_test.cpp @@ -0,0 +1,139 @@ +/* + * 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 "notification_media_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationMediaContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetAVToken_00001 + * @tc.desc: Test SetAVToken parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, SetAVToken_00001, Function | SmallTest | Level1) +{ + std::shared_ptr avToken = nullptr; + auto rrc = std::make_shared(); + rrc->SetAVToken(avToken); + EXPECT_EQ(rrc->GetAVToken(), avToken); +} + +/** + * @tc.name: SetShownActions_00001 + * @tc.desc: Test SetShownActions parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, SetShownActions_00001, Function | SmallTest | Level1) +{ + std::vector actions; + auto rrc = std::make_shared(); + rrc->SetShownActions(actions); + EXPECT_EQ(rrc->GetShownActions(), actions); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string ret = "NotificationMediaContent{ title = , text = , " + "additionalText = , avToken = null, sequenceNumbers = }"; + + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMediaContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_multiline_content_test.cpp b/frameworks/ans/test/unittest/notification_multiline_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f786ab7783c744e8e75fe6f6ca493afd4c40f066 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_multiline_content_test.cpp @@ -0,0 +1,153 @@ +/* + * 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 "notification_multiline_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationMultiLineContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetExpandedTitle_00001 + * @tc.desc: Test SetExpandedTitle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, SetExpandedTitle_00001, Function | SmallTest | Level1) +{ + std::string exTitle = "ExTitle"; + auto rrc = std::make_shared(); + rrc->SetExpandedTitle(exTitle); + EXPECT_EQ(rrc->GetExpandedTitle(), exTitle); +} + +/** + * @tc.name: SetBriefText_00001 + * @tc.desc: Test SetBriefText parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, SetBriefText_00001, Function | SmallTest | Level1) +{ + std::string briefText = "BriefText"; + auto rrc = std::make_shared(); + rrc->SetBriefText(briefText); + EXPECT_EQ(rrc->GetBriefText(), briefText); +} + +/** + * @tc.name: AddSingleLine_00001 + * @tc.desc: Test AddSingleLine parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, AddSingleLine_00001, Function | SmallTest | Level1) +{ + std::string oneLine = "OneLine"; + auto rrc = std::make_shared(); + rrc->AddSingleLine(oneLine); + std::vector result = rrc->GetAllLines(); + EXPECT_EQ(result.size(), 1); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string ret = "NotificationMultiLineContent{ title = , text = , " + "additionalText = , briefText = , expandedTitle = , allLines = [] }"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationMultiLineContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationMultiLineContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationMultiLineContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_picture_content_test.cpp b/frameworks/ans/test/unittest/notification_picture_content_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb7ab773e5e3362b26374156ddb4c63e2a2d296a --- /dev/null +++ b/frameworks/ans/test/unittest/notification_picture_content_test.cpp @@ -0,0 +1,153 @@ +/* + * 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 "notification_picture_content.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationPictureContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetExpandedTitle_00001 + * @tc.desc: Test SetExpandedTitle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationPictureContentTest, SetExpandedTitle_00001, Function | SmallTest | Level1) +{ + std::string exTitle = "ExTitle"; + auto rrc = std::make_shared(); + rrc->SetExpandedTitle(exTitle); + EXPECT_EQ(rrc->GetExpandedTitle(), exTitle); +} + +/** + * @tc.name: SetBriefText_00001 + * @tc.desc: Test SetBriefText parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationPictureContentTest, SetBriefText_00001, Function | SmallTest | Level1) +{ + std::string briefText = "BriefText"; + auto rrc = std::make_shared(); + rrc->SetBriefText(briefText); + EXPECT_EQ(rrc->GetBriefText(), briefText); +} + +/** + * @tc.name: SetBigPicture_00001 + * @tc.desc: Test SetBigPicture parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationPictureContentTest, SetBigPicture_00001, Function | SmallTest | Level1) +{ + std::shared_ptr bigPicture = std::make_shared(); + auto rrc = std::make_shared(); + rrc->SetBigPicture(bigPicture); + EXPECT_EQ(rrc->GetBigPicture(), bigPicture); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationPictureContentTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string ret = "NotificationPictureContent{ title = , text = , " + "additionalText = , briefText = , expandedTitle = , bigPicture = null }"; + + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationPictureContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationPictureContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationPictureContentTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationPictureContentTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_sorting_map_test.cpp b/frameworks/ans/test/unittest/notification_sorting_map_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2283ad3fc38932c394e0e08eb855a994b54cbfe --- /dev/null +++ b/frameworks/ans/test/unittest/notification_sorting_map_test.cpp @@ -0,0 +1,103 @@ +/* + * 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 "notification_sorting_map.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationSortingMapTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetKey_00001 + * @tc.desc: Test SetKey parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingMapTest, SetKey_00001, Function | SmallTest | Level1) +{ + std::vector sortingList; + std::string key = "Key"; + auto rrc = std::make_shared(sortingList); + NotificationSorting sorting; + rrc->SetNotificationSorting(sortingList); + EXPECT_EQ(rrc->GetNotificationSorting(key, sorting), false); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingMapTest, Marshalling_00001, Function | SmallTest | Level1) +{ + std::vector sortingList; + Parcel parcel; + auto rrc = std::make_shared(sortingList); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingMapTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + std::vector sortingList; + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(sortingList); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingMapTest, Dump_00001, Function | SmallTest | Level1) +{ + std::vector sortingList; + std::string key = "Key"; + auto rrc = std::make_shared(sortingList); + rrc->SetKey(key); + std::string ret = "NotificationSortingMap{ sortedkey = [Key, ] }"; + EXPECT_EQ(rrc->Dump(), ret); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_sorting_test.cpp b/frameworks/ans/test/unittest/notification_sorting_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c4062e70644822dcd4a99da45087467a2b13180 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_sorting_test.cpp @@ -0,0 +1,136 @@ +/* + * 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 "notification_sorting_map.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationSortingTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingTest, Marshalling_00001, Function | SmallTest | Level1) +{ + NotificationSorting sorting; + Parcel parcel; + auto rrc = std::make_shared(sorting); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Marshalling_00002 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingTest, Marshalling_00002, Function | SmallTest | Level1) +{ + NotificationSorting sorting; + Parcel parcel; + auto rrc = std::make_shared(sorting); + rrc->SetKey(""); + rrc->ReadFromParcel(parcel); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + NotificationSorting sorting; + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(sorting); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationSortingTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + NotificationSorting sorting; + auto rrc = std::make_shared(sorting); + EXPECT_EQ(rrc->ReadFromParcel(parcel), true); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationSortingTest, Dump_00001, Function | SmallTest | Level1) +{ + NotificationSorting sorting; + Parcel parcel; + std::string groupKeyOverride = "GroupKeyOverride"; + std::string key = "Key"; + int32_t importance = 10; + uint64_t ranking = 20; + int32_t visibleness =30; + bool isDisplayBadge = false; + bool isHiddenNotification = true; + auto rrc = std::make_shared(sorting); + rrc->SetGroupKeyOverride(groupKeyOverride); + rrc->SetKey(key); + rrc->SetImportance(importance); + rrc->SetRanking(ranking); + rrc->SetVisiblenessOverride(visibleness); + rrc->SetDisplayBadge(isDisplayBadge); + rrc->SetHiddenNotification(isHiddenNotification); + std::string ret = "NotificationSorting{ key = Key, ranking = 20, " + "importance = 10, visiblenessOverride = 30, isDisplayBadge = false, " + "isHiddenNotification = true, groupKeyOverride = GroupKeyOverride, " + "slot = NotificationSlot{ id = OTHER, name = OTHER, description = , " + "type = 3, level = 1, isBypassDnd = false, visibleness = 3, sound = , " + "isLightEnabled = false, lightColor = 0, isVibrate = false, " + "vibration = , isShowBadge = true, enabled = true } }"; + EXPECT_EQ(rrc->Dump(), ret); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_subscribe_info_test.cpp b/frameworks/ans/test/unittest/notification_subscribe_info_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67124ee7d5d53ef3c44d5bb5b518306f4edb2f5d --- /dev/null +++ b/frameworks/ans/test/unittest/notification_subscribe_info_test.cpp @@ -0,0 +1,132 @@ +/* + * 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 "notification_subscribe_info.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationSubscribeInfoTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: AddAppName_00001 + * @tc.desc: Test AddAppName parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, AddAppName_00001, Function | SmallTest | Level1) +{ + std::string appName = "AppName"; + NotificationSubscribeInfo subscribeInfo; + auto rrc = std::make_shared(subscribeInfo); + rrc->AddAppName(appName); + std::vector result = rrc->GetAppNames(); + EXPECT_EQ(result.size(), 1); +} + +/** + * @tc.name: AddAppNames_00001 + * @tc.desc: Test AddAppNames parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, AddAppNames_00001, Function | SmallTest | Level1) +{ + std::vector appNames; + NotificationSubscribeInfo subscribeInfo; + auto rrc = std::make_shared(subscribeInfo); + rrc->AddAppNames(appNames); + std::vector result = rrc->GetAppNames(); + EXPECT_EQ(result.size(), 0); +} + +/** + * @tc.name: AddAppUserId_00001 + * @tc.desc: Test AddAppUserId parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, AddAppUserId_00001, Function | SmallTest | Level1) +{ + int32_t userId = 10; + NotificationSubscribeInfo subscribeInfo; + auto rrc = std::make_shared(subscribeInfo); + rrc->AddAppUserId(userId); + EXPECT_EQ(rrc->GetAppUserId(), userId); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + NotificationSubscribeInfo subscribeInfo; + auto rrc = std::make_shared(subscribeInfo); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + NotificationSubscribeInfo subscribeInfo; + std::shared_ptr result = + std::make_shared(subscribeInfo); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationSubscribeInfoTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + NotificationSubscribeInfo subscribeInfo; + auto rrc = std::make_shared(subscribeInfo); + EXPECT_EQ(rrc->ReadFromParcel(parcel), true); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_template_test.cpp b/frameworks/ans/test/unittest/notification_template_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a35029cbd0cb9f2ae8c2d7cb63648079c714164 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_template_test.cpp @@ -0,0 +1,123 @@ +/* + * 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 "notification_template.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationTemplateTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetTemplateName_00001 + * @tc.desc: Test SetTemplateName parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTemplateTest, SetTemplateName_00001, Function | SmallTest | Level1) +{ + std::string name = "Name"; + auto rrc = std::make_shared(); + rrc->SetTemplateName(name); + EXPECT_EQ(rrc->GetTemplateName(), name); +} + +/** + * @tc.name: SetTemplateData_00001 + * @tc.desc: Test SetTemplateData parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTemplateTest, SetTemplateData_00001, Function | SmallTest | Level1) +{ + std::shared_ptr data = std::make_shared(); + auto rrc = std::make_shared(); + rrc->SetTemplateData(data); + EXPECT_EQ(rrc->GetTemplateData(), data); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTemplateTest, Dump_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string ret = "templateName = , templateData = null"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationTemplateTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTemplateTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTemplateTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..759e89bac7fede4cde2fb0dbc8cab565a56b7850 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -0,0 +1,350 @@ +/* + * 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 "notification.h" +#undef private +#undef protected + +#include "notification_request.h" +#include "parcel.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: GetBundleName_00001 + * @tc.desc: Test when request_ is nullptr get parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTest, GetBundleName_00001, Function | SmallTest | Level1) +{ + sptr request = nullptr; + auto rrc = std::make_shared(request); + std::string ret = ""; + EXPECT_EQ(rrc->GetBundleName(), ret); + EXPECT_EQ(rrc->GetCreateBundle(), ret); + EXPECT_EQ(rrc->GetLabel(), ret); + EXPECT_EQ(rrc->GetId(), -1); + EXPECT_EQ(rrc->GetUid(), 0); + EXPECT_EQ(rrc->GetPid(), 0); + EXPECT_EQ(rrc->IsUnremovable(), false); + EXPECT_EQ(rrc->IsGroup(), false); + EXPECT_EQ(rrc->IsFloatingIcon(), false); + EXPECT_EQ(rrc->GetUserId(), 0); +} + +/** + * @tc.name: GetLedLightColor_00001 + * @tc.desc: Test GetLedLightColor parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTest, GetLedLightColor_00001, Function | SmallTest | Level1) +{ + int32_t color = 10; + std::string deviceId = "DeviceId"; + sptr request = nullptr; + auto rrc = std::make_shared(deviceId, request); + rrc->SetLedLightColor(color); + EXPECT_EQ(rrc->GetLedLightColor(), color); +} + +/** + * @tc.name: GetLockscreenVisibleness_00001 + * @tc.desc: Test GetLockscreenVisibleness parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTest, GetLockscreenVisibleness_00001, Function | SmallTest | Level1) +{ + NotificationConstant::VisiblenessType visbleness = NotificationConstant::VisiblenessType::PUBLIC; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetLockScreenVisbleness(visbleness); + EXPECT_EQ(rrc->GetLockscreenVisibleness(), visbleness); +} + +/** + * @tc.name: GetGroup_00001 + * @tc.desc: Test GetGroup parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetGroup_00001, Function | SmallTest | Level1) +{ + sptr request = nullptr; + auto rrc = std::make_shared(request); + std::string ret = ""; + EXPECT_EQ(rrc->GetGroup(), ret); +} + +/** + * @tc.name: GetGroup_00002 + * @tc.desc: Test when request_ is not nullptr get parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetGroup_00002, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + auto rrc = std::make_shared(request); + std::string ret = ""; + EXPECT_EQ(rrc->GetGroup(), ret); + EXPECT_EQ(rrc->GetPid(), 0); + EXPECT_EQ(rrc->IsUnremovable(), false); + EXPECT_EQ(rrc->IsGroup(), false); + EXPECT_EQ(rrc->IsFloatingIcon(), false); +} + +/** + * @tc.name: GetPostTime_00001 + * @tc.desc: Test GetPostTime parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetPostTime_00001, Function | SmallTest | Level1) +{ + int64_t time = 10; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetPostTime(time); + EXPECT_EQ(rrc->GetPostTime(), time); +} + +/** + * @tc.name: GetSound_00001 + * @tc.desc: Test GetSound parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetSound_00001, Function | SmallTest | Level1) +{ + Uri sound = Uri("sound"); + bool enable = true; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetSound(sound); + rrc->SetEnableSound(enable); + EXPECT_EQ(rrc->GetSound(), sound); +} + +/** + * @tc.name: GetVibrationStyle_00001 + * @tc.desc: Test GetVibrationStyle parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetVibrationStyle_00001, Function | SmallTest | Level1) +{ + std::vector style; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetVibrationStyle(style); + EXPECT_EQ(rrc->GetVibrationStyle(), style); +} + +/** + * @tc.name: GetRemindType_00001 + * @tc.desc: Test GetRemindType parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetRemindType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::RemindType reminType = NotificationConstant::RemindType::NONE; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetRemindType(reminType); + EXPECT_EQ(rrc->GetRemindType(), reminType); +} + +/** + * @tc.name: GenerateNotificationKey_00001 + * @tc.desc: Test GenerateNotificationKey parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GenerateNotificationKey_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + int32_t userId = 10; + int32_t uid = 20; + std::string label = "Lable"; + int32_t id = 30; + sptr request = nullptr; + auto rrc = std::make_shared(deviceId, request); + std::string result = "DeviceId_10_20_Lable_30"; + EXPECT_EQ(rrc->GenerateNotificationKey(deviceId, userId, uid, label, id), result); +} + +/** + * @tc.name: IsRemoveAllowed_00001 + * @tc.desc: Test IsRemoveAllowed parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, IsRemoveAllowed_00001, Function | SmallTest | Level1) +{ + bool removeAllowed = true; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetRemoveAllowed(removeAllowed); + EXPECT_EQ(rrc->IsRemoveAllowed(), removeAllowed); +} + +/** + * @tc.name: GetSourceType_00001 + * @tc.desc: Test GetSourceType parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetSourceType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SourceType sourceType = NotificationConstant::SourceType::TYPE_NORMAL; + sptr request = nullptr; + auto rrc = std::make_shared(request); + rrc->SetSourceType(sourceType); + EXPECT_EQ(rrc->GetSourceType(), sourceType); +} + +/** + * @tc.name: GetDeviceId_00001 + * @tc.desc: Test GetDeviceId parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetDeviceId_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + auto rrc = std::make_shared(deviceId, request); + EXPECT_EQ(rrc->GetDeviceId(), deviceId); +} + +/** + * @tc.name: Dump_00001 + * @tc.desc: Test Dump parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + auto rrc = std::make_shared(deviceId, request); + std::string ret = "Notification{ key = DeviceId_-1_0__0, ledLightColor = 0, " + "lockscreenVisbleness = 0, remindType = -1, isRemoveAllowed = true, sourceType = 0, " + "deviceId = DeviceId, request = NotificationRequest{ notificationId = 0, " + "slotType = 3, createTime = 0, deliveryTime = 0, autoDeletedTime = 0, settingsText = , " + "creatorBundleName = , creatorPid = 0, creatorUid = 0, ownerBundleName = , " + "ownerUid = 0, groupName = , statusBarText = , label = , shortcutId = , " + "sortingKey = , groupAlertType = 0, color = 0, badgeNumber = 0, visiblenessType = 0, " + "progressValue = 0, progressMax = 0, badgeStyle = 0, classification = , " + "notificationContentType = 0, showDeliveryTime = false, tapDismissed = true, " + "colorEnabled = false, alertOneTime = false, showStopwatch = false, isCountdown = false, " + "inProgress = false, groupOverview = false, progressIndeterminate = false, " + "unremovable = false, floatingIcon = false, onlyLocal = false, permitted = true, " + "isAgent = false, removalWantAgent = null, maxScreenWantAgent = null, additionalParams = null, " + "littleIcon = null, bigIcon = null, notificationContent = null, publicNotification = null, " + "notificationTemplate = null, actionButtons = empty, messageUsers = empty, " + "userInputHistory = empty, distributedOptions = NotificationDistributedOptions" + "{ isDistributed = true, devicesSupportDisplay = [], devicesSupportOperate = [] }, " + "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1 }, " + "postTime = 0, sound = nullptr, vibrationStyle = [] }"; + EXPECT_EQ(rrc->Dump(), ret); +} + +/** + * @tc.name: MarshallingBool_00001 + * @tc.desc: Test MarshallingBool parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, MarshallingBool_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + auto rrc = std::make_shared(deviceId, request); + EXPECT_EQ(rrc->MarshallingBool(parcel), true); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBHI + */ +HWTEST_F(NotificationTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + auto rrc = std::make_shared(deviceId, request); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + std::shared_ptr result = + std::make_shared(deviceId, request); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + std::string deviceId = "DeviceId"; + sptr request = new NotificationRequest(); + auto rrc = std::make_shared(deviceId, request); + EXPECT_EQ(rrc->ReadFromParcel(parcel), true); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_user_input_test.cpp b/frameworks/ans/test/unittest/notification_user_input_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa7a7098d24689d8092fbfd879582737159ed020 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_user_input_test.cpp @@ -0,0 +1,133 @@ +/* + * 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 "notification_user_input.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationUserInputTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: NotificationUserInput_00001 + * @tc.desc: Test NotificationUserInput parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Dump_00001, Function | SmallTest | Level1) +{ + std::string inputKey = "InputKey"; + std::string tag = "Tag"; + std::vector options; + bool permitFreeFormInput = true; + std::set permitMimeTypes; + std::shared_ptr additional = nullptr; + Notification::NotificationConstant::InputEditType editType = + Notification::NotificationConstant::InputEditType(1); + auto rrc = std::make_shared(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, + additional, editType); + std::string ret = rrc->GetInputKey(); + EXPECT_EQ(ret, inputKey); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, FromJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + std::shared_ptr userInput = nullptr; + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_helper_test.cpp b/frameworks/ans/test/unittest/reminder_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..549c42cb19ba10c8f40270fec63cb847aa76fcc1 --- /dev/null +++ b/frameworks/ans/test/unittest/reminder_helper_test.cpp @@ -0,0 +1,121 @@ +/* + * 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_request.h" +#undef private +#undef protected + +#include "ans_inner_errors.h" +#include "reminder_helper.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class ReminderHelperTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: PublishReminder_00001 + * @tc.desc: Test PublishReminder parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, PublishReminder_00001, Function | SmallTest | Level1) +{ + ReminderRequest reminder; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.PublishReminder(reminder); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: CancelReminder_00001 + * @tc.desc: Test CancelReminder parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, CancelReminder_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 10; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.CancelReminder(reminderId); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelAllReminders_00001 + * @tc.desc: Test CancelAllReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, CancelAllReminders_00001, Function | SmallTest | Level1) +{ + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.CancelAllReminders(); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetValidReminders_00001 + * @tc.desc: Test GetValidReminders parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, GetValidReminders_00001, Function | SmallTest | Level1) +{ + std::vector> validReminders; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.GetValidReminders(validReminders); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: AddNotificationSlot_00001 + * @tc.desc: Test AddNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, AddNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationSlot slot; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.AddNotificationSlot(slot); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveNotificationSlot_00001 + * @tc.desc: Test RemoveNotificationSlot parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(ReminderHelperTest, RemoveNotificationSlot_00001, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; + ReminderHelper reminderHelper; + ErrCode ret = reminderHelper.RemoveNotificationSlot(slotType); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp index 4c0389860b254cac551fed6cecb5ae9f68a629f5..77097c01a317073f6486832dc499aae1ffd4637d 100644 --- a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp @@ -15,8 +15,13 @@ #include -#include "ans_log_wrapper.h" +#define private public +#define protected public #include "reminder_request_alarm.h" +#undef private +#undef protected + +#include "ans_log_wrapper.h" #include "reminder_helper.h" using namespace testing::ext; @@ -131,5 +136,165 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | uint8_t expectedVal = 0; EXPECT_TRUE(rrc->GetRepeatDay() == expectedVal) << "repeatDays () should be 0"; } + +/** + * @tc.name: IsRepeatReminder_00100 + * @tc.desc: Test IsRepeatReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, IsRepeatReminder_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->IsRepeatReminder(), false); + EXPECT_EQ(rrc->UpdateNextReminder(), false); +} + +/** + * @tc.name: IsRepeatReminder_00200 + * @tc.desc: Test IsRepeatReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, IsRepeatReminder_00200, Function | SmallTest | Level1) +{ + uint8_t arr[] = {1, 1, 5, 5, 7, 7, 7}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 1, daysOfWeek); + EXPECT_EQ(rrc->IsRepeatReminder(), true); + EXPECT_EQ(rrc->UpdateNextReminder(), true); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_00100 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, PreGetNextTriggerTimeIgnoreSnooze_00100, Function | SmallTest | Level1) +{ + bool ignoreRepeat = true; + bool forceToGetNext = true; + uint8_t arr[] = {1, 1, 5, 5, 7, 7, 7}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 1, daysOfWeek); + rrc->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext); + EXPECT_EQ(rrc->GetNextTriggerTime(forceToGetNext), + rrc->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext)); +} + +/** + * @tc.name: GetDaysOfWeek_00100 + * @tc.desc: Test GetDaysOfWeek parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, GetDaysOfWeek_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + auto ret = rrc->GetDaysOfWeek(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.name: OnDateTimeChange_00100 + * @tc.desc: Test OnDateTimeChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, OnDateTimeChange_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->OnDateTimeChange(), false); +} + +/** + * @tc.name: OnTimeZoneChange_00100 + * @tc.desc: Test OnTimeZoneChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, OnTimeZoneChange_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->OnTimeZoneChange(), false); +} + +/** + * @tc.name: RecoverFromDb_00100 + * @tc.desc: Test RecoverFromDb parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, RecoverFromDb_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + std::shared_ptr resultSet = nullptr; + rrc->RecoverFromDb(resultSet); + uint8_t ret = rrc->GetRepeatDay(); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + std::shared_ptr result = + std::make_shared(0, 0, daysOfWeek); + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI + */ +HWTEST_F(ReminderRequestAlarmTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} } } \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index 33a51584bd8a49b17d2e2f22d458f6745a564e6d..2195a5dd4502d3310cd7e5eadb9739e5a5d3acf4 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -15,8 +15,13 @@ #include -#include "ans_log_wrapper.h" +#define private public +#define protected public #include "reminder_request_calendar.h" +#undef private +#undef protected + +#include "ans_log_wrapper.h" #include "reminder_helper.h" using namespace testing::ext; @@ -299,5 +304,154 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00900, Function | SmallTest | EXPECT_TRUE(1 == calendar->GetMinute()) << "Set minute error."; EXPECT_TRUE(0 == calendar->GetSecond()) << "Set seconds error."; } + +/** + * @tc.name: initDateTime_01000 + * @tc.desc: Test InitDateTime parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, initDateTime_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + calendar->InitDateTime(); + EXPECT_EQ(calendar->IsRepeatReminder(), true); +} + +/** + * @tc.name: OnDateTimeChange_01000 + * @tc.desc: Test OnDateTimeChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, OnDateTimeChange_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->OnDateTimeChange(), false); +} + +/** + * @tc.name: OnTimeZoneChange_01000 + * @tc.desc: Test OnTimeZoneChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, OnTimeZoneChange_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->OnTimeZoneChange(), false); +} + +/** + * @tc.name: UpdateNextReminder_01000 + * @tc.desc: Test UpdateNextReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->UpdateNextReminder(), true); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_01000 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, PreGetNextTriggerTimeIgnoreSnooze_01000, Function | SmallTest | Level1) +{ + bool ignoreRepeat = true; + bool forceToGetNext = true; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext), + calendar->GetNextTriggerTime()); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_02000 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, PreGetNextTriggerTimeIgnoreSnooze_02000, Function | SmallTest | Level1) +{ + bool ignoreRepeat = false; + bool forceToGetNext = true; + time_t now; + time(&now); // unit is seconds. + tm *tmp = localtime(&now); + EXPECT_NE(nullptr, tmp); + tm nowTime = *tmp; + nowTime.tm_year += 1; + std::vector repeatMonths; + std::vector repeatDays; + repeatMonths.push_back(-1); + repeatDays.push_back(1); + auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + EXPECT_EQ(calendar->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext), 0); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + if (nullptr != calendar) { + if (nullptr == calendar->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI + */ +HWTEST_F(ReminderRequestCalendarTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->ReadFromParcel(parcel), false); +} } } \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 9d12b7e4e47ebcd3df2972cfd35b4fade60a0170..4ec41634ecaf39bcd07b5494520dda64a8f183c1 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -560,9 +560,10 @@ HWTEST_F(ReminderRequestTest, CanShow_00002, Function | SmallTest | Level1) */ HWTEST_F(ReminderRequestTest, Dump_00001, Function | SmallTest | Level1) { - std::string ret = "Reminder[reminderId=-1, type=3, state='Inactive, nextTriggerTime=1970-01-01 00:00:00]"; + std::string ret = "Reminder[reminderId=-1, type=3, state='Inactive, nextTriggerTime=1970-01-01 "; auto rrc = std::make_shared(); - EXPECT_EQ(rrc->Dump(), ret); + std::string res = rrc->Dump(); + EXPECT_EQ(res.substr(0, res.size()-9), ret); } /** @@ -942,8 +943,9 @@ 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); + std::string ret = ":08"; + std::string res = rrc->GetShowTime(showTime); + EXPECT_EQ(res.substr(2, res.size()), ret); } /** @@ -957,8 +959,9 @@ 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); + std::string ret = ":08"; + std::string res = rrc->GetShowTime(showTime); + EXPECT_EQ(res.substr(2, res.size()), ret); } /** diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 35b830b1b111a73287d374ea153cf260983362b1..606ba3b08cdd1cd144174bd9747209a0a3814d75 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -94,7 +94,7 @@ ohos_shared_library("ans_core") { "os_account:os_account_innerkits", "relational_store:native_rdb", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] install_images = [ system_base_dir ] relative_install_dir = "platformsdk" diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 3b40c55fe1b4a7373aadafe99a0dfa4ec086736f..a2a91826869321f8f5329ce35dd80659dbda8774 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -339,14 +339,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) = 0; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) = 0; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 89c5129ff4af667afd1618b426bab049f4321a18..4d736b1a23cfb13c2937ba8c6367df6beb024e4f 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -327,14 +327,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 55207f7d31e70c8392daa630fbe8d8bd4f974d7b..a770d555391faa3ef72ac1641030f45354169bdc 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -343,14 +343,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 0afd8a3b4876bd7482ac5f41a3fa5c9e83bc9680..59faa10115491f1a5f047e3e1be55e30a359eb0d 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -276,15 +276,6 @@ public: */ ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allows the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allows the current application to publish notifications on a specified device. * diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 466eeb00ba6ba8fa51690300f97c5f74bfe5631a..195a3f443b7360bc8dcff1b7e278d5ee25750105 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1103,12 +1103,6 @@ ErrCode AnsManagerProxy::UpdateSlots( return result; } -ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGI("enter"); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 64eaa72e99a316774e4e9d30838386093f61de0d..3b39d6b93e793bf0e7cd5d5eb46ea57d65d46d30 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -1998,12 +1998,6 @@ ErrCode AnsManagerStub::UpdateSlots( return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); - return ERR_INVALID_OPERATION; -} - ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 2860aa3dbd6fa45eecf5291d4a0aeb1a555c2096..67371739decf88f299ace83565aefb7c94df601f 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -373,16 +373,6 @@ ErrCode AnsNotification::IsAllowedNotifySelf(bool &allowed) return ansManagerProxy_->IsAllowedNotifySelf(allowed); } -ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId) -{ - ANS_LOGD("enter"); - if (!GetAnsManagerProxy()) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return ansManagerProxy_->RequestEnableNotification(deviceId); -} - ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, bool &popFlag) { ANS_LOGD("enter"); diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4c83fcdbea05321ae2fb10a4ec8728f4be6ecb33 --- /dev/null +++ b/frameworks/core/test/unittest/BUILD.gn @@ -0,0 +1,27 @@ +# 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. + +group("unittest") { + testonly = true + deps = [] + + deps += [ + "ans_callback_stub_test:unittest", + "ans_image_util_test:unittest", + "ans_manager_death_recipient_test:unittest", + "ans_manager_proxy_test:unittest", + "ans_manager_stub_test:unittest", + "ans_subscriber_proxy_test:unittest", + "ans_subscriber_stub_test:unittest", + ] +} diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..78c8bad857396478e2b9d1f96b95e28a03bd2148 --- /dev/null +++ b/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_callback_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_callback_stub_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_callback_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp b/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e507a144a3f1131045339f92def385f2133d8b2 --- /dev/null +++ b/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp @@ -0,0 +1,116 @@ +/* + * 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 + +#include "ans_callback_stub.h" +#include "ans_inner_errors.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsCallbackStubImpl : public AnsCallbackStub { + bool OnEnableNotification(bool isAllow) override + { + return false; + } +}; + +class AnsCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + + void SetUp() + { + ansCallbackStub_ = new AnsCallbackStubImpl(); + } + void TearDown() {} + sptr ansCallbackStub_; +}; + +/** + * @tc.name: OnRemoteRequest01 + * @tc.desc: Test if the descriptor is wrong. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: OnRemoteRequest02 + * @tc.desc: Test if can not read a bool from data failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest02, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: OnRemoteRequest03 + * @tc.desc: Test unknow code failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest03, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(1, data, reply, option); + EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: OnRemoteRequest04 + * @tc.desc: Test OnRemoteRequest success. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest04, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + data.WriteBool(true); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} diff --git a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..366fadf47e3cd1f7cf7f0a044ca1e977b91ab5ff --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn @@ -0,0 +1,62 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_image_util_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "${core_path}/common/include", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + "../mock", + ] + + sources = [ + "${core_path}/common/src/ans_log_wrapper.cpp", + "${core_path}/src/ans_image_util.cpp", + "../mock/mock_image_packer.cpp", + "../mock/mock_image_source.cpp", + "../mock/mock_pixel_map.cpp", + "ans_image_util_unit_test.cpp", + ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_image_util_test" ] +} diff --git a/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..718f1272734813506c1f84143c7d89c273efcba5 --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp @@ -0,0 +1,658 @@ + /* + * 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 "ans_image_util.h" +#include "image_packer.h" +#include "pixel_map.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +extern void MockImagePackerGetSupportedFormats(uint32_t mockRet); +extern void MockImagePackerStartPacking(const uint8_t* mockRet); +extern void MockImagePackerFinalizePacking(uint32_t mockRet); +extern void MockResetImagePackerState(); + +extern void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode); +extern void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode); +extern void MockImageSourceGetSupportedFormats(uint32_t mockRet); +extern void MockResetImageSourceState(); + +extern void MockPixelMapGetByteCount(int32_t mockRet); +extern void MockResetPixelMapState(); + +class AnsImageUtilUnitTest : public testing::Test { +public: + AnsImageUtilUnitTest() {} + + virtual ~AnsImageUtilUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsImageUtilUnitTest::SetUpTestCase() {} + +void AnsImageUtilUnitTest::TearDownTestCase() {} + +void AnsImageUtilUnitTest::SetUp() {} + +void AnsImageUtilUnitTest::TearDown() {} + +/* + * @tc.name: PackImageTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_FALSE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: PackImageTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string format = ":"; + std::string res = imageUtil->PackImage(nullptr, format); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string res = imageUtil->PackImage(pixelMap, ""); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_TRUE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: UnPackImageTest_0100 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0200 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = ""; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0300 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0400 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0500 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0600 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: PackImage2FileTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_TRUE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0200, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = nullptr; + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0300, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = ""; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = ""; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0500 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0500, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0100 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0200 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = ""; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0300 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = ""; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + + +/* + * @tc.name: CreatePixelMapTest_0400 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0500 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0600 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: CreatePixelMapTest_0700 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0700, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0800 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0800, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: BinToHexTest_0100 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = "12112221"; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_NE("", res); +} + +/* + * @tc.name: BinToHexTest_0200 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = ""; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0100 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "12112221"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_NE("", res); +} + +/* + * @tc.name: HexToBinTest_0200 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = ""; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0300 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0400 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0400, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123x"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f679b5f0bf9e5be449e1917304afb6cad4767d18 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_manager_death_recipient_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_manager_death_recipient_unit_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_death_recipient_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5be0520978c55eb02f675d8732d30ee3f979c3f0 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp @@ -0,0 +1,69 @@ +/* + * 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 "ans_manager_death_recipient.h" +#include "ans_notification.h" +#undef private +#undef protected + +#include "iremote_broker.h" +#include "singleton.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsManagerDeathRecipientUnitTest : public testing::Test { +public: + AnsManagerDeathRecipientUnitTest() {} + + virtual ~AnsManagerDeathRecipientUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsManagerDeathRecipientUnitTest::SetUpTestCase() {} + +void AnsManagerDeathRecipientUnitTest::TearDownTestCase() {} + +void AnsManagerDeathRecipientUnitTest::SetUp() {} + +void AnsManagerDeathRecipientUnitTest::TearDown() {} + +/* + * @tc.name: OnRemoteDiedTest_0100 + * @tc.desc: test if AnsManagerDeathRecipient's OnRemoteDied function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsManagerDeathRecipientUnitTest, OnRemoteDiedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerDeathRecipientUnitTest, OnRemoteDiedTest_0100, TestSize.Level1"; + std::shared_ptr recipient = std::make_shared(); + ASSERT_NE(nullptr, recipient); + recipient->OnRemoteDied(nullptr); + EXPECT_EQ(DelayedSingleton::GetInstance()->ansManagerProxy_, nullptr); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9a66f5d3834146e3a3d41f62ae260482d28e5c68 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn @@ -0,0 +1,60 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_manager_proxy_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + "../mock/", + "${inner_api_path}", + ] + + sources = [ + "../mock/mock_message_parcel.cpp", + "ans_manager_proxy_unit_test.cpp", + ] + + deps = [ + "${core_path}:ans_core", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_proxy_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42dacd18b5ac5d36517684c5e1a9d1823684e60c --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -0,0 +1,5749 @@ +/* + * 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 +#include + +#define private public +#define protected public +#include "ans_manager_proxy.h" +#include "notification_subscriber.h" +#undef private +#undef protected +#include "ans_const_define.h" +#include "ans_manager_interface.h" +#include "ans_inner_errors.h" +#include "message_parcel.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; +using namespace std::placeholders; + +extern void MockWriteInterfaceToken(bool mockRet); + +namespace OHOS { +namespace Notification { +class AnsManagerProxyUnitTest : public testing::Test { +public: + AnsManagerProxyUnitTest() {} + + virtual ~AnsManagerProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsManagerProxyUnitTest::SetUpTestCase() +{ + MockWriteInterfaceToken(true); +} + +void AnsManagerProxyUnitTest::TearDownTestCase() {} + +void AnsManagerProxyUnitTest::SetUp() {} + +void AnsManagerProxyUnitTest::TearDown() {} + +int SendRequestReplace(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, bool retBool, bool setRetBool) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetBool) { + reply.WriteBool(retBool); + } + return 0; +} + +int SendRequestReplaceNum(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, uint64_t retNum, bool setRetNum) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetNum) { + reply.WriteUint64(retNum); + } + return 0; +} + +int SendRequestReplaceString(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, std::string retStr, bool setRetStr) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetStr) { + reply.WriteString(retStr); + } + return 0; +} + +class TestSubscriber : public NotificationSubscriber { +public: + void OnConnected() override + {} + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnEnabledNotificationChanged( + const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnConsumed(const std::shared_ptr &request) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} +}; + +/* + * @tc.name: InnerTransactTest_0100 + * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_OK, res); +} + +/* + * @tc.name: InnerTransactTest_0200 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: InnerTransactTest_0300 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); +} + +/* + * @tc.name: InnerTransactTest_0400 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; + std::shared_ptr proxy = std::make_shared(nullptr); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: PublishTest_0100 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + sptr notification = nullptr; + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishTest_0200 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0300 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = ""; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0400 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishTest_0500 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishTest_0600 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0100 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishToDeviceTest_0200 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0300 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = ""; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0400 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: PublishToDeviceTest_0500 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0600 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0100 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0200 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = ""; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0300 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelTest_0400 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelTest_0500 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0100 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0200 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAllTest_0300 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0400 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0100 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0200 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = ""; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0300 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAsBundleTest_0400 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0500 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0100 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0200 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotByTypeTest_0300 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0400 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0100 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0200 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0300 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0400 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotsTest_0500 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0600 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0100 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0200 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = ""; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0300 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, popFlag); +} + +/* + * @tc.name: RequestEnableNotificationTest_0400 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0500 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0600 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0100 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0200 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveSlotByTypeTest_0300 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0400 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0100 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0200 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveAllSlotsTest_0300 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0400 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceSlot(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t slotNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (slotNum == 1) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteParcelable(slot); + } + if (slotNum > 1) { + reply.WriteInt32(slotNum); + for (size_t i = 0; i < slotNum; i++) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteStrongParcelable(slot); + } + } + return 0; +} + +/* + * @tc.name: GetSlotByTypeTest_0100 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0200 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_OK, result); + EXPECT_NE(nullptr, slot); +} +/* + * @tc.name: GetSlotByTypeTest_0300 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0400 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0100 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0200 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsTest_0300 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0400 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0100 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0200 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0300 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0400 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0500 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0600 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceNotifications(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t notificationNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (notificationNum > 0) { + reply.WriteInt32(notificationNum); + for (size_t i = 0; i < notificationNum; i++) { + sptr request = new (std::nothrow) NotificationRequest(0); + reply.WriteStrongParcelable(request); + } + } + + return 0; +} + +/* + * @tc.name: GetActiveNotificationsTest_0100 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0200 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); +} +/* + * @tc.name: GetActiveNotificationsTest_0300 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0400 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0500 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0100 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0200 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0300 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0400 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0500 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0100 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0200 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); +} +/* + * @tc.name: GetAllActiveNotificationsTest_0300 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0400 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetAllActiveNotificationsTest_0500 + * @tc.desc: test GetAllActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0100 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0200 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0300 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); +} +/* + * @tc.name: GetSpecialActiveNotificationsTest_0400 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0500 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSpecialActiveNotificationsTest_0600 + * @tc.desc: test GetSpecialActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationAgentTest_0100 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationAgentTest_0200 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = ""; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetNotificationAgentTest_0300 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationAgentTest_0400 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationAgentTest_0500 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0100 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0200 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, true, "0", true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0300 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0400 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, false, "0", true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0500 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, true, "0", false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0100 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0200 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = ""; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0300 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, canPublish); +} + +/* + * @tc.name: CanPublishAsBundleTest_0400 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0500 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0600 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0100 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0200 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0300 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = ""; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0400 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishAsBundleTest_0500 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0600 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0100 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0200 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationBadgeNumTest_0300 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0400 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0100 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0200 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetBundleImportanceTest_0300 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0400 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0500 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0100 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0200 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, granted); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0300 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0400 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0500 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0100 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0200 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0300 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0400 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0100 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0200 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allow); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0300 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0400 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0500 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0100 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0200 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveNotificationTest_0300 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveNotificationTest_0400 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0500 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0100 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0200 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0300 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0400 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0500 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0100 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0200 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteTest_0300 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteTest_0400 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0500 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0100 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0200 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteByBundleTest_0300 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteByBundleTest_0400 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0500 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0100 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0200 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllTest_0300 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0400 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0100 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0200 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0300 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsByBundleTest_0400 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0500 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0600 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0100 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0200 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0300 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0400 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0400, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0500 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: UpdateSlotsTest_0600 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0700 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0100 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0200 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0300 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0400 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0500 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0600 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0100 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0200 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0300 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0400 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0500 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0100 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0200 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: SubscribeTest_0300 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0400 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0500 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UnsubscribeTest_0100 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0200 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: UnsubscribeTest_0300 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0400 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0500 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0100 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0200 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, suspended); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0300 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0400 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0500 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0100 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0200 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +/* + * @tc.name: GetCurrentAppSortingTest_0300 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0400 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0100 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0200 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifyTest_0300 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0400 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0500 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0100 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0200 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0300 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0400 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0500 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0600 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0100 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0200 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0300 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, support); +} + +/* + * @tc.name: IsSupportTemplateTest_0400 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0500 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0600 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0100 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0200 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledByUserTest_0300 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0400 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0100 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0200 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllByUserTest_0300 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0400 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f0b1edc232e5dc511c8f6b1f54becbfff141d3d8 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_manager_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_manager_stub_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..357b5ef74fcf7dae2e861853cbd9d19ec56dd43e --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -0,0 +1,1797 @@ +/* + * 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 "ans_manager_stub.h" +#undef private +#undef protected + +#include "ans_inner_errors.h" + + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class AnsManagerStubTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() + { + ansManagerStub_ = new AnsManagerStub(); + } + void TearDown() {} + sptr ansManagerStub_; +}; + +/** + * @tc.name: OnRemoteRequest01 + * @tc.desc: Test if get the wrong descriptor. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0001, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: OnRemoteRequest02 + * @tc.desc: Test if get the wrong code. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0002, Function | SmallTest | Level1) +{ + uint32_t code = 267; + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: HandlePublish01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublish02 + * @tc.desc: Test if the label is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublish03 + * @tc.desc: Test if the notification is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishToDevice01 + * @tc.desc: Test HandlePublishToDevice succeeds; + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishToDevice02 + * @tc.desc: Test if the notification is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishToDevice03 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel01 + * @tc.desc: Test HandleCancel succeeds + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancel02 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel03 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAll01 + * @tc.desc: Test HandleCancelAll succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle02 + * @tc.desc: Test if the notificationId in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle04 + * @tc.desc: Test if the userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddSlotByType01 + * @tc.desc: Test HandleAddSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleAddSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::ADD_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveSlotByType01 + * @tc.desc: Test HandleRemoveSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllSlots01 + * @tc.desc: Test HandleRemoveAllSlots succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotByType01 + * @tc.desc: Test HandleGetSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle01 + * @tc.desc: Test HandleGetSlotNumAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetActiveNotifications01 + * @tc.desc: Test HandleGetActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetActiveNotificationNums01 + * @tc.desc: Test HandleGetActiveNotificationNums succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationNums01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ACTIVE_NOTIFICATION_NUMS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetAllActiveNotifications01 + * @tc.desc: Test HandleGetAllActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetAllActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ALL_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationAgent01 + * @tc.desc: Test HandleSetNotificationAgent succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationAgent01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string agent = "this is a agent"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(agent); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationAgent02 + * @tc.desc: Test if the agent in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationAgent02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetNotificationAgent01 + * @tc.desc: Test HandleGetNotificationAgent succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetNotificationAgent01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCanPublishAsBundle01 + * @tc.desc: Test HandleCanPublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCanPublishAsBundle02 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle01 + * @tc.desc: Test HandlePublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishAsBundle02 + * @tc.desc: Test if the notification in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum01 + * @tc.desc: Test HandleSetNotificationBadgeNum succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t num = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(num); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum02 + * @tc.desc: Test if the num in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetBundleImportance01 + * @tc.desc: Test HandleGetBundleImportance succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetBundleImportance01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_BUNDLE_IMPORTANCE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate01 + * @tc.desc: Test HandleSetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(date); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate02 + * @tc.desc: Test if the date in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetDoNotDisturbDate01 + * @tc.desc: Test HandleGetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDoesSupportDoNotDisturbMode01 + * @tc.desc: Test HandleDoesSupportDoNotDisturbMode01 succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDoesSupportDoNotDisturbMode01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DOES_SUPPORT_DO_NOT_DISTURB_MODE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification01 + * @tc.desc: Test HandlePublishContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr request = new NotificationRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(request); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification02 + * @tc.desc: Test if the request in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification01 + * @tc.desc: Test HandleCancelContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification02 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsNotificationPolicyAccessGranted01 + * @tc.desc: Test HandleIsNotificationPolicyAccessGranted succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleIsNotificationPolicyAccessGranted01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::IS_NOTIFICATION_POLICY_ACCESS_GRANTED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetPrivateNotificationsAllowed02 + * @tc.desc: Test if the allow in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetPrivateNotificationsAllowed02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_PRIVATIVE_NOTIFICATIONS_ALLOWED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetPrivateNotificationsAllowed01 + * @tc.desc: Test HandleGetPrivateNotificationsAllowed succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetPrivateNotificationsAllowed01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_PRIVATIVE_NOTIFICATIONS_ALLOWED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification01 + * @tc.desc: Test HandleRemoveNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification04 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification05 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification05, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveAllNotifications01 + * @tc.desc: Test HandleRemoveAllNotifications succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllNotifications02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete01 + * @tc.desc: Test HandleDelete succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDelete02 + * @tc.desc: Test if the key in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete03 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteByBundle01 + * @tc.desc: Test HandleDeleteByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDeleteByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteAll01 + * @tc.desc: Test HandleDeleteAll succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle01 + * @tc.desc: Test HandleGetSlotsByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots01 + * @tc.desc: Test HandleUpdateSlots succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + sptr slot1 = new NotificationSlot(); + sptr slot2 = new NotificationSlot(); + sptr slot3 = new NotificationSlot(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + data.WriteStrongParcelable(slot1); + data.WriteStrongParcelable(slot2); + data.WriteStrongParcelable(slot3); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleUpdateSlots02 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots03 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRequestEnableNotification01 + * @tc.desc: Test HandleRequestEnableNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRequestEnableNotification02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles01 + * @tc.desc: Test HandleSetNotificationsEnabledForAllBundles succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForSpecialBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle03 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle04 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle01 + * @tc.desc: Test HandleSetShowBadgeEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} +} +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..52625fec91c036ccbb095d0ef7a7709147a75d90 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_subscriber_proxy_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + "../mock/", + ] + + sources = [ "ans_subscriber_proxy_unit_test.cpp" ] + + deps = [ + "${core_path}:ans_core", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_subscriber_proxy_test" ] +} diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..826199bf2fa43ce5358272734bf61f9fcd09dd42 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp @@ -0,0 +1,569 @@ +/* + * 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 "ans_subscriber_proxy.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsSubscriberProxyUnitTest : public testing::Test { +public: + AnsSubscriberProxyUnitTest() {} + + virtual ~AnsSubscriberProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsSubscriberProxyUnitTest::SetUpTestCase() {} + +void AnsSubscriberProxyUnitTest::TearDownTestCase() {} + +void AnsSubscriberProxyUnitTest::SetUp() {} + +void AnsSubscriberProxyUnitTest::TearDown() {} + +/* + * @tc.name: InnerTransactTest_0100 + * @tc.desc: test if AnsSubscriberProxy's InnerTransact function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_OK, res); +} + +/* + * @tc.name: InnerTransactTest_0200 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: InnerTransactTest_0300 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); +} + +/* + * @tc.name: InnerTransactTest_0400 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; + std::shared_ptr proxy = std::make_shared(nullptr); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: OnConsumed_0100 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification); +} + +/* + * @tc.name: OnConsumed_0200 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification); +} + +/* + * @tc.name: OnConsumed_0300 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnConsumed(nullptr); +} + +/* + * @tc.name: OnConsumed_0400 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumed_0500 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumed_0600 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(nullptr, notificationMap); +} + +/* + * @tc.name: OnConsumed_0700 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification, nullptr); +} + +/* + * @tc.name: OnCanceled_0100 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnCanceled(notification); +} + +/* + * @tc.name: OnCanceled_0200 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnCanceled(notification); +} + +/* + * @tc.name: OnCanceled_0300 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnCanceled(nullptr); +} + +/* + * @tc.name: OnCanceled_0400 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0500 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0600 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(nullptr, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0700 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, nullptr, deleteReason); +} + +/* + * @tc.name: OnUpdated_0100 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnUpdated_0200 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnOnUpdated_0300 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnOnUpdated_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnOnUpdated_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnUpdated(nullptr); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0100 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); + ASSERT_NE(nullptr, date); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0200 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); + ASSERT_NE(nullptr, date); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0100 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); + ASSERT_NE(nullptr, callbackData); + proxy->OnEnabledNotificationChanged(callbackData); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0200 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); + ASSERT_NE(nullptr, callbackData); + proxy->OnEnabledNotificationChanged(callbackData); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a949040500505f56c58110d7d03c5243f2a56022 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_subscriber_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_subscriber_stub_unit_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_subscriber_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..acf8e39a56190a75a6094e178038aaf04ebbc36f --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp @@ -0,0 +1,490 @@ +/* + * Copyright (c) 2021 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 "ans_subscriber_stub.h" +#include "ans_inner_errors.h" +#include "ans_notification.h" +#undef private +#undef protected + +#include "message_option.h" +#include "message_parcel.h" +#include "parcel.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class AnsSubscriberStubUnitTest : public testing::Test { +public: + AnsSubscriberStubUnitTest() {} + + virtual ~AnsSubscriberStubUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; + + sptr stub_; +}; + +void AnsSubscriberStubUnitTest::SetUpTestCase() +{ +} + +void AnsSubscriberStubUnitTest::TearDownTestCase() +{ +} + +void AnsSubscriberStubUnitTest::SetUp() +{ + stub_ = new AnsSubscriberStub(); +} + +void AnsSubscriberStubUnitTest::TearDown() +{ +} + +/** +* @tc.name: OnRemoteRequest01 +* @tc.desc: test descriptor check failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest01, Function | MediumTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool bRet = data.WriteInterfaceToken(u"error descriptor"); + EXPECT_TRUE(bRet) << "write token error"; + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_CONNECTED); + + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, OBJECT_NULL) << "descriptor error"; +} + +/** +* @tc.name: OnRemoteRequest02 +* @tc.desc: test code error +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + + + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED + 1); + + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_TRUE(res != NO_ERROR); +} + +/** +* @tc.name: OnRemoteRequest03 +* @tc.desc: test function error +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED); + stub_->interfaces_[AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED] = nullptr; + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_TRUE(res != NO_ERROR); +} + +/** +* @tc.name: OnRemoteRequest04 +* @tc.desc: test ON_CONNECTED success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_CONNECTED); + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, NO_ERROR); +} + +/** +* @tc.name: HandleOnConnected +* @tc.desc: test HandleOnConnected success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConnected, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConnected(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnDisconnected +* @tc.desc: test HandleOnDisconnected success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDisconnected, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnDisconnected(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnConsumed01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumed01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumed(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumed02 +* @tc.desc: test notification success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumed02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + ErrCode res = stub_->HandleOnConsumed(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnConsumedMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap04 +* @tc.desc: test HandleOnConsumedMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnCanceled01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceled01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnCanceled(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceled02 +* @tc.desc: test HandleOnCanceled success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceled02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnCanceled(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnCanceledMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap04 +* @tc.desc: test read reason failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap05 +* @tc.desc: test HandleOnCanceledMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap05, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + int32_t reason = 0; + data.WriteInt32(reason); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnUpdated01 +* @tc.desc: test notificationMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnUpdated(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnUpdated02 +* @tc.desc: test HandleOnUpdated success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notificationMap = new NotificationSortingMap(); + data.WriteParcelable(notificationMap); + + ErrCode res = stub_->HandleOnUpdated(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnDoNotDisturbDateChange01 +* @tc.desc: test callbackData failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnDoNotDisturbDateChange02 +* @tc.desc: test HandleOnDoNotDisturbDateChange success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notifcallbackDataication = new EnabledNotificationCallbackData(); + data.WriteParcelable(notifcallbackDataication); + + ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnEnabledNotificationChanged01 +* @tc.desc: test callbackData failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnEnabledNotificationChanged02 +* @tc.desc: test HandleOnEnabledNotificationChanged success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notifcallbackDataication = new EnabledNotificationCallbackData(); + data.WriteParcelable(notifcallbackDataication); + + ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); + EXPECT_EQ(res, ERR_OK); +} +} +} diff --git a/frameworks/core/test/unittest/mock/mock_i_remote_object.h b/frameworks/core/test/unittest/mock/mock_i_remote_object.h new file mode 100644 index 0000000000000000000000000000000000000000..769c32e8dd0f8c3fd1117a6c9371d74139f1c3ee --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_i_remote_object.h @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H +#define BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H + +#include "gmock/gmock.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Notification { +class MockIRemoteObject : public IRemoteObject { +public: + MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} + + ~MockIRemoteObject() {} + + int32_t GetObjectRefCount() override + { + return 0; + } + + MOCK_METHOD(int, SendRequest, (uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; +} // namespace Notification +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_packer.cpp b/frameworks/core/test/unittest/mock/mock_image_packer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8063acfc93e5c74128f5369fd26004665bc906f4 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_packer.cpp @@ -0,0 +1,139 @@ +/* + * 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 "image_packer.h" +#include "mock_image_related_class.h" +#include "securec.h" + +namespace { +const uint8_t COUNT = 64; +uint32_t g_mockImagePackerGetSupportedFormatsRet = 0; +const uint8_t *g_mockImagePackerStartPackingRet = nullptr; +uint32_t g_mockImagePackerFinalizePackingRet = 16; +} + +void MockImagePackerGetSupportedFormats(uint32_t mockRet) +{ + g_mockImagePackerGetSupportedFormatsRet = mockRet; +} + +void MockImagePackerStartPacking(const uint8_t *mockRet) +{ + g_mockImagePackerStartPackingRet = mockRet; +} + +void MockImagePackerFinalizePacking(uint32_t mockRet) +{ + g_mockImagePackerFinalizePackingRet = mockRet; +} + +void MockResetImagePackerState() +{ + g_mockImagePackerGetSupportedFormatsRet = 0; + g_mockImagePackerStartPackingRet = nullptr; + g_mockImagePackerFinalizePackingRet = 16; // 16 :initial test result +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; +using namespace MultimediaPlugin; + +uint32_t ImagePacker::GetSupportedFormats(std::set &formats) +{ + return g_mockImagePackerGetSupportedFormatsRet; +} + +uint32_t ImagePacker::StartPackingImpl(const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(uint8_t *outputData, uint32_t maxSize, const PackOption &option) +{ + memcpy_s(outputData, COUNT, g_mockImagePackerStartPackingRet, COUNT); + return 0; +} + +uint32_t ImagePacker::StartPacking(const std::string &filePath, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(const int &fd, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(std::ostream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPackingAdapter(PackerStream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(PixelMap &pixelMap) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source, uint32_t index) +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking() +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking(int64_t &packedSize) +{ + packedSize = g_mockImagePackerFinalizePackingRet; + return 0; +} + +bool ImagePacker::GetEncoderPlugin(const PackOption &option) +{ + return true; +} + +void ImagePacker::CopyOptionsToPlugin(const PackOption &opts, PlEncodeOptions &plOpts) +{} + +void ImagePacker::FreeOldPackerStream() +{} + +bool ImagePacker::IsPackOptionValid(const PackOption &option) +{ + return true; +} + +// class reference need explicit constructor and destructor, otherwise unique_ptr use unnormal +ImagePacker::ImagePacker() +{} + +ImagePacker::~ImagePacker() +{} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_image_related_class.h b/frameworks/core/test/unittest/mock/mock_image_related_class.h new file mode 100644 index 0000000000000000000000000000000000000000..3d34c4cf76e7d5233eb484a3c500b8acac2138f9 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_related_class.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H +#define BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H + +namespace OHOS { +namespace Media { +class SourceStream {}; +class PackerStream {}; +} // namespace Media + +namespace ImagePlugin { +class AbsImageEncoder {}; +class AbsImageDecoder {}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_source.cpp b/frameworks/core/test/unittest/mock/mock_image_source.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57314557bfaa1e5278d90054c2e566d397c59648 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_source.cpp @@ -0,0 +1,373 @@ +/* + * Copyright (C) 2021 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. + */ + +#define private public +#define protected public +#include "image_source.h" +#undef private +#undef protected +#include "mock_image_related_class.h" + +namespace { +bool g_mockImageSourceCreateImageSourceRet = true; +uint32_t g_mockImageSourceCreateImageSourceErrorCode = 0; +bool g_mockImageSourceCreatePixelMapRet = true; +uint32_t g_mockImageSourceCreatePixelMapErrorCode = 0; +uint32_t g_mockImageSourceGetSupportedFormatsRet = 0; +} + +void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreateImageSourceRet = mockRet; + g_mockImageSourceCreateImageSourceErrorCode = errorCode; +} + +void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreatePixelMapRet = mockRet; + g_mockImageSourceCreatePixelMapErrorCode = errorCode; +} + +void MockImageSourceGetSupportedFormats(uint32_t mockRet) +{ + g_mockImageSourceGetSupportedFormatsRet = mockRet; +} + +void MockResetImageSourceState() +{ + g_mockImageSourceCreateImageSourceRet = true; + g_mockImageSourceCreateImageSourceErrorCode = 0; + g_mockImageSourceCreatePixelMapRet = true; + g_mockImageSourceCreatePixelMapErrorCode = 0; +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; + +uint32_t ImageSource::GetSupportedFormats(std::set &formats) +{ + return g_mockImageSourceGetSupportedFormatsRet; +} + +std::unique_ptr ImageSource::CreateImageSource(std::unique_ptr is, + const SourceOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const uint8_t *data, uint32_t size, + const SourceOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const std::string &pathName, const SourceOptions &opts, + uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const int fd, const SourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalImageSource(const IncrementalSourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +void ImageSource::Reset() +{} + +std::unique_ptr ImageSource::CreatePixelMapEx(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreatePixelMapErrorCode; + if (g_mockImageSourceCreatePixelMapRet) { + PixelMap *pixelMap = new (std::nothrow) PixelMap(); + return std::unique_ptr(pixelMap); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreatePixelMap(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalPixelMap(uint32_t index, const DecodeOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::PromoteDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + ImageDecodingState &state, uint8_t &decodeProgress) +{ + return 0; +} + +void ImageSource::DetachIncrementalDecoding(PixelMap &pixelMap) +{} + +uint32_t ImageSource::UpdateData(const uint8_t *data, uint32_t size, bool isCompleted) +{ + return 0; +} + +DecodeEvent ImageSource::GetDecodeEvent() +{ + return decodeEvent_; +} + +uint32_t ImageSource::GetImageInfo(uint32_t index, ImageInfo &imageInfo) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const std::string &path) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const int fd) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, uint8_t *data, uint32_t size) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value) +{ + return 0; +} + +const SourceInfo &ImageSource::GetSourceInfo(uint32_t &errorCode) +{ + return sourceInfo_; +} + +void ImageSource::RegisterListener(PeerListener *listener) +{} + +void ImageSource::UnRegisterListener(PeerListener *listener) +{} + +void ImageSource::AddDecodeListener(DecodeListener *listener) +{} + +void ImageSource::RemoveDecodeListener(DecodeListener *listener) +{} + +ImageSource::~ImageSource() +{} + +bool ImageSource::IsStreamCompleted() +{ + return true; +} + +ImageSource::ImageSource(std::unique_ptr &&stream, const SourceOptions &opts) +{} + +ImageSource::FormatAgentMap ImageSource::InitClass() +{ + FormatAgentMap tempAgentMap; + return tempAgentMap; +} + +uint32_t ImageSource::CheckEncodedFormat(AbsImageFormatAgent &agent) +{ + return 0; +} + +uint32_t ImageSource::CheckFormatHint(const std::string &formatHint, FormatAgentMap::iterator &formatIter) +{ + return 0; +} + +uint32_t ImageSource::GetEncodedFormat(const std::string &formatHint, std::string &format) +{ + return 0; +} + +uint32_t ImageSource::OnSourceRecognized(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::OnSourceUnresolved() +{ + return 0; +} + +uint32_t ImageSource::DecodeSourceInfo(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::DecodeImageInfo(uint32_t index, ImageStatusMap::iterator &iter) +{ + return 0; +} + +uint32_t ImageSource::InitMainDecoder() +{ + return 0; +} + +AbsImageDecoder *ImageSource::CreateDecoder(uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::SetDecodeOptions(std::unique_ptr &decoder, uint32_t index, + const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo) +{ + return 0; +} + +uint32_t ImageSource::UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo, + PixelMap &pixelMap) +{ + return 0; +} + +void ImageSource::CopyOptionsToPlugin(const DecodeOptions &opts, PixelDecodeOptions &plOpts) +{} + +void ImageSource::CopyOptionsToProcOpts(const DecodeOptions &opts, DecodeOptions &procOpts, PixelMap &pixelMap) +{} + +ImageSource::ImageStatusMap::iterator ImageSource::GetValidImageStatus(uint32_t index, uint32_t &errorCode) +{ + return imageStatusMap_.find(index); +} + +uint32_t ImageSource::AddIncrementalContext(PixelMap &pixelMap, IncrementalRecordMap::iterator &iterator) +{ + return 0; +} + +uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + IncrementalDecodingContext &recordContext) +{ + return 0; +} + +const NinePatchInfo &ImageSource::GetNinePatchInfo() const +{ + return ninePatchInfo_; +} + +void ImageSource::SetMemoryUsagePreference(const MemoryUsagePreference preference) +{} + +MemoryUsagePreference ImageSource::GetMemoryUsagePreference() +{ + return preference_; +} + +uint32_t ImageSource::GetRedactionArea(const int &fd, const int &redactionType, + std::vector> &ranges) +{ + return 0; +} + +void ImageSource::SetIncrementalSource(const bool isIncrementalSource) +{ + isIncrementalSource_ = isIncrementalSource; +} + +bool ImageSource::IsIncrementalSource() +{ + return isIncrementalSource_; +} + +FinalOutputStep ImageSource::GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch) +{ + return FinalOutputStep::NO_CHANGE; +} + +bool ImageSource::HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch) +{ + return true; +} + +bool ImageSource::ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight) +{ + return false; +} + +bool ImageSource::ImageConverChange(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo) +{ + return true; +} + +std::unique_ptr ImageSource::DecodeBase64(const uint8_t *data, uint32_t size) +{ + return DecodeBase64(""); +} + +std::unique_ptr ImageSource::DecodeBase64(const std::string &data) +{ + return nullptr; +} + +bool ImageSource::IsSpecialYUV() +{ + return true; +} + +bool ImageSource::ConvertYUV420ToRGBA(uint8_t *data, uint32_t size, + bool isSupportOdd, bool isAddUV, uint32_t &errorCode) +{ + return true; +} + +std::unique_ptr ImageSource::CreatePixelMapForYUV(uint32_t &errorCode) +{ + return nullptr; +} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_message_parcel.cpp b/frameworks/core/test/unittest/mock/mock_message_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba501f6f99c64e2eb7cbbdb58532e01e11388445 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_message_parcel.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2021 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 "message_parcel.h" +#include "iremote_object.h" + +namespace { + bool g_mockWriteInterfaceTokenRet = true; +} + +void MockWriteInterfaceToken(bool mockRet) +{ + g_mockWriteInterfaceTokenRet = mockRet; +} + +namespace OHOS { + +MessageParcel::MessageParcel() +{} + +MessageParcel::MessageParcel(Allocator *allocator) + : Parcel(allocator) +{ + writeRawDataFd_ = -1; + readRawDataFd_ = -1; + kernelMappedWrite_ = nullptr; + kernelMappedRead_ = nullptr; + rawData_ = nullptr; + rawDataSize_ = 0; +} + +MessageParcel::~MessageParcel() +{} + + +#ifndef CONFIG_IPC_SINGLE +bool MessageParcel::WriteDBinderProxy(const sptr &object, uint32_t handle, uint64_t stubIndex) +{ + return true; +} +#endif + +bool MessageParcel::WriteRemoteObject(const sptr &object) +{ + return true; +} + +sptr MessageParcel::ReadRemoteObject() +{ + sptr temp = ReadObject(); + return temp; +} + +bool MessageParcel::WriteFileDescriptor(int fd) +{ + return true; +} + +int MessageParcel::ReadFileDescriptor() +{ + return 0; +} + +void MessageParcel::ClearFileDescriptor() +{} + +bool MessageParcel::ContainFileDescriptors() const +{ + return true; +} + +bool MessageParcel::WriteInterfaceToken(std::u16string name) +{ + return g_mockWriteInterfaceTokenRet; +} + +std::u16string MessageParcel::ReadInterfaceToken() +{ + return ReadString16(); +} + +bool MessageParcel::WriteRawData(const void *data, size_t size) +{ + return true; +} + +bool MessageParcel::RestoreRawData(std::shared_ptr rawData, size_t size) +{ + return true; +} + +const void *MessageParcel::ReadRawData(size_t size) +{ + return nullptr; +} + +const void *MessageParcel::GetRawData() const +{ + return nullptr; +} + +size_t MessageParcel::GetRawDataSize() const +{ + return 0; +} + +size_t MessageParcel::GetRawDataCapacity() const +{ + return 0; +} + +void MessageParcel::WriteNoException() +{ + WriteInt32(0); +} + +int32_t MessageParcel::ReadException() +{ + return 0; +} + +bool MessageParcel::WriteAshmem(sptr ashmem) +{ + return true; +} + +sptr MessageParcel::ReadAshmem() +{ + return nullptr; +} + +bool MessageParcel::Append(MessageParcel &data) +{ + return true; +} +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_pixel_map.cpp b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1bd9daa2a00144b276d6b92835748745dd7b5077 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2021 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 "pixel_map.h" + +namespace { +int32_t g_mockPixelMapGetByteCountRet = 128; +} + +void MockPixelMapGetByteCount(int32_t mockRet) +{ + g_mockPixelMapGetByteCountRet = mockRet; +} + +void MockResetPixelMapState() +{ + g_mockPixelMapGetByteCountRet = 128; // 128 :initial test result +} +namespace OHOS { +namespace Media { +PixelMap::~PixelMap() +{} + +void PixelMap::FreePixelMap() __attribute__((no_sanitize("cfi"))) +{} + +void PixelMap::ReleaseSharedMemory(void *addr, void *context, uint32_t size) +{} + +void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, CustomFreePixelMap func) +{} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, + const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, int32_t offset, + int32_t stride, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::CheckParams(const uint32_t *colors, uint32_t colorLength, int32_t offset, int32_t stride, + const InitializationOptions &opts) +{ + return true; +} + +std::unique_ptr PixelMap::Create(const InitializationOptions &opts) +{ + return nullptr; +} + +void PixelMap::UpdatePixelsAlpha(const AlphaType &alphaType, const PixelFormat &pixelFormat, uint8_t *dstPixels, + PixelMap dstPixelMap) +{} + +std::unique_ptr PixelMap::Create(PixelMap &source, const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(PixelMap &source, const Rect &srcRect, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageInfo, const ImageInfo &dstImageInfo, + const Rect &srcRect, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::ScalePixelMap(const Size &targetSize, const Size &dstSize, const ScaleMode &scaleMode, + PixelMap &dstPixelMap) +{ + return true; +} + +void PixelMap::InitDstImageInfo(const InitializationOptions &opts, const ImageInfo &srcImageInfo, + ImageInfo &dstImageInfo) +{} + +bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::IsSameSize(const Size &src, const Size &dst) +{ + return true; +} + +bool PixelMap::GetPixelFormatDetail(const PixelFormat format) +{ + return true; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info) +{ + return 0; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused) +{ + return 0; +} + +const uint8_t *PixelMap::GetPixel8(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint16_t *PixelMap::GetPixel16(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint32_t *PixelMap::GetPixel32(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint8_t *PixelMap::GetPixel(int32_t x, int32_t y) +{ + return nullptr; +} + +bool PixelMap::GetARGB32Color(int32_t x, int32_t y, uint32_t &color) +{ + return true; +} + +bool PixelMap::ALPHA8ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB565ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::ARGB8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGBA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::BGRA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +int32_t PixelMap::GetPixelBytes() +{ + return 0; +} + +int32_t PixelMap::GetRowBytes() +{ + return 0; +} + +int32_t PixelMap::GetByteCount() +{ + return g_mockPixelMapGetByteCountRet; +} + +int32_t PixelMap::GetWidth() +{ + return 0; +} + +int32_t PixelMap::GetHeight() +{ + return 0; +} + +int32_t PixelMap::GetBaseDensity() +{ + return 0; +} + +void PixelMap::GetImageInfo(ImageInfo &imageInfo) +{} + +PixelFormat PixelMap::GetPixelFormat() +{ + return imageInfo_.pixelFormat; +} + +ColorSpace PixelMap::GetColorSpace() +{ + return imageInfo_.colorSpace; +} + +AlphaType PixelMap::GetAlphaType() +{ + return imageInfo_.alphaType; +} + +const uint8_t *PixelMap::GetPixels() +{ + return data_; +} + +uint8_t PixelMap::GetARGB32ColorA(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorR(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorG(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorB(uint32_t color) +{ + return 0; +} + +bool PixelMap::IsSameImage(const PixelMap &other) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, uint8_t *dst) +{ + return 0; +} + +bool PixelMap::CheckPixelsInput(const uint8_t *dst, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, const uint32_t &offset, const uint32_t &stride, + const Rect ®ion, uint8_t *dst) +{ + return 0; +} + +uint32_t PixelMap::ReadPixel(const Position &pos, uint32_t &dst) +{ + return 0; +} + +uint32_t PixelMap::ResetConfig(const Size &size, const PixelFormat &format) +{ + return 0; +} + +bool PixelMap::SetAlphaType(const AlphaType &alphaType) +{ + return true; +} + +uint32_t PixelMap::WritePixel(const Position &pos, const uint32_t &color) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize) +{ + return 0; +} + +bool PixelMap::WritePixels(const uint32_t &color) +{ + return true; +} + +AllocatorType PixelMap::GetAllocatorType() +{ + return allocatorType_; +} + +void *PixelMap::GetFd() const +{ + return context_; +} + +void PixelMap::ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size) +{} + +bool PixelMap::WriteImageData(Parcel &parcel, size_t size) const +{ + return true; +} + +uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) +{ + return nullptr; +} + +bool PixelMap::WriteFileDescriptor(Parcel &parcel, int fd) +{ + return true; +} + +int PixelMap::ReadFileDescriptor(Parcel &parcel) +{ + return 0; +} + +bool PixelMap::WriteImageInfo(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::Marshalling(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::ReadImageInfo(Parcel &parcel, ImageInfo &imgInfo) +{ + return true; +} + +PixelMap *PixelMap::Unmarshalling(Parcel &parcel) +{ + return nullptr; +} + +uint32_t PixelMap::SetAlpha(const float percent) +{ + return 0; +} + +void PixelMap::scale(float xAxis, float yAxis) +{} + +void PixelMap::translate(float xAxis, float yAxis) +{} + +void PixelMap::rotate(float degrees) +{} + +void PixelMap::flip(bool xAxis, bool yAxis) +{} + +uint32_t PixelMap::crop(const Rect &rect) +{ + return 0; +} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index a1aa00bcbce945571656f9053881c582e13073d3..bf8794ab15339ff4f36a1c43eb94d5c83360e1c8 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -76,7 +76,7 @@ ohos_shared_library("notification") { "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 621f0ecb49921d268fa504a9aa464b38c2c82975..66ad696445cf29a1afdad34d30a6e261921fef0f 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -213,8 +213,8 @@ public: * @param errCode Indicates the error code returned by the callback * @param result Indicates the result returned by the callback */ - static void SetCallback( - const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); + static void SetCallback(const napi_env &env, + const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result, bool newType); /** * @brief Calls the callback with the result @@ -234,8 +234,8 @@ public: * @param errorCode Indicates the error code returned by the callback * @param result Indicates the result returned by the callback */ - static void SetPromise( - const napi_env &env, const napi_deferred &deferred, const int32_t &errorCode, const napi_value &result); + static void SetPromise(const napi_env &env, + const napi_deferred &deferred, const int32_t &errorCode, const napi_value &result, bool newType); /** * @brief Gets the returned result by the callback when an error occurs @@ -1546,7 +1546,7 @@ public: * @param errCode Indicates specified err code * @return Returns a napi value with specified error object for callback */ - static napi_value CreateErrorValue(napi_env env, int32_t errCode); + static napi_value CreateErrorValue(napi_env env, int32_t errCode, bool newType); static bool IsValidRemoveReason(int32_t reasonType); static void NapiThrow(napi_env env, int32_t errCode); diff --git a/frameworks/js/napi/include/enable_notification.h b/frameworks/js/napi/include/enable_notification.h index 51b0faf9f635ef748b5b7a886d9d92e19aa47d22..70c2fb23d4a6985be1dd732a2474a555a9ae159d 100644 --- a/frameworks/js/napi/include/enable_notification.h +++ b/frameworks/js/napi/include/enable_notification.h @@ -39,6 +39,7 @@ struct AsyncCallbackInfoIsEnable { napi_async_work asyncWork = nullptr; IsEnableParams params; CallbackPromiseInfo info; + bool newInterface = false; bool allowed = false; }; diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 400bbc4b05247892d61a9ff331df93a6e2da9c49..75cd7bd05b17c898d848ac9b0c7febbe129e1356 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -93,7 +93,7 @@ public: static void HandleErrCode(const napi_env &env, int32_t errCode); static void ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, - const napi_value &result); + const napi_value &result, bool isThrow = false); static void SetCallback(const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); diff --git a/frameworks/js/napi/include/subscribe.h b/frameworks/js/napi/include/subscribe.h index 44b4a4eee3080ee652ba416644891dba63daab87..547107c67745f64b3cd48c7e253468812901d170 100644 --- a/frameworks/js/napi/include/subscribe.h +++ b/frameworks/js/napi/include/subscribe.h @@ -167,7 +167,7 @@ static std::vector DeletingSubscriber; bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, SubscriberInstancesInfo &subscriberInfo); bool AddSubscriberInstancesInfo(const napi_env &env, const SubscriberInstancesInfo &subscriberInfo); -bool DelSubscriberInstancesInfo(const napi_env &env, SubscriberInstance *subscriber); +bool DelSubscriberInstancesInfo(const napi_env &env, const SubscriberInstance *subscriber); bool AddDeletingSubscriber(SubscriberInstance *subscriber); void DelDeletingSubscriber(SubscriberInstance *subscriber); diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index ab665789b3dd5cc0ef27c58b726f5071a815fc5e..e6fe747c0e34c78e63eac6903dbdc0c9cdfa90d4 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -69,8 +69,14 @@ napi_value Common::NapiGetUndefined(napi_env env) return result; } -napi_value Common::CreateErrorValue(napi_env env, int32_t errCode) +napi_value Common::CreateErrorValue(napi_env env, int32_t errCode, bool newType) { + ANS_LOGI("enter, errorCode[%{public}d]", errCode); + napi_value error = Common::NapiGetNull(env); + if (errCode == ERR_OK && newType) { + return error; + } + napi_value code = nullptr; napi_create_int32(env, errCode, &code); @@ -79,7 +85,6 @@ napi_value Common::CreateErrorValue(napi_env env, int32_t errCode) napi_value message = nullptr; napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &message); - napi_value error = nullptr; napi_create_error(env, nullptr, message, &error); napi_set_named_property(env, error, "code", code); return error; @@ -89,7 +94,7 @@ void Common::NapiThrow(napi_env env, int32_t errCode) { ANS_LOGI("enter"); - napi_throw(env, CreateErrorValue(env, errCode)); + napi_throw(env, CreateErrorValue(env, errCode, true)); } napi_value Common::GetCallbackErrorValue(napi_env env, int32_t errCode) @@ -122,15 +127,15 @@ void Common::ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInf { ANS_LOGI("enter errorCode=%{public}d", info.errorCode); if (info.isCallback) { - SetCallback(env, info.callback, info.errorCode, result); + SetCallback(env, info.callback, info.errorCode, result, false); } else { - SetPromise(env, info.deferred, info.errorCode, result); + SetPromise(env, info.deferred, info.errorCode, result, false); } ANS_LOGI("end"); } void Common::SetCallback( - const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result) + const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result, bool newType) { ANS_LOGI("enter"); napi_value undefined = nullptr; @@ -140,7 +145,7 @@ void Common::SetCallback( napi_value resultout = nullptr; napi_get_reference_value(env, callbackIn, &callback); napi_value results[ARGS_TWO] = {nullptr}; - results[PARAM0] = CreateErrorValue(env, errorCode); + results[PARAM0] = CreateErrorValue(env, errorCode, newType); results[PARAM1] = result; NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &results[PARAM0], &resultout)); ANS_LOGI("end"); @@ -160,14 +165,14 @@ void Common::SetCallback( ANS_LOGI("end"); } -void Common::SetPromise( - const napi_env &env, const napi_deferred &deferred, const int32_t &errorCode, const napi_value &result) +void Common::SetPromise(const napi_env &env, + const napi_deferred &deferred, const int32_t &errorCode, const napi_value &result, bool newType) { ANS_LOGI("enter"); if (errorCode == ERR_OK) { napi_resolve_deferred(env, deferred, result); } else { - napi_reject_deferred(env, deferred, CreateErrorValue(env, errorCode)); + napi_reject_deferred(env, deferred, CreateErrorValue(env, errorCode, newType)); } ANS_LOGI("end"); } @@ -180,7 +185,7 @@ napi_value Common::JSParaError(const napi_env &env, const napi_ref &callback) napi_value promise = nullptr; napi_deferred deferred = nullptr; napi_create_promise(env, &deferred, &promise); - SetPromise(env, deferred, ERROR, Common::NapiGetNull(env)); + SetPromise(env, deferred, ERROR, Common::NapiGetNull(env), false); return promise; } @@ -4716,9 +4721,9 @@ void Common::CreateReturnValue(const napi_env &env, const CallbackPromiseInfo &i ANS_LOGI("enter errorCode=%{public}d", info.errorCode); int32_t errorCode = info.errorCode == ERR_OK ? ERR_OK : ErrorToExternal(info.errorCode); if (info.isCallback) { - SetCallback(env, info.callback, errorCode, result); + SetCallback(env, info.callback, errorCode, result, true); } else { - SetPromise(env, info.deferred, errorCode, result); + SetPromise(env, info.deferred, errorCode, result, true); } ANS_LOGI("end"); } diff --git a/frameworks/js/napi/src/enable_notification.cpp b/frameworks/js/napi/src/enable_notification.cpp index 322deb14711efd04cb29eb718ba815cb2fcaa488..71b10ba00760bb3c9646660935b3700a68b54a99 100644 --- a/frameworks/js/napi/src/enable_notification.cpp +++ b/frameworks/js/napi/src/enable_notification.cpp @@ -187,7 +187,11 @@ void AsyncCompleteCallbackIsNotificationEnabled(napi_env env, napi_status status AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); napi_value result = nullptr; napi_get_boolean(env, asynccallbackinfo->allowed, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->newInterface) { + Common::CreateReturnValue(env, asynccallbackinfo->info, result); + } else { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + } if (asynccallbackinfo->info.callback != nullptr) { napi_delete_reference(env, asynccallbackinfo->info.callback); } diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 99d8ac439e7afa79d35df219a80c56880766f274..ad252fb331f4e08d5ff26243afc720eeb2f4183c 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("notificationmanager") { "../get_active.cpp", "../publish.cpp", "../slot.cpp", + "init_module.cpp", "napi_cancel.cpp", "napi_display_badge.cpp", "napi_distributed.cpp", @@ -65,7 +66,7 @@ ohos_shared_library("notificationmanager") { "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 36de4d82744b3842d4a383d3f3c86610ee5601c7..d328bc47cc6dcb84675ccb4aaecbca1dc6947d94 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -210,8 +210,8 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) return Common::NapiGetUndefined(env); } - AsyncCallbackInfoIsEnable *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoIsEnable {.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoIsEnable *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoIsEnable { + .env = env, .params = params, .newInterface = true}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -221,18 +221,29 @@ napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) napi_value resourceName = nullptr; napi_create_string_latin1(env, "RequestEnableNotification", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call - napi_create_async_work(env, - nullptr, - resourceName, + napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { ANS_LOGI("RequestEnableNotification napi_create_async_work start"); AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); std::string deviceId {""}; - asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId); - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + bool popFlag = false; + asynccallbackinfo->info.errorCode = NotificationHelper::RequestEnableNotification(deviceId, popFlag); + asynccallbackinfo->params.allowToPop = popFlag; + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, allowToPop = %{public}d", + asynccallbackinfo->info.errorCode, asynccallbackinfo->params.allowToPop); + if (asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop) { + ANS_LOGI("Begin to start notification dialog"); + auto *callbackInfo = static_cast(data); + StartNotificationDialog(callbackInfo); + } + }, + [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfoIsEnable *asynccallbackinfo = static_cast(data); + if (!(asynccallbackinfo->info.errorCode == ERR_OK && asynccallbackinfo->params.allowToPop)) { + AsyncCompleteCallbackNapiIsNotificationEnabled(env, status, data); + } }, - AsyncCompleteCallbackNapiIsNotificationEnabled, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn index d116b4430f4ddbfb3e11ef5880b0f613db6427f8..57b4ba33e91e99df63d090e2269a34ca314fa9af 100644 --- a/frameworks/js/napi/src/reminder/BUILD.gn +++ b/frameworks/js/napi/src/reminder/BUILD.gn @@ -49,7 +49,7 @@ ohos_shared_library("reminderagent") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ @@ -94,7 +94,7 @@ ohos_shared_library("reminderagentmanager") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 1d46fd682ff175a6ae8f39d5254f999b0992eabc..4d4e65b1be9a0fa1d43916a9cc0b2b2317e390f5 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -48,6 +48,7 @@ struct AsyncCallbackInfo { napi_ref callback = nullptr; napi_value result = nullptr; int32_t reminderId = -1; + bool isThrow = false; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; std::shared_ptr reminder = nullptr; @@ -259,10 +260,10 @@ napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn, cons return nullptr; } if (callbackIn) { - ReminderCommon::SetCallback(env, callbackIn, ERR_REMINDER_INVALID_PARAM, - result); + NotificationNapi::Common::SetCallback(env, callbackIn, ERR_REMINDER_INVALID_PARAM, + result, false); } - return ReminderCommon::JSParaError(env, callbackIn); + return NotificationNapi::Common::JSParaError(env, callbackIn); } napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThrow) @@ -286,6 +287,7 @@ napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThr napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->reminderId = params.reminderId; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -306,7 +308,7 @@ napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThr std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGI("Cancel napi_create_async_work complete end"); }, (void *)asynccallbackinfo, @@ -351,6 +353,7 @@ napi_value CancelAllRemindersInner(napi_env env, napi_callback_info info, bool i // promise napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -371,7 +374,7 @@ napi_value CancelAllRemindersInner(napi_env env, napi_callback_info info, bool i std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGD("CancelAll napi_create_async_work complete end"); }, (void *)asynccallbackinfo, @@ -476,7 +479,7 @@ void ParseReminderCalendar(const napi_env &env, const ReminderRequest &reminder, } void ParseReminder( - const napi_env &env, const ReminderRequest::ReminderType &type, ReminderRequest &reminder, napi_value &result) + const napi_env &env, const ReminderRequest::ReminderType &type, const ReminderRequest &reminder, napi_value &result) { switch (type) { case ReminderRequest::ReminderType::TIMER: { @@ -658,6 +661,7 @@ napi_value InnerGetValidReminders(napi_env env, napi_callback_info info, bool is // promise napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -687,7 +691,7 @@ napi_value InnerGetValidReminders(napi_env env, napi_callback_info info, bool is } ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); + env, asynccallbackinfo->info, asynccallbackinfo->result, asynccallbackinfo->isThrow); } }, (void *)asynccallbackinfo, @@ -734,6 +738,7 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->reminder = params.reminder; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -765,7 +770,7 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh } ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); + env, asynccallbackinfo->info, asynccallbackinfo->result, asynccallbackinfo->isThrow); ANSR_LOGI("Publish napi_create_async_work complete end"); } }, @@ -814,6 +819,7 @@ napi_value AddSlotInner(napi_env env, napi_callback_info info, bool isThrow) SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->inType = params.inType; asynccallbackinfo->info.errorCode = params.errCode; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -835,7 +841,7 @@ napi_value AddSlotInner(napi_env env, napi_callback_info info, bool isThrow) std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGD("AddSlot napi_create_async_work complete end."); }, (void *)asynccallbackinfo, diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 68642259b719f1ae390723123ab5b3e302e9bb93..95d0eefdcfb953e66a369d836b600d60a99e2ec9 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -552,8 +552,7 @@ void ReminderCommon::HandleErrCode(const napi_env &env, int32_t errCode) if (errCode == ERR_OK) { return; } - std::string errCodeMsg = FindErrMsg(env, errCode); - errCodeMsg = reminderErrCodeMsgMap[errCode]; + std::string errCodeMsg = reminderErrCodeMsgMap[errCode]; napi_throw_error(env, std::to_string(errCode).c_str(), errCodeMsg.c_str()); } @@ -568,11 +567,15 @@ std::string ReminderCommon::FindErrMsg(const napi_env &env, const int32_t errCod } void ReminderCommon::ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, - const napi_value &result) + const napi_value &result, bool isThrow) { ANSR_LOGI("enter errorCode=%{public}d", info.errorCode); if (info.isCallback) { - SetCallback(env, info.callback, info.errorCode, result); + if (isThrow) { + SetCallback(env, info.callback, info.errorCode, result); + } else { + NotificationNapi::Common::SetCallback(env, info.callback, info.errorCode, result, false); + } } else { SetPromise(env, info, result); } @@ -593,7 +596,7 @@ void ReminderCommon::SetCallback( results[0] = NotificationNapi::Common::NapiGetNull(env); } else { std::string errMsg = FindErrMsg(env, errCode); - results[0] = GetCallbackErrorValue(env, errCode, errMsg); + results[0] = GetCallbackErrorValue(env, errCode, errMsg); } results[1] = result; NAPI_CALL_RETURN_VOID(env, diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index c128d88c4a3a8c864eb24a1062c52546e09f943f..c3d9eef18fddadd8e79809ca04d1071e18d4341f 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -101,8 +101,8 @@ napi_value SetSubscribeCallbackData(const napi_env &env, // vibrationValues?: Array napi_value arr = nullptr; napi_create_array(env, &arr); - uint32_t count = 0; if (request->EnableVibrate()) { + uint32_t count = 0; for (auto vec : request->GetVibrationStyle()) { napi_value nVibrationValue = nullptr; napi_create_int64(env, vec, &nVibrationValue); @@ -232,7 +232,7 @@ void SubscriberInstance::OnCanceled(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnCanceled); if (ret != 0) { @@ -327,7 +327,7 @@ void SubscriberInstance::OnConsumed(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnConsumed); if (ret != 0) { @@ -406,7 +406,7 @@ void SubscriberInstance::OnUpdate(const std::shared_ptr return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnUpdate); if (ret != 0) { @@ -474,7 +474,7 @@ void SubscriberInstance::OnConnected() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnConnected); if (ret != 0) { @@ -545,7 +545,7 @@ void SubscriberInstance::OnDisconnected() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDisconnected); if (ret != 0) { @@ -613,7 +613,7 @@ void SubscriberInstance::OnDied() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDied); if (ret != 0) { @@ -694,7 +694,7 @@ void SubscriberInstance::OnDoNotDisturbDateChange(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDoNotDisturbDateChange); if (ret != 0) { @@ -776,7 +776,7 @@ void SubscriberInstance::OnEnabledNotificationChanged( return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnEnabledNotificationChanged); if (ret != 0) { @@ -1038,7 +1038,7 @@ bool AddSubscriberInstancesInfo(const napi_env &env, const SubscriberInstancesIn return true; } -bool DelSubscriberInstancesInfo(const napi_env &env, SubscriberInstance *subscriber) +bool DelSubscriberInstancesInfo(const napi_env &env, const SubscriberInstance *subscriber) { ANS_LOGI("enter"); if (subscriber == nullptr) { diff --git a/frameworks/js/napi/src/subscribe/BUILD.gn b/frameworks/js/napi/src/subscribe/BUILD.gn index c18561fa6f9d2885996d70586731456fe40fa685..6d1d3eccacd7ac1ac7a88da5405c3d46c45724a3 100644 --- a/frameworks/js/napi/src/subscribe/BUILD.gn +++ b/frameworks/js/napi/src/subscribe/BUILD.gn @@ -53,7 +53,7 @@ ohos_shared_library("notificationsubscribe") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/test/moduletest/mock/blob.cpp b/frameworks/test/moduletest/mock/blob.cpp index 540888d0f6f0bddd56e2f06b1af89b6658802a38..9acb0f99ddf2a48f540001de8bea5a3bd729e4fb 100644 --- a/frameworks/test/moduletest/mock/blob.cpp +++ b/frameworks/test/moduletest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index c982bac66f53f61528f7da49a7af7b8cc98887cc..e153cc4e02f4aa3117ee32a55c6ca91c67fc236f 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -278,15 +278,6 @@ public: */ static ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allow the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - static ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allow the current application to publish notifications on a specified device. * diff --git a/sa_profile/3203.xml b/sa_profile/3203.xml index 6b23aaf57a30735e861a504790aab516bbb4f5ce..0e657d6487e8896f60696b6962851eca1e50586e 100755 --- a/sa_profile/3203.xml +++ b/sa_profile/3203.xml @@ -19,7 +19,7 @@ libans.z.so 1301 3299 - 5000 + 60000 true false 1 diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 7843be17ff5049f6e7f497f3ca8ad725688e8286..c76765868e2952a85a6f2e351620cfbde09ca17f 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -76,7 +76,8 @@ ohos_shared_library("libans") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", - "time_service:time_service", + "relational_store:native_rdb", + "time_service:time_client", "window_manager:libdm", ] external_deps += component_external_deps diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 27f7a86632a48ac7252a73509e26ab76d36f0e9f..958a4331aace703deefab906745494f334a0f760 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -339,14 +339,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 7548eb5f797d1ecb61d6e3ffbdb4b994647151f2..da1f339f13852f2f663c400b3eaf72fd70640233 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -261,6 +261,7 @@ public: void OnDistributedKvStoreDeathRecipient(); void InitSettingFromDisturbDB(); void RemoveSettings(int32_t userId); + void RemoveAnsBundleDbInfo(const sptr &bundleOption); private: ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 6aee6f7c3c95df3818b26b45ef5fa87c65e175e5..e2123a89ed9cc8fc0ac812cf8b1a46942f402a98 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -163,6 +163,7 @@ public: bool RemoveNotificationEnable(const int32_t userId); bool RemoveDoNotDisturbDate(const int32_t userId); + bool RemoveAnsBundleDbInfo(std::string bundleName, int32_t uid); private: void TryTwice(const std::function &func) const; diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 450655e8db68f7d24a556e28dced99d9e73acf1d..895c80478544c04ae352a7c6e530863b96fb4ee3 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -287,6 +287,7 @@ public: bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; void RemoveNotificationEnable(const int32_t userId); void RemoveDoNotDisturbDate(const int32_t userId); + void SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey); private: std::map isEnabledAllNotification_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 881d5dddea2008f8a6ac7a141a880b1aa3eb0645..aef1db1735d913780c60f4d9a5010b4109d26b71 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1434,12 +1434,6 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( return result; } -ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1590,6 +1584,7 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(bool &allowed) ErrCode AdvancedNotificationService::IsAllowedNotifySelf(const sptr &bundleOption, bool &allowed) { + ANS_LOGD("%{public}s", __FUNCTION__); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } @@ -2101,7 +2096,7 @@ ErrCode AdvancedNotificationService::FlowControl(const std::shared_ptr> sorted = notificationList_; sorted.sort(SortNotificationsByLevelAndTime); - recordToRemove = bundleList.front(); + recordToRemove = sorted.front(); SendFlowControlOccurHiSysEvent(recordToRemove); notificationList_.remove(sorted.front()); } @@ -2145,6 +2140,8 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrbundleOption->GetBundleName() == bundle->GetBundleName()) && - (record->bundleOption->GetUid() == bundleOption->GetUid()) && + (record->bundleOption->GetUid() == bundle->GetUid()) && #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED (record->deviceId.empty()) && #endif @@ -3693,7 +3690,7 @@ void AdvancedNotificationService::SendSubscribeHiSysEvent(int32_t pid, int32_t u eventInfo.userId = info->GetAppUserId(); std::vector appNames = info->GetAppNames(); eventInfo.bundleName = std::accumulate(appNames.begin(), appNames.end(), std::string(""), - [appNames](const std::string bundleName, const std::string &str) { + [appNames](const std::string &bundleName, const std::string &str) { return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); } @@ -3716,7 +3713,7 @@ void AdvancedNotificationService::SendUnSubscribeHiSysEvent(int32_t pid, int32_t eventInfo.userId = info->GetAppUserId(); std::vector appNames = info->GetAppNames(); eventInfo.bundleName = std::accumulate(appNames.begin(), appNames.end(), std::string(""), - [appNames](const std::string bundleName, const std::string &str) { + [appNames](const std::string &bundleName, const std::string &str) { return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); } diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 8d12e9f2cc822339a5fab3e46b7c66bc592415b6..19e7daaa05cc99edb614db2693c108df102ee419 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -701,5 +701,13 @@ bool NotificationPreferences::CheckApiCompatibility(const sptrCheckApiCompatibility(bundleOption); } + +void NotificationPreferences::RemoveAnsBundleDbInfo(const sptr &bundleOption) +{ + ANS_LOGE("%{public}s", __FUNCTION__); + if (preferncesDB_ != nullptr && bundleOption != nullptr) { + preferncesDB_->RemoveAnsBundleDbInfo(bundleOption->GetBundleName(), bundleOption->GetUid()); + } +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 811dd544c79213cec04fc966c08ca5036b143f4c..b8b64fcbbd171989f328daf847f558032f6cfdef 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -313,13 +313,14 @@ DistributedKv::Status NotificationPreferencesDatabase::GetKvStore() if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Return error: %{public}d.", status); } else { - ANS_LOGD("Get kvStore success."); + ANS_LOGI("Get kvStore success."); } return status; } void NotificationPreferencesDatabase::CloseKvStore() { + ANS_LOGI("Close kvStore success."); dataManager_.CloseKvStore(appId_, kvStorePtr_); } @@ -471,6 +472,7 @@ bool NotificationPreferencesDatabase::PutPrivateNotificationsAllowed( bool NotificationPreferencesDatabase::PutNotificationsEnabledForBundle( const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &enabled) { + ANS_LOGD("%{public}s, enabled[%{public}d]", __FUNCTION__, enabled); if (bundleInfo.GetBundleName().empty()) { ANS_LOGE("Bundle name is null."); return false; @@ -961,7 +963,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( } } - info.SetBundleInfo(bunldeInfo); + info.SetBundleInfoFromDb(bunldeInfo, bundleKey); } } @@ -1115,6 +1117,7 @@ std::string NotificationPreferencesDatabase::GenerateBundleKey( * KEY_ANS_BUNDLE_bundlename_ * */ + ANS_LOGD("%{public}s, bundleKey[%{public}s] type[%{public}s]", __FUNCTION__, bundleKey.c_str(), type.c_str()); std::string key = std::string().append(KEY_ANS_BUNDLE).append(KEY_UNDER_LINE).append(bundleKey).append(KEY_UNDER_LINE); if (!type.empty()) { @@ -1475,5 +1478,25 @@ bool NotificationPreferencesDatabase::RemoveDoNotDisturbDate(const int32_t userI ANS_LOGD("%{public}s remove DoNotDisturb date, userId : %{public}d", __FUNCTION__, userId); return true; } + +bool NotificationPreferencesDatabase::RemoveAnsBundleDbInfo(std::string bundleName, int32_t uid) +{ + if (!CheckKvStore()) { + ANS_LOGE("KvStore is nullptr."); + return false; + } + + std::string key = KEY_BUNDLE_LABEL + bundleName + std::to_string(uid); + DistributedKv::Key enableKey(key); + DistributedKv::Status status = kvStorePtr_->Delete(enableKey); + CloseKvStore(); + if (status != DistributedKv::Status::SUCCESS) { + ANS_LOGE("Delete ans bundle db info failed, bundle[%{public}s:%{public}d]", bundleName.c_str(), uid); + return false; + } + + ANS_LOGE("Remove ans bundle db info, bundle[%{public}s:%{public}d]", bundleName.c_str(), uid); + return true; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 2ab4e39f8afd934ab52ce464e6a7a8e29cce8f86..b0cb322b468c6bd94d0835f74176285d653af554 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -240,5 +240,10 @@ void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId) { doNotDisturbDate_.erase(userId); } + +void NotificationPreferencesInfo::SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey) +{ + infos_.insert_or_assign(bundleKey, info); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 1b55a7c8d5c984895bc19ece0496a8bdc0777bd1..0646309d23db1e5b3d0607aef668ff3164f55ad3 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("ans_unit_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_access_token_helper.cpp", + "mock/mock_accesstoken_kit.cpp", "mock/mock_bundle_manager_helper.cpp", "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", @@ -61,6 +62,7 @@ ohos_unittest("ans_unit_test") { "notification_subscriber_manager_test.cpp", "permission_filter_test.cpp", "reminder_data_manager_test.cpp", + "system_event_observer_test.cpp", ] configs = [ "//commonlibrary/c_utils/base:utils_config" ] @@ -98,9 +100,10 @@ ohos_unittest("ans_unit_test") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] if (device_usage) { @@ -123,4 +126,6 @@ group("unittest") { deps = [] deps += [ ":ans_unit_test" ] + + deps += [ "access_token_helper_test:unittest" ] } diff --git a/services/ans/test/unittest/access_token_helper_test/BUILD.gn b/services/ans/test/unittest/access_token_helper_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b4c64162190a1982b05fd993da1995ece789bd03 --- /dev/null +++ b/services/ans/test/unittest/access_token_helper_test/BUILD.gn @@ -0,0 +1,71 @@ +# 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("access_token_helper_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + "/${services_path}/ans/include", + ] + + sources = [ + "${services_path}/ans/src/access_token_helper.cpp", + "${services_path}/ans/test/unittest/mock/mock_accesstoken_kit.cpp", + "access_token_helper_test.cpp", + ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "multimedia_image_framework:image_native", + "multimedia_player_framework:media_client", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":access_token_helper_test" ] +} diff --git a/services/ans/test/unittest/access_token_helper_test/access_token_helper_test.cpp b/services/ans/test/unittest/access_token_helper_test/access_token_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69a0fca56ee0fceac1bad0712177aee4ddafb5c5 --- /dev/null +++ b/services/ans/test/unittest/access_token_helper_test/access_token_helper_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2021 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 +#include "accesstoken_kit.h" +#define private public +#define protected public +#include "access_token_helper.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +#undef private +#undef protected +using namespace testing::ext; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace Notification { + +extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); +extern void MockDlpType(DlpType mockRet); +extern void MockApl(ATokenAplEnum mockRet); +class AccessTokenHelperTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr stub_; +}; + +void AccessTokenHelperTest::SetUpTestCase() +{ +} + +void AccessTokenHelperTest::TearDownTestCase() +{ +} + +void AccessTokenHelperTest::SetUp() +{ + stub_ = std::make_shared(); +} + +void AccessTokenHelperTest::TearDown() +{ +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : VerifyCallerPermission_00100 + * @tc.desc : VerifyCallerPermission success + */ +HWTEST_F(AccessTokenHelperTest, VerifyCallerPermission_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + string permission; + EXPECT_TRUE(stub_->VerifyCallerPermission(tokenID, permission)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : VerifyNativeToken_00100 + * @tc.desc : VerifyNativeToken success + */ +HWTEST_F(AccessTokenHelperTest, VerifyNativeToken_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_TRUE(stub_->VerifyNativeToken(tokenID)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00100 + * @tc.desc : IsSystemHap Token Type TOKEN_NATIVE + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00100, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_TRUE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00200 + * @tc.desc : IsSystemHap Token Type TOKEN_HAP + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00200, Function | SmallTest | Level1) +{ + MockApl(ATokenAplEnum::APL_SYSTEM_CORE); + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + EXPECT_TRUE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00300 + * @tc.desc : IsSystemHap Token Type TOKEN_HAP + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00300, Function | SmallTest | Level1) +{ + MockApl(ATokenAplEnum::APL_NORMAL); + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + EXPECT_FALSE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsDlpHap_00100 + * @tc.desc : IsDlpHap Token Type TOKEN_HAP + */ +HWTEST_F(AccessTokenHelperTest, IsDlpHap_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + MockDlpType(DlpType::DLP_READ); + EXPECT_TRUE(stub_->IsDlpHap(tokenID)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsDlpHap_00200 + * @tc.desc : IsDlpHap Token Type TOKEN_NATIVE + */ +HWTEST_F(AccessTokenHelperTest, IsDlpHap_00200, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + MockDlpType(DlpType::DLP_COMMON); + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_FALSE(stub_->IsDlpHap(tokenID)); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp index fce488e4deb216ecf38d0bedb7b53cd15aace5ad..c15bcefa287e5e2aad119f9c02388b194244ef1f 100644 --- a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp @@ -15,7 +15,8 @@ #include #include - +#define private public +#define protected public #include "advanced_notification_service_ability.h" using namespace testing::ext; @@ -42,5 +43,33 @@ HWTEST_F( bool runOnCreate = true; AdvancedNotificationServiceAbility(systemAbilityId, runOnCreate); } + +/** + * @tc.number : AdvancedNotificationServiceAbilityTest_00200 + * @tc.name : ANS_AdvancedNotificationServiceAbility_0200 + * @tc.desc : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00200, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate); + test.OnStart(); +} + +/** + * @tc.number : AdvancedNotificationServiceAbilityTest_00300 + * @tc.name : ANS_AdvancedNotificationServiceAbility_0300 + * @tc.desc : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00300, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate); + test.OnStop(); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index e0aba8c89a6574cde5641594dbc436571b42198a..4fd77c09f2ffc472cdbbea85db11ba9a1980f44d 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -32,6 +32,10 @@ #include "notification_preferences.h" #include "notification_subscriber.h" #include "system_event_observer.h" +#include "notification_constant.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" +#include "want_params.h" using namespace testing::ext; using namespace OHOS::Media; @@ -56,24 +60,36 @@ sptr AdvancedNotificationServiceTest::advancedNotif void AdvancedNotificationServiceTest::SetUpTestCase() { + GTEST_LOG_(INFO) << "SetUpTestCase start"; advancedNotificationService_ = AdvancedNotificationService::GetInstance(); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + GTEST_LOG_(INFO) << "SetUpTestCase end"; } void AdvancedNotificationServiceTest::TearDownTestCase() { + GTEST_LOG_(INFO) << "TearDownTestCase start"; advancedNotificationService_ = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase end"; } void AdvancedNotificationServiceTest::SetUp() { + GTEST_LOG_(INFO) << "SetUp start"; + NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); advancedNotificationService_->CancelAll(); + + GTEST_LOG_(INFO) << "SetUp end"; } void AdvancedNotificationServiceTest::TearDown() -{} +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + GTEST_LOG_(INFO) << "TearDown"; +} inline void SleepForFC() { @@ -1744,7 +1760,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13000, /** * @tc.number : AdvancedNotificationServiceTest_13100 * @tc.name : ANS_RequestEnableNotification_0100 - * @tc.desc : Test RequestEnableNotification function when the result is ERR_ANS_INVALID_PARAM + * @tc.desc : Test whether to pop dialog * @tc.require : issueI5S4VP */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, Function | SmallTest | Level1) @@ -1753,7 +1769,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); std::string deviceId = "DeviceId"; - EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId), (int)ERR_ANS_INVALID_PARAM); + bool needPop = false; + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, needPop), (int)ERR_ANS_INVALID_PARAM); } /** @@ -1765,7 +1782,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13200, Function | SmallTest | Level1) { sptr reminder = nullptr; - EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), -1); + EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_REMINDER_PERMISSION_DENIED); } /** @@ -2091,5 +2108,1139 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); } + +/** + * @tc.number : AdvancedNotificationServiceTest_15700 + * @tc.name : PrepareNotificationRequest_0100 + * @tc.desc : Test PrepareNotificationRequest function when notification is agent. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test start"; + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + + req->SetContent(content); + req->SetIsAgentNotification(true); + EXPECT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_ANS_NON_SYSTEM_APP); + GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_15800 + * @tc.name : GenerateBundleOption_0100 + * @tc.desc : Test GenerateBundleOption function when bundle name is null. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + EXPECT_EQ(advancedNotificationService_->GenerateBundleOption(), nullptr); + GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16000 + * @tc.name : CancelPreparedNotification_1000 + * @tc.desc : Test CancelPreparedNotification function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start"; + + int32_t notificationId = 0; + std::string label = "testLabel"; + sptr bundleOption = nullptr; + EXPECT_EQ(advancedNotificationService_->CancelPreparedNotification(notificationId, label, bundleOption), + ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16100 + * @tc.name : PrepareNotificationInfo_1000 + * @tc.desc : Test PrepareNotificationInfo function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start"; + + sptr req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + req->SetCreatorUserId(DEFAULT_USER_ID); + req->SetIsAgentNotification(true); + advancedNotificationService_->Publish(label, req); + SleepForFC(); + + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end"; +} + + +/** + * @tc.number : AdvancedNotificationServiceTest_16200 + * @tc.name : ANS_CancelAsBundle_0200 + * @tc.desc : Test CancelAsBundle function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + int32_t notificationId = 1; + std::string representativeBundle = "RepresentativeBundle"; + int32_t userId = 1; + int result = ERR_ANS_NON_SYSTEM_APP; + EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result); + + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16300 + * @tc.name : ANS_CancelAsBundle_0300 + * @tc.desc : Test CancelAsBundle function when uid is less than 0. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + int32_t notificationId = 1; + std::string representativeBundle = "RepresentativeBundle"; + int32_t userId = 0; + int result = ERR_ANS_INVALID_UID; + EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result); + + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16400 + * @tc.name : ANS_AddSlots_0100 + * @tc.desc : Test AddSlots function whith not system app + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16600 + * @tc.name : ANS_AddSlots_0300 + * @tc.desc : Test AddSlots function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16700 + * @tc.name : ANS_AddSlots_0400 + * @tc.desc : Test AddSlots function with invalid bundle option + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test start"; + + std::vector> slots; + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16800 + * @tc.name : ANS_GetSlots_0100 + * @tc.desc : Test GetSlots function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->GetSlots(slots), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16900 + * @tc.name : ANS_GetActiveNotifications_0100 + * @tc.desc : Test function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + std::vector> notifications; + EXPECT_EQ(advancedNotificationService_->GetActiveNotifications(notifications), ERR_ANS_INVALID_BUNDLE); + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetActiveNotificationNums(num), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->SetNotificationBadgeNum(num), ERR_ANS_INVALID_BUNDLE); + int32_t importance = 2; + EXPECT_EQ(advancedNotificationService_->GetBundleImportance(importance), ERR_ANS_INVALID_BUNDLE); + bool allow = true; + EXPECT_EQ(advancedNotificationService_->SetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->GetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabled(allow), ERR_ANS_INVALID_BUNDLE); + + sptr slot = new NotificationSlot(NotificationConstant::OTHER); + EXPECT_EQ(advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->RemoveSlotByType(NotificationConstant::OTHER), ERR_ANS_INVALID_BUNDLE); + + std::string deviceId = "DeviceId"; + bool needPop = false; + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, needPop), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(needPop), ERR_ANS_INVALID_BUNDLE); + sptr bundleOption; + EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(bundleOption, needPop), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_ANS_INVALID_BUNDLE); + + int32_t reminderId = 1; + EXPECT_EQ(advancedNotificationService_->CancelReminder(reminderId), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->CancelAllReminders(), ERR_ANS_INVALID_BUNDLE); + + std::vector> reminders; + EXPECT_EQ(advancedNotificationService_->GetValidReminders(reminders), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->RemoveAllSlots(), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER), + ERR_ANS_INVALID_BUNDLE); + + std::string groupName = "name"; + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_BUNDLE); + + bool enabled = true; + EXPECT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17000 + * @tc.name : ANS_GetSetActiveNotifications_0100 + * @tc.desc : Test SetNotificationAgent and GetNotificationAgent function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + std::string agent = "agent"; + EXPECT_EQ(advancedNotificationService_->SetNotificationAgent(agent), ERR_INVALID_OPERATION); + EXPECT_EQ(advancedNotificationService_->GetNotificationAgent(agent), ERR_INVALID_OPERATION); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17100 + * @tc.name : ANS_GetSetActiveNotifications_0100 + * @tc.desc : Test function with NON_SYSTEM_APP_UID + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + std::string key = "key"; + int32_t removeReason = 0; + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + EXPECT_EQ(advancedNotificationService_->Delete(key, removeReason), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteByBundle(bundleOption), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_ANS_NON_SYSTEM_APP); + + bool enable = true; + EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + std::vector> notifications; + EXPECT_EQ(advancedNotificationService_->GetAllActiveNotifications(notifications), ERR_ANS_NON_SYSTEM_APP); + + std::vector keys; + EXPECT_EQ(advancedNotificationService_->GetSpecialActiveNotifications(keys, notifications), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForAllBundles(key, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( + std::string(), bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->IsAllowedNotify(enable), ERR_ANS_NON_SYSTEM_APP); + + int32_t notificationId = 1; + EXPECT_EQ(advancedNotificationService_->RemoveNotification(bundleOption, notificationId, + key, removeReason), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->RemoveAllNotifications(bundleOption), ERR_ANS_NON_SYSTEM_APP); + + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_ANS_NON_SYSTEM_APP); + + std::string groupName = "group"; + EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_NON_SYSTEM_APP); + + sptr date = nullptr; + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->EnableDistributed(enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), + ERR_ANS_NON_SYSTEM_APP); + + int32_t userId = 1; + EXPECT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption, + NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption, + NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17200 + * @tc.name : ANS_DeleteAll_0100 + * @tc.desc : Test DeleteAll function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK); + SleepForFC(); + req->SetCreatorUserId(SUBSCRIBE_USER_INIT); + std::shared_ptr notification = std::make_shared(req); + EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17300 + * @tc.name : ANS_GetSlotsByBundle_0100 + * @tc.desc : Test GetSlotsByBundle function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test start"; + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + + std::vector> slots; + EXPECT_EQ(advancedNotificationService_->GetSlotsByBundle( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->UpdateSlots( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots), + ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17400 + * @tc.name : Subscribe_1000 + * @tc.desc : Test Subscribe function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "Subscribe_1000 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "Subscribe_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17500 + * @tc.name : Unsubscribe_1000 + * @tc.desc : Test Subscribe function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "Unsubscribe_1000 test start"; + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "Unsubscribe_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17600 + * @tc.name : GetAppTargetBundle_1000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; + + sptr bundleOption = nullptr; + + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_OK); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17700 + * @tc.name : GetAppTargetBundle_2000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + sptr targetBundle = nullptr; + bundleOption->SetBundleName("test"); + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17800 + * @tc.name : GetAppTargetBundle_3000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + sptr targetBundle = nullptr; + bundleOption->SetBundleName("test"); + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_OK); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17900 + * @tc.name : PublishReminder_1000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; + + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + int32_t reminderId = 1; + sptr reminder = new ReminderRequest(reminderId); + reminder->InitNotificationRequest(); + EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_REMINDER_NOTIFICATION_NOT_ENABLE); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18000 + * @tc.name : PublishReminder_2000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; + + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + int32_t reminderId = 1; + sptr reminder = new ReminderRequest(reminderId); + reminder->InitNotificationRequest(); + EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18100 + * @tc.name : ActiveNotificationDump_1000 + * @tc.desc : Test ActiveNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18200 + * @tc.name : RecentNotificationDump_1000 + * @tc.desc : Test RecentNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->RecentNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18300 + * @tc.name : DistributedNotificationDump_1000 + * @tc.desc : Test DistributedNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18400 + * @tc.name : SetRecentNotificationCount_1000 + * @tc.desc : Test SetRecentNotificationCount function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test start"; + + std::string arg = "1100"; + EXPECT_EQ(advancedNotificationService_->SetRecentNotificationCount(arg), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18500 + * @tc.name : OnBundleRemoved_1000 + * @tc.desc : Test OnBundleRemoved function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->OnBundleRemoved(bundleOption); + + GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18600 + * @tc.name : OnScreenOn_1000 + * @tc.desc : Test OnScreenOn function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnScreenOn_1000 test start"; + + advancedNotificationService_->OnScreenOn(); + advancedNotificationService_->OnScreenOff(); + advancedNotificationService_->OnDistributedKvStoreDeathRecipient(); + + GTEST_LOG_(INFO) << "OnScreenOn_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18700 + * @tc.name : AddSlotByType_1000 + * @tc.desc : Test AddSlotByType function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "AddSlotByType_1000 test start"; + + EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::SERVICE_REMINDER), + ERR_OK); + + GTEST_LOG_(INFO) << "AddSlotByType_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18800 + * @tc.name : GetSlotNumAsBundle_1000 + * @tc.desc : Test GetSlotNumAsBundle function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_OK); + + GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18900 + * @tc.name : CancelGroup_1000 + * @tc.desc : Test CancelGroup function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelGroup_1000 test start"; + + std::string groupName = ""; + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "CancelGroup_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19000 + * @tc.name : RemoveGroupByBundle_1000 + * @tc.desc : Test RemoveGroupByBundle function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test start"; + + std::string groupName = "group"; + sptr bundleOption = nullptr; + EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19100 + * @tc.name : ANS_IsDistributedEnabled_0100 + * @tc.desc : Test IsDistributedEnabled function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test start"; + + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnabled(enabled), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19200 + * @tc.name : EnableDistributedByBundle_0100 + * @tc.desc : Test EnableDistributedByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19300 + * @tc.name : IsDistributedEnableByBundle_0100 + * @tc.desc : Test IsDistributedEnableByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = true; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19400 + * @tc.name : IsDistributedEnableByBundle_0200 + * @tc.desc : Test IsDistributedEnableByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19500 + * @tc.name : GetDeviceRemindType_0100 + * @tc.desc : Test GetDeviceRemindType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test start"; + + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_OK); + + GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19600 + * @tc.name : GetLocalNotificationKeys_0100 + * @tc.desc : Test GetLocalNotificationKeys function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->GetLocalNotificationKeys(bundleOption); + + GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19700 + * @tc.name : CheckDistributedNotificationType_0100 + * @tc.desc : Test CheckDistributedNotificationType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start"; + + sptr req = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19800 + * @tc.name : CheckDistributedNotificationType_0200 + * @tc.desc : Test CheckDistributedNotificationType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test start"; + + sptr req = new NotificationRequest(); + std::vector devices; + devices.push_back("a"); + devices.push_back("b"); + devices.push_back("c"); + req->GetNotificationDistributedOptions().SetDevicesSupportDisplay(devices); + EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19900 + * @tc.name : OnDistributedPublish_0100 + * @tc.desc : Test OnDistributedPublish function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + sptr request = new NotificationRequest(); + + advancedNotificationService_->OnDistributedPublish(deviceId, bundleName, request); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20000 + * @tc.name : OnDistributedUpdate_0100 + * @tc.desc : Test OnDistributedUpdate function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + sptr request = new NotificationRequest(); + + advancedNotificationService_->OnDistributedUpdate(deviceId, bundleName, request); + + GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20100 + * @tc.name : OnDistributedDelete_0100 + * @tc.desc : Test OnDistributedDelete function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + std::string label = "testLabel"; + int32_t id = 1; + + advancedNotificationService_->OnDistributedDelete(deviceId, bundleName, label, id); + + GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20200 + * @tc.name : CheckPublishWithoutApp_0100 + * @tc.desc : Test CheckPublishWithoutApp function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test start"; + + int32_t userId = 1; + sptr request = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false); + + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20300 + * @tc.name : CheckPublishWithoutApp_0200 + * @tc.desc : Test CheckPublishWithoutApp function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test start"; + + int32_t userId = SYSTEM_APP_UID; + sptr request = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false); + + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20400 + * @tc.name : TriggerRemoveWantAgent_0100 + * @tc.desc : Test TriggerRemoveWantAgent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test start"; + + sptr request = new NotificationRequest(); + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + + request->SetRemovalWantAgent(wantAgent); + advancedNotificationService_->TriggerRemoveWantAgent(request); + + GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20500 + * @tc.name : DeleteAllByUser_0100 + * @tc.desc : Test DeleteAllByUser function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test start"; + + int32_t userId = -2; + EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_INVALID_PARAM); + + sptr date = nullptr; + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDateByUser(userId, date), ERR_ANS_INVALID_PARAM); + GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20600 + * @tc.name : OnResourceRemove_0100 + * @tc.desc : Test OnResourceRemove function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnResourceRemove_0100 test start"; + + int32_t userId = -2; + advancedNotificationService_->OnResourceRemove(userId); + + GTEST_LOG_(INFO) << "OnResourceRemove_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20700 + * @tc.name : OnBundleDataCleared_0100 + * @tc.desc : Test OnBundleDataCleared function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->OnBundleDataCleared(bundleOption); + + GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20800 + * @tc.name : GetDisplayPosition_0100 + * @tc.desc : Test GetDisplayPosition function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test start"; + + int offsetX = 1; + int offsetY = 1; + int width = 1; + int height = 1; + bool wideScreen = 1; + advancedNotificationService_->GetDisplayPosition(offsetX, offsetY, width, height, wideScreen); + + GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20900 + * @tc.name : GetDumpInfo_0100 + * @tc.desc : Test GetDumpInfo function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDumpInfo_0100 test start"; + + std::vector args; + args.push_back(Str8ToStr16("args")); + std::string result = "result"; + advancedNotificationService_->GetDumpInfo(args, result); + + GTEST_LOG_(INFO) << "GetDumpInfo_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21000 + * @tc.name : GetDumpInfo_0200 + * @tc.desc : Test GetDumpInfo function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDumpInfo_0200 test start"; + + std::vector args; + args.push_back(Str8ToStr16("-h")); + std::string result = "result"; + advancedNotificationService_->GetDumpInfo(args, result); + + GTEST_LOG_(INFO) << "GetDumpInfo_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21100 + * @tc.name : SendFlowControlOccurHiSysEvent_0100 + * @tc.desc : Test SendFlowControlOccurHiSysEvent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test start"; + + std::shared_ptr record = nullptr; + advancedNotificationService_->SendFlowControlOccurHiSysEvent(record); + + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21200 + * @tc.name : SendFlowControlOccurHiSysEvent_0200 + * @tc.desc : Test SendFlowControlOccurHiSysEvent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test start"; + + std::shared_ptr record = std::make_shared(); + record->request = new NotificationRequest(); + record->bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->SendFlowControlOccurHiSysEvent(record); + + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test end"; +} + } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/ans_ut_constant.h b/services/ans/test/unittest/ans_ut_constant.h index 2e8a9b906e41865a65c23cf3691128f5326aaa8f..c13d7d004be69508b4876c7cac3dccb7d218b29e 100644 --- a/services/ans/test/unittest/ans_ut_constant.h +++ b/services/ans/test/unittest/ans_ut_constant.h @@ -27,6 +27,7 @@ constexpr int32_t SYSTEM_APP_UID = 100; constexpr int32_t NON_SYSTEM_APP_UID = 1000; constexpr int32_t NON_BUNDLE_NAME_UID = 2000; const std::string TEST_DEFUALT_BUNDLE = "bundleName"; +constexpr int32_t TEST_SUBSCRIBE_USER_INIT = -1; } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/bundle_manager_helper_test.cpp b/services/ans/test/unittest/bundle_manager_helper_test.cpp index 0e29e8528450a406075fa76bd90bb56c3d4098af..60bac7438bb4ce0e8e11ed1936b5bc52b61cdd5e 100644 --- a/services/ans/test/unittest/bundle_manager_helper_test.cpp +++ b/services/ans/test/unittest/bundle_manager_helper_test.cpp @@ -109,16 +109,18 @@ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00500, Level1) } /** - * @tc.number : AccessTokenHelperTest_00100 - * @tc.name : IsSystemHap - * @tc.desc : Test IsSystemHap function when the parameeter are normal + * @tc.number : GetDistributedNotificationEnabled_00100 + * @tc.name : GetDistributedNotificationEnabled + * @tc.desc : Test GetDistributedNotificationEnabled function when the parameeter are normal * @tc.require : issueI5S4VP */ -HWTEST_F(BundleManagerHelperTest, AccessTokenHelperTest_00100, Level1) +HWTEST_F(BundleManagerHelperTest, GetDistributedNotificationEnabled_00100, Level1) { - AccessTokenHelper accessTokenHelper; - bool result = accessTokenHelper.IsSystemHap(); - EXPECT_EQ(result, false); + std::string bundle = "Bundle"; + int32_t userId = 1; + BundleManagerHelper bundleManagerHelper; + bool result = bundleManagerHelper.GetDistributedNotificationEnabled(bundle, userId); + EXPECT_EQ(result, true); } } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/mock/blob.cpp b/services/ans/test/unittest/mock/blob.cpp index 540888d0f6f0bddd56e2f06b1af89b6658802a38..9acb0f99ddf2a48f540001de8bea5a3bd729e4fb 100644 --- a/services/ans/test/unittest/mock/blob.cpp +++ b/services/ans/test/unittest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { diff --git a/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..424907538c35ffd0d7a919a1def18cb1e0511669 --- /dev/null +++ b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp @@ -0,0 +1,68 @@ +/* + * 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 "accesstoken_kit.h" +#include "ans_log_wrapper.h" +#include "ans_ut_constant.h" +#include "ipc_skeleton.h" + +using namespace OHOS::Security::AccessToken; +namespace OHOS { +namespace Notification { +namespace { +ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID; +DlpType g_mockDlpType = DlpType::DLP_COMMON; +ATokenAplEnum g_mockApl = ATokenAplEnum::APL_NORMAL; +} + +void MockGetTokenTypeFlag(ATokenTypeEnum mockRet) +{ + g_mockGetTokenTypeFlagRet = mockRet; +} +void MockDlpType(DlpType mockRet) +{ + g_mockDlpType = mockRet; +} +void MockApl(ATokenAplEnum mockRet) +{ + g_mockApl = mockRet; +} +} +} +namespace OHOS { +namespace Security { +namespace AccessToken { +int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) +{ + if (tokenID == Notification::NON_NATIVE_TOKEN) { + return PERMISSION_DENIED; + } + return PERMISSION_GRANTED; +} + +ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) +{ + return Notification::g_mockGetTokenTypeFlagRet; +} + +int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& info) +{ + info.dlpType = Notification::g_mockDlpType; + info.apl = Notification::g_mockApl; + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp index fa0d3eb61358b4024540942ee05530f1f1b724ac..501bf9e10e714341be801df9b7bd77e372f5021a 100644 --- a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp +++ b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -38,12 +38,16 @@ std::string BundleManagerHelper::GetBundleNameByUid(int uid) int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) { - return NON_SYSTEM_APP_UID; + if (userId == 0) { + return -1; + } else { + return NON_SYSTEM_APP_UID; + } } bool BundleManagerHelper::IsSystemApp(int uid) { - return (uid == SYSTEM_APP_UID); + return (uid == SYSTEM_APP_UID || uid == NON_BUNDLE_NAME_UID); } bool BundleManagerHelper::CheckApiCompatibility(const sptr &bundleOption) diff --git a/services/ans/test/unittest/notification_preferences_database_test.cpp b/services/ans/test/unittest/notification_preferences_database_test.cpp index d0ac919380836dcc52c3468c74ffcfefb5178105..b5840c723530c774aa354f60dce575144d507492 100644 --- a/services/ans/test/unittest/notification_preferences_database_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_test.cpp @@ -489,5 +489,383 @@ HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbDate_00100, Func int32_t userId = 1; EXPECT_EQ(preferncesDB_->RemoveDoNotDisturbDate(userId), true); } + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00100 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_name"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00200 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_importance"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00300 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_showBadge"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00400 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_badgeTotalNum"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00500 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_privateAllowed"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00600 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_enabledNotification"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00700 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_poppedDialog"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00800 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_uid"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00100 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_id"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00200 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_name"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00300 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_description"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00400 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_level"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00500 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_showBadge"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00600 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableLight"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00700 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableVibration"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00800 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_ledLightColor"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00900 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00900, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_lockscreenVisibleness"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01000 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01000, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_sound"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01100 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_vibrationSytle"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01200 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableBypassDnd"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01300 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enabled"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index fed80303fd33f8cf851c240b1f0141a5533c4183..33bd1bcdd2325a11ce6823076573f439c1840b3d 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -17,7 +17,11 @@ #include "ans_inner_errors.h" #include "ans_ut_constant.h" +#define private public +#define protected public #include "notification_preferences.h" +#undef private +#undef protected using namespace testing::ext; namespace OHOS { @@ -127,6 +131,21 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | Sma EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK); } +/** + * @tc.number : AddNotificationSlots_00600 + * @tc.name : + * @tc.desc : Add a notification slot into distrube DB , return is ERR_OK. + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(nullptr, slots), (int)ERR_OK); +} + + + /** * @tc.number : RemoveNotificationSlot_00100 * @tc.name : @@ -180,6 +199,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00400, Function | S (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationSlot_00500 + * @tc.name : + * @tc.desc : Remove a notification slot from disturbe DB , return is ERR_OK + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER), + (int)ERR_OK); +} + /** * @tc.number : RemoveNotificationForBundle_00100 * @tc.name : @@ -215,6 +247,18 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00300, Functio (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationForBundle_00400 + * @tc.name : + * @tc.desc : Remove notification for bundle from disturbe DB when bundle name is null, return is + * ERR_ANS_INVALID_PARAM; + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : UpdateNotificationSlots_00100 * @tc.name : @@ -289,6 +333,20 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : UpdateNotificationSlots_00600 + * @tc.name : + * @tc.desc : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(nullptr, slots), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlot_00100 * @tc.name : @@ -347,6 +405,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | Smal (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : GetNotificationSlot_00500 + * @tc.name : + * @tc.desc : Update notification slot group into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | SmallTest | Level1) +{ + sptr slot; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER, slot), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationAllSlots_00100 * @tc.name : @@ -411,6 +483,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00400, Function | EXPECT_EQ((int)slotsResult.size(), 0); } +/** + * @tc.number : GetNotificationAllSlots_00500 + * @tc.name : + * @tc.desc : Get all notification slots from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00500, Function | SmallTest | Level1) +{ + std::vector> slotsResult; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(nullptr, slotsResult), + (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ((int)slotsResult.size(), 0); +} + /** * @tc.number : SetShowBadge_00100 * @tc.name : @@ -458,6 +544,18 @@ HWTEST_F(NotificationPreferencesTest, IsShowBadge_00200, Function | SmallTest | (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : IsShowBadge_00300 + * @tc.name : + * @tc.desc : Get bunlde show badge from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, IsShowBadge_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(nullptr, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetImportance_00100 * @tc.name : @@ -481,6 +579,18 @@ HWTEST_F(NotificationPreferencesTest, SetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetImportance_00300 + * @tc.name : + * @tc.desc : Set bundle importance into disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetImportance_00300, Function | SmallTest | Level1) +{ + int importance = 1; + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(nullptr, importance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetImportance_00100 * @tc.name : @@ -508,6 +618,18 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetImportance_00300 + * @tc.name : + * @tc.desc : Get bundle importance from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetImportance_00300, Function | SmallTest | Level1) +{ + int getImportance = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(nullptr, getImportance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetTotalBadgeNums_00100 * @tc.name : @@ -557,6 +679,18 @@ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallT (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetTotalBadgeNums_00300 + * @tc.name : + * @tc.desc : Get total badge nums from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00300, Function | SmallTest | Level1) +{ + int totalBadgeNum = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(nullptr, totalBadgeNum), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetPrivateNotificationsAllowed_00100 * @tc.name : @@ -580,6 +714,18 @@ HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Set private notification allowed badge nums into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetPrivateNotificationsAllowed(nullptr, true), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetPrivateNotificationsAllowed_00100 * @tc.name : @@ -608,6 +754,19 @@ HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Get private notification allowed badge nums from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + bool allow = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetPrivateNotificationsAllowed(nullptr, allow), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabledForBundle_00100 * @tc.name : @@ -631,12 +790,24 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00200, Fu (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Set notification enable for bundle into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(nullptr, false), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationsEnabledForBundle_00100 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB, return is ERR_OK. */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1) { EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleOption_, false), (int)ERR_OK); @@ -647,18 +818,31 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Fu } /** - * @tc.number : GetNotificationsEnabledForBundle_00100 + * @tc.number : GetNotificationsEnabledForBundle_00200 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB when bundle name is null, return is * ERR_ANS_INVALID_PARAM. */ -HWTEST_F(NotificationPreferencesTest, NotificationPreferencesTest_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1) { bool enabled = false; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleEmptyOption_, enabled), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Get notification enable for bundle from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + bool enabled = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(nullptr, enabled), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabled_00100 * @tc.name : @@ -670,7 +854,18 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00100, Function | } /** - * @tc.number : GetNotificationsEnabled + * @tc.number : SetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Set enable notification into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, true), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : GetNotificationsEnabled_00100 * @tc.name : * @tc.desc : Get enable notification from disturbe DB, return is ERR_OK */ @@ -682,6 +877,36 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | EXPECT_TRUE(enable); } +/** + * @tc.number : GetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Same user can get enable setting, different user can not get. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); + EXPECT_TRUE(enable); + + enable = false; + EXPECT_EQ( + (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); + EXPECT_FALSE(enable); +} + +/** + * @tc.number : GetNotificationsEnabled_00300 + * @tc.name : + * @tc.desc : Get enable notification from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetDoNotDisturbDate_00100 * @tc.name : @@ -701,6 +926,26 @@ HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK); } +/** + * @tc.number : SetDoNotDisturbDate_00200 + * @tc.name : + * @tc.desc : Set disturbe mode into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00200, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, date), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetDoNotDisturbDate_00100 * @tc.name : @@ -725,24 +970,6 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ(getDate->GetEndDate(), endDate); } -/** - * @tc.number : GetNotificationsEnabled_00200 - * @tc.name : - * @tc.desc : Same user can get enable setting, different user can not get. - */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) -{ - EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); - bool enable = false; - EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); - EXPECT_TRUE(enable); - - enable = false; - EXPECT_EQ( - (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); - EXPECT_FALSE(enable); -} - /** * @tc.number : GetDoNotDisturbDate_00200 * @tc.name : @@ -771,6 +998,18 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00200, Function | Smal NON_SYSTEM_APP_UID, getExsitDate), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetDoNotDisturbDate_00300 + * @tc.name : + * @tc.desc : Get disturbe mode from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00300, Function | SmallTest | Level1) +{ + sptr getDate; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, getDate), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetHasPoppedDialog_00100 * @tc.name : @@ -825,6 +1064,19 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00200, Funct (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : AddNotificationBundleProperty_00300 + * @tc.name : AddNotificationBundleProperty + * @tc.desc : Add a notification BundleProperty into distrube DB when bundlename is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : RemoveNotificationAllSlots_00100 * @tc.name : RemoveNotificationAllSlots @@ -851,6 +1103,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00200, Function (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : RemoveNotificationAllSlots_00300 + * @tc.name : RemoveNotificationAllSlots + * @tc.desc : Test RemoveNotificationAllSlots function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlotsNumForBundle_00100 * @tc.name : GetNotificationSlotsNumForBundle @@ -878,5 +1143,153 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00200, Fu EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundleEmptyOption_, num), (int)ERR_ANS_INVALID_PARAM); } + +/** + * @tc.number : GetNotificationSlotsNumForBundle_00300 + * @tc.name : GetNotificationSlotsNumForBundle + * @tc.desc : Test GetNotificationSlotsNumForBundle function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Function | SmallTest | Level1) +{ + uint64_t num = 2; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(nullptr, num), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00100 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00200 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function, return ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00100 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00200 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function, return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00300 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00100 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00200 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when bundle not existed, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00300 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is different type, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00400 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function after add notification slot, return is ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_slot_filter_test.cpp b/services/ans/test/unittest/notification_slot_filter_test.cpp index 90e5730dce3032169e07761c9ab0f090b67776e8..f08f6978a91cf099ce6fcc82d342f3b9f885d76f 100644 --- a/services/ans/test/unittest/notification_slot_filter_test.cpp +++ b/services/ans/test/unittest/notification_slot_filter_test.cpp @@ -21,6 +21,7 @@ #include "notification_slot.h" #undef private #undef protected +#include "ans_inner_errors.h" #include "notification_slot_filter.h" #include "notification_subscribe_info.h" @@ -77,6 +78,20 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00200, Function * @tc.desc : Test OnPublish function */ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00300, Function | SmallTest | Level1) +{ + NotificationSlotFilter notificationSlotFilter; + std::shared_ptr record = std::make_shared(); + ErrCode result = notificationSlotFilter.OnPublish(record); + EXPECT_EQ(result, ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST); +} + + +/** + * @tc.number : NotificationSlotFilterTest_00400 + * @tc.name : ANS_OnPublish_0200 + * @tc.desc : Test OnPublish function + */ +HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00400, Function | SmallTest | Level1) { NotificationSlotFilter notificationSlotFilter; std::shared_ptr record = std::make_shared(); diff --git a/services/ans/test/unittest/system_event_observer_test.cpp b/services/ans/test/unittest/system_event_observer_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b0baeda394e4e58de65e9c8ac489a3740051e60 --- /dev/null +++ b/services/ans/test/unittest/system_event_observer_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 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 + +#define private public +#define protected public +#include "system_event_observer.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "common_event_support.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class SystemEventObserverTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr stub_; +}; + +void SystemEventObserverTest::SetUpTestCase() +{ +} + +void SystemEventObserverTest::TearDownTestCase() +{ +} + +void SystemEventObserverTest::SetUp() +{ + ISystemEvent iSystemEvent; + stub_ = std::make_shared(iSystemEvent); +} + +void SystemEventObserverTest::TearDown() +{ +} + +/** + * @tc.number : OnReceiveEvent_001 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_001, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED)); + + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_002 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_002, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED)); + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_003 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_003, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_004 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_004, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED)); + stub_->OnReceiveEvent(data); +} + +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/distributed/test/unittest/distributed_notification_manager_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_test.cpp index 5328d77126b3650568a78aebd87f75b59dc72eeb..2e5416ad9d66016ecb853a67e7a7bb1110138be4 100644 --- a/services/distributed/test/unittest/distributed_notification_manager_test.cpp +++ b/services/distributed/test/unittest/distributed_notification_manager_test.cpp @@ -266,7 +266,8 @@ HWTEST_F(DistributedNotificationManagerTest, Distributed_DeleteCallback_00100, F * @tc.number : Distributed_OnDistributedKvStoreDeathRecipient_00100 * @tc.desc : text OnDistributedKvStoreDeathRecipient function. */ -HWTEST_F(DistributedNotificationManagerTest, Distributed_OnDistributedKvStoreDeathRecipient_00100, Function | SmallTest | Level1) +HWTEST_F(DistributedNotificationManagerTest, Distributed_OnDistributedKvStoreDeathRecipient_00100, + Function | SmallTest | Level1) { EXPECT_EQ(distributedManager_->OnDistributedKvStoreDeathRecipient(), ERR_OK); } diff --git a/services/distributed/test/unittest/mock/mock_blob.cpp b/services/distributed/test/unittest/mock/mock_blob.cpp index d55add0bd2799e9014613be509014c0b60be6dae..490a6675829d9bd1909c0bc3d3f3abef52de68b1 100644 --- a/services/distributed/test/unittest/mock/mock_blob.cpp +++ b/services/distributed/test/unittest/mock/mock_blob.cpp @@ -90,18 +90,5 @@ std::string Blob::ToString() const return str; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} } // namespace DistributedKv } // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index f61ff50735b1250f9440a29e772e7ff540629780..553b20c74e3434d4db758afc224ec67edd56e199 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -84,9 +84,10 @@ ohos_moduletest("ans_module_test") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] if (device_usage) { diff --git a/services/test/moduletest/mock/blob.cpp b/services/test/moduletest/mock/blob.cpp index 540888d0f6f0bddd56e2f06b1af89b6658802a38..9acb0f99ddf2a48f540001de8bea5a3bd729e4fb 100644 --- a/services/test/moduletest/mock/blob.cpp +++ b/services/test/moduletest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d6e02cf41a0273d34b723e517471b88edcce209b..2871d134dc9f04596590ee32247be655e09451db 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,23 +18,78 @@ group("fuzztest") { "addnotificationslot_fuzzer:AddNotificationSlotFuzzTest", "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", + "anscallbackstub_fuzzer:AnsCallbackStubFuzzTest", + "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", + "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", + "ansmanagerstubannexthree_fuzzer:AnsManagerStubAnnexThreeFuzzTest", + "ansmanagerstubannextwo_fuzzer:AnsManagerStubAnnexTwoFuzzTest", + "anssubscriberproxy_fuzzer:AnsSubscriberProxyFuzzTest", + "anssubscriberstub_fuzzer:AnsSubscriberStubFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", "enabledistributed_fuzzer:EnableDistributedFuzzTest", + "enablednotificationcallbackdata_fuzzer:EnabledNotificationCallbackDataFuzzTest", "getactivenotificationnums_fuzzer:GetActiveNotificationNumsFuzzTest", "getallactivenotifications_fuzzer:GetAllActiveNotificationsFuzzTest", "getbundleimportance_fuzzer:GetBundleImportanceFuzzTest", "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "messageuser_fuzzer:MessageUserFuzzTest", + "notification_fuzzer:NotificationFuzzTest", + "notificationactionbutton_fuzzer:NotificationActionButtonFuzzTest", + "notificationannex_fuzzer:NotificationAnnexFuzzTest", + "notificationbasiccontent_fuzzer:NotificationBasicContentFuzzTest", + "notificationbundleoption_fuzzer:NotificationBundleOptionFuzzTest", + "notificationcontent_fuzzer:NotificationContentFuzzTest", + "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", + "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationconversationalmessageannex_fuzzer:NotificationConversationalMessageAnnexFuzzTest", + "notificationdistributedoptions_fuzzer:NotificationDistributedOptionsFuzzTest", + "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", + "notificationflags_fuzzer:NotificationFlagsFuzzTest", + "notificationhelper_fuzzer:NotificationHelperFuzzTest", + "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", + "notificationlongtextcontentannex_fuzzer:NotificationLongTextContentAnnexFuzzTest", + "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", + "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", + "notificationmultilinecontentannex_fuzzer:NotificationMultiLineContentAnnexFuzzTest", + "notificationnormalcontent_fuzzer:NotificationNormalContentFuzzTest", + "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", + "notificationpicturecontentannex_fuzzer:NotificationPictureContentAnnexFuzzTest", + "notificationrequest_fuzzer:NotificationRequestFuzzTest", + "notificationrequestannex_fuzzer:NotificationRequestAnnexFuzzTest", + "notificationslot_fuzzer:NotificationSlotFuzzTest", + "notificationsorting_fuzzer:NotificationSortingFuzzTest", + "notificationsortingannex_fuzzer:NotificationSortingAnnexFuzzTest", + "notificationsortingmap_fuzzer:NotificationSortingMapFuzzTest", + "notificationsortingmapannex_fuzzer:NotificationSortingMapAnnexFuzzTest", + "notificationsubscribeInfo_fuzzer:NotificationSubscribeInfoFuzzTest", + "notificationtemplate_fuzzer:NotificationTemplateFuzzTest", + "notificationtemplateannex_fuzzer:NotificationTemplateAnnexFuzzTest", + "notificationuserinput_fuzzer:NotificationUserInputFuzzTest", + "notificationuserinputannex_fuzzer:NotificationUserInputAnnexFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", + "readfromparcel_fuzzer:ReadFromParcelFuzzTest", + "reminderhelper_fuzzer:ReminderHelperFuzzTest", + "reminderrequest_fuzzer:ReminderRequestFuzzTest", + "reminderrequestalarm_fuzzer:ReminderRequestAlarmFuzzTest", + "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestannexthree_fuzzer:ReminderRequestAnnexThreeFuzzTest", + "reminderrequestcalendar_fuzzer:ReminderRequestCalendarFuzzTest", + "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", + "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", + "reminderstore_fuzzer:ReminderStoreFuzzTest", + "reminderstoreannex_fuzzer:ReminderStoreAnnexFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", "setdonotdisturbdate_fuzzer:SetDoNotDisturbDateFuzzTest", "setnotificationbadgenum_fuzzer:SetNotificationBadgeNumFuzzTest", "setnotificationsenabledforallbundles_fuzzer:SetNotificationsEnabledForAllBundlesFuzzTest", + "setprogressbar_fuzzer:SetProgressBarFuzzTest", + "settemplate_fuzzer:SetTemplateFuzzTest", ] } diff --git a/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp b/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp index d107c934b9d772a73cac3b13524c020a52988195..65029144d8db551c6cb214e6b9138e3c98237f77 100644 --- a/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp +++ b/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp @@ -57,7 +57,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn b/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f83638039abd45dc17c81d3e5a9e910fedf405ed --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsCallbackStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anscallbackstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anscallbackstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsCallbackStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17d19877d640174603ae57ffd9fa78d0df9ae9f5 --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_callback_stub.h" +#undef private +#undef protected +#include "anscallbackstub_fuzzer.h" +#include "notification_request.h" + +using namespace OHOS::Notification; + +namespace OHOS { +class AnsCallbackStubImpl : public AnsCallbackStub { + bool OnEnableNotification(bool isAllow) override + { + return false; + } +}; + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + std::string stringData(data); + std::shared_ptr ansCallbackStub = + std::make_shared(); + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test OnRemoteRequest function + ansCallbackStub->OnRemoteRequest(code, datas, reply, flags); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1acf06ab4814bc17581da53b813716d0d778fa5c --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anscallbackstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/corpus/init b/test/fuzztest/anscallbackstub_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/project.xml b/test/fuzztest/anscallbackstub_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a4671ff43964c744d67ab139e30aef5a2e407d6b --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/ansmanagerstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ab8b4bbd83ec970111d815eae39d5c4addb1d221 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -0,0 +1,234 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstub_fuzzer.h" +#include "notification_request.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::AnsManagerStub ansManagerStub; + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + ansManagerStub.OnRemoteRequest(code, datas, reply, flags); + ansManagerStub.HandlePublish(datas, reply); + ansManagerStub.HandlePublishToDevice(datas, reply); + ansManagerStub.HandleCancel(datas, reply); + ansManagerStub.HandleCancelAll(datas, reply); + ansManagerStub.HandleCancelAsBundle(datas, reply); + ansManagerStub.HandleAddSlotByType(datas, reply); + ansManagerStub.HandleAddSlots(datas, reply); + ansManagerStub.HandleRemoveSlotByType(datas, reply); + ansManagerStub.HandleRemoveAllSlots(datas, reply); + ansManagerStub.HandleGetSlots(datas, reply); + ansManagerStub.HandleGetSlotByType(datas, reply); + ansManagerStub.HandleGetSlotNumAsBundle(datas, reply); + ansManagerStub.HandleGetActiveNotifications(datas, reply); + ansManagerStub.HandleGetActiveNotificationNums(datas, reply); + ansManagerStub.HandleGetAllActiveNotifications(datas, reply); + ansManagerStub.HandleGetSpecialActiveNotifications(datas, reply); + ansManagerStub.HandleSetNotificationAgent(datas, reply); + ansManagerStub.HandleGetNotificationAgent(datas, reply); + ansManagerStub.HandleCanPublishAsBundle(datas, reply); + ansManagerStub.HandlePublishAsBundle(datas, reply); + ansManagerStub.HandleSetNotificationBadgeNum(datas, reply); + ansManagerStub.HandleGetBundleImportance(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDate(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDate(datas, reply); + ansManagerStub.HandleDoesSupportDoNotDisturbMode(datas, reply); + ansManagerStub.HandlePublishContinuousTaskNotification(datas, reply); + ansManagerStub.HandleCancelContinuousTaskNotification(datas, reply); + ansManagerStub.HandleIsNotificationPolicyAccessGranted(datas, reply); + ansManagerStub.HandleSetPrivateNotificationsAllowed(datas, reply); + ansManagerStub.HandleGetPrivateNotificationsAllowed(datas, reply); + ansManagerStub.HandleRemoveNotification(datas, reply); + ansManagerStub.HandleRemoveAllNotifications(datas, reply); + ansManagerStub.HandleDelete(datas, reply); + ansManagerStub.HandleDeleteByBundle(datas, reply); + ansManagerStub.HandleDeleteAll(datas, reply); + ansManagerStub.HandleGetSlotsByBundle(datas, reply); + ansManagerStub.HandleUpdateSlots(datas, reply); + ansManagerStub.HandleRequestEnableNotification(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForBundle(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForAllBundles(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForSpecialBundle(datas, reply); + ansManagerStub.HandleSetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); + ansManagerStub.HandleSubscribe(datas, reply); + ansManagerStub.HandleUnsubscribe(datas, reply); + ansManagerStub.HandleAreNotificationsSuspended(datas, reply); + ansManagerStub.HandleGetCurrentAppSorting(datas, reply); + ansManagerStub.HandleIsAllowedNotify(datas, reply); + ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); + ansManagerStub.HandleIsSpecialBundleAllowedNotify(datas, reply); + ansManagerStub.HandleCancelGroup(datas, reply); + ansManagerStub.HandleRemoveGroupByBundle(datas, reply); + ansManagerStub.HandleIsDistributedEnabled(datas, reply); + ansManagerStub.HandleEnableDistributed(datas, reply); + ansManagerStub.HandleEnableDistributedByBundle(datas, reply); + ansManagerStub.HandleEnableDistributedSelf(datas, reply); + ansManagerStub.HandleIsDistributedEnableByBundle(datas, reply); + ansManagerStub.HandleGetDeviceRemindType(datas, reply); + ansManagerStub.HandleShellDump(datas, reply); + ansManagerStub.HandlePublishReminder(datas, reply); + ansManagerStub.HandleCancelReminder(datas, reply); + ansManagerStub.HandleCancelAllReminders(datas, reply); + ansManagerStub.HandleGetValidReminders(datas, reply); + ansManagerStub.HandleIsSupportTemplate(datas, reply); + ansManagerStub.HandleIsSpecialUserAllowedNotifyByUser(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledByUser(datas, reply); + ansManagerStub.HandleDeleteAllByUser(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleSetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply); + ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply); + sptr notification = new Notification::NotificationRequest(); + const std::string label = "this is a notification label"; + ansManagerStub.Publish(label, notification); + const std::string deviceId = "this is a notification deviceId"; + ansManagerStub.PublishToDevice(notification, deviceId); + int notificationId = 1; + ansManagerStub.Cancel(notificationId, label); + ansManagerStub.CancelAll(); + const std::string representativeBundle = "this is a notification representativeBundle"; + int32_t userId = 1; + ansManagerStub.CancelAsBundle(notificationId, representativeBundle, userId); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + ansManagerStub.AddSlotByType(slotType); + std::vector> slots; + ansManagerStub.AddSlots(slots); + ansManagerStub.RemoveSlotByType(slotType); + ansManagerStub.RemoveAllSlots(); + sptr slot = new Notification::NotificationSlot(); + ansManagerStub.GetSlotByType(slotType, slot); + ansManagerStub.GetSlots(slots); + sptr bundleOption = new Notification::NotificationBundleOption(); + uint64_t num = 1; + ansManagerStub.GetSlotNumAsBundle(bundleOption, num); + std::vector> notifications; + ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotificationNums(num); + std::vector> notificationss; + ansManagerStub.GetAllActiveNotifications(notificationss); + std::vector key; + ansManagerStub.GetSpecialActiveNotifications(key, notificationss); + std::string agent = "this is a notification agent"; + ansManagerStub.SetNotificationAgent(agent); + ansManagerStub.GetNotificationAgent(agent); + bool canPublish = true; + ansManagerStub.CanPublishAsBundle(representativeBundle, canPublish); + ansManagerStub.PublishAsBundle(notification, representativeBundle); + ansManagerStub.SetNotificationBadgeNum(num); + int importance = 1; + ansManagerStub.GetBundleImportance(importance); + bool granted = true; + ansManagerStub.HasNotificationPolicyAccessPermission(granted); + bool allow = true; + ansManagerStub.SetPrivateNotificationsAllowed(allow); + int32_t removeReason = 1; + ansManagerStub.RemoveNotification(bundleOption, notificationId, label, removeReason); + ansManagerStub.RemoveAllNotifications(bundleOption); + const std::string keys = "this is a notification keys"; + ansManagerStub.Delete(keys, removeReason); + ansManagerStub.DeleteByBundle(bundleOption); + ansManagerStub.DeleteAll(); + ansManagerStub.GetSlotsByBundle(bundleOption, slots); + ansManagerStub.UpdateSlots(bundleOption, slots); + bool popFlag = true; + ansManagerStub.RequestEnableNotification(deviceId, popFlag); + const std::string bundle = "this is a notification bundle"; + bool enabled = true; + ansManagerStub.SetNotificationsEnabledForBundle(bundle, enabled); + ansManagerStub.SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, enabled); + ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, enabled); + ansManagerStub.GetShowBadgeEnabled(enabled); + bool suspended = true; + ansManagerStub.AreNotificationsSuspended(suspended); + sptr sortingMap = new Notification::NotificationSortingMap(); + ansManagerStub.GetCurrentAppSorting(sortingMap); + bool allowed = true; + ansManagerStub.IsAllowedNotify(allowed); + ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allowed); + const std::string groupName = "this is a notification groupName"; + ansManagerStub.CancelGroup(groupName); + ansManagerStub.RemoveGroupByBundle(bundleOption, groupName); + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansManagerStub.SetDoNotDisturbDate(date); + ansManagerStub.GetDoNotDisturbDate(date); + bool doesSupport = true; + ansManagerStub.DoesSupportDoNotDisturbMode(doesSupport); + ansManagerStub.IsDistributedEnabled(enabled); + ansManagerStub.EnableDistributedByBundle(bundleOption, enabled); + ansManagerStub.EnableDistributedSelf(enabled); + ansManagerStub.IsDistributedEnableByBundle(bundleOption, enabled); + Notification::NotificationConstant::RemindType remindType; + ansManagerStub.GetDeviceRemindType(remindType); + sptr request = new Notification::NotificationRequest(); + ansManagerStub.PublishContinuousTaskNotification(request); + ansManagerStub.CancelContinuousTaskNotification(label, notificationId); + sptr reminder = new Notification::ReminderRequest(); + ansManagerStub.PublishReminder(reminder); + const int32_t reminderId = 1; + ansManagerStub.CancelReminder(reminderId); + std::vector> reminders; + ansManagerStub.GetValidReminders(reminders); + ansManagerStub.CancelAllReminders(); + const std::string templateName = "this is a notification templateName"; + bool support = true; + ansManagerStub.IsSupportTemplate(templateName, support); + ansManagerStub.IsSpecialUserAllowedNotify(userId, allowed); + const int32_t deviceIds = 1; + ansManagerStub.SetNotificationsEnabledByUser(deviceIds, enabled); + ansManagerStub.DeleteAllByUser(userId); + ansManagerStub.SetDoNotDisturbDate(date); + ansManagerStub.GetDoNotDisturbDate(date); + ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ansManagerStub.GetEnabledForBundleSlot(bundleOption, slotType, enabled); + const std::string cmd = "this is a notification cmd"; + std::vector dumpInfo; + ansManagerStub.ShellDump(cmd, bundle, userId, dumpInfo); + ansManagerStub.SetSyncNotificationEnabledWithoutApp(userId, enabled); + ansManagerStub.GetSyncNotificationEnabledWithoutApp(userId, enabled); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a6a9b4924d33ab16ac6696df91297b1ab0b8ea58 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstub_fuzzer/corpus/init b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstub_fuzzer/project.xml b/test/fuzztest/ansmanagerstub_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7f8a8e82fb439c6c0022197da77641d215742e0a --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de16b4132f29332f9628dd6665d7cddf3ef1fc25 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + MessageParcel datas; + MessageParcel reply; + ansManagerStub.HandleDelete(datas, reply); + ansManagerStub.HandleDeleteByBundle(datas, reply); + ansManagerStub.HandleDeleteAll(datas, reply); + ansManagerStub.HandleGetSlotsByBundle(datas, reply); + ansManagerStub.HandleUpdateSlots(datas, reply); + ansManagerStub.HandleRequestEnableNotification(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForBundle(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForAllBundles(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForSpecialBundle(datas, reply); + ansManagerStub.HandleSetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); + ansManagerStub.HandleSubscribe(datas, reply); + ansManagerStub.HandleUnsubscribe(datas, reply); + ansManagerStub.HandleAreNotificationsSuspended(datas, reply); + ansManagerStub.HandleGetCurrentAppSorting(datas, reply); + ansManagerStub.HandleIsAllowedNotify(datas, reply); + ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); + ansManagerStub.HandleIsSpecialBundleAllowedNotify(datas, reply); + ansManagerStub.HandleCancelGroup(datas, reply); + ansManagerStub.HandleRemoveGroupByBundle(datas, reply); + ansManagerStub.HandleIsDistributedEnabled(datas, reply); + ansManagerStub.HandleEnableDistributed(datas, reply); + ansManagerStub.HandleEnableDistributedByBundle(datas, reply); + ansManagerStub.HandleEnableDistributedSelf(datas, reply); + ansManagerStub.HandleIsDistributedEnableByBundle(datas, reply); + ansManagerStub.HandleGetDeviceRemindType(datas, reply); + ansManagerStub.HandleShellDump(datas, reply); + ansManagerStub.HandlePublishReminder(datas, reply); + ansManagerStub.HandleCancelReminder(datas, reply); + ansManagerStub.HandleCancelAllReminders(datas, reply); + ansManagerStub.HandleGetValidReminders(datas, reply); + ansManagerStub.HandleIsSupportTemplate(datas, reply); + ansManagerStub.HandleIsSpecialUserAllowedNotifyByUser(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledByUser(datas, reply); + ansManagerStub.HandleDeleteAllByUser(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDateByUser(datas, reply); + return ansManagerStub.HandleSetEnabledForBundleSlot(datas, reply); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..330d8b85b4bec8f4d53cf290532384071b96e162 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannex_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..69d0849c61e8b011eb7cb012d3f28d33a0757269 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexThreeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannexthree_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannexthree_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexThreeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8fa6cd0f35dc869d36798b9eac7991f622ccf33 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannexthree_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + bool allow = *data % ENABLE; + ansManagerStub.GetPrivateNotificationsAllowed(allow); + sptr bundleOption = new Notification::NotificationBundleOption(); + int notificationId = 1; + std::string stringData(data); + int32_t removeReason = static_cast(GetU32Data(data)); + ansManagerStub.RemoveNotification(bundleOption, notificationId, stringData, removeReason); + ansManagerStub.RemoveAllNotifications(bundleOption); + ansManagerStub.Delete(stringData, removeReason); + ansManagerStub.DeleteByBundle(bundleOption); + ansManagerStub.DeleteAll(); + sptr slot = new Notification::NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + ansManagerStub.GetSlotsByBundle(bundleOption, slots); + ansManagerStub.SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, allow); + ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, allow); + ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, allow); + ansManagerStub.GetShowBadgeEnabled(allow); + ansManagerStub.AreNotificationsSuspended(allow); + sptr sortingMap = new Notification::NotificationSortingMap(); + ansManagerStub.GetCurrentAppSorting(sortingMap); + ansManagerStub.IsAllowedNotify(allow); + ansManagerStub.IsAllowedNotifySelf(allow); + ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allow); + ansManagerStub.CancelGroup(stringData); + ansManagerStub.RemoveGroupByBundle(bundleOption, stringData); + ansManagerStub.DoesSupportDoNotDisturbMode(allow); + ansManagerStub.IsDistributedEnabled(allow); + ansManagerStub.EnableDistributed(allow); + ansManagerStub.EnableDistributedByBundle(bundleOption, allow); + ansManagerStub.EnableDistributedSelf(allow); + ansManagerStub.IsDistributedEnableByBundle(bundleOption, allow); + int32_t remindType = static_cast(*data % SLOT_TYPE_NUM); + Notification::NotificationConstant::RemindType remind = + Notification::NotificationConstant::RemindType(remindType); + ansManagerStub.GetDeviceRemindType(remind); + sptr request = new Notification::NotificationRequest(); + ansManagerStub.PublishContinuousTaskNotification(request); + ansManagerStub.CancelContinuousTaskNotification(stringData, removeReason); + ansManagerStub.CancelReminder(removeReason); + return ansManagerStub.CancelAllReminders(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ec514818a31fc21b568147d7d47d9d07f86c6942 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannexthree_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ab0e817f3dc5b515cf81afa584cafe4a8e938a8e --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexTwoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannextwo_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannextwo_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexTwoFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e310e1843609586b6d13a5445319ca08e1b9eb57 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp @@ -0,0 +1,95 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannextwo_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + MessageParcel datas; + MessageParcel reply; + ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply); + ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply); + std::string stringData(data); + sptr notification = new Notification::NotificationRequest(); + ansManagerStub.Publish(stringData, notification); + ansManagerStub.PublishToDevice(notification, stringData); + int notificationId = 1; + ansManagerStub.Cancel(notificationId, stringData); + ansManagerStub.CancelAll(); + int32_t notificationIds = static_cast(GetU32Data(data)); + int32_t userId = static_cast(GetU32Data(data)); + ansManagerStub.CancelAsBundle(notificationIds, stringData, userId); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + ansManagerStub.AddSlotByType(slotType); + sptr slot = new Notification::NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + ansManagerStub.AddSlots(slots); + ansManagerStub.RemoveSlotByType(slotType); + ansManagerStub.RemoveAllSlots(); + ansManagerStub.GetSlotByType(slotType, slot); + ansManagerStub.GetSlots(slots); + sptr bundleOption = new Notification::NotificationBundleOption(); + uint64_t num = 1; + ansManagerStub.GetSlotNumAsBundle(bundleOption, num); + sptr notificationer = new Notification::NotificationRequest(); + std::vector> notifications; + notifications.emplace_back(notificationer); + ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotificationNums(num); + sptr notificatione = new Notification::Notification(); + std::vector> notificationes; + notificationes.emplace_back(notificatione); + ansManagerStub.GetAllActiveNotifications(notificationes); + std::vector key; + key.emplace_back(stringData); + ansManagerStub.GetSpecialActiveNotifications(key, notificationes); + ansManagerStub.SetNotificationAgent(stringData); + ansManagerStub.GetNotificationAgent(stringData); + bool canPublish = *data % ENABLE; + ansManagerStub.CanPublishAsBundle(stringData, canPublish); + ansManagerStub.PublishAsBundle(notificationer, stringData); + ansManagerStub.SetNotificationBadgeNum(notificationId); + ansManagerStub.GetBundleImportance(notificationId); + ansManagerStub.HasNotificationPolicyAccessPermission(canPublish); + return ansManagerStub.SetPrivateNotificationsAllowed(canPublish); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5302226367564e411522410e9d289ab37cdab0ac --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannextwo_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn b/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d2ddb41dc3a565f8e5f926559adac6a95b4ee9c4 --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsSubscriberProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anssubscriberproxy_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anssubscriberproxy_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsSubscriberProxyFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85ee11544080bc783c829c08c3c9bf665fdccedc --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_subscriber_proxy.h" +#undef private +#undef protected +#include "anssubscriberproxy_fuzzer.h" +#include "notification_request.h" +#include "notification_subscriber.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr impl; + Notification::AnsSubscriberProxy ansSubscriberProxy(impl); + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test InnerTransact function + ansSubscriberProxy.InnerTransact(code, flags, datas, reply); + // test InnerTransact function + ansSubscriberProxy.OnConnected(); + // test InnerTransact function + ansSubscriberProxy.OnDisconnected(); + // test InnerTransact function + sptr notification = new Notification::Notification(); + ansSubscriberProxy.OnConsumed(notification); + // test InnerTransact function + sptr notificationMap = new Notification::NotificationSortingMap(); + ansSubscriberProxy.OnConsumed(notification, notificationMap); + // test OnCanceled function + ansSubscriberProxy.OnCanceled(notification); + // test OnCanceled function + int32_t deleteReason = 1; + ansSubscriberProxy.OnCanceled(notification, notificationMap, deleteReason); + // test OnCanceled function + ansSubscriberProxy.OnUpdated(notificationMap); + // test OnCanceled function + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansSubscriberProxy.OnDoNotDisturbDateChange(date); + // test OnEnabledNotificationChanged function + sptr callbackData = new Notification::EnabledNotificationCallbackData(); + ansSubscriberProxy.OnEnabledNotificationChanged(callbackData); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0cdd0af1241914f75392a0e5645b2dfe29784074 --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H +#define TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anssubscriberproxy_fuzzer" + +#endif // TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init b/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/project.xml b/test/fuzztest/anssubscriberproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn b/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2d73d3f0534f63c7f84e38a25029fd58735bd3a2 --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsSubscriberStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anssubscriberstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anssubscriberstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsSubscriberStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..25e72818e1ebb6ea6f8fe2dc5bb0bed49458d55c --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp @@ -0,0 +1,90 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "ans_subscriber_stub.h" +#undef private +#undef protected +#include "anssubscriberstub_fuzzer.h" +#include "notification_request.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::AnsSubscriberStub ansSubscriberStub; + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test OnRemoteRequest function + ansSubscriberStub.OnRemoteRequest(code, datas, reply, flags); + // test HandleOnConnected function + ansSubscriberStub.HandleOnConnected(datas, reply); + // test HandleOnDisconnected function + ansSubscriberStub.HandleOnDisconnected(datas, reply); + // test HandleOnConsumed function + ansSubscriberStub.HandleOnConsumed(datas, reply); + // test HandleOnConsumedMap function + ansSubscriberStub.HandleOnConsumedMap(datas, reply); + // test HandleOnCanceled function + ansSubscriberStub.HandleOnCanceled(datas, reply); + // test HandleOnCanceledMap function + ansSubscriberStub.HandleOnCanceledMap(datas, reply); + // test HandleOnUpdated function + ansSubscriberStub.HandleOnUpdated(datas, reply); + // test HandleOnDoNotDisturbDateChange function + ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply); + // test HandleOnEnabledNotificationChanged function + ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply); + // test OnConnected function + ansSubscriberStub.OnConnected(); + // test OnDisconnected function + ansSubscriberStub.OnDisconnected(); + // test OnConsumed function + sptr notification = new Notification::Notification(); + ansSubscriberStub.OnConsumed(notification); + // test OnConsumed function + sptr notificationMap = new Notification::NotificationSortingMap(); + ansSubscriberStub.OnConsumed(notification, notificationMap); + // test OnCanceled function + ansSubscriberStub.OnCanceled(notification); + // test OnCanceled function + int32_t deleteReason = 1; + ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason); + // test OnUpdated function + ansSubscriberStub.OnUpdated(notificationMap); + // test OnDoNotDisturbDateChange function + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansSubscriberStub.OnDoNotDisturbDateChange(date); + // test OnEnabledNotificationChanged function + sptr callbackData = new Notification::EnabledNotificationCallbackData(); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ec87efa9b8a624fe9aa563fb2b8521a5abc38af7 --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anssubscriberstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anssubscriberstub_fuzzer/corpus/init b/test/fuzztest/anssubscriberstub_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anssubscriberstub_fuzzer/project.xml b/test/fuzztest/anssubscriberstub_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp index d24e2df048a4ef304300d4bafe79ea78b62a91bc..8d97595d5694569c213dc433657174850672366c 100644 --- a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp +++ b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp @@ -50,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp index d6fc7949ba48be5a44a15a6b4f2513cadab90fc1..8a9d4f58d946ae7529a74325659c8e3413bb09a4 100644 --- a/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp +++ b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp @@ -47,7 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn b/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..354fe3dce3f9e0d7cf0adde7c29378128018237f --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("EnabledNotificationCallbackDataFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/enablednotificationcallbackdata_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "enablednotificationcallbackdata_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EnabledNotificationCallbackDataFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init b/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd2f683238f7a43ea795b1767d1f56da85f14cf6 --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "enabled_notification_callback_data.h" +#undef private +#undef protected +#include "enablednotificationcallbackdata_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + uid_t uid = static_cast(GetU32Data(data)); + bool enabled = *data % ENABLE; + Notification::EnabledNotificationCallbackData enabledNotificationCallbackData(stringData, uid, enabled); + // test SetBundle function + enabledNotificationCallbackData.SetBundle(stringData); + // test SetUid function + enabledNotificationCallbackData.SetUid(uid); + // test SetEnable function + enabledNotificationCallbackData.SetEnable(enabled); + // test GetBundle function + enabledNotificationCallbackData.GetBundle(); + // test GetUid function + enabledNotificationCallbackData.GetUid(); + // test GetEnable function + enabledNotificationCallbackData.GetEnable(); + // test Dump function + enabledNotificationCallbackData.Dump(); + // test Unmarshalling function + Parcel parcel; + enabledNotificationCallbackData.Unmarshalling(parcel); + enabledNotificationCallbackData.ReadFromParcel(parcel); + return enabledNotificationCallbackData.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8553a05fadd167e5bcbf36bce53674c9c088a2f5 --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H +#define TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "enablednotificationcallbackdata_fuzzer" + +#endif // TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml b/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp index 255bf5db7834aa9cb3288de62d7db950b3bfe7b0..e809f6570697d0cb47d3a97ae250a8a50e259057 100644 --- a/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp +++ b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp @@ -48,7 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp index 94a46feb1cc710595a8d87893cb5b68f288337de..6a8eca2aab803680b226f8321dd0b7f352b76c5d 100644 --- a/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp @@ -42,7 +42,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/messageuser_fuzzer/BUILD.gn b/test/fuzztest/messageuser_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..743510799d46c0bd82f32d3b451534a4c2ea8cec --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("MessageUserFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/messageuser_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "messageuser_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":MessageUserFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/messageuser_fuzzer/corpus/init b/test/fuzztest/messageuser_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47210c4a270c45fd7f877fe4473f22e059b3d0b5 --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "message_user.h" +#undef private +#undef protected +#include "messageuser_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string key(data); + Notification::MessageUser messageUser; + // test SetKey function + messageUser.SetKey(key); + // test SetName function + std::string name(data); + messageUser.SetName(name); + // test SetPixelMap function + std::shared_ptr pixelMap = std::make_shared(); + messageUser.SetPixelMap(pixelMap); + // test SetUri function + Uri uri(key); + messageUser.SetUri(uri); + // test SetMachine function + bool enabled = *data % ENABLE; + messageUser.SetMachine(enabled); + // test SetUserAsImportant function + messageUser.SetUserAsImportant(enabled); + // test GetKey function + messageUser.GetKey(); + // test GetName function + messageUser.GetName(); + // test GetPixelMap function + messageUser.GetPixelMap(); + // test GetUri function + messageUser.GetUri(); + // test IsMachine function + messageUser.IsMachine(); + // test IsUserImportant function + messageUser.IsUserImportant(); + // test ToJson function + nlohmann::json jsonObject; + messageUser.ToJson(jsonObject); + messageUser.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8e6a27836e7fc3fa8a797debe2389e9f3c9b07ef --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H +#define TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "messageuser_fuzzer" + +#endif // TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/project.xml b/test/fuzztest/messageuser_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notification_fuzzer/BUILD.gn b/test/fuzztest/notification_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..42f5e01251dc2a77bfe17bedc6858e2159975d51 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notification_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notification_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notification_fuzzer/corpus/init b/test/fuzztest/notification_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notification_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notification_fuzzer/notification_fuzzer.cpp b/test/fuzztest/notification_fuzzer/notification_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44e090751aed5d754026358c38c9221fdd1dde27 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/notification_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification.h" +#undef private +#undef protected +#include "notification_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(stringData, request); + notification.EnableLight(); + notification.EnableSound(); + notification.EnableVibrate(); + notification.GetBundleName(); + notification.GetCreateBundle(); + notification.GetLabel(); + notification.GetLedLightColor(); + notification.GetLockscreenVisibleness(); + notification.GetGroup(); + notification.GetId(); + notification.GetKey(); + notification.GetNotificationRequest(); + notification.GetPostTime(); + notification.GetSound(); + notification.GetUid(); + notification.GetPid(); + notification.IsUnremovable(); + notification.GetVibrationStyle(); + notification.IsGroup(); + notification.IsFloatingIcon(); + notification.GetRemindType(); + notification.IsRemoveAllowed(); + Parcel parcel; + return notification.MarshallingBool(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notification_fuzzer/notification_fuzzer.h b/test/fuzztest/notification_fuzzer/notification_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..59b3a51743f272e853c4ccd6fe268ffc6b90d108 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/notification_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notification_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notification_fuzzer/project.xml b/test/fuzztest/notification_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notification_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..990c9dba24aa350c27cb2e4f3cce8e6dbcdd78f8 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationActionButtonFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationactionbutton_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationactionbutton_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationActionButtonFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationactionbutton_fuzzer/corpus/init b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10982a6b7f16af3231c44740612ba8dbcc619707 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_action_button.h" +#undef private +#undef protected +#include "notificationactionbutton_fuzzer.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" +#include "want_params.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + std::string title(data); + std::shared_ptr actionButton = + Notification::NotificationActionButton::Create(nullptr, title, wantAgent); + if (actionButton == nullptr) { + return false; + } + // test AddAdditionalData function + AAFwk::WantParams extras; + actionButton->AddAdditionalData(extras); + // test AddMimeTypeOnlyUserInput function + std::shared_ptr userInput = + std::make_shared(); + actionButton->AddMimeTypeOnlyUserInput(userInput); + actionButton->AddNotificationUserInput(userInput); + // test GetMimeTypeOnlyUserInputs function + actionButton->GetMimeTypeOnlyUserInputs(); + // test GetUserInput function + actionButton->GetUserInput(); + // test IsAutoCreatedReplies function + actionButton->IsAutoCreatedReplies(); + // test IsContextDependent function + actionButton->IsContextDependent(); + // test GetSemanticActionButton function + actionButton->GetSemanticActionButton(); + // test GetIcon function + actionButton->GetIcon(); + // test GetTitle function + actionButton->GetTitle(); + // test GetWantAgent function + actionButton->GetWantAgent(); + // test Dump function + actionButton->Dump(); + // test ToJson function + nlohmann::json jsonObject; + actionButton->ToJson(jsonObject); + actionButton->FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + actionButton->Marshalling(parcel); + actionButton->Unmarshalling(parcel); + actionButton->ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..32b8806cc4cd8bf3a4b6b7aeff2575187b05b925 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationactionbutton_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/project.xml b/test/fuzztest/notificationactionbutton_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationannex_fuzzer/BUILD.gn b/test/fuzztest/notificationannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..44d67fcb9f5d20108b50cf13cf8172baca00a73b --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationannex_fuzzer/corpus/init b/test/fuzztest/notificationannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..453e0059e019c1aee96abdf8f391be8403e1ec47 --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification.h" +#undef private +#undef protected +#include "notificationannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(stringData, request); + notification.GetSourceType(); + notification.GetDeviceId(); + Uri sound(stringData); + notification.SetSound(sound); + Parcel parcel; + return notification.MarshallingBool(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6b9608293d6d665ec1c9c69bbb10951d4d8dff87 --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationannex_fuzzer/project.xml b/test/fuzztest/notificationannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn b/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..13e4c66349cef2347ca1360903cae61bd1d6e260 --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationBasicContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationbasiccontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationbasiccontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationBasicContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init b/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b05ab2abe757bd8fa425d85156b059b387d3f32 --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_basic_content.h" +#undef private +#undef protected +#include "notificationbasiccontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::shared_ptr notificationBasicContent = + std::make_shared(); + // test GetAdditionalText function + notificationBasicContent->GetAdditionalText(); + // test GetText function + notificationBasicContent->GetText(); + // test GetTitle function + notificationBasicContent->GetTitle(); + // test GetTitle function + notificationBasicContent->GetTitle(); + // test ReadFromJson function + nlohmann::json jsonObject; + notificationBasicContent->ReadFromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7dcf5e00aa3df1ad51b5ce2299168543bef1844e --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationbasiccontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/project.xml b/test/fuzztest/notificationbasiccontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn b/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f28fb32fffb55ebc16db481fe4866558973561b4 --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationBundleOptionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationbundleoption_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationbundleoption_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationBundleOptionFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationbundleoption_fuzzer/corpus/init b/test/fuzztest/notificationbundleoption_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..882e445e3f029ecb31ef2fa0799568e48c2a1611 --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_bundle_option.h" +#undef private +#undef protected +#include "notificationbundleoption_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string bundleNametitle(data); + int32_t uid = static_cast(GetU32Data(data)); + std::shared_ptr notificationBundleOption = + std::make_shared(bundleNametitle, uid); + // test GetUid function + notificationBundleOption->GetUid(); + // test Dump function + notificationBundleOption->Dump(); + // test Unmarshalling function + Parcel parcel; + notificationBundleOption->Unmarshalling(parcel); + notificationBundleOption->ReadFromParcel(parcel); + return notificationBundleOption->Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ff6ffcdc88a3ba5b762b2b00271b34e0ccd7d3ce --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationbundleoption_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationbundleoption_fuzzer/project.xml b/test/fuzztest/notificationbundleoption_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f093ca3f17af0a4ab90cf60e7c55296c214099f0 --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationcontent_fuzzer/corpus/init b/test/fuzztest/notificationcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b913e0a6e3c3fd8eafbb7910dad03242cd81ecf --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_content.h" +#undef private +#undef protected +#include "notificationcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::shared_ptr normalContent = + std::make_shared(); + std::shared_ptr longTextContent = + std::make_shared(); + std::shared_ptr pictureContent = + std::make_shared(); + std::shared_ptr conversationContent = + std::make_shared(); + std::shared_ptr multiLineContent = + std::make_shared(); + std::shared_ptr mediaContent = + std::make_shared(); + if ((normalContent == nullptr) || (longTextContent == nullptr) || (pictureContent == nullptr) || + (conversationContent == nullptr) || (multiLineContent == nullptr) || (mediaContent == nullptr)) { + return false; + } + Notification::NotificationContent notificationContent(normalContent); + Notification::NotificationContent notificationLongTextContent(longTextContent); + Notification::NotificationContent notificationPictureContent(pictureContent); + Notification::NotificationContent notificationConversationContent(conversationContent); + Notification::NotificationContent notificationMultiLineContent(multiLineContent); + Notification::NotificationContent notificationMediaContent(mediaContent); + // test Dump function + notificationContent.GetContentType(); + // test Dump function + notificationContent.GetNotificationContent(); + // test Dump function + notificationContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationContent.ToJson(jsonObject); + notificationContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationContent.Unmarshalling(parcel); + notificationContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f38e46696eac200c1119a9f3444886fcf5ddc7ec --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/project.xml b/test/fuzztest/notificationcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bec34b5e456785c58b2c034350c7206d07c8aa6a --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationConversationalContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationconversationalcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationconversationalcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationConversationalContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/corpus/init b/test/fuzztest/notificationconversationalcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1139f318903bd79c5e4f30120833cefecf52b21b --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_conversational_content.h" +#undef private +#undef protected +#include "notificationconversationalcontent_fuzzer.h" + +#define DISABLE_FUZZ +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::MessageUser messageUser; + Notification::NotificationConversationalContent NotificationConversationalContent(messageUser); + NotificationConversationalContent.GetMessageUser(); + std::string stringData(data); + NotificationConversationalContent.SetConversationTitle(stringData); + NotificationConversationalContent.GetConversationTitle(); + NotificationConversationalContent.IsConversationGroup(); + bool enabled = *data % ENABLE; + NotificationConversationalContent.SetConversationGroup(enabled); + int64_t timestamp = 1; + NotificationConversationalContent.AddConversationalMessage(stringData, timestamp, messageUser); + Notification::NotificationConversationalContent::MessagePtr message; + NotificationConversationalContent.AddConversationalMessage(message); + NotificationConversationalContent.GetAllConversationalMessages(); + NotificationConversationalContent.Dump(); + Parcel parcel; + NotificationConversationalContent.Marshalling(parcel); + NotificationConversationalContent.Unmarshalling(parcel); + return NotificationConversationalContent.ReadFromParcel(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { +#ifndef DISABLE_FUZZ + OHOS::DoSomethingInterestingWithMyAPI(ch, size); +#endif + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.h b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..20494fc74176155d9e4a96341e13e7193f50ef49 --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationconversationalcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_NOTIFICATIONCONVERSATIONALCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/project.xml b/test/fuzztest/notificationconversationalcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationconversationalmessage_fuzzer/BUILD.gn b/test/fuzztest/notificationconversationalmessage_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d7bbfd8d8f7728180f2363a05cca80e8f71bc4e4 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessage_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationConversationalMessageFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationconversationalmessage_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationconversationalmessage_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationConversationalMessageFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationconversationalmessage_fuzzer/corpus/init b/test/fuzztest/notificationconversationalmessage_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationconversationalmessage_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.cpp b/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb47d23831d70ff75f18a4d6927fdb9a31fdb21f --- /dev/null +++ b/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "notification_conversational_message.h" +#include "notificationconversationalmessage_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int64_t timestamp = 1; + Notification::MessageUser sender; + Notification::NotificationConversationalMessage notificationConversationalMessage( + stringData, timestamp, sender); + notificationConversationalMessage.GetText(); + notificationConversationalMessage.GetSender(); + notificationConversationalMessage.GetMimeType(); + notificationConversationalMessage.GetUri(); + return notificationConversationalMessage.GetArrivedTime(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.h b/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..56abc86accf9c76907289af38a1319134ad24672 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationconversationalmessage_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessage_fuzzer/project.xml b/test/fuzztest/notificationconversationalmessage_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationconversationalmessage_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn b/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1a63c08b771f56ea110c3f6462dd1d850622ac58 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationConversationalMessageAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationconversationalmessageannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationconversationalmessageannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationConversationalMessageAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init b/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ab2e76fa3840cb108a728ed69f6f6d1ebef7e7d --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_conversational_message.h" +#undef private +#undef protected +#include "notificationconversationalmessageannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int64_t timestamp = 1; + Notification::MessageUser sender; + Notification::NotificationConversationalMessage notificationConversationalMessage( + stringData, timestamp, sender); + std::string uri(data); + std::shared_ptr uriPtr = std::make_shared(uri); + notificationConversationalMessage.SetData(stringData, uriPtr); + nlohmann::json jsonObject; + notificationConversationalMessage.ToJson(jsonObject); + notificationConversationalMessage.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c8c06c465d3251a155f2a38e9a04b04773ec5bc2 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationconversationalmessageannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml b/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..559ffbc70d293d28442a9c0a2cd02489d8262b24 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationDistributedOptionsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationdistributedoptions_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationdistributedoptions_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationDistributedOptionsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0750e4835a67e7db8a77a092995ec9d67bda0fb1 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "notification_distributed_options.h" +#include "notificationdistributedoptions_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + bool distribute = *data % ENABLE; + std::vector dvsDisplay; + std::vector dvsOperate; + dvsDisplay.emplace_back(stringData); + dvsOperate.emplace_back(stringData); + Notification::NotificationDistributedOptions notificationDistributedOptions(distribute, dvsDisplay, dvsOperate); + // test IsDistributed function + notificationDistributedOptions.IsDistributed(); + // test GetDevicesSupportDisplay function + notificationDistributedOptions.GetDevicesSupportDisplay(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test Dump function + notificationDistributedOptions.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationDistributedOptions.ToJson(jsonObject); + notificationDistributedOptions.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + return notificationDistributedOptions.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..083e196698ba04d56c9a1c12c27222651e1d3c69 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationdistributedoptions_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/BUILD.gn b/test/fuzztest/notificationdonotdisturbdate_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3e6eb1146d55ba9345ca13d6ce533a98d699dd9d --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationDoNotDisturbDateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationdonotdisturbdate_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationdonotdisturbdate_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationDoNotDisturbDateFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/corpus/init b/test/fuzztest/notificationdonotdisturbdate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6503996dd66c0ea0c54e35a9f11a8fa1dd9f65c2 --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 "notification_do_not_disturb_date.h" +#include "notificationdonotdisturbdate_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int64_t beginDate = 1; + int64_t endDate = 3; + uint32_t type = GetU32Data(data); + Notification::NotificationConstant::DoNotDisturbType disturbType = + Notification::NotificationConstant::DoNotDisturbType(type); + Notification::NotificationDoNotDisturbDate notificationDoNotDisturbDate(disturbType, beginDate, endDate); + notificationDoNotDisturbDate.SetDoNotDisturbType(disturbType); + notificationDoNotDisturbDate.GetDoNotDisturbType(); + notificationDoNotDisturbDate.SetBeginDate(beginDate); + notificationDoNotDisturbDate.GetBeginDate(); + notificationDoNotDisturbDate.SetEndDate(endDate); + notificationDoNotDisturbDate.Dump(); + return notificationDoNotDisturbDate.GetEndDate(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.h b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7d5b711d0dc6850a59215601c98c6a24ffec4bf2 --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONDONOTDISTURBDATE_FUZZER_NOTIFICATIONDONOTDISTURBDATE_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONDONOTDISTURBDATE_FUZZER_NOTIFICATIONDONOTDISTURBDATE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationdonotdisturbdate_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONDONOTDISTURBDATE_FUZZER_NOTIFICATIONDONOTDISTURBDATE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/project.xml b/test/fuzztest/notificationdonotdisturbdate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationflags_fuzzer/BUILD.gn b/test/fuzztest/notificationflags_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..447895fb78f92cc5b42d9b4bc0be46895da09ac3 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationFlagsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationflags_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationflags_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationFlagsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationflags_fuzzer/corpus/init b/test/fuzztest/notificationflags_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40ddcc291fe3d9bfc8cf2114f46f1de89b37987a --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_flags.h" +#undef private +#undef protected +#include "notificationflags_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationFlags notificationFlags; + // test IsSoundEnabled function + notificationFlags.IsSoundEnabled(); + // test IsVibrationEnabled function + notificationFlags.IsVibrationEnabled(); + // test Dump function + notificationFlags.Dump(); + // test ToJson function + nlohmann::json jsonObject; + if (jsonObject.is_null() or !jsonObject.is_object()) { + return false; + } + notificationFlags.ToJson(jsonObject); + notificationFlags.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationFlags.Unmarshalling(parcel); + notificationFlags.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9c68c8131bd2c14d66f655d4b6e599b7377d2801 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationflags_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/project.xml b/test/fuzztest/notificationflags_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationhelper_fuzzer/BUILD.gn b/test/fuzztest/notificationhelper_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..608cc9ae5e6dde6d5edf410521fa774418853200 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationHelperFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationhelper_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationhelper_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationHelperFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationhelper_fuzzer/corpus/init b/test/fuzztest/notificationhelper_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff1f5e769a9d19ddc7921cc803633e14b5065e08 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_helper.h" +#undef private +#undef protected +#include "notificationhelper_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationHelper notificationHelper; + // test IsSoundEnabled function + std::string representativeBundle(data); + Notification::NotificationRequest request; + notificationHelper.PublishNotificationAsBundle(representativeBundle, request); + notificationHelper.RemoveNotifications(); + int32_t userId = static_cast(GetU32Data(data)); + bool enabled = *data % ENABLE; + notificationHelper.SetNotificationsEnabledForAllBundles(userId, enabled); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b95e3f322cde4e8e97499438bb9a9f7deb68b532 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationhelper_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationhelper_fuzzer/project.xml b/test/fuzztest/notificationhelper_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationlongtextcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationlongtextcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..355cc5b530dbf7ce4eeebb41f9fefdbba86d1b11 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationLongTextContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationlongtextcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationlongtextcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationLongTextContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationlongtextcontent_fuzzer/corpus/init b/test/fuzztest/notificationlongtextcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationlongtextcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.cpp b/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0851d74ad35f34e510e565e5e18c8422248aad0 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "notification_long_text_content.h" +#include "notificationlongtextcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationLongTextContent notificationLongTextContent(stringData); + notificationLongTextContent.SetExpandedTitle(stringData); + notificationLongTextContent.GetExpandedTitle(); + notificationLongTextContent.SetBriefText(stringData); + notificationLongTextContent.GetBriefText(); + notificationLongTextContent.SetLongText(stringData); + notificationLongTextContent.GetLongText(); + notificationLongTextContent.Dump(); + Parcel parcel; + return notificationLongTextContent.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.h b/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0e3a0fc037ce7706a7b921b9a3e32da114252757 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENT_FUZZER_NOTIFICATIONLONGTEXTCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENT_FUZZER_NOTIFICATIONLONGTEXTCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationlongtextcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENT_FUZZER_NOTIFICATIONLONGTEXTCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontent_fuzzer/project.xml b/test/fuzztest/notificationlongtextcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationlongtextcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b84ce50d4f2b3ace5743ba89d4830430e0b3f340 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationLongTextContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationlongtextcontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationlongtextcontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationLongTextContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init b/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bac2a0b5077e3b3158dabb0a7fa0d0b48df9b0b7 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_long_text_content.h" +#undef private +#undef protected +#include "notificationlongtextcontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationLongTextContent notificationLongTextContent(stringData); + nlohmann::json jsonObject; + notificationLongTextContent.ToJson(jsonObject); + notificationLongTextContent.FromJson(jsonObject); + Parcel parcel; + notificationLongTextContent.Unmarshalling(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..93bb449ff5b6f5f88187f3888bc0e7266ad2eee0 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationlongtextcontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml b/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn b/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..88e74fbdaabd2970378f59dd42e705e366ffd184 --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationMediaContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationmediacontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationmediacontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationMediaContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationmediacontent_fuzzer/corpus/init b/test/fuzztest/notificationmediacontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..308d7c700e4dc6212ad58ea483730150ab23353f --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_media_content.h" +#undef private +#undef protected +#include "notificationmediacontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationMediaContent notificationMediaContent; + // test SetAVToken function + std::shared_ptr avToken = nullptr; + notificationMediaContent.SetAVToken(avToken); + // test SetShownActions function + std::vector actions; + notificationMediaContent.SetShownActions(actions); + // test GetAVToken function + notificationMediaContent.GetAVToken(); + // test GetShownActions function + notificationMediaContent.GetShownActions(); + // test Dump function + notificationMediaContent.Dump(); + // test Unmarshalling function + Parcel parcel; + notificationMediaContent.Unmarshalling(parcel); + notificationMediaContent.ReadFromParcel(parcel); + return notificationMediaContent.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a6594080c9614f5db86dc3cca2dd3fe1182a8325 --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationmediacontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationmediacontent_fuzzer/project.xml b/test/fuzztest/notificationmediacontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationmultilinecontent_fuzzer/BUILD.gn b/test/fuzztest/notificationmultilinecontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7d7e7199814f5b60c9ff7294ae9d0656cfd0bd46 --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationMultiLineContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationmultilinecontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationmultilinecontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationMultiLineContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationmultilinecontent_fuzzer/corpus/init b/test/fuzztest/notificationmultilinecontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.cpp b/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a72016f0828d313d67dd6c1afa24a4fef4f77a2 --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "notification_multiline_content.h" +#include "notificationmultilinecontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationMultiLineContent notificationMultiLineContent; + notificationMultiLineContent.SetExpandedTitle(stringData); + notificationMultiLineContent.GetExpandedTitle(); + notificationMultiLineContent.SetBriefText(stringData); + notificationMultiLineContent.GetBriefText(); + notificationMultiLineContent.AddSingleLine(stringData); + notificationMultiLineContent.GetAllLines(); + notificationMultiLineContent.Dump(); + Parcel parcel; + return notificationMultiLineContent.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.h b/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4f808e102c173c29ebd20ad82fc340b0cf52a332 --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENT_FUZZER_NOTIFICATIONMULTILINECONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENT_FUZZER_NOTIFICATIONMULTILINECONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationmultilinecontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENT_FUZZER_NOTIFICATIONMULTILINECONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontent_fuzzer/project.xml b/test/fuzztest/notificationmultilinecontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d18e78d23d9ec80c98e209d4e7f54a81ffa9922c --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationMultiLineContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationmultilinecontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationmultilinecontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationMultiLineContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init b/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..223cd379fa44dd0d0ba37b49d7a17aa024ffed75 --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_multiline_content.h" +#undef private +#undef protected +#include "notificationmultilinecontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationMultiLineContent notificationMultiLineContent; + nlohmann::json jsonObject; + notificationMultiLineContent.ToJson(jsonObject); + notificationMultiLineContent.FromJson(jsonObject); + Parcel parcel; + notificationMultiLineContent.Unmarshalling(parcel); + notificationMultiLineContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e3d596d6c8456f68ec44af5023b958d94826002a --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationmultilinecontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml b/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dab3a817d475d948ade3b8908731079a108ac5b0 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationNormalContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationnormalcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationnormalcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationNormalContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a81c96f872bc007cdb92d3ca5d283a52414af6e --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_normal_content.h" +#undef private +#undef protected +#include "notificationnormalcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationNormalContent notificationNormalContent; + // test Dump function + notificationNormalContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationNormalContent.ToJson(jsonObject); + notificationNormalContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationNormalContent.Unmarshalling(parcel); + notificationNormalContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8033ab597fcf05e75d8a25c91a0d447a1a1cf062 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationnormalcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/project.xml b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn b/test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7be6722b299ac8e8fbad7b552da9f361bfffaf39 --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationPictureContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationpicturecontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationpicturecontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationPictureContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/corpus/init b/test/fuzztest/notificationpicturecontent_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.cpp b/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..02a49cc345d3a3b7ea22d73fec837f5d0b1aef6f --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "notification_picture_content.h" +#include "notificationpicturecontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationPictureContent notificationPictureContent; + notificationPictureContent.SetExpandedTitle(stringData); + notificationPictureContent.GetExpandedTitle(); + notificationPictureContent.SetBriefText(stringData); + notificationPictureContent.GetBriefText(); + std::shared_ptr bigPicture = std::make_shared(); + notificationPictureContent.SetBigPicture(bigPicture); + notificationPictureContent.GetBigPicture(); + notificationPictureContent.Dump(); + Parcel parcel; + return notificationPictureContent.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.h b/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b9591d93a3166e7d6d19cc2a240971a9348c2671 --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONPICTURECONTENT_FUZZER_NOTIFICATIONPICTURECONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONPICTURECONTENT_FUZZER_NOTIFICATIONPICTURECONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationpicturecontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONPICTURECONTENT_FUZZER_NOTIFICATIONPICTURECONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/project.xml b/test/fuzztest/notificationpicturecontent_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0defda83170f61edc324f324cb43897cabc29f4d --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationPictureContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationpicturecontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationpicturecontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationPictureContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init b/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ecb02f796e8eecada49eb59832eafab38b2f4d2 --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_picture_content.h" +#undef private +#undef protected +#include "notificationpicturecontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationPictureContent notificationPictureContent; + nlohmann::json jsonObject; + notificationPictureContent.ToJson(jsonObject); + notificationPictureContent.FromJson(jsonObject); + Parcel parcel; + notificationPictureContent.Unmarshalling(parcel); + notificationPictureContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..680d2a79a730c54eef61573ace6d893c67a6088b --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationpicturecontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml b/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationrequest_fuzzer/BUILD.gn b/test/fuzztest/notificationrequest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ce301ebe114e3f0d6389b7b62ac39560709d67a9 --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationRequestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationrequest_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationrequest_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationRequestFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationrequest_fuzzer/corpus/init b/test/fuzztest/notificationrequest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c4d88955789b70d44faa19b3e910c7a39901ab5 --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp @@ -0,0 +1,83 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_action_button.h" +#undef private +#undef protected +#include "notificationrequest_fuzzer.h" +#include "notification_request.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t FLAG_STATUS = 11; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t notificationId = static_cast(GetU32Data(data)); + Notification::NotificationRequest request(notificationId); + request.IsInProgress(); + bool enabled = *data % ENABLE; + request.SetInProgress(enabled); + request.IsUnremovable(); + request.SetUnremovable(enabled); + request.GetBadgeNumber(); + request.GetNotificationId(); + std::shared_ptr wantAgent = nullptr; + request.SetWantAgent(wantAgent); + request.GetWantAgent(); + request.SetRemovalWantAgent(wantAgent); + request.GetRemovalWantAgent(); + request.SetMaxScreenWantAgent(wantAgent); + request.GetMaxScreenWantAgent(); + std::shared_ptr extras = nullptr; + request.SetAdditionalData(extras); + request.GetAdditionalData(); + request.GetDeliveryTime(); + request.IsShowDeliveryTime(); + request.SetShowDeliveryTime(enabled); + // make NotificationActionButton paramter + std::shared_ptr actionButton = + std::make_shared(); + // make semanticActionButton paramter + int32_t semanticAction = static_cast(*data % FLAG_STATUS); + Notification::NotificationConstant::SemanticActionButton semanticActionButton = + Notification::NotificationConstant::SemanticActionButton(semanticAction); + actionButton->SetSemanticActionButton(semanticActionButton); + actionButton->SetAutoCreatedReplies(enabled); + actionButton->SetContextDependent(enabled); + request.AddActionButton(actionButton); + request.ClearActionButtons(); + request.IsPermitSystemGeneratedContextualActionButtons(); + request.SetPermitSystemGeneratedContextualActionButtons(enabled); + return request.IsAgentNotification(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.h b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..820fab9ac1ae5fb859b4d7c0cebe8355c7e4ce47 --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONREQUEST_FUZZER_NOTIFICATIONREQUEST_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONREQUEST_FUZZER_NOTIFICATIONREQUEST_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationrequest_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONREQUEST_FUZZER_NOTIFICATIONREQUEST_FUZZER_H diff --git a/test/fuzztest/notificationrequest_fuzzer/project.xml b/test/fuzztest/notificationrequest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn b/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e6dcd86ad3d672e8bce2ce8f3bb8aefaa12d0c28 --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationRequestAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationrequestannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationrequestannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationRequestAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationrequestannex_fuzzer/corpus/init b/test/fuzztest/notificationrequestannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9fae7ec24bcc877dd7f9fac266e94234cdf4a4e1 --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_request.h" +#undef private +#undef protected +#include "notificationrequestannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + int32_t notificationId = static_cast(GetU32Data(data)); + Notification::NotificationRequest request(notificationId); + pid_t pid = *data; + request.SetCreatorPid(pid); + request.Dump(); + nlohmann::json jsonObject; + request.ToJson(jsonObject); + request.FromJson(jsonObject); + request.ConvertObjectsToJson(jsonObject); + request.ConvertObjectsToJson(jsonObject); + Notification::NotificationRequest* target = new Notification::NotificationRequest(notificationId); + request.ConvertJsonToNum(target, jsonObject); + request.ConvertJsonToString(target, jsonObject); + request.ConvertJsonToEnum(target, jsonObject); + request.ConvertJsonToBool(target, jsonObject); + request.ConvertJsonToPixelMap(target, jsonObject); + request.ConvertJsonToNotificationContent(target, jsonObject); + request.ConvertJsonToNotificationActionButton(target, jsonObject); + request.ConvertJsonToNotificationDistributedOptions(target, jsonObject); + request.ConvertJsonToNotificationFlags(target, jsonObject); + return request.IsAgentNotification(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f264ff8f38fa3aa91e3a3c0f944ef0492a8e1aa3 --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationrequestannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H diff --git a/test/fuzztest/notificationrequestannex_fuzzer/project.xml b/test/fuzztest/notificationrequestannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationslot_fuzzer/BUILD.gn b/test/fuzztest/notificationslot_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..af8ba11b97a6128fbc8d2c7c009a9ad220371c51 --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSlotFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationslot_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationslot_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSlotFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationslot_fuzzer/corpus/init b/test/fuzztest/notificationslot_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5148f22111d1761d1715d02ea145b262d83206f8 --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_slot.h" +#undef private +#undef protected +#include "notificationslot_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSlot notificationSlot; + bool enabled = *data % ENABLE; + notificationSlot.CanEnableLight(); + notificationSlot.CanVibrate(); + notificationSlot.GetDescription(); + notificationSlot.GetId(); + notificationSlot.GetLedLightColor(); + notificationSlot.GetLevel(); + notificationSlot.GetType(); + notificationSlot.GetLockScreenVisibleness(); + notificationSlot.GetName(); + notificationSlot.GetSound(); + notificationSlot.GetVibrationStyle(); + notificationSlot.IsEnableBypassDnd(); + notificationSlot.EnableBypassDnd(enabled); + notificationSlot.IsShowBadge(); + notificationSlot.EnableBadge(enabled); + notificationSlot.SetEnable(enabled); + notificationSlot.GetEnable(); + Parcel parcel; + notificationSlot.ReadFromParcel(parcel); + notificationSlot.Unmarshalling(parcel); + return notificationSlot.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4a3f47bde605345953a708d1502ec8c3b4f2d7b5 --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationslot_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationslot_fuzzer/project.xml b/test/fuzztest/notificationslot_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsorting_fuzzer/BUILD.gn b/test/fuzztest/notificationsorting_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..24965e38a0b84fa177d2a779dc6bd28c41d199fe --- /dev/null +++ b/test/fuzztest/notificationsorting_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsorting_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsorting_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsorting_fuzzer/corpus/init b/test/fuzztest/notificationsorting_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationsorting_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.cpp b/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44e0cd096cbda7ce1e61fc7ba2da458d269fe0df --- /dev/null +++ b/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#undef private +#undef protected +#include "notificationsorting_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationSorting notificationSorting; + sptr slot = nullptr; + notificationSorting.SetSlot(slot); + notificationSorting.SetGroupKeyOverride(stringData); + notificationSorting.Dump(); + notificationSorting.SetKey(stringData); + int32_t importance = static_cast(GetU32Data(data)); + notificationSorting.SetImportance(importance); + uint64_t ranking = 1; + notificationSorting.SetRanking(ranking); + notificationSorting.SetVisiblenessOverride(importance); + notificationSorting.SetDisplayBadge(*data % ENABLE); + notificationSorting.SetHiddenNotification(*data % ENABLE); + Parcel parcel; + return notificationSorting.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.h b/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a12719d23750fc42fa9e7a16be1c8ae36f6dcb40 --- /dev/null +++ b/test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTING_FUZZER_NOTIFICATIONSORTING_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTING_FUZZER_NOTIFICATIONSORTING_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsorting_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTING_FUZZER_NOTIFICATIONSORTING_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsorting_fuzzer/project.xml b/test/fuzztest/notificationsorting_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationsorting_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn b/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..396489de57d5bd1e0c83853a049cf46b9b1e7344 --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsortingannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsortingannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsortingannex_fuzzer/corpus/init b/test/fuzztest/notificationsortingannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6be90e7ed1c032362b60ef574ea5c685dfbf38c9 --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#undef private +#undef protected +#include "notificationsortingannex_fuzzer.h" + +namespace OHOS { + + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSorting notificationSorting; + Parcel parcel; + notificationSorting.ReadFromParcel(parcel); + notificationSorting.Unmarshalling(parcel); + return notificationSorting.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7cb527a2dc317030ebb5d987e70f5d9b87261e4e --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsortingannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsortingannex_fuzzer/project.xml b/test/fuzztest/notificationsortingannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingmap_fuzzer/BUILD.gn b/test/fuzztest/notificationsortingmap_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..954cf28cc99fa5ada63f0508efdadd7a56a35e7f --- /dev/null +++ b/test/fuzztest/notificationsortingmap_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingMapFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsortingmap_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsortingmap_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingMapFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsortingmap_fuzzer/corpus/init b/test/fuzztest/notificationsortingmap_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationsortingmap_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c386d2014051a6fe99c4a38445fd4238c321646 --- /dev/null +++ b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#include "notification_sorting_map.h" +#undef private +#undef protected +#include "notificationsortingmap_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationSortingMap notificationSortingMap; + notificationSortingMap.SetKey(stringData); + Notification::NotificationSorting notificationSorting; + notificationSorting.SetKey(stringData); + notificationSortingMap.GetNotificationSorting(stringData, notificationSorting); + std::vector sortingList; + sortingList.emplace_back(notificationSorting); + notificationSortingMap.SetNotificationSorting(sortingList); + notificationSortingMap.Dump(); + Parcel parcel; + return notificationSortingMap.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.h b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..206d41e61fde1cf1d994c4155178188c8d3cd2a7 --- /dev/null +++ b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTINGMAP_FUZZER_NOTIFICATIONSORTINGMAP_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTINGMAP_FUZZER_NOTIFICATIONSORTINGMAP_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsortingmap_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTINGMAP_FUZZER_NOTIFICATIONSORTINGMAP_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmap_fuzzer/project.xml b/test/fuzztest/notificationsortingmap_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationsortingmap_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn b/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f449870f61f795a651e69ee3aee243927828a348 --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingMapAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsortingmapannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsortingmapannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingMapAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init b/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4830a47aa9bebd48da6d781b3b7fa53710dbbf56 --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#include "notification_sorting_map.h" +#undef private +#undef protected +#include "notificationsortingmapannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSortingMap notificationSortingMap; + Parcel parcel; + notificationSortingMap.Unmarshalling(parcel); + return notificationSortingMap.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..dd76b2481c715d5d4190a44c227a70279d82196b --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsortingmapannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml b/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsubscribeInfo_fuzzer/BUILD.gn b/test/fuzztest/notificationsubscribeInfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7bb9acd99de7dc554ae9dd9d5ad843fdeeec3948 --- /dev/null +++ b/test/fuzztest/notificationsubscribeInfo_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSubscribeInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsubscribeInfo_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsubscribeInfo_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSubscribeInfoFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsubscribeInfo_fuzzer/corpus/init b/test/fuzztest/notificationsubscribeInfo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationsubscribeInfo_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.cpp b/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e4facc057a6bc4f1b6fa30478770f1bee39512a9 --- /dev/null +++ b/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "notification_subscribe_info.h" +#include "notificationsubscribeInfo_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationSubscribeInfo sotificationSubscribeInfo; + sotificationSubscribeInfo.AddAppName(stringData); + std::vector appNames; + appNames.emplace_back(stringData); + sotificationSubscribeInfo.AddAppNames(appNames); + sotificationSubscribeInfo.GetAppNames(); + int32_t userId = static_cast(GetU32Data(data)); + sotificationSubscribeInfo.AddAppUserId(userId); + sotificationSubscribeInfo.GetAppUserId(); + sotificationSubscribeInfo.Dump(); + Parcel parcel; + return sotificationSubscribeInfo.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.h b/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..91b59a03205b1017fd6902ae222e3d822462d73c --- /dev/null +++ b/test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSUBSCRIBEINFO_FUZZER_NOTIFICATIONSUBSCRIBEINFO_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSUBSCRIBEINFO_FUZZER_NOTIFICATIONSUBSCRIBEINFO_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsubscribeInfo_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSUBSCRIBEINFO_FUZZER_NOTIFICATIONSUBSCRIBEINFO_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsubscribeInfo_fuzzer/project.xml b/test/fuzztest/notificationsubscribeInfo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationsubscribeInfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationtemplate_fuzzer/BUILD.gn b/test/fuzztest/notificationtemplate_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0468912b053e861d3df783b7f311c3a999882f86 --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationTemplateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationtemplate_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationtemplate_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationTemplateFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationtemplate_fuzzer/corpus/init b/test/fuzztest/notificationtemplate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.cpp b/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a016380fecdab1487748a3df5dc4d456b51b5853 --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "notification_template.h" +#include "notificationtemplate_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationTemplate notificationTemplate; + notificationTemplate.SetTemplateName(stringData); + notificationTemplate.GetTemplateName(); + std::shared_ptr datas = std::make_shared(); + notificationTemplate.SetTemplateData(datas); + notificationTemplate.GetTemplateData(); + notificationTemplate.Dump(); + Parcel parcel; + return notificationTemplate.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.h b/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a5a06504c46f77e1a51e7c49048bf6534429ff18 --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONTEMPLATE_FUZZER_NOTIFICATIONTEMPLATE_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONTEMPLATE_FUZZER_NOTIFICATIONTEMPLATE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationtemplate_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONTEMPLATE_FUZZER_NOTIFICATIONTEMPLATE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationtemplate_fuzzer/project.xml b/test/fuzztest/notificationtemplate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn b/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..262ac70cdedfb62dcae287f787b628fef57ac1bb --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationTemplateAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationtemplateannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationtemplateannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationTemplateAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init b/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98a8fc8f74303eb2fdabe9874ed09c3d4cc041c1 --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_template.h" +#include "notification_conversational_content.h" +#undef private +#undef protected +#include "notificationtemplateannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationTemplate notificationTemplate; + Parcel parcel; + notificationTemplate.Unmarshalling(parcel); + notificationTemplate.ReadFromParcel(parcel); + Notification::MessageUser messageUser; + Notification::NotificationConversationalContent NotificationConversationalContent(messageUser); + nlohmann::json jsonObject; + NotificationConversationalContent.ToJson(jsonObject); + NotificationConversationalContent.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..50b6df6e83778c7c343bf1369d584ba2810558d8 --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationtemplateannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/project.xml b/test/fuzztest/notificationtemplateannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn b/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f97967eb06e3618e1177eddb7c02ef818290e90c --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationUserInputFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationuserinput_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationuserinput_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationUserInputFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationuserinput_fuzzer/corpus/init b/test/fuzztest/notificationuserinput_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..31e00655b78013ea1e334d11dfa3703af55970e7 --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp @@ -0,0 +1,84 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_user_input.h" +#undef private +#undef protected +#include "notificationuserinput_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t INPUT_EDIT_TYPE = 3; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationUserInput notificationUserInput(stringData); + AAFwk::Want want; + uint8_t sources = *data % ENABLE; + Notification::NotificationConstant::InputsSource source = + Notification::NotificationConstant::InputsSource(sources); + notificationUserInput.SetInputsSource(want, source); + notificationUserInput.GetInputsSource(want); + std::shared_ptr input = + std::make_shared(); + std::vector> userInputs; + userInputs.emplace_back(input); + AAFwk::WantParams additional; + notificationUserInput.AddInputsToWant(userInputs, want, additional); + notificationUserInput.GetInputsFromWant(want); + notificationUserInput.Create(stringData); + notificationUserInput.GetInputKey(); + notificationUserInput.AddAdditionalData(additional); + notificationUserInput.GetAdditionalData(); + uint8_t inputEditTypes = *data % INPUT_EDIT_TYPE; + Notification::NotificationConstant::InputEditType inputEditType = + Notification::NotificationConstant::InputEditType(inputEditTypes); + notificationUserInput.SetEditType(inputEditType); + notificationUserInput.GetEditType(); + std::vector options; + options.emplace_back(stringData); + notificationUserInput.SetOptions(options); + notificationUserInput.GetOptions(); + bool doPermit = *data % ENABLE; + notificationUserInput.SetPermitMimeTypes(stringData, doPermit); + notificationUserInput.GetPermitMimeTypes(); + notificationUserInput.IsMimeTypeOnly(); + notificationUserInput.SetTag(stringData); + notificationUserInput.GetTag(); + notificationUserInput.SetPermitFreeFormInput(doPermit); + notificationUserInput.IsPermitFreeFormInput(); + notificationUserInput.Dump(); + Parcel parcel; + notificationUserInput.ReadFromParcel(parcel); + return notificationUserInput.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4ca3acc2e820e7e93def3dd9799aebc7751a30ca --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationuserinput_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationuserinput_fuzzer/project.xml b/test/fuzztest/notificationuserinput_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn b/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..db8a5f6fd81f8940a524a9a1d4d6c6ea677b7dce --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationUserInputAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationuserinputannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationuserinputannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationUserInputAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init b/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b9fc30ea9174fb99145799b61e91370876e4aa8 --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification_user_input.h" +#undef private +#undef protected +#include "notificationuserinputannex_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t INPUT_EDIT_TYPE = 3; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationUserInput notificationUserInput(stringData); + AAFwk::Want want; + Notification::NotificationUserInput userInput(stringData); + std::map> results; + notificationUserInput.AddMimeInputToWant(userInput, want, results); + std::string inputKey(data); + std::string tag(data); + std::vector options; + options.emplace_back(stringData); + bool permitFreeFormInput = *data % ENABLE; + std::set permitMimeTypes; + std::shared_ptr additional; + uint8_t inputEditTypes = *data % INPUT_EDIT_TYPE; + Notification::NotificationConstant::InputEditType inputEditType = + Notification::NotificationConstant::InputEditType(inputEditTypes); + std::shared_ptr notificationUserInputs = + Notification::NotificationUserInput::Create(inputKey, tag, options, permitFreeFormInput, + permitMimeTypes, additional, inputEditType); + Notification::NotificationUserInput notificationUserInputannex + (inputKey, tag, options, permitFreeFormInput, permitMimeTypes, additional, inputEditType); + nlohmann::json jsonObject; + notificationUserInputannex.ToJson(jsonObject); + notificationUserInputannex.FromJson(jsonObject); + Parcel parcel; + return notificationUserInput.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..03d07efec5ea722dfd61f1584a89b609844d6857 --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationuserinputannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/project.xml b/test/fuzztest/notificationuserinputannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/readfromparcel_fuzzer/BUILD.gn b/test/fuzztest/readfromparcel_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e097b97e0beaf3981aa7779ea4018c1795bab21c --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReadFromParcelFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/readfromparcel_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "readfromparcel_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReadFromParcelFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/readfromparcel_fuzzer/corpus/init b/test/fuzztest/readfromparcel_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/readfromparcel_fuzzer/project.xml b/test/fuzztest/readfromparcel_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5de86ce087b2684aa635c19be18eca84852b925b --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp @@ -0,0 +1,91 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "notification.h" +#undef private +#undef protected +#include "readfromparcel_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SOURCE_TYPE = 3; + constexpr uint8_t SLOT_VISIBLENESS_TYPE_NUM = 4; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(request); + Parcel parcel; + notification.MarshallingString(parcel); + notification.MarshallingInt32(parcel); + notification.MarshallingInt64(parcel); + notification.MarshallingParcelable(parcel); + notification.Marshalling(parcel); + notification.ReadFromParcelBool(parcel); + notification.ReadFromParcelString(parcel); + notification.ReadFromParcelInt32(parcel); + notification.ReadFromParcelInt64(parcel); + notification.ReadFromParcelParcelable(parcel); + notification.Unmarshalling(parcel); + bool enabled = *data % ENABLE; + notification.SetEnableSound(enabled); + notification.SetEnableLight(enabled); + notification.SetEnableVibration(enabled); + int32_t color = static_cast(GetU32Data(data)); + notification.SetLedLightColor(color); + uint8_t visibleness = *data % SLOT_VISIBLENESS_TYPE_NUM; + Notification::NotificationConstant::VisiblenessType visiblenessType = + Notification::NotificationConstant::VisiblenessType(visibleness); + notification.SetLockScreenVisbleness(visiblenessType); + int64_t time = 2; + notification.SetPostTime(time); + std::vector style; + style.emplace_back(time); + notification.SetVibrationStyle(style); + int32_t remindType = static_cast(*data % SLOT_TYPE_NUM); + Notification::NotificationConstant::RemindType remind = + Notification::NotificationConstant::RemindType(remindType); + notification.SetRemindType(remind); + notification.GenerateNotificationKey(stringData, color, color, stringData, color); + notification.SetRemoveAllowed(enabled); + int32_t source = static_cast(*data % SOURCE_TYPE); + Notification::NotificationConstant::SourceType sourceType = + Notification::NotificationConstant::SourceType(source); + notification.SetSourceType(sourceType); + notification.Dump(); + return notification.ReadFromParcel(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e0617c5e6c8ac7fa0eab50750685cc46c9dfba37 --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H +#define TEST_FUZZTEST_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "readfromparcel_fuzzer" + +#endif // TEST_FUZZTEST_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderhelper_fuzzer/BUILD.gn b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4402544bb1c63403fa6c6df43fb10443ca094aea --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderHelperFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderhelper_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderhelper_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderHelperFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderhelper_fuzzer/corpus/init b/test/fuzztest/reminderhelper_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderhelper_fuzzer/project.xml b/test/fuzztest/reminderhelper_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c3c8cca2231c88708b6dd4fbf1245b78fc91485 --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_helper.h" +#undef private +#undef protected +#include "reminderhelper_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::ReminderRequest reminder; + reminder.SetContent(stringData); + reminder.SetExpiredContent(stringData); + Notification::ReminderHelper::PublishReminder(reminder); + int32_t reminderId = static_cast(*data); + Notification::ReminderHelper::CancelReminder(reminderId); + sptr valid = new Notification::ReminderRequest(); + std::vector> validReminders; + validReminders.emplace_back(valid); + Notification::ReminderHelper::GetValidReminders(validReminders); + Notification::NotificationSlot notificationSlot; + bool enabled = *data % ENABLE; + notificationSlot.SetEnableLight(enabled); + notificationSlot.SetEnableVibration(enabled); + Notification::ReminderHelper::AddNotificationSlot(notificationSlot); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + Notification::ReminderHelper::RemoveNotificationSlot(slotType); + return Notification::ReminderHelper::CancelAllReminders(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f4f5d94b2a8229448aafeed4465938a2b1c69518 --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H +#define TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderhelper_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequest_fuzzer/BUILD.gn b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..122306ed63f2bb0e25371a58c871fd3d485dc7f6 --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderrequest_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequest_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequest_fuzzer/corpus/init b/test/fuzztest/reminderrequest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequest_fuzzer/project.xml b/test/fuzztest/reminderrequest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d6cdaea23b783624056f6f73fafd9a0102dc06e --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -0,0 +1,102 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected +#include "reminderrequest_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t ACTION_BUTTON_TYPE = 3; + constexpr uint8_t COLUMN_TYPE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.CanRemove(); + reminderRequest.CanShow(); + reminderRequest.Dump(); + uint8_t types = *data % ACTION_BUTTON_TYPE; + Notification::ReminderRequest::ActionButtonType type = + Notification::ReminderRequest::ActionButtonType(types); + reminderRequest.SetActionButton(stringData, type); + reminderRequest.SetContent(stringData); + reminderRequest.SetExpiredContent(stringData); + bool enabled = *data % ENABLE; + reminderRequest.SetExpired(enabled); + reminderRequest.InitReminderId(); + reminderRequest.InitUserId(reminderId); + reminderRequest.InitUid(reminderId); + reminderRequest.IsExpired(); + reminderRequest.IsShowing(); + reminderRequest.OnClose(enabled); + reminderRequest.OnDateTimeChange(); + uint64_t oriTriggerTime = 2; + uint64_t optTriggerTimes = 2; + reminderRequest.HandleSysTimeChange(oriTriggerTime, optTriggerTimes); + uint64_t oldZoneTriggerTime = 1; + uint64_t newZoneTriggerTime = 2; + uint64_t optTriggerTime = 3; + reminderRequest.HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, optTriggerTime); + reminderRequest.OnSameNotificationIdCovered(); + reminderRequest.OnShow(enabled, enabled, enabled); + reminderRequest.OnShowFail(); + reminderRequest.OnSnooze(); + reminderRequest.OnStart(); + reminderRequest.OnStop(); + reminderRequest.OnTerminate(); + reminderRequest.OnTimeZoneChange(); + std::shared_ptr resultSet = + std::make_shared(); + uint8_t column = *data % COLUMN_TYPE; + Notification::ReminderRequest::DbRecoveryType columnType = + Notification::ReminderRequest::DbRecoveryType(column); + reminderRequest.RecoverInt64FromDb(resultSet, stringData, columnType); + reminderRequest.RecoverFromDb(resultSet); + reminderRequest.RecoverActionButton(resultSet); + reminderRequest.StringSplit(stringData, stringData); + reminderRequest.RecoverWantAgent(stringData, *data); + std::shared_ptr< Notification::ReminderRequest::MaxScreenAgentInfo> maxScreenWantAgentInfo = + std::make_shared< Notification::ReminderRequest::MaxScreenAgentInfo>(); + reminderRequest.SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); + reminderRequest.SetNotificationId(reminderId); + uint8_t typed = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = + Notification::NotificationConstant::SlotType(typed); + reminderRequest.SetSlotType(slotType); + reminderRequest.SetSnoozeContent(stringData); + return reminderRequest.ShouldShowImmediately(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f6d20f9a0674a862604a75c44f4221927e098134 --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequest_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5648157aaec035e5fcccad7c8e6563ec17bbc7c2 --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestAlarmFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestalarm_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestalarm_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestAlarmFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/project.xml b/test/fuzztest/reminderrequestalarm_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e36cfa81ab41312205f630c7f4c27e41a2ba80b7 --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp @@ -0,0 +1,94 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request_alarm.h" +#undef private +#undef protected +#include "reminderrequestalarm_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t HOUR = 24; + constexpr uint8_t MINUTE = 60; + constexpr uint8_t WEEK = 7; + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + uint8_t hour = *data % HOUR; + uint8_t minute = *data % MINUTE; + uint8_t week = *data % WEEK; + std::vector daysOfWeek; + daysOfWeek.push_back(week); + auto rrc = std::make_shared(hour, minute, daysOfWeek); + // test SetDaysOfWeek function + bool enabled = *data % ENABLE; + rrc->SetDaysOfWeek(enabled, daysOfWeek); + // test GetDaysOfWeek function + rrc->GetDaysOfWeek(); + // test CheckParamValid function + rrc->CheckParamValid(); + // test IsRepeatReminder function + rrc->IsRepeatReminder(); + // test PreGetNextTriggerTimeIgnoreSnooze function + rrc->PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + // test GetNextTriggerTime function + rrc->GetNextTriggerTime(enabled); + // test GetNextAlarm function + time_t now; + (void)time(&now); // unit is seconds. + time_t target = *data % ENABLE; + rrc->GetNextAlarm(now, target); + // test IsRepeatDay function + int32_t day = static_cast(GetU32Data(data)); + rrc->IsRepeatDay(day); + // test GetHour function + rrc->GetHour(); + // test GetMinute function + rrc->GetMinute(); + // test GetRepeatDay function + rrc->GetRepeatDay(); + // test OnDateTimeChange function + rrc->OnDateTimeChange(); + // test OnTimeZoneChange function + rrc->OnTimeZoneChange(); + // test UpdateNextReminder function + rrc->UpdateNextReminder(); + // test Unmarshalling function + Parcel parcel; + rrc->Unmarshalling(parcel); + rrc->ReadFromParcel(parcel); + // test RecoverFromDb function + std::shared_ptr resultSet = + std::make_shared(); + rrc->RecoverFromDb(resultSet); + return rrc->Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3b5e31f1808d63fe05e29b3c84b1c0dbe7b9ec5e --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestalarm_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1e4aae33126c7274ec590f42cce6b840c2558a93 --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestannex_fuzzer/corpus/init b/test/fuzztest/reminderrequestannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannex_fuzzer/project.xml b/test/fuzztest/reminderrequestannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87483032c9c954d10d5e42b8bab8cb020d360cdc --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp @@ -0,0 +1,86 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected +#include "reminderrequestannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.SetSnoozeTimes(*data); + reminderRequest.SetSnoozeTimesDynamic(*data); + uint64_t timeIntervalInSeconds = 1; + reminderRequest.SetTimeInterval(timeIntervalInSeconds); + reminderRequest.SetTitle(stringData); + reminderRequest.SetTriggerTimeInMilli(timeIntervalInSeconds); + std::shared_ptr< Notification::ReminderRequest::WantAgentInfo> wantAgentInfo = + std::make_shared< Notification::ReminderRequest::WantAgentInfo>(); + reminderRequest.SetWantAgentInfo(wantAgentInfo); + reminderRequest.ShouldShowImmediately(); + reminderRequest.GetActionButtons(); + reminderRequest.GetContent(); + reminderRequest.GetExpiredContent(); + reminderRequest.GetMaxScreenWantAgentInfo(); + reminderRequest.GetNotificationId(); + reminderRequest.GetNotificationRequest(); + reminderRequest.GetReminderId(); + reminderRequest.GetReminderTimeInMilli(); + reminderRequest.SetReminderId(reminderId); + reminderRequest.SetReminderTimeInMilli(timeIntervalInSeconds); + uint64_t ringDurationInSeconds = 0; + reminderRequest.SetRingDuration(ringDurationInSeconds); + reminderRequest.GetSlotType(); + reminderRequest.GetSnoozeContent(); + reminderRequest.GetSnoozeTimes(); + reminderRequest.GetSnoozeTimesDynamic(); + reminderRequest.GetState(); + reminderRequest.GetTimeInterval(); + reminderRequest.GetTriggerTimeInMilli(); + reminderRequest.GetUserId(); + reminderRequest.GetUid(); + reminderRequest.GetWantAgentInfo(); + reminderRequest.GetReminderType(); + reminderRequest.GetRingDuration(); + reminderRequest.UpdateNextReminder(); + reminderRequest.SetNextTriggerTime(); + Parcel parcel; + reminderRequest.Marshalling(parcel); + reminderRequest.Unmarshalling(parcel); + reminderRequest.ReadFromParcel(parcel); + reminderRequest.InitNotificationRequest(); + reminderRequest.InitServerObj(); + return reminderRequest.IsAlerting(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8dd7714cfbcd9b10a5fa067bf47dc101f9ab64f1 --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcontinuate_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bea9b9743fbf4b2a297d558da2a2b77ed4999a56 --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestAnnexThreeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestannexthree_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestannexthree_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestAnnexThreeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml b/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e0a45d9de28f8cf6a37b5a349a9d09d4af5a5d6 --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected +#include "reminderrequestannexthree_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.GetTitle(); + uint64_t showTime = 2; + reminderRequest.ReminderRequest::GetShowTime(showTime); + Notification::ReminderRequest::TimeTransferType type = Notification::ReminderRequest::TimeTransferType::YEAR; + int32_t cTime = static_cast(GetU32Data(data)); + reminderRequest.GetActualTime(type, cTime); + reminderRequest.GetCTime(type, cTime); + int32_t uid = static_cast(GetU32Data(data)); + reminderRequest.GetUserId(uid); + return reminderRequest.IsAlerting(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..cee6c1ae2813b77b82d037da7247cf04c48fd20c --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestannexthree_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..645f134620e2ec90bffa44af2d08ddbcb8b2a8e4 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestCalendarFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestcalendar_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestcalendar_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestCalendarFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml b/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9b914de28dc6d2b3762cd304c03ccb61ea03ed8 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request_calendar.h" +#undef private +#undef protected +#include "reminderrequestcalendar_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t MONTHS = 12; + constexpr uint8_t DAYS = 31; + constexpr uint16_t YEAR = 365; + constexpr uint16_t HOURS = 24; + constexpr uint16_t MINUTES = 60; + constexpr uint16_t SECONDS = 60; + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + struct tm nowTime; + uint8_t months = *data % MONTHS; + uint8_t days = *data % DAYS; + std::vector repeatMonths; + std::vector repeatDays; + repeatMonths.push_back(months); + repeatDays.push_back(days); + Notification::ReminderRequestCalendar reminderRequestCalendar(nowTime, repeatMonths, repeatDays); + // test SetNextTriggerTime function + reminderRequestCalendar.SetNextTriggerTime(); + // test InitDateTime function + reminderRequestCalendar.InitDateTime(); + // test InitDateTime function + reminderRequestCalendar.InitDateTime(nowTime); + // test SetDay function + bool enabled = *data % ENABLE; + reminderRequestCalendar.SetDay(days, enabled); + // test SetMonth function + reminderRequestCalendar.SetMonth(months, enabled); + // test SetRepeatMonths function + reminderRequestCalendar.SetRepeatMonths(repeatMonths); + // test SetRepeatDaysOfMonth function + reminderRequestCalendar.SetRepeatDaysOfMonth(repeatDays); + // test GetRepeatMonths function + reminderRequestCalendar.GetRepeatMonths(); + // test GetRepeatDays function + reminderRequestCalendar.GetRepeatDays(); + // test GetDaysOfMonth function + uint16_t year = *data % YEAR; + reminderRequestCalendar.GetDaysOfMonth(year, months); + // test GetNextDay function + struct tm target; + reminderRequestCalendar.GetNextDay(year, months, nowTime, target); + // test GetNextTriggerTime function + reminderRequestCalendar.GetNextTriggerTime(); + // test GetNextTriggerTimeAsRepeatReminder function + struct tm tarTime; + reminderRequestCalendar.GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime); + // test GetTimeInstantMilli function + uint8_t hour = *data % HOURS; + uint8_t minute = *data % MINUTES; + uint8_t second = *data % SECONDS; + reminderRequestCalendar.GetTimeInstantMilli(year, months, days, hour, minute, second); + // test IsRepeatReminder function + reminderRequestCalendar.IsRepeatReminder(); + // test IsRepeatMonth function + reminderRequestCalendar.IsRepeatMonth(months); + // test IsRepeatDay function + reminderRequestCalendar.IsRepeatDay(days); + // test OnDateTimeChange function + reminderRequestCalendar.OnDateTimeChange(); + // test OnTimeZoneChange function + reminderRequestCalendar.OnTimeZoneChange(); + // test UpdateNextReminder function + reminderRequestCalendar.UpdateNextReminder(); + // test PreGetNextTriggerTimeIgnoreSnooze function + reminderRequestCalendar.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + // test RecoverFromDb function + std::shared_ptr resultSet = + std::make_shared(); + reminderRequestCalendar.RecoverFromDb(resultSet); + // test Unmarshalling function + Parcel parcel; + reminderRequestCalendar.Unmarshalling(parcel); + reminderRequestCalendar.ReadFromParcel(parcel); + return reminderRequestCalendar.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..12064cc9305b6533f2d8898acece727ff5848de0 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcalendar_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..434728b57feceb3704b00128bbd572b9e109b3f9 --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestContinuateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestcontinuate_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestcontinuate_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestContinuateFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init b/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml b/test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef2550eac54179828c15efeb5baad5d4b73a93aa --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected +#include "reminderrequestcontinuate_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.GetButtonInfo(); + return reminderRequest.GetUid(reminderId, stringData); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1f4efe2d809f71f44e7df67d2ae0c2706915fc41 --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcontinuate_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3707f52fd553ca82ada6a2f6b611dca327e92901 --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestTimerFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequesttimer_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequesttimer_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestTimerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/project.xml b/test/fuzztest/reminderrequesttimer_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ede3ee51c5a8a95dec04d569cb8bc188f35360b --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_request_timer.h" +#undef private +#undef protected +#include "reminderrequesttimer_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + uint64_t countDownTimeInSeconds = 0; + std::string stringData(data); + Notification::ReminderRequestTimer reminderRequestTimer(countDownTimeInSeconds); + reminderRequestTimer.GetInitInfo(); + bool enabled = *data % ENABLE; + reminderRequestTimer.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + reminderRequestTimer.OnDateTimeChange(); + reminderRequestTimer.OnTimeZoneChange(); + reminderRequestTimer.UpdateNextReminder(); + reminderRequestTimer.CheckParamsValid(countDownTimeInSeconds); + reminderRequestTimer.UpdateTimeInfo(stringData); + Parcel parcel; + reminderRequestTimer.Unmarshalling(parcel); + reminderRequestTimer.Marshalling(parcel); + return reminderRequestTimer.ReadFromParcel(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..57e21d8da55154c46553f8f8639a40b05f2a47e5 --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequesttimer_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstore_fuzzer/BUILD.gn b/test/fuzztest/reminderstore_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b65769865f5627138de0b1753ad9475c61a82e38 --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstore_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderstore_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstore_fuzzer/corpus/init b/test/fuzztest/reminderstore_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderstore_fuzzer/project.xml b/test/fuzztest/reminderstore_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc42c3047878a175aefcd149e1560ec8c56bfbae --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminderstore_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::ReminderStore reminderStore; + int32_t oldVersion = static_cast(GetU32Data(data)); + reminderStore.Init(); + reminderStore.InitData(); + reminderStore.Delete(oldVersion); + reminderStore.DeleteUser(oldVersion); + reminderStore.Delete(stringData, oldVersion); + return reminderStore.Delete(stringData); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..80cc11dea78a573e7fcc746871344666867a2689 --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstore_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..edfc9cfd48a137c368d269c134e59e76860763c6 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstoreannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderstoreannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstoreannex_fuzzer/corpus/init b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderstoreannex_fuzzer/project.xml b/test/fuzztest/reminderstoreannex_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99e1ef7c0ca4c8415c27febb18b23549e23892b0 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminderstoreannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::ReminderStore reminderStore; + // test GetReminders function + std::string queryCondition(data); + reminderStore.GetReminders(queryCondition); + // test GetAllValidReminders function + reminderStore.GetAllValidReminders(); + // test Query function + reminderStore.Query(queryCondition); + // test GetBundleOption function + sptr bundleOption; + int32_t reminderId = static_cast(GetU32Data(data)); + reminderStore.GetBundleOption(reminderId, bundleOption); + // test GetInt32Val function + std::shared_ptr resultSet = std::make_shared(); + std::string name(data); + int32_t value = static_cast(GetU32Data(data)); + reminderStore.GetInt32Val(resultSet, name, value); + std::string value1(data); + reminderStore.GetStringVal(resultSet, name, value1); + // test BuildReminder function + reminderStore.BuildReminder(resultSet); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..590bc3f13a328bef7fab98df62736c25fb6fc7e1 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstoreannex_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp b/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp index 31fe973f1db869b479ff88bbdf4b1d25a5a0f864..5740274d457b9e5b3fd9dc3c7594ba63ce0cfb4b 100644 --- a/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp +++ b/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp @@ -37,7 +37,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp index 2ba0e8a3cc28649a675dd68ca6c72ed5fdbf0785..74d4ad5bc9d0de35f15a77f2ad8ece37c1cafe41 100644 --- a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp +++ b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp @@ -21,7 +21,8 @@ namespace OHOS { { // test RequestEnableNotification function std::string deviceId(data); - Notification::NotificationHelper::RequestEnableNotification(deviceId); + bool needPop = true; + Notification::NotificationHelper::RequestEnableNotification(deviceId, needPop); // test AreNotificationsSuspended function bool suspended = true; Notification::NotificationHelper::AreNotificationsSuspended(suspended); diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp index b02ccad339c6cbe906aac29992a1f6008411f233..11cc5836b2734e9a1f26a6972bfb6aa7e9d1b892 100644 --- a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp @@ -47,7 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/setprogressbar_fuzzer/BUILD.gn b/test/fuzztest/setprogressbar_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c22dfc560c0e2e248e4c0303263d2ef94329651c --- /dev/null +++ b/test/fuzztest/setprogressbar_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("SetProgressBarFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/setprogressbar_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setprogressbar_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SetProgressBarFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/setprogressbar_fuzzer/corpus/init b/test/fuzztest/setprogressbar_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/setprogressbar_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/setprogressbar_fuzzer/project.xml b/test/fuzztest/setprogressbar_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/setprogressbar_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.cpp b/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82067d5e231c6d1ba582203629eaa5c710ecf60e --- /dev/null +++ b/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * 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 "setprogressbar_fuzzer.h" +#include "notification_request.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t notificationId = static_cast(GetU32Data(data)); + Notification::NotificationRequest request(notificationId); + bool enabled = *data % ENABLE; + request.SetIsAgentNotification(enabled); + std::shared_ptr messageUser = nullptr; + request.AddMessageUser(messageUser); + request.IsAlertOneTime(); + uint64_t deletedTime = 1; + request.SetAutoDeletedTime(deletedTime); + request.GetAutoDeletedTime(); + std::shared_ptr icon = nullptr; + request.SetLittleIcon(icon); + request.SetBigIcon(icon); + request.GetClassification(); + request.GetColor(); + request.IsColorEnabled(); + request.IsCountdownTimer(); + request.GetGroupAlertType(); + request.IsGroupOverview(); + request.GetGroupName(); + request.IsOnlyLocal(); + request.SetOnlyLocal(enabled); + request.SetSettingsText(stringData); + request.GetSettingsText(); + request.GetCreateTime(); + request.IsShowStopwatch(); + request.SetShowStopwatch(enabled); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + request.SetSlotType(slotType); + request.GetSlotType(); + request.SetSortingKey(stringData); + request.GetSortingKey(); + request.SetStatusBarText(stringData); + request.GetStatusBarText(); + return request.IsTapDismissed(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.h b/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..235d8b114633fd645da610866305fa3dfc14084d --- /dev/null +++ b/test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_SETPROGRESSBAR_FUZZER_SETPROGRESSBAR_FUZZER_H +#define TEST_FUZZTEST_SETPROGRESSBAR_FUZZER_SETPROGRESSBAR_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "setprogressbar_fuzzer" + +#endif // TEST_FUZZTEST_SETPROGRESSBAR_FUZZER_SETPROGRESSBAR_FUZZER_H diff --git a/test/fuzztest/settemplate_fuzzer/BUILD.gn b/test/fuzztest/settemplate_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..831a6a8e1a66d03c1c028ac0cbe308cd2caf6984 --- /dev/null +++ b/test/fuzztest/settemplate_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("SetTemplateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/settemplate_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "settemplate_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SetTemplateFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/settemplate_fuzzer/corpus/init b/test/fuzztest/settemplate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/settemplate_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/settemplate_fuzzer/project.xml b/test/fuzztest/settemplate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/settemplate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.cpp b/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d280ccb2f69e0839e44a93b60c820976d417b832 --- /dev/null +++ b/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.cpp @@ -0,0 +1,98 @@ +/* + * 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 "settemplate_fuzzer.h" +#define private public +#define protected public +#include "notification_request.h" +#undef private +#undef protected + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t VISIBLENESS_TYPE_NUM = 4; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t notificationId = static_cast(GetU32Data(data)); + Notification::NotificationRequest request(notificationId); + bool enabled = *data % ENABLE; + request.SetTapDismissed(enabled); + uint8_t type = *data % VISIBLENESS_TYPE_NUM; + Notification::NotificationConstant::VisiblenessType VisiblenessType = + Notification::NotificationConstant::VisiblenessType(type); + request.SetVisibleness(VisiblenessType); + request.GetVisibleness(); + request.GetBadgeIconStyle(); + request.SetShortcutId(stringData); + request.GetShortcutId(); + request.SetFloatingIcon(enabled); + request.IsFloatingIcon(); + request.SetProgressBar(notificationId, notificationId, enabled); + request.GetProgressMax(); + request.GetProgressValue(); + request.IsProgressIndeterminate(); + std::vector text; + text.emplace_back(stringData); + request.SetNotificationUserInputHistory(text); + request.GetNotificationUserInputHistory(); + std::shared_ptr other = nullptr; + request.SetPublicNotification(other); + request.GetPublicNotification(); + request.GetNotificationHashCode(); + request.GetOwnerBundleName(); + request.GetCreatorBundleName(); + request.GetCreatorPid(); + request.SetCreatorUid(notificationId); + request.GetCreatorUid(); + request.SetOwnerUid(notificationId); + request.GetOwnerUid(); + request.GetLabel(); + request.SetDistributed(enabled); + request.SetDevicesSupportDisplay(text); + request.SetDevicesSupportOperate(text); + request.GetNotificationDistributedOptions(); + request.SetCreatorUserId(notificationId); + request.GetCreatorUserId(); + request.SetOwnerUserId(notificationId); + request.GetOwnerUserId(); + request.GetNowSysTime(); + std::shared_ptr templ = + std::make_shared(); + if (templ != nullptr) { + templ->SetTemplateName(stringData); + } + request.SetTemplate(templ); + request.GetTemplate(); + request.GetFlags(); + request.SetReceiverUserId(notificationId); + return request.GetReceiverUserId(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.h b/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5259411d41e7dd1a308894d93ada0b0997c2e076 --- /dev/null +++ b/test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef TEST_FUZZTEST_SETTEMPLATE_FUZZER_SETTEMPLATE_FUZZER_H +#define TEST_FUZZTEST_SETTEMPLATE_FUZZER_SETTEMPLATE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "settemplate_fuzzer" + +#endif // TEST_FUZZTEST_SETTEMPLATE_FUZZER_SETTEMPLATE_FUZZER_H diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index 0906e4684375359167dbf75cd086f383e234fccb..1d4b04f71e30f1beeadfbc67a961bb49344c0f5f 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -244,7 +244,6 @@ void NotificationShellCommand::CheckDumpOpt() ErrCode NotificationShellCommand::RunAsSettingCommand() { - std::vector infos; int option = getopt_long(argc_, argv_, SETTING_SHORT_OPTIONS, SETTING_LONG_OPTIONS, nullptr); if (option == '?') { if (optopt == 'c') { @@ -264,6 +263,7 @@ ErrCode NotificationShellCommand::RunAsSettingCommand() resultReceiver_.append(SETTING_HELP_MSG); return ERR_INVALID_VALUE; } + std::vector infos; std::string cmd = COMMAND_SET_RECENT_COUNT; cmd.append(" ").append(std::string(optarg)); return RunDumpCmd(cmd, "", SUBSCRIBE_USER_INIT, infos);