diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 3a0baca5d00cb36570767f655b697870b351be62..a952eb31cfbbdb4874d79eaaa7b22c2f832b2531 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -32,9 +32,24 @@ 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/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..ff5eedb5ef0a72ff303ebd0f8580b7dfef2bba11 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -0,0 +1,1054 @@ +/* + * 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; + ErrCode ret = notificationHelper.RequestEnableNotification(deviceId); + EXPECT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); +} + +/** + * @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_OK); +} + +/** + * @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/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/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/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..074baef984bd4de7e1e5743f57991011105492bb 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", 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/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 68642259b719f1ae390723123ab5b3e302e9bb93..67206e20bb13c30c05ba3a44b331a129902c85c0 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -593,7 +593,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/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/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 881d5dddea2008f8a6ac7a141a880b1aa3eb0645..971858661da736fa8bde337374847055f6a451f8 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2250,7 +2250,7 @@ ErrCode AdvancedNotificationService::RemoveNotification(const sptrbundleOption->GetBundleName() == bundle->GetBundleName()) && - (record->bundleOption->GetUid() == bundleOption->GetUid()) && + (record->bundleOption->GetUid() == bundle->GetUid()) && #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED (record->deviceId.empty()) && #endif diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index e0aba8c89a6574cde5641594dbc436571b42198a..505ffe42b95c636e9c14f5f23bc10ebd15dd2846 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1744,7 +1744,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 +1753,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 +1766,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); } /** 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/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d6e02cf41a0273d34b723e517471b88edcce209b..d5fc03f35e6f7bbccee99c36afe3b18c14da3411 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -28,13 +28,31 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "notification_fuzzer:NotificationFuzzTest", + "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", + "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", + "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", + "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", + "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", + "notificationrequest_fuzzer:NotificationRequestFuzzTest", + "notificationsorting_fuzzer:NotificationSortingFuzzTest", + "notificationsortingmap_fuzzer:NotificationSortingMapFuzzTest", + "notificationsubscribeInfo_fuzzer:NotificationSubscribeInfoFuzzTest", + "notificationtemplate_fuzzer:NotificationTemplateFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", + "readfromparcel_fuzzer:ReadFromParcelFuzzTest", + "reminderrequest_fuzzer:ReminderRequestFuzzTest", + "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "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/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/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..d843842862f1fcce6b8047aff1617ce29a23c5b4 --- /dev/null +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_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 "notification_conversational_content.h" +#undef private +#undef protected +#include "notificationconversationalcontent_fuzzer.h" + +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()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + 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/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..8641146ba7789768d3eb613323a6f2659b8cbb10 --- /dev/null +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_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_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); + 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/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/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/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/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/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/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/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/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/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/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/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/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