From 3d301c903f9c9e65d31a921f2dec45d98c647115 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Tue, 18 Oct 2022 14:36:19 +0800 Subject: [PATCH 01/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5WBBH?= =?UTF-8?q?=20Description:ans=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90=E5=8D=87?= =?UTF-8?q?04=20Sig:SIG=5FApplicationFramework=20Feature=20or=20Bugfix:Bug?= =?UTF-8?q?fix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: I35a1ed1244cfe0f9d7e55e15bab1b0e60bad1cc7 --- frameworks/ans/test/unittest/BUILD.gn | 7 + .../notification_do_not_disturb_date_test.cpp | 158 ++++++++++++++++++ .../test/unittest/notification_flags_test.cpp | 137 +++++++++++++++ .../notification_long_text_content_test.cpp | 110 ++++++++++++ .../notification_media_content_test.cpp | 139 +++++++++++++++ .../notification_multiline_content_test.cpp | 153 +++++++++++++++++ .../notification_picture_content_test.cpp | 153 +++++++++++++++++ .../unittest/notification_template_test.cpp | 123 ++++++++++++++ 8 files changed, 980 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_do_not_disturb_date_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_flags_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_long_text_content_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_media_content_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_multiline_content_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_picture_content_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_template_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 3a0baca5d..309ae7792 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -34,7 +34,14 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/enabled_notification_callback_data_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_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_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_template_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_do_not_disturb_date_test.cpp b/frameworks/ans/test/unittest/notification_do_not_disturb_date_test.cpp new file mode 100644 index 000000000..c254f89eb --- /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 000000000..165ee044e --- /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_long_text_content_test.cpp b/frameworks/ans/test/unittest/notification_long_text_content_test.cpp new file mode 100644 index 000000000..d4285a781 --- /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 000000000..3929d6b14 --- /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 000000000..f786ab778 --- /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 000000000..eb7ab773e --- /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_template_test.cpp b/frameworks/ans/test/unittest/notification_template_test.cpp new file mode 100644 index 000000000..8a35029cb --- /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 -- Gitee From 811f6fbaad1ed39901ee99fc8a7fa418b94b687a Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 18 Oct 2022 18:47:23 +0800 Subject: [PATCH 02/44] fixed 7c49cc2 from https://gitee.com/fangJinliang1/notification_ans_standard/pulls/635 depend timeout modify Signed-off-by: fangJinliang1 Change-Id: Ic6b8174abde78e8a239a3cc52110d01dfd7e55a1 --- sa_profile/3203.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sa_profile/3203.xml b/sa_profile/3203.xml index 6b23aaf57..0e657d648 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 -- Gitee From be88a2ad433a9319790ef15c0110a113d0060125 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 12 Oct 2022 19:36:05 +0800 Subject: [PATCH 03/44] callback set nullptr when return success Signed-off-by: fangJinliang1 Change-Id: I5bccf8e70f51c669bad6720a87fd50f76c871e93 Signed-off-by: fangJinliang1 --- frameworks/js/napi/include/common.h | 10 +++--- frameworks/js/napi/src/common.cpp | 31 +++++++++++-------- frameworks/js/napi/src/manager/BUILD.gn | 1 + frameworks/js/napi/src/reminder/publish.cpp | 2 +- .../ans/src/advanced_notification_service.cpp | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 621f0ecb4..66ad69644 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/src/common.cpp b/frameworks/js/napi/src/common.cpp index ab665789b..e6fe747c0 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/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 4ccde131a..be9ad9625 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/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 428c7d21a..4c4fb9179 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -226,7 +226,7 @@ napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn, cons { if (callbackIn) { NotificationNapi::Common::SetCallback(env, callbackIn, NotificationNapi::ERROR, - result); + result, false); } return NotificationNapi::Common::JSParaError(env, callbackIn); } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 40eba448f..ae03c8081 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2277,7 +2277,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 -- Gitee From 7da6fd16a886e3468b4973a288a516236931c37c Mon Sep 17 00:00:00 2001 From: FangJinliang Date: Tue, 18 Oct 2022 11:41:15 +0000 Subject: [PATCH 04/44] update frameworks/js/napi/src/reminder/publish.cpp. Signed-off-by: FangJinliang --- frameworks/js/napi/src/reminder/publish.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 95b0d1372..1d46fd682 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -260,7 +260,7 @@ napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn, cons } if (callbackIn) { ReminderCommon::SetCallback(env, callbackIn, ERR_REMINDER_INVALID_PARAM, - result, false); + result); } return ReminderCommon::JSParaError(env, callbackIn); } -- Gitee From 7a7274666f99a0ab0c287ed3d9428edd68f59460 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Wed, 19 Oct 2022 11:13:08 +0800 Subject: [PATCH 05/44] add notification request fuzz Signed-off-by: liuyanzhi Change-Id: I06f15a723da08e2582252315eaa7c76f6d4aeb0c --- test/fuzztest/BUILD.gn | 3 + .../notificationrequest_fuzzer/BUILD.gn | 55 +++++++++++ .../notificationrequest_fuzzer/corpus/init | 13 +++ .../notificationrequest_fuzzer.cpp | 83 ++++++++++++++++ .../notificationrequest_fuzzer.h | 23 +++++ .../notificationrequest_fuzzer/project.xml | 25 +++++ test/fuzztest/setprogressbar_fuzzer/BUILD.gn | 54 ++++++++++ .../setprogressbar_fuzzer/corpus/init | 13 +++ .../setprogressbar_fuzzer/project.xml | 25 +++++ .../setprogressbar_fuzzer.cpp | 77 +++++++++++++++ .../setprogressbar_fuzzer.h | 23 +++++ test/fuzztest/settemplate_fuzzer/BUILD.gn | 54 ++++++++++ test/fuzztest/settemplate_fuzzer/corpus/init | 13 +++ test/fuzztest/settemplate_fuzzer/project.xml | 25 +++++ .../settemplate_fuzzer/settemplate_fuzzer.cpp | 98 +++++++++++++++++++ .../settemplate_fuzzer/settemplate_fuzzer.h | 23 +++++ 16 files changed, 607 insertions(+) create mode 100644 test/fuzztest/notificationrequest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationrequest_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp create mode 100644 test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.h create mode 100644 test/fuzztest/notificationrequest_fuzzer/project.xml create mode 100644 test/fuzztest/setprogressbar_fuzzer/BUILD.gn create mode 100644 test/fuzztest/setprogressbar_fuzzer/corpus/init create mode 100644 test/fuzztest/setprogressbar_fuzzer/project.xml create mode 100644 test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.cpp create mode 100644 test/fuzztest/setprogressbar_fuzzer/setprogressbar_fuzzer.h create mode 100644 test/fuzztest/settemplate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/settemplate_fuzzer/corpus/init create mode 100644 test/fuzztest/settemplate_fuzzer/project.xml create mode 100644 test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.cpp create mode 100644 test/fuzztest/settemplate_fuzzer/settemplate_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d6e02cf41..29b780aba 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -28,6 +28,7 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "notificationrequest_fuzzer:NotificationRequestFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", @@ -36,5 +37,7 @@ group("fuzztest") { "setdonotdisturbdate_fuzzer:SetDoNotDisturbDateFuzzTest", "setnotificationbadgenum_fuzzer:SetNotificationBadgeNumFuzzTest", "setnotificationsenabledforallbundles_fuzzer:SetNotificationsEnabledForAllBundlesFuzzTest", + "setprogressbar_fuzzer:SetProgressBarFuzzTest", + "settemplate_fuzzer:SetTemplateFuzzTest", ] } diff --git a/test/fuzztest/notificationrequest_fuzzer/BUILD.gn b/test/fuzztest/notificationrequest_fuzzer/BUILD.gn new file mode 100644 index 000000000..ce301ebe1 --- /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 000000000..1b910144f --- /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 000000000..4c4d88955 --- /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 000000000..820fab9ac --- /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 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationrequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setprogressbar_fuzzer/BUILD.gn b/test/fuzztest/setprogressbar_fuzzer/BUILD.gn new file mode 100644 index 000000000..c22dfc560 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..82067d5e2 --- /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 000000000..235d8b114 --- /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 000000000..831a6a8e1 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..d280ccb2f --- /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 000000000..5259411d4 --- /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 -- Gitee From c26337d6d468d0ac796e6a211f9ed9b6f7da5992 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Thu, 20 Oct 2022 16:21:23 +0800 Subject: [PATCH 06/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5WRQ2?= =?UTF-8?q?=20Description:ans=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90=E5=8D=87?= =?UTF-8?q?05=20Sig:SIG=5FApplicationFramework=20Feature=20or=20Bugfix:Bug?= =?UTF-8?q?fix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: Idb7e9d1c9507812bc01e24d3afc2ac56f5f9fb4f --- frameworks/ans/test/unittest/BUILD.gn | 4 + .../notification_bundle_option_test.cpp | 135 +++ .../unittest/notification_helper_test.cpp | 1054 +++++++++++++++++ .../notification_subscribe_info_test.cpp | 132 +++ .../test/unittest/reminder_helper_test.cpp | 121 ++ 5 files changed, 1446 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_bundle_option_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_helper_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_subscribe_info_test.cpp create mode 100644 frameworks/ans/test/unittest/reminder_helper_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 309ae7792..cd52aea69 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -32,16 +32,20 @@ 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_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_subscribe_info_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_template_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 000000000..da271a3f6 --- /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_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp new file mode 100644 index 000000000..d369a109a --- /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_INVALID_BUNDLE); +} + +/** + * @tc.name: AreNotificationsSuspended_00001 + * @tc.desc: Test AreNotificationsSuspended parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, AreNotificationsSuspended_00001, Function | SmallTest | Level1) +{ + bool suspended = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.AreNotificationsSuspended(suspended); + EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); +} + +/** + * @tc.name: HasNotificationPolicyAccessPermission_00001 + * @tc.desc: Test HasNotificationPolicyAccessPermission parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, HasNotificationPolicyAccessPermission_00001, Function | SmallTest | Level1) +{ + bool hasPermission = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.HasNotificationPolicyAccessPermission(hasPermission); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetBundleImportance_00001 + * @tc.desc: Test GetBundleImportance parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetBundleImportance_00001, Function | SmallTest | Level1) +{ + NotificationSlot::NotificationLevel importance = NotificationSlot::NotificationLevel::LEVEL_NONE; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetBundleImportance(importance); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveNotification_00001 + * @tc.desc: Test RemoveNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotification_00001, Function | SmallTest | Level1) +{ + std::string key = "Key"; + int32_t removeReason = 2; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotification(key, removeReason); + EXPECT_EQ(ret, (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); +} + +/** + * @tc.name: RemoveNotification_00002 + * @tc.desc: Test RemoveNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotification_00002, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + int32_t notificationId = 10; + std::string label = "Label"; + int32_t removeReason = 2; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotification(bundleOption, notificationId, label, removeReason); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveAllNotifications_00001 + * @tc.desc: Test RemoveAllNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveAllNotifications_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveAllNotifications(bundleOption); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveNotificationsByBundle_00001 + * @tc.desc: Test RemoveNotificationsByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotificationsByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotificationsByBundle(bundleOption); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: RemoveNotifications_00001 + * @tc.desc: Test RemoveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveNotifications_00001, Function | SmallTest | Level1) +{ + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveNotifications(); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetNotificationSlotsForBundle_00001 + * @tc.desc: Test GetNotificationSlotsForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetNotificationSlotsForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::vector> slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetNotificationSlotsForBundle(bundleOption, slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: UpdateNotificationSlots_00001 + * @tc.desc: Test UpdateNotificationSlots parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, UpdateNotificationSlots_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::vector> slots; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.UpdateNotificationSlots(bundleOption, slots); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetAllActiveNotifications_00001 + * @tc.desc: Test GetAllActiveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetAllActiveNotifications_00001, Function | SmallTest | Level1) +{ + std::vector> notification; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetAllActiveNotifications(notification); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: GetAllActiveNotifications_00002 + * @tc.desc: Test GetAllActiveNotifications parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetAllActiveNotifications_00002, Function | SmallTest | Level1) +{ + std::vector key; + std::vector> notification; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetAllActiveNotifications(key, notification); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: IsAllowedNotify_00002 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00002, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(bundleOption, allowed); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetNotificationsEnabledForAllBundles_00001 + * @tc.desc: Test SetNotificationsEnabledForAllBundles parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetNotificationsEnabledForAllBundles_00001, Function | SmallTest | Level1) +{ + std::string deviceId = "DeviceId"; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetNotificationsEnabledForAllBundles(deviceId, enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: SetShowBadgeEnabledForBundle_00001 + * @tc.desc: Test SetShowBadgeEnabledForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetShowBadgeEnabledForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetShowBadgeEnabledForBundle_00001 + * @tc.desc: Test GetShowBadgeEnabledForBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetShowBadgeEnabledForBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: GetShowBadgeEnabled_00001 + * @tc.desc: Test GetShowBadgeEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetShowBadgeEnabled_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetShowBadgeEnabled(enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: CancelGroup_00001 + * @tc.desc: Test CancelGroup parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelGroup_00001, Function | SmallTest | Level1) +{ + std::string groupName = "GroupName"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelGroup(groupName); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: RemoveGroupByBundle_00001 + * @tc.desc: Test RemoveGroupByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, RemoveGroupByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + std::string groupName = "GroupName"; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.RemoveGroupByBundle(bundleOption, groupName); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: SetDoNotDisturbDate_00001 + * @tc.desc: Test SetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, SetDoNotDisturbDate_00001, Function | SmallTest | Level1) +{ + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.SetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetDoNotDisturbDate_00001 + * @tc.desc: Test GetDoNotDisturbDate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetDoNotDisturbDate_00001, Function | SmallTest | Level1) +{ + NotificationDoNotDisturbDate doNotDisturbDate; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetDoNotDisturbDate(doNotDisturbDate); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: DoesSupportDoNotDisturbMode_00001 + * @tc.desc: Test DoesSupportDoNotDisturbMode parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, DoesSupportDoNotDisturbMode_00001, Function | SmallTest | Level1) +{ + bool doesSupport = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.DoesSupportDoNotDisturbMode(doesSupport); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsDistributedEnabled_00001 + * @tc.desc: Test IsDistributedEnabled parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsDistributedEnabled_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsDistributedEnabled(enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: EnableDistributed_00001 + * @tc.desc: Test EnableDistributed parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributed_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributed(enabled); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: EnableDistributedByBundle_00001 + * @tc.desc: Test EnableDistributedByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributedByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributedByBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: EnableDistributedSelf_00001 + * @tc.desc: Test EnableDistributedSelf parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, EnableDistributedSelf_00001, Function | SmallTest | Level1) +{ + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.EnableDistributedSelf(enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: IsDistributedEnableByBundle_00001 + * @tc.desc: Test IsDistributedEnableByBundle parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsDistributedEnableByBundle_00001, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOption; + bool enabled = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsDistributedEnableByBundle(bundleOption, enabled); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); +} + +/** + * @tc.name: GetDeviceRemindType_00001 + * @tc.desc: Test GetDeviceRemindType parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, GetDeviceRemindType_00001, Function | SmallTest | Level1) +{ + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.GetDeviceRemindType(remindType); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: PublishContinuousTaskNotification_00001 + * @tc.desc: Test PublishContinuousTaskNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, PublishContinuousTaskNotification_00001, Function | SmallTest | Level1) +{ + NotificationRequest request; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.PublishContinuousTaskNotification(request); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.name: CancelContinuousTaskNotification_00001 + * @tc.desc: Test CancelContinuousTaskNotification parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, CancelContinuousTaskNotification_00001, Function | SmallTest | Level1) +{ + std::string label = "label"; + int32_t notificationId = 10; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.CancelContinuousTaskNotification(label, notificationId); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsSupportTemplate_00001 + * @tc.desc: Test IsSupportTemplate parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsSupportTemplate_00001, Function | SmallTest | Level1) +{ + std::string templateName = "TemplateName"; + bool support = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsSupportTemplate(templateName, support); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: IsAllowedNotify_00003 + * @tc.desc: Test IsAllowedNotify parameters. + * @tc.type: FUNC + * @tc.require: issueI5WRQ2 + */ +HWTEST_F(NotificationHelperTest, IsAllowedNotify_00003, Function | SmallTest | Level1) +{ + int32_t userId = 10; + bool allowed = true; + NotificationHelper notificationHelper; + ErrCode ret = notificationHelper.IsAllowedNotify(userId, allowed); + EXPECT_EQ(ret, (int)ERR_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_subscribe_info_test.cpp b/frameworks/ans/test/unittest/notification_subscribe_info_test.cpp new file mode 100644 index 000000000..67124ee7d --- /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/reminder_helper_test.cpp b/frameworks/ans/test/unittest/reminder_helper_test.cpp new file mode 100644 index 000000000..d14ccdc21 --- /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_TRANSACT_FAILED); +} + +/** + * @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_TRANSACT_FAILED); +} + +/** + * @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_OK); +} + +/** + * @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 -- Gitee From 44d8ca854cada4911663d862616b51631b975aee Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 20 Oct 2022 19:13:47 +0800 Subject: [PATCH 07/44] add reminder fuzz Signed-off-by: liuyanzhi Change-Id: I47f653c770dc15b472ba4dc030e01a322b8f1e1b --- test/fuzztest/BUILD.gn | 3 + test/fuzztest/notification_fuzzer/BUILD.gn | 54 ++++++++++ test/fuzztest/notification_fuzzer/corpus/init | 13 +++ .../notification_fuzzer.cpp | 70 ++++++++++++ .../notification_fuzzer/notification_fuzzer.h | 23 ++++ test/fuzztest/notification_fuzzer/project.xml | 25 +++++ test/fuzztest/readfromparcel_fuzzer/BUILD.gn | 54 ++++++++++ .../readfromparcel_fuzzer/corpus/init | 13 +++ .../readfromparcel_fuzzer/project.xml | 25 +++++ .../readfromparcel_fuzzer.cpp | 91 ++++++++++++++++ .../readfromparcel_fuzzer.h | 23 ++++ test/fuzztest/reminderrequest_fuzzer/BUILD.gn | 55 ++++++++++ .../reminderrequest_fuzzer/corpus/init | 13 +++ .../reminderrequest_fuzzer/project.xml | 25 +++++ .../reminderrequest_fuzzer.cpp | 102 ++++++++++++++++++ .../reminderrequest_fuzzer.h | 23 ++++ 16 files changed, 612 insertions(+) create mode 100644 test/fuzztest/notification_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notification_fuzzer/corpus/init create mode 100644 test/fuzztest/notification_fuzzer/notification_fuzzer.cpp create mode 100644 test/fuzztest/notification_fuzzer/notification_fuzzer.h create mode 100644 test/fuzztest/notification_fuzzer/project.xml create mode 100644 test/fuzztest/readfromparcel_fuzzer/BUILD.gn create mode 100644 test/fuzztest/readfromparcel_fuzzer/corpus/init create mode 100644 test/fuzztest/readfromparcel_fuzzer/project.xml create mode 100644 test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp create mode 100644 test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h create mode 100644 test/fuzztest/reminderrequest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequest_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequest_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 29b780aba..29af3c9bb 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -28,9 +28,12 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "notification_fuzzer:NotificationFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", + "readfromparcel_fuzzer:ReadFromParcelFuzzTest", + "reminderrequest_fuzzer:ReminderRequestFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/notification_fuzzer/BUILD.gn b/test/fuzztest/notification_fuzzer/BUILD.gn new file mode 100644 index 000000000..42f5e0125 --- /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 000000000..1b910144f --- /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 000000000..44e090751 --- /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 000000000..59b3a5174 --- /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 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notification_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 000000000..e097b97e0 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..5de86ce08 --- /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 000000000..e0617c5e6 --- /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 000000000..122306ed6 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..4d6cdaea2 --- /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 000000000..f6d20f9a0 --- /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 -- Gitee From aa7a904807c504fb96b621a9ca9fb03df1191f0c Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Thu, 20 Oct 2022 20:04:13 +0800 Subject: [PATCH 08/44] =?UTF-8?q?napiRequestEnableNotification=E9=80=82?= =?UTF-8?q?=E9=85=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: Ie485f3b839db9b1c7816914f7feeb78f6f049ab9 --- .../js/napi/include/enable_notification.h | 1 + .../js/napi/src/enable_notification.cpp | 6 ++++- .../src/manager/napi_enable_notification.cpp | 27 +++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/frameworks/js/napi/include/enable_notification.h b/frameworks/js/napi/include/enable_notification.h index 51b0faf9f..70c2fb23d 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/enable_notification.cpp b/frameworks/js/napi/src/enable_notification.cpp index 322deb147..71b10ba00 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/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 36de4d827..d328bc47c 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); -- Gitee From c5015d698a2d8f2ee9eaae5aeb3356c95db7f3e3 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Fri, 21 Oct 2022 09:52:30 +0800 Subject: [PATCH 09/44] UT modify Signed-off-by: fangJinliang1 Change-Id: I143fdf0d57f3f6adc0db5b022116e1a4274e3762 --- .../test/unittest/advanced_notification_service_test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index e0aba8c89..505ffe42b 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); } /** -- Gitee From 4ede838a49d42f13602089f6268f8955ce1e45cf Mon Sep 17 00:00:00 2001 From: yuyaozhi Date: Fri, 21 Oct 2022 14:36:30 +0800 Subject: [PATCH 10/44] Fix error message of distributed Signed-off-by: yuyaozhi --- frameworks/js/napi/src/reminder/reminder_common.cpp | 2 +- .../test/unittest/distributed_notification_manager_test.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 68642259b..67206e20b 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/services/distributed/test/unittest/distributed_notification_manager_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_test.cpp index 5328d7712..2e5416ad9 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); } -- Gitee From 11feea7d33a6d02af061b9ab0618d7ca26319198 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Fri, 21 Oct 2022 20:25:14 +0800 Subject: [PATCH 11/44] add fuzz test Signed-off-by: liuyanzhi Change-Id: I1e3874d8a124f0157cbe4b722adb2e1a9030ebd1 --- test/fuzztest/BUILD.gn | 2 + .../reminderrequestannex_fuzzer/BUILD.gn | 56 ++++++++++++ .../reminderrequestannex_fuzzer/corpus/init | 13 +++ .../reminderrequestannex_fuzzer/project.xml | 25 ++++++ .../reminderrequestannex_fuzzer.cpp | 86 +++++++++++++++++++ .../reminderrequestannex_fuzzer.h | 23 +++++ .../reminderrequestcontinuate_fuzzer/BUILD.gn | 56 ++++++++++++ .../corpus/init | 13 +++ .../project.xml | 25 ++++++ .../reminderrequestcontinuate_fuzzer.cpp | 45 ++++++++++ .../reminderrequestcontinuate_fuzzer.h | 23 +++++ 11 files changed, 367 insertions(+) create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 29af3c9bb..c6c14e7a9 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -34,6 +34,8 @@ group("fuzztest") { "publishnotification_fuzzer:PublishNotificationFuzzTest", "readfromparcel_fuzzer:ReadFromParcelFuzzTest", "reminderrequest_fuzzer:ReminderRequestFuzzTest", + "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..1e4aae331 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..87483032c --- /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 000000000..8dd7714cf --- /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 000000000..434728b57 --- /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 000000000..1b910144f --- /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 000000000..6e8ad2cfd --- /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 000000000..ef2550eac --- /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 000000000..1f4efe2d8 --- /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 -- Gitee From f6ea0bc1550698857e650ed06e586ada3ae9339d Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Mon, 24 Oct 2022 10:40:39 +0800 Subject: [PATCH 12/44] notification fuzz Signed-off-by: liuyanzhi Change-Id: Ibdfcfe16aa1a3428e746f981ce939d5eab737d6a --- test/fuzztest/BUILD.gn | 5 ++ .../BUILD.gn | 55 ++++++++++++++++ .../corpus/init | 13 ++++ ...tificationconversationalcontent_fuzzer.cpp | 62 +++++++++++++++++++ ...notificationconversationalcontent_fuzzer.h | 23 +++++++ .../project.xml | 25 ++++++++ .../BUILD.gn | 55 ++++++++++++++++ .../corpus/init | 13 ++++ ...tificationconversationalmessage_fuzzer.cpp | 46 ++++++++++++++ ...notificationconversationalmessage_fuzzer.h | 23 +++++++ .../project.xml | 25 ++++++++ .../BUILD.gn | 55 ++++++++++++++++ .../corpus/init | 13 ++++ .../notificationdonotdisturbdate_fuzzer.cpp | 49 +++++++++++++++ .../notificationdonotdisturbdate_fuzzer.h | 23 +++++++ .../project.xml | 25 ++++++++ .../BUILD.gn | 55 ++++++++++++++++ .../corpus/init | 13 ++++ .../notificationlongtextcontent_fuzzer.cpp | 47 ++++++++++++++ .../notificationlongtextcontent_fuzzer.h | 23 +++++++ .../project.xml | 25 ++++++++ .../BUILD.gn | 55 ++++++++++++++++ .../corpus/init | 13 ++++ .../notificationmultilinecontent_fuzzer.cpp | 47 ++++++++++++++ .../notificationmultilinecontent_fuzzer.h | 23 +++++++ .../project.xml | 25 ++++++++ 26 files changed, 836 insertions(+) create mode 100644 test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationconversationalcontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.h create mode 100644 test/fuzztest/notificationconversationalcontent_fuzzer/project.xml create mode 100644 test/fuzztest/notificationconversationalmessage_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationconversationalmessage_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.cpp create mode 100644 test/fuzztest/notificationconversationalmessage_fuzzer/notificationconversationalmessage_fuzzer.h create mode 100644 test/fuzztest/notificationconversationalmessage_fuzzer/project.xml create mode 100644 test/fuzztest/notificationdonotdisturbdate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationdonotdisturbdate_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp create mode 100644 test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.h create mode 100644 test/fuzztest/notificationdonotdisturbdate_fuzzer/project.xml create mode 100644 test/fuzztest/notificationlongtextcontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationlongtextcontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationlongtextcontent_fuzzer/notificationlongtextcontent_fuzzer.h create mode 100644 test/fuzztest/notificationlongtextcontent_fuzzer/project.xml create mode 100644 test/fuzztest/notificationmultilinecontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationmultilinecontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationmultilinecontent_fuzzer/notificationmultilinecontent_fuzzer.h create mode 100644 test/fuzztest/notificationmultilinecontent_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index c6c14e7a9..eb1c319f1 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -29,6 +29,11 @@ group("fuzztest") { "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", "notification_fuzzer:NotificationFuzzTest", + "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", + "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", + "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", + "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationconversationalcontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..bec34b5e4 --- /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 000000000..1b910144f --- /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 000000000..d84384286 --- /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 000000000..20494fc74 --- /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 000000000..6e8ad2cfd --- /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 000000000..d7bbfd8d8 --- /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 000000000..1b910144f --- /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 000000000..bb47d2383 --- /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 000000000..56abc86ac --- /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 000000000..6e8ad2cfd --- /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 000000000..3e6eb1146 --- /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 000000000..1b910144f --- /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 000000000..8641146ba --- /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 000000000..7d5b711d0 --- /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 000000000..6e8ad2cfd --- /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 000000000..355cc5b53 --- /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 000000000..1b910144f --- /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 000000000..e0851d74a --- /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 000000000..0e3a0fc03 --- /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 000000000..6e8ad2cfd --- /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 000000000..7d7e71998 --- /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 000000000..1b910144f --- /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 000000000..6a72016f0 --- /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 000000000..4f808e102 --- /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 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationmultilinecontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From 56bc8dd06a7a01471d67a6580d2823943e290b86 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Mon, 24 Oct 2022 14:54:09 +0800 Subject: [PATCH 13/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5XCBJ?= =?UTF-8?q?=20Description:=E9=94=99=E8=AF=AF=E7=94=A8=E4=BE=8B=20Sig:SIG?= =?UTF-8?q?=5FApplicationFramework=20Feature=20or=20Bugfix:Bugfix=20Binary?= =?UTF-8?q?=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: I51e346351db9c9a0bc61d18a69a6485fd89aabb1 --- frameworks/ans/test/unittest/notification_helper_test.cpp | 2 +- frameworks/ans/test/unittest/reminder_helper_test.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index d369a109a..ff5eedb5e 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -418,7 +418,7 @@ HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | Sma std::string deviceId = "DeviceId"; NotificationHelper notificationHelper; ErrCode ret = notificationHelper.RequestEnableNotification(deviceId); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); } /** diff --git a/frameworks/ans/test/unittest/reminder_helper_test.cpp b/frameworks/ans/test/unittest/reminder_helper_test.cpp index d14ccdc21..549c42cb1 100644 --- a/frameworks/ans/test/unittest/reminder_helper_test.cpp +++ b/frameworks/ans/test/unittest/reminder_helper_test.cpp @@ -60,7 +60,7 @@ 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_TRANSACT_FAILED); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); } /** @@ -73,7 +73,7 @@ HWTEST_F(ReminderHelperTest, CancelAllReminders_00001, Function | SmallTest | Le { ReminderHelper reminderHelper; ErrCode ret = reminderHelper.CancelAllReminders(); - EXPECT_EQ(ret, (int)ERR_ANS_TRANSACT_FAILED); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); } /** @@ -87,7 +87,7 @@ HWTEST_F(ReminderHelperTest, GetValidReminders_00001, Function | SmallTest | Lev std::vector> validReminders; ReminderHelper reminderHelper; ErrCode ret = reminderHelper.GetValidReminders(validReminders); - EXPECT_EQ(ret, (int)ERR_OK); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); } /** -- Gitee From 433dfb9cc6e7aa1733a70b0dde662460ccb1f77a Mon Sep 17 00:00:00 2001 From: wujiqin Date: Mon, 24 Oct 2022 16:58:22 +0800 Subject: [PATCH 14/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5XEL6?= =?UTF-8?q?=20Description:=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90=E5=8D=8706?= =?UTF-8?q?=20Sig:SIG=5FApplicationFramework=20Feature=20or=20Bugfix:Bugfi?= =?UTF-8?q?x=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: Ic25dbe3dc39bce3fcdbdd7c4cbcc37929a3d5a59 --- frameworks/ans/test/unittest/BUILD.gn | 4 + ...tification_conversational_content_test.cpp | 100 +++++ .../notification_sorting_map_test.cpp | 103 ++++++ .../unittest/notification_sorting_test.cpp | 136 +++++++ .../ans/test/unittest/notification_test.cpp | 350 ++++++++++++++++++ 5 files changed, 693 insertions(+) create mode 100644 frameworks/ans/test/unittest/notification_conversational_content_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_sorting_map_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_sorting_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index cd52aea69..a952eb31c 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("ans_reminder_unit_test") { "${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", @@ -43,8 +44,11 @@ ohos_unittest("ans_reminder_unit_test") { "${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", 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 000000000..0c91fb360 --- /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_sorting_map_test.cpp b/frameworks/ans/test/unittest/notification_sorting_map_test.cpp new file mode 100644 index 000000000..c2283ad3f --- /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 000000000..3c4062e70 --- /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_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp new file mode 100644 index 000000000..759e89bac --- /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 -- Gitee From 32533bdd950a5db701fd65ae9e44447645788e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Tue, 25 Oct 2022 16:01:04 +0800 Subject: [PATCH 15/44] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86xts?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- .../napi/include/reminder/reminder_common.h | 2 +- frameworks/js/napi/src/reminder/publish.cpp | 22 ++++++++++++------- .../js/napi/src/reminder/reminder_common.cpp | 8 +++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 400bbc4b0..75cd7bd05 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -93,7 +93,7 @@ public: static void HandleErrCode(const napi_env &env, int32_t errCode); static void ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, - const napi_value &result); + const napi_value &result, bool isThrow = false); static void SetCallback(const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 1d46fd682..8a3634270 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -48,6 +48,7 @@ struct AsyncCallbackInfo { napi_ref callback = nullptr; napi_value result = nullptr; int32_t reminderId = -1; + bool isThrow = false; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; std::shared_ptr reminder = nullptr; @@ -259,10 +260,10 @@ napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn, cons return nullptr; } if (callbackIn) { - ReminderCommon::SetCallback(env, callbackIn, ERR_REMINDER_INVALID_PARAM, - result); + NotificationNapi::Common::SetCallback(env, callbackIn, ERR_REMINDER_INVALID_PARAM, + result, false); } - return ReminderCommon::JSParaError(env, callbackIn); + return NotificationNapi::Common::JSParaError(env, callbackIn); } napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThrow) @@ -286,6 +287,7 @@ napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThr napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->reminderId = params.reminderId; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -306,7 +308,7 @@ napi_value CancelReminderInner(napi_env env, napi_callback_info info, bool isThr std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGI("Cancel napi_create_async_work complete end"); }, (void *)asynccallbackinfo, @@ -351,6 +353,7 @@ napi_value CancelAllRemindersInner(napi_env env, napi_callback_info info, bool i // promise napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -371,7 +374,7 @@ napi_value CancelAllRemindersInner(napi_env env, napi_callback_info info, bool i std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGD("CancelAll napi_create_async_work complete end"); }, (void *)asynccallbackinfo, @@ -658,6 +661,7 @@ napi_value InnerGetValidReminders(napi_env env, napi_callback_info info, bool is // promise napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -687,7 +691,7 @@ napi_value InnerGetValidReminders(napi_env env, napi_callback_info info, bool is } ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); + env, asynccallbackinfo->info, asynccallbackinfo->result, asynccallbackinfo->isThrow); } }, (void *)asynccallbackinfo, @@ -734,6 +738,7 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh napi_value promise = nullptr; SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->reminder = params.reminder; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -765,7 +770,7 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh } ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); + env, asynccallbackinfo->info, asynccallbackinfo->result, asynccallbackinfo->isThrow); ANSR_LOGI("Publish napi_create_async_work complete end"); } }, @@ -814,6 +819,7 @@ napi_value AddSlotInner(napi_env env, napi_callback_info info, bool isThrow) SetAsynccallbackinfo(env, *asynccallbackinfo, promise); asynccallbackinfo->inType = params.inType; asynccallbackinfo->info.errorCode = params.errCode; + asynccallbackinfo->isThrow = isThrow; // resource name napi_value resourceName = nullptr; @@ -835,7 +841,7 @@ napi_value AddSlotInner(napi_env env, napi_callback_info info, bool isThrow) std::unique_ptr callbackPtr { asynccallbackinfo }; ReminderCommon::ReturnCallbackPromise( - env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env)); + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); ANSR_LOGD("AddSlot napi_create_async_work complete end."); }, (void *)asynccallbackinfo, diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 68642259b..55475fb0a 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -568,11 +568,15 @@ std::string ReminderCommon::FindErrMsg(const napi_env &env, const int32_t errCod } void ReminderCommon::ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, - const napi_value &result) + const napi_value &result, bool isThrow) { ANSR_LOGI("enter errorCode=%{public}d", info.errorCode); if (info.isCallback) { - SetCallback(env, info.callback, info.errorCode, result); + if (isThrow) { + SetCallback(env, info.callback, info.errorCode, result); + } else { + NotificationNapi::Common::SetCallback(env, info.callback, info.errorCode, result, false); + } } else { SetPromise(env, info, result); } -- Gitee From c54df4204bd3346cb89b77aca9b315651c6341e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Tue, 25 Oct 2022 17:15:48 +0800 Subject: [PATCH 16/44] =?UTF-8?q?IssueNo:=20#I5XMRB=20Description:=20Fuzz?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=A4=B1=E8=B4=A5=EF=BC=88head-buffer-overfl?= =?UTF-8?q?ow=EF=BC=89=20Sig:=20SIG=5FApplicationFramework=20Feature=20or?= =?UTF-8?q?=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: I6b4a0c9f80abdc2f5c23dc4bda572a45bd687f62 --- .../addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp | 2 +- test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp | 2 +- .../enabledistributed_fuzzer/enabledistributed_fuzzer.cpp | 2 +- .../getallactivenotifications_fuzzer.cpp | 2 +- .../getnotificationslotsforbundle_fuzzer.cpp | 2 +- .../removenotificationsbybundle_fuzzer.cpp | 2 +- .../setnotificationsenabledforallbundles_fuzzer.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp b/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp index d107c934b..65029144d 100644 --- a/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp +++ b/test/fuzztest/addnotificationslot_fuzzer/addnotificationslot_fuzzer.cpp @@ -57,7 +57,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp index d24e2df04..8d97595d5 100644 --- a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp +++ b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp @@ -50,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp index d6fc7949b..8a9d4f58d 100644 --- a/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp +++ b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp @@ -47,7 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp index 255bf5db7..e809f6570 100644 --- a/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp +++ b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp @@ -48,7 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp index 94a46feb1..6a8eca2aa 100644 --- a/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp @@ -42,7 +42,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp b/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp index 31fe973f1..5740274d4 100644 --- a/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp +++ b/test/fuzztest/removenotificationsbybundle_fuzzer/removenotificationsbybundle_fuzzer.cpp @@ -37,7 +37,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp index b02ccad33..11cc5836b 100644 --- a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp @@ -47,7 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ char *ch = ParseData(data, size); - if (ch != nullptr) { + if (ch != nullptr && size > GetU32Size()) { OHOS::DoSomethingInterestingWithMyAPI(ch, size); free(ch); ch = nullptr; -- Gitee From e9a5b1d7afa950493e6d927bcf3aa5f1002814f8 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Tue, 25 Oct 2022 17:52:36 +0800 Subject: [PATCH 17/44] add templete fuzz Signed-off-by: liuyanzhi Change-Id: I257f3649207c77247a284a88b3d3d015b4a27156 --- test/fuzztest/BUILD.gn | 5 ++ .../BUILD.gn | 55 +++++++++++++++++ .../corpus/init | 13 ++++ .../notificationpicturecontent_fuzzer.cpp | 48 +++++++++++++++ .../notificationpicturecontent_fuzzer.h | 23 ++++++++ .../project.xml | 25 ++++++++ .../notificationsorting_fuzzer/BUILD.gn | 55 +++++++++++++++++ .../notificationsorting_fuzzer/corpus/init | 13 ++++ .../notificationsorting_fuzzer.cpp | 59 +++++++++++++++++++ .../notificationsorting_fuzzer.h | 23 ++++++++ .../notificationsorting_fuzzer/project.xml | 25 ++++++++ .../notificationsortingmap_fuzzer/BUILD.gn | 55 +++++++++++++++++ .../notificationsortingmap_fuzzer/corpus/init | 13 ++++ .../notificationsortingmap_fuzzer.cpp | 53 +++++++++++++++++ .../notificationsortingmap_fuzzer.h | 23 ++++++++ .../notificationsortingmap_fuzzer/project.xml | 25 ++++++++ .../notificationsubscribeInfo_fuzzer/BUILD.gn | 55 +++++++++++++++++ .../corpus/init | 13 ++++ .../notificationsubscribeInfo_fuzzer.cpp | 49 +++++++++++++++ .../notificationsubscribeInfo_fuzzer.h | 23 ++++++++ .../project.xml | 25 ++++++++ .../notificationtemplate_fuzzer/BUILD.gn | 55 +++++++++++++++++ .../notificationtemplate_fuzzer/corpus/init | 13 ++++ .../notificationtemplate_fuzzer.cpp | 46 +++++++++++++++ .../notificationtemplate_fuzzer.h | 23 ++++++++ .../notificationtemplate_fuzzer/project.xml | 25 ++++++++ 26 files changed, 840 insertions(+) create mode 100644 test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationpicturecontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationpicturecontent_fuzzer/notificationpicturecontent_fuzzer.h create mode 100644 test/fuzztest/notificationpicturecontent_fuzzer/project.xml create mode 100644 test/fuzztest/notificationsorting_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationsorting_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.cpp create mode 100644 test/fuzztest/notificationsorting_fuzzer/notificationsorting_fuzzer.h create mode 100644 test/fuzztest/notificationsorting_fuzzer/project.xml create mode 100644 test/fuzztest/notificationsortingmap_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationsortingmap_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp create mode 100644 test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.h create mode 100644 test/fuzztest/notificationsortingmap_fuzzer/project.xml create mode 100644 test/fuzztest/notificationsubscribeInfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationsubscribeInfo_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.cpp create mode 100644 test/fuzztest/notificationsubscribeInfo_fuzzer/notificationsubscribeInfo_fuzzer.h create mode 100644 test/fuzztest/notificationsubscribeInfo_fuzzer/project.xml create mode 100644 test/fuzztest/notificationtemplate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationtemplate_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.cpp create mode 100644 test/fuzztest/notificationtemplate_fuzzer/notificationtemplate_fuzzer.h create mode 100644 test/fuzztest/notificationtemplate_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index eb1c319f1..d5fc03f35 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -34,7 +34,12 @@ group("fuzztest") { "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", diff --git a/test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn b/test/fuzztest/notificationpicturecontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..7be6722b2 --- /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 000000000..1b910144f --- /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 000000000..02a49cc34 --- /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 000000000..b9591d93a --- /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 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationpicturecontent_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 000000000..24965e38a --- /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 000000000..1b910144f --- /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 000000000..44e0cd096 --- /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 000000000..a12719d23 --- /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 000000000..6e8ad2cfd --- /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 000000000..954cf28cc --- /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 000000000..1b910144f --- /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 000000000..8c386d201 --- /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 000000000..206d41e61 --- /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 000000000..6e8ad2cfd --- /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 000000000..7bb9acd99 --- /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 000000000..1b910144f --- /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 000000000..e4facc057 --- /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 000000000..91b59a032 --- /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 000000000..6e8ad2cfd --- /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 000000000..0468912b0 --- /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 000000000..1b910144f --- /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 000000000..a016380fe --- /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 000000000..a5a06504c --- /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 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationtemplate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From 09ee1c2ee36fc743a0410b8f8d7514216f52828b Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Wed, 26 Oct 2022 10:52:37 +0800 Subject: [PATCH 18/44] =?UTF-8?q?RequestEnableNotification=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=E9=80=82=E9=85=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: I2ad42689b2a6c739c4ca4aada6bffdaf85e8b84d --- frameworks/ans/src/notification_helper.cpp | 5 ----- .../ans/test/unittest/notification_helper_test.cpp | 3 ++- frameworks/core/include/ans_manager_interface.h | 8 -------- frameworks/core/include/ans_manager_proxy.h | 8 -------- frameworks/core/include/ans_manager_stub.h | 8 -------- frameworks/core/include/ans_notification.h | 9 --------- frameworks/core/src/ans_callback_stub.cpp | 4 ++-- frameworks/core/src/ans_manager_proxy.cpp | 6 ------ frameworks/core/src/ans_manager_stub.cpp | 6 ------ frameworks/core/src/ans_notification.cpp | 10 ---------- interfaces/inner_api/notification_helper.h | 9 --------- services/ans/include/advanced_notification_service.h | 8 -------- services/ans/src/advanced_notification_service.cpp | 6 ------ .../setnotificationbadgenum_fuzzer.cpp | 3 ++- 14 files changed, 6 insertions(+), 87 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index ec6963f02..1f8fb1710 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -154,11 +154,6 @@ ErrCode NotificationHelper::IsAllowedNotifySelf(bool &allowed) return DelayedSingleton::GetInstance()->IsAllowedNotifySelf(allowed); } -ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId) -{ - return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId); -} - ErrCode NotificationHelper::RequestEnableNotification(std::string &deviceId, bool &popFlag) { return DelayedSingleton::GetInstance()->RequestEnableNotification(deviceId, popFlag); diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index ff5eedb5e..e7b70338e 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -417,7 +417,8 @@ HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | Sma { std::string deviceId = "DeviceId"; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.RequestEnableNotification(deviceId); + bool needPop = true; + ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, needPop); EXPECT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); } diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 3b40c55fe..a2a918268 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -339,14 +339,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) = 0; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) = 0; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 89c5129ff..4d736b1a2 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -327,14 +327,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 55207f7d3..a770d5553 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -343,14 +343,6 @@ public: virtual ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 0afd8a3b4..59faa1011 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -276,15 +276,6 @@ public: */ ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allows the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allows the current application to publish notifications on a specified device. * diff --git a/frameworks/core/src/ans_callback_stub.cpp b/frameworks/core/src/ans_callback_stub.cpp index ecf76a676..4d01d6131 100644 --- a/frameworks/core/src/ans_callback_stub.cpp +++ b/frameworks/core/src/ans_callback_stub.cpp @@ -37,8 +37,8 @@ int32_t AnsCallbackStub::OnRemoteRequest( if (InterfaceCode::ON_ENABLE_NOTIFICATION_CALLBACK == code) { bool result = false; if (!data.ReadBool(result)) { - ANS_LOGE("read notification enabled result failed."); - return ERR_ANS_PARCELABLE_FAILED; + ANS_LOGE("Notification not allowed by user."); + return ERR_ANS_PERMISSION_DENIED; } ANS_LOGD("result = %{public}d", result); OnEnableNotification(result); diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 466eeb00b..195a3f443 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -1103,12 +1103,6 @@ ErrCode AnsManagerProxy::UpdateSlots( return result; } -ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AnsManagerProxy::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGI("enter"); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 64eaa72e9..3b39d6b93 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -1998,12 +1998,6 @@ ErrCode AnsManagerStub::UpdateSlots( return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); - return ERR_INVALID_OPERATION; -} - ErrCode AnsManagerStub::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGE("AnsManagerStub::RequestEnableNotification called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 2860aa3db..67371739d 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -373,16 +373,6 @@ ErrCode AnsNotification::IsAllowedNotifySelf(bool &allowed) return ansManagerProxy_->IsAllowedNotifySelf(allowed); } -ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId) -{ - ANS_LOGD("enter"); - if (!GetAnsManagerProxy()) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return ansManagerProxy_->RequestEnableNotification(deviceId); -} - ErrCode AnsNotification::RequestEnableNotification(std::string &deviceId, bool &popFlag) { ANS_LOGD("enter"); diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index c982bac66..e153cc4e0 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -278,15 +278,6 @@ public: */ static ErrCode IsAllowedNotifySelf(bool &allowed); - /** - * @brief Allow the current application to publish notifications on a specified device. - * - * @param deviceId Indicates the ID of the device running the application. At present, this parameter can - * only be null or an empty string, indicating the current device. - * @return Returns set notifications enabled for default bundle result. - */ - static ErrCode RequestEnableNotification(std::string &deviceId); - /** * @brief Allow the current application to publish notifications on a specified device. * diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 27f7a8663..958a4331a 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -339,14 +339,6 @@ public: ErrCode UpdateSlots( const sptr &bundleOption, const std::vector> &slots) override; - /** - * @brief Allow notifications to be sent based on the deviceId. - * - * @param deviceId Indicates the device Id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode RequestEnableNotification(const std::string &deviceId) override; - /** * @brief Allow notifications to be sent based on the deviceId. * diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 971858661..05481b8e7 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1434,12 +1434,6 @@ ErrCode AdvancedNotificationService::GetSpecialActiveNotifications( return result; } -ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId) -{ - ANS_LOGE("[RequestEnableNotification] fail: deprecated."); - return ERR_ANS_NOT_ALLOWED; -} - ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, bool &popFlag) { ANS_LOGD("%{public}s", __FUNCTION__); diff --git a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp index 2ba0e8a3c..84d309dd9 100644 --- a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp +++ b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp @@ -21,7 +21,8 @@ namespace OHOS { { // test RequestEnableNotification function std::string deviceId(data); - Notification::NotificationHelper::RequestEnableNotification(deviceId); + boo needPop = true; + Notification::NotificationHelper::RequestEnableNotification(deviceId, needPop); // test AreNotificationsSuspended function bool suspended = true; Notification::NotificationHelper::AreNotificationsSuspended(suspended); -- Gitee From d4e9ca0f606abd80e411f3a7bec876d33b45970a Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Wed, 26 Oct 2022 03:35:38 +0000 Subject: [PATCH 19/44] update test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp. Signed-off-by: chenyuyan --- .../setnotificationbadgenum_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp index 84d309dd9..74d4ad5bc 100644 --- a/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp +++ b/test/fuzztest/setnotificationbadgenum_fuzzer/setnotificationbadgenum_fuzzer.cpp @@ -21,7 +21,7 @@ namespace OHOS { { // test RequestEnableNotification function std::string deviceId(data); - boo needPop = true; + bool needPop = true; Notification::NotificationHelper::RequestEnableNotification(deviceId, needPop); // test AreNotificationsSuspended function bool suspended = true; -- Gitee From 04497973295162119cbb0c4697f8d9073766fb90 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Wed, 26 Oct 2022 17:03:46 +0800 Subject: [PATCH 20/44] add fuzz test Signed-off-by: liuyanzhi Change-Id: I652cf84dca4ee4df5fd5274d4f96ab82802bd2be --- test/fuzztest/BUILD.gn | 4 + .../notificationuserinput_fuzzer/BUILD.gn | 55 ++++++++++++ .../notificationuserinput_fuzzer/corpus/init | 13 +++ .../notificationuserinput_fuzzer.cpp | 84 +++++++++++++++++++ .../notificationuserinput_fuzzer.h | 23 +++++ .../notificationuserinput_fuzzer/project.xml | 25 ++++++ test/fuzztest/reminderhelper_fuzzer/BUILD.gn | 55 ++++++++++++ .../reminderhelper_fuzzer/corpus/init | 13 +++ .../reminderhelper_fuzzer/project.xml | 25 ++++++ .../reminderhelper_fuzzer.cpp | 64 ++++++++++++++ .../reminderhelper_fuzzer.h | 23 +++++ .../reminderrequesttimer_fuzzer/BUILD.gn | 56 +++++++++++++ .../reminderrequesttimer_fuzzer/corpus/init | 13 +++ .../reminderrequesttimer_fuzzer/project.xml | 25 ++++++ .../reminderrequesttimer_fuzzer.cpp | 57 +++++++++++++ .../reminderrequesttimer_fuzzer.h | 23 +++++ test/fuzztest/reminderstore_fuzzer/BUILD.gn | 55 ++++++++++++ .../fuzztest/reminderstore_fuzzer/corpus/init | 13 +++ .../fuzztest/reminderstore_fuzzer/project.xml | 25 ++++++ .../reminderstore_fuzzer.cpp | 49 +++++++++++ .../reminderstore_fuzzer.h | 23 +++++ 21 files changed, 723 insertions(+) create mode 100644 test/fuzztest/notificationuserinput_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationuserinput_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp create mode 100644 test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h create mode 100644 test/fuzztest/notificationuserinput_fuzzer/project.xml create mode 100644 test/fuzztest/reminderhelper_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderhelper_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderhelper_fuzzer/project.xml create mode 100644 test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp create mode 100644 test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h create mode 100644 test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequesttimer_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequesttimer_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h create mode 100644 test/fuzztest/reminderstore_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderstore_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderstore_fuzzer/project.xml create mode 100644 test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp create mode 100644 test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index d5fc03f35..11a4f1f1c 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -40,12 +40,16 @@ group("fuzztest") { "notificationsortingmap_fuzzer:NotificationSortingMapFuzzTest", "notificationsubscribeInfo_fuzzer:NotificationSubscribeInfoFuzzTest", "notificationtemplate_fuzzer:NotificationTemplateFuzzTest", + "notificationuserinput_fuzzer:NotificationUserInputFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", "readfromparcel_fuzzer:ReadFromParcelFuzzTest", + "reminderhelper_fuzzer:ReminderHelperFuzzTest", "reminderrequest_fuzzer:ReminderRequestFuzzTest", "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", + "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", + "reminderstore_fuzzer:ReminderStoreFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn b/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn new file mode 100644 index 000000000..f97967eb0 --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationUserInputFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationuserinput_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationuserinput_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationUserInputFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationuserinput_fuzzer/corpus/init b/test/fuzztest/notificationuserinput_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp new file mode 100644 index 000000000..31e00655b --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_user_input.h" +#undef private +#undef protected +#include "notificationuserinput_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t INPUT_EDIT_TYPE = 3; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationUserInput notificationUserInput(stringData); + AAFwk::Want want; + uint8_t sources = *data % ENABLE; + Notification::NotificationConstant::InputsSource source = + Notification::NotificationConstant::InputsSource(sources); + notificationUserInput.SetInputsSource(want, source); + notificationUserInput.GetInputsSource(want); + std::shared_ptr input = + std::make_shared(); + std::vector> userInputs; + userInputs.emplace_back(input); + AAFwk::WantParams additional; + notificationUserInput.AddInputsToWant(userInputs, want, additional); + notificationUserInput.GetInputsFromWant(want); + notificationUserInput.Create(stringData); + notificationUserInput.GetInputKey(); + notificationUserInput.AddAdditionalData(additional); + notificationUserInput.GetAdditionalData(); + uint8_t inputEditTypes = *data % INPUT_EDIT_TYPE; + Notification::NotificationConstant::InputEditType inputEditType = + Notification::NotificationConstant::InputEditType(inputEditTypes); + notificationUserInput.SetEditType(inputEditType); + notificationUserInput.GetEditType(); + std::vector options; + options.emplace_back(stringData); + notificationUserInput.SetOptions(options); + notificationUserInput.GetOptions(); + bool doPermit = *data % ENABLE; + notificationUserInput.SetPermitMimeTypes(stringData, doPermit); + notificationUserInput.GetPermitMimeTypes(); + notificationUserInput.IsMimeTypeOnly(); + notificationUserInput.SetTag(stringData); + notificationUserInput.GetTag(); + notificationUserInput.SetPermitFreeFormInput(doPermit); + notificationUserInput.IsPermitFreeFormInput(); + notificationUserInput.Dump(); + Parcel parcel; + notificationUserInput.ReadFromParcel(parcel); + return notificationUserInput.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h new file mode 100644 index 000000000..4ca3acc2e --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/notificationuserinput_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationuserinput_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONUSERINPUT_FUZZER_NOTIFICATIONUSERINPUT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationuserinput_fuzzer/project.xml b/test/fuzztest/notificationuserinput_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationuserinput_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderhelper_fuzzer/BUILD.gn b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn new file mode 100644 index 000000000..4402544bb --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderHelperFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderhelper_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderhelper_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderHelperFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderhelper_fuzzer/corpus/init b/test/fuzztest/reminderhelper_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderhelper_fuzzer/project.xml b/test/fuzztest/reminderhelper_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp new file mode 100644 index 000000000..4c3c8cca2 --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_helper.h" +#undef private +#undef protected +#include "reminderhelper_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::ReminderRequest reminder; + reminder.SetContent(stringData); + reminder.SetExpiredContent(stringData); + Notification::ReminderHelper::PublishReminder(reminder); + int32_t reminderId = static_cast(*data); + Notification::ReminderHelper::CancelReminder(reminderId); + sptr valid = new Notification::ReminderRequest(); + std::vector> validReminders; + validReminders.emplace_back(valid); + Notification::ReminderHelper::GetValidReminders(validReminders); + Notification::NotificationSlot notificationSlot; + bool enabled = *data % ENABLE; + notificationSlot.SetEnableLight(enabled); + notificationSlot.SetEnableVibration(enabled); + Notification::ReminderHelper::AddNotificationSlot(notificationSlot); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + Notification::ReminderHelper::RemoveNotificationSlot(slotType); + return Notification::ReminderHelper::CancelAllReminders(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h new file mode 100644 index 000000000..f4f5d94b2 --- /dev/null +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H +#define TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderhelper_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERHELPER_FUZZER_REMINDERHELPER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn new file mode 100644 index 000000000..3707f52fd --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestTimerFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequesttimer_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequesttimer_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestTimerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/project.xml b/test/fuzztest/reminderrequesttimer_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp new file mode 100644 index 000000000..1b9d9365c --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_request_timer.h" +#undef private +#undef protected +#include "reminderrequesttimer_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + uint64_t countDownTimeInSeconds = 0; + std::string stringData(data); + Notification::ReminderRequestTimer reminderRequestTimer(countDownTimeInSeconds); + reminderRequestTimer.GetInitInfo(); + bool enabled = *data % ENABLE; + reminderRequestTimer.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + reminderRequestTimer.OnDateTimeChange(); + reminderRequestTimer.OnTimeZoneChange(); + reminderRequestTimer.UpdateNextReminder(); + reminderRequestTimer.CheckParamsValid(countDownTimeInSeconds); + reminderRequestTimer.UpdateTimeInfo(stringData); + Parcel parcel; + reminderRequestTimer.Marshalling(parcel); + return reminderRequestTimer.ReadFromParcel(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h new file mode 100644 index 000000000..57e21d8da --- /dev/null +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequesttimer_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTTIMER_FUZZER_REMINDERREQUESTTIMER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstore_fuzzer/BUILD.gn b/test/fuzztest/reminderstore_fuzzer/BUILD.gn new file mode 100644 index 000000000..b65769865 --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstore_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderstore_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstore_fuzzer/corpus/init b/test/fuzztest/reminderstore_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderstore_fuzzer/project.xml b/test/fuzztest/reminderstore_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp new file mode 100644 index 000000000..bc42c3047 --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminderstore_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::ReminderStore reminderStore; + int32_t oldVersion = static_cast(GetU32Data(data)); + reminderStore.Init(); + reminderStore.InitData(); + reminderStore.Delete(oldVersion); + reminderStore.DeleteUser(oldVersion); + reminderStore.Delete(stringData, oldVersion); + return reminderStore.Delete(stringData); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h new file mode 100644 index 000000000..80cc11dea --- /dev/null +++ b/test/fuzztest/reminderstore_fuzzer/reminderstore_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstore_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTORE_FUZZER_H \ No newline at end of file -- Gitee From a21535090de5eebd240a78145c52c09a15e32dce Mon Sep 17 00:00:00 2001 From: liqiang Date: Thu, 27 Oct 2022 11:13:29 +0800 Subject: [PATCH 21/44] =?UTF-8?q?AnsManagerDeathRecipient=20=E5=88=86?= =?UTF-8?q?=E6=94=AF=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqiang Change-Id: I2efd7ca69f4bd48eeb85a0643c05694f96fc6138 --- bundle.json | 1 + frameworks/core/test/unittest/BUILD.gn | 19 +++++ .../ans_manager_death_recipient_test/BUILD.gn | 50 +++++++++++++ .../ans_manager_death_recipient_unit_test.cpp | 70 +++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 frameworks/core/test/unittest/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp diff --git a/bundle.json b/bundle.json index 47ec4cac1..29f7ae753 100644 --- a/bundle.json +++ b/bundle.json @@ -105,6 +105,7 @@ "//base/notification/distributed_notification_service/services/test/moduletest:moduletest", "//base/notification/distributed_notification_service/frameworks/test/moduletest:moduletest", "//base/notification/distributed_notification_service/frameworks/ans/test/unittest:unittest", + "//base/notification/distributed_notification_service/frameworks/core/test/unittest:unittest", "//base/notification/distributed_notification_service/test:systemtest", "//base/notification/distributed_notification_service/tools:unittest", "//base/notification/distributed_notification_service/test/bechmarktest:benchmarktest", diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn new file mode 100644 index 000000000..03136185d --- /dev/null +++ b/frameworks/core/test/unittest/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("unittest") { + testonly = true + deps = [] + + deps += [ "ans_manager_death_recipient_test:unittest" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn new file mode 100644 index 000000000..f679b5f0b --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_manager_death_recipient_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_manager_death_recipient_unit_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_death_recipient_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp new file mode 100644 index 000000000..b8f3400b6 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.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. + */ + +#include + +#define private public +#define protected public +#include "ans_manager_death_recipient.h" +#include "ans_notification.h" +#undef private +#undef protected + +#include "iremote_broker.h" +#include "singleton.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsManagerDeathRecipientUnitTest : public testing::Test { +public: + AnsManagerDeathRecipientUnitTest() {} + + virtual ~AnsManagerDeathRecipientUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsManagerDeathRecipientUnitTest::SetUpTestCase() {} + +void AnsManagerDeathRecipientUnitTest::TearDownTestCase() {} + +void AnsManagerDeathRecipientUnitTest::SetUp() {} + +void AnsManagerDeathRecipientUnitTest::TearDown() {} + +/* + * @tc.name: OnRemoteDiedTest_0100 + * @tc.desc: test if AnsManagerDeathRecipient's OnRemoteDied function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + * + */ +HWTEST_F(AnsManagerDeathRecipientUnitTest, OnRemoteDiedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerDeathRecipientUnitTest, OnRemoteDiedTest_0100, TestSize.Level1"; + std::shared_ptr recipient = std::make_shared(); + ASSERT_NE(nullptr, recipient); + recipient->OnRemoteDied(nullptr); + EXPECT_EQ(DelayedSingleton::GetInstance()->ansManagerProxy_, nullptr); +} \ No newline at end of file -- Gitee From d94d1aef1f48769b4be982530ddf253bd18d20dc Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 27 Oct 2022 15:31:32 +0800 Subject: [PATCH 22/44] uadd stub fuzz Signed-off-by: liuyanzhi Change-Id: Iea718eb999a96463e287a99d6bfe0734576f5fcb --- test/fuzztest/BUILD.gn | 2 + test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn | 55 +++++++++++++ .../ansmanagerstub_fuzzer.cpp | 79 ++++++++++++++++++ .../ansmanagerstub_fuzzer.h | 23 ++++++ .../ansmanagerstub_fuzzer/corpus/init | 13 +++ .../ansmanagerstub_fuzzer/project.xml | 25 ++++++ .../ansmanagerstubannex_fuzzer/BUILD.gn | 56 +++++++++++++ .../ansmanagerstubannex_fuzzer.cpp | 82 +++++++++++++++++++ .../ansmanagerstubannex_fuzzer.h | 23 ++++++ .../ansmanagerstubannex_fuzzer/corpus/init | 13 +++ .../ansmanagerstubannex_fuzzer/project.xml | 25 ++++++ 11 files changed, 396 insertions(+) create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/project.xml create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 11a4f1f1c..0091642d5 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,6 +18,8 @@ group("fuzztest") { "addnotificationslot_fuzzer:AddNotificationSlotFuzzTest", "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", + "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", + "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", diff --git a/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn new file mode 100644 index 000000000..a4671ff43 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/ansmanagerstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp new file mode 100644 index 000000000..36a919d2d --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstub_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::AnsManagerStub ansManagerStub; + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + ansManagerStub.OnRemoteRequest(code, datas, reply, flags); + ansManagerStub.HandlePublish(datas, reply); + ansManagerStub.HandlePublishToDevice(datas, reply); + ansManagerStub.HandleCancel(datas, reply); + ansManagerStub.HandleCancelAll(datas, reply); + ansManagerStub.HandleCancelAsBundle(datas, reply); + ansManagerStub.HandleAddSlotByType(datas, reply); + ansManagerStub.HandleAddSlots(datas, reply); + ansManagerStub.HandleRemoveSlotByType(datas, reply); + ansManagerStub.HandleRemoveAllSlots(datas, reply); + ansManagerStub.HandleGetSlots(datas, reply); + ansManagerStub.HandleGetSlotByType(datas, reply); + ansManagerStub.HandleGetSlotNumAsBundle(datas, reply); + ansManagerStub.HandleGetActiveNotifications(datas, reply); + ansManagerStub.HandleGetActiveNotificationNums(datas, reply); + ansManagerStub.HandleGetAllActiveNotifications(datas, reply); + ansManagerStub.HandleGetSpecialActiveNotifications(datas, reply); + ansManagerStub.HandleSetNotificationAgent(datas, reply); + ansManagerStub.HandleGetNotificationAgent(datas, reply); + ansManagerStub.HandleCanPublishAsBundle(datas, reply); + ansManagerStub.HandlePublishAsBundle(datas, reply); + ansManagerStub.HandleSetNotificationBadgeNum(datas, reply); + ansManagerStub.HandleGetBundleImportance(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDate(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDate(datas, reply); + ansManagerStub.HandleDoesSupportDoNotDisturbMode(datas, reply); + ansManagerStub.HandlePublishContinuousTaskNotification(datas, reply); + ansManagerStub.HandleCancelContinuousTaskNotification(datas, reply); + ansManagerStub.HandleIsNotificationPolicyAccessGranted(datas, reply); + ansManagerStub.HandleSetPrivateNotificationsAllowed(datas, reply); + ansManagerStub.HandleGetPrivateNotificationsAllowed(datas, reply); + ansManagerStub.HandleRemoveNotification(datas, reply); + return ansManagerStub.HandleRemoveAllNotifications(datas, reply); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h new file mode 100644 index 000000000..a6a9b4924 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstub_fuzzer/corpus/init b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstub_fuzzer/project.xml b/test/fuzztest/ansmanagerstub_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..7f8a8e82f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp new file mode 100644 index 000000000..de16b4132 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + MessageParcel datas; + MessageParcel reply; + ansManagerStub.HandleDelete(datas, reply); + ansManagerStub.HandleDeleteByBundle(datas, reply); + ansManagerStub.HandleDeleteAll(datas, reply); + ansManagerStub.HandleGetSlotsByBundle(datas, reply); + ansManagerStub.HandleUpdateSlots(datas, reply); + ansManagerStub.HandleRequestEnableNotification(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForBundle(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForAllBundles(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForSpecialBundle(datas, reply); + ansManagerStub.HandleSetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); + ansManagerStub.HandleSubscribe(datas, reply); + ansManagerStub.HandleUnsubscribe(datas, reply); + ansManagerStub.HandleAreNotificationsSuspended(datas, reply); + ansManagerStub.HandleGetCurrentAppSorting(datas, reply); + ansManagerStub.HandleIsAllowedNotify(datas, reply); + ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); + ansManagerStub.HandleIsSpecialBundleAllowedNotify(datas, reply); + ansManagerStub.HandleCancelGroup(datas, reply); + ansManagerStub.HandleRemoveGroupByBundle(datas, reply); + ansManagerStub.HandleIsDistributedEnabled(datas, reply); + ansManagerStub.HandleEnableDistributed(datas, reply); + ansManagerStub.HandleEnableDistributedByBundle(datas, reply); + ansManagerStub.HandleEnableDistributedSelf(datas, reply); + ansManagerStub.HandleIsDistributedEnableByBundle(datas, reply); + ansManagerStub.HandleGetDeviceRemindType(datas, reply); + ansManagerStub.HandleShellDump(datas, reply); + ansManagerStub.HandlePublishReminder(datas, reply); + ansManagerStub.HandleCancelReminder(datas, reply); + ansManagerStub.HandleCancelAllReminders(datas, reply); + ansManagerStub.HandleGetValidReminders(datas, reply); + ansManagerStub.HandleIsSupportTemplate(datas, reply); + ansManagerStub.HandleIsSpecialUserAllowedNotifyByUser(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledByUser(datas, reply); + ansManagerStub.HandleDeleteAllByUser(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDateByUser(datas, reply); + return ansManagerStub.HandleSetEnabledForBundleSlot(datas, reply); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h new file mode 100644 index 000000000..330d8b85b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannex_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From 26fa36dc7cf849a791671456529cfb078f478a18 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Thu, 27 Oct 2022 18:40:46 +0800 Subject: [PATCH 23/44] =?UTF-8?q?=E6=96=B0=E5=A2=9Eans=5Fcallback=E2=80=94?= =?UTF-8?q?=E2=80=94stubTDD=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: Idcd9c42cb88e9abfdd6772a63a8f056a23280387 --- frameworks/core/src/ans_callback_stub.cpp | 4 +- frameworks/core/test/unittest/BUILD.gn | 7 +- .../unittest/ans_callback_stub_test/BUILD.gn | 50 ++++++++ .../ans_callback_stub_test.cpp | 116 ++++++++++++++++++ 4 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp diff --git a/frameworks/core/src/ans_callback_stub.cpp b/frameworks/core/src/ans_callback_stub.cpp index 4d01d6131..ecf76a676 100644 --- a/frameworks/core/src/ans_callback_stub.cpp +++ b/frameworks/core/src/ans_callback_stub.cpp @@ -37,8 +37,8 @@ int32_t AnsCallbackStub::OnRemoteRequest( if (InterfaceCode::ON_ENABLE_NOTIFICATION_CALLBACK == code) { bool result = false; if (!data.ReadBool(result)) { - ANS_LOGE("Notification not allowed by user."); - return ERR_ANS_PERMISSION_DENIED; + ANS_LOGE("read notification enabled result failed."); + return ERR_ANS_PARCELABLE_FAILED; } ANS_LOGD("result = %{public}d", result); OnEnableNotification(result); diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 03136185d..6a047e709 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -9,11 +9,14 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. group("unittest") { testonly = true deps = [] - deps += [ "ans_manager_death_recipient_test:unittest" ] + deps += [ + "ans_callback_stub_test:unittest", + "ans_manager_death_recipient_test:unittest", + ] } diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn new file mode 100644 index 000000000..78c8bad85 --- /dev/null +++ b/frameworks/core/test/unittest/ans_callback_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_callback_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_callback_stub_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_callback_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp b/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp new file mode 100644 index 000000000..4e507a144 --- /dev/null +++ b/frameworks/core/test/unittest/ans_callback_stub_test/ans_callback_stub_test.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ans_callback_stub.h" +#include "ans_inner_errors.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsCallbackStubImpl : public AnsCallbackStub { + bool OnEnableNotification(bool isAllow) override + { + return false; + } +}; + +class AnsCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + + void SetUp() + { + ansCallbackStub_ = new AnsCallbackStubImpl(); + } + void TearDown() {} + sptr ansCallbackStub_; +}; + +/** + * @tc.name: OnRemoteRequest01 + * @tc.desc: Test if the descriptor is wrong. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest01, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: OnRemoteRequest02 + * @tc.desc: Test if can not read a bool from data failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest02, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: OnRemoteRequest03 + * @tc.desc: Test unknow code failed. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest03, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(1, data, reply, option); + EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: OnRemoteRequest04 + * @tc.desc: Test OnRemoteRequest success. + * @tc.type: FUNC + * @tc.require: issueI5XO2O + */ +HWTEST_F(AnsCallbackStubTest, OnRemoteRequest04, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsCallbackStub::GetDescriptor()); + data.WriteBool(true); + + int32_t ret = ansCallbackStub_->OnRemoteRequest(0, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} -- Gitee From d06243de93026dbd41ea70c96e3e3c32dc5305a1 Mon Sep 17 00:00:00 2001 From: liqiang Date: Fri, 28 Oct 2022 10:06:34 +0800 Subject: [PATCH 24/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5Y6A4?= =?UTF-8?q?=20Description:AnsSubscriberProxy=E5=A2=9E=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=20Sig:=20SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:=20Binary=20Source:No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqiang Change-Id: Ic4ff3d96ebb201e838588bb8af3c86491a930100 --- frameworks/core/test/unittest/BUILD.gn | 1 + .../ans_manager_death_recipient_unit_test.cpp | 1 - .../ans_subscriber_proxy_test/BUILD.gn | 55 ++ .../ans_subscriber_proxy_unit_test.cpp | 569 ++++++++++++++++++ .../test/unittest/mock/mock_i_remote_object.h | 78 +++ 5 files changed, 703 insertions(+), 1 deletion(-) create mode 100644 frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_i_remote_object.h diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 6a047e709..4b4e565eb 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -18,5 +18,6 @@ group("unittest") { deps += [ "ans_callback_stub_test:unittest", "ans_manager_death_recipient_test:unittest", + "ans_subscriber_proxy_test:unittest", ] } diff --git a/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp index b8f3400b6..5be052097 100644 --- a/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_death_recipient_test/ans_manager_death_recipient_unit_test.cpp @@ -57,7 +57,6 @@ void AnsManagerDeathRecipientUnitTest::TearDown() {} * @tc.desc: test if AnsManagerDeathRecipient's OnRemoteDied function executed as expected in normal case. * @tc.type: FUNC * @tc.require: #I5SJ62 - * */ HWTEST_F(AnsManagerDeathRecipientUnitTest, OnRemoteDiedTest_0100, Function | MediumTest | Level1) { diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn new file mode 100644 index 000000000..52625fec9 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_subscriber_proxy_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + "../mock/", + ] + + sources = [ "ans_subscriber_proxy_unit_test.cpp" ] + + deps = [ + "${core_path}:ans_core", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_subscriber_proxy_test" ] +} diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp new file mode 100644 index 000000000..826199bf2 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp @@ -0,0 +1,569 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ans_subscriber_proxy.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "ipc_types.h" +#include "mock_i_remote_object.h" +#include "notification.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +class AnsSubscriberProxyUnitTest : public testing::Test { +public: + AnsSubscriberProxyUnitTest() {} + + virtual ~AnsSubscriberProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsSubscriberProxyUnitTest::SetUpTestCase() {} + +void AnsSubscriberProxyUnitTest::TearDownTestCase() {} + +void AnsSubscriberProxyUnitTest::SetUp() {} + +void AnsSubscriberProxyUnitTest::TearDown() {} + +/* + * @tc.name: InnerTransactTest_0100 + * @tc.desc: test if AnsSubscriberProxy's InnerTransact function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_OK, res); +} + +/* + * @tc.name: InnerTransactTest_0200 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: InnerTransactTest_0300 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); +} + +/* + * @tc.name: InnerTransactTest_0400 + * @tc.desc: test AnsSubscriberProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; + std::shared_ptr proxy = std::make_shared(nullptr); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: OnConsumed_0100 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification); +} + +/* + * @tc.name: OnConsumed_0200 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification); +} + +/* + * @tc.name: OnConsumed_0300 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnConsumed(nullptr); +} + +/* + * @tc.name: OnConsumed_0400 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumed_0500 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(notification, notificationMap); +} + +/* + * @tc.name: OnConsumed_0600 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnConsumed(nullptr, notificationMap); +} + +/* + * @tc.name: OnConsumed_0700 + * @tc.desc: test AnsSubscriberProxy's OnConsumed function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnConsumed_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnConsumed(notification, nullptr); +} + +/* + * @tc.name: OnCanceled_0100 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnCanceled(notification); +} + +/* + * @tc.name: OnCanceled_0200 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + proxy->OnCanceled(notification); +} + +/* + * @tc.name: OnCanceled_0300 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnCanceled(nullptr); +} + +/* + * @tc.name: OnCanceled_0400 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0500 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0600 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + int32_t deleteReason = 0; + proxy->OnCanceled(nullptr, notificationMap, deleteReason); +} + +/* + * @tc.name: OnCanceled_0700 + * @tc.desc: test AnsSubscriberProxy's OnCanceled function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnCanceled_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + ASSERT_NE(nullptr, notification); + int32_t deleteReason = 0; + proxy->OnCanceled(notification, nullptr, deleteReason); +} + +/* + * @tc.name: OnUpdated_0100 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnUpdated_0200 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnUpdated_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnUpdated_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + ASSERT_NE(nullptr, notificationMap); + proxy->OnUpdated(notificationMap); +} + +/* + * @tc.name: OnOnUpdated_0300 + * @tc.desc: test AnsSubscriberProxy's OnUpdated function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnOnUpdated_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnOnUpdated_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + proxy->OnUpdated(nullptr); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0100 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); + ASSERT_NE(nullptr, date); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnDoNotDisturbDateChange_0200 + * @tc.desc: test AnsSubscriberProxy's OnDoNotDisturbDateChange function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnDoNotDisturbDateChange_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr date = new (std::nothrow) NotificationDoNotDisturbDate(); + ASSERT_NE(nullptr, date); + proxy->OnDoNotDisturbDateChange(date); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0100 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); + ASSERT_NE(nullptr, callbackData); + proxy->OnEnabledNotificationChanged(callbackData); +} + +/* + * @tc.name: OnEnabledNotificationChanged_0200 + * @tc.desc: test AnsSubscriberProxy's OnEnabledNotificationChanged function + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyUnitTest, OnEnabledNotificationChanged_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr callbackData = new (std::nothrow) EnabledNotificationCallbackData(); + ASSERT_NE(nullptr, callbackData); + proxy->OnEnabledNotificationChanged(callbackData); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/mock/mock_i_remote_object.h b/frameworks/core/test/unittest/mock/mock_i_remote_object.h new file mode 100644 index 000000000..d37235cd5 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_i_remote_object.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gmock/gmock.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Notification { +class MockIRemoteObject : public IRemoteObject { +public: + MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} + + ~MockIRemoteObject() {} + + int32_t GetObjectRefCount() override + { + return 0; + } + + MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; +} // namespace Notification +} // namespace OHOS -- Gitee From fb7a6ece62dbcd36d2a7621256311fbf1a949115 Mon Sep 17 00:00:00 2001 From: wangkailong Date: Thu, 27 Oct 2022 20:15:21 +0800 Subject: [PATCH 25/44] =?UTF-8?q?ans=5Fsubscriber=5Fstub=E6=96=B0=E5=A2=9E?= =?UTF-8?q?tdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkailong Change-Id: I5b730208c6dcb355be9edf812852773def2ebf15 --- frameworks/core/test/unittest/BUILD.gn | 1 + .../ans_subscriber_stub_test/BUILD.gn | 50 ++ .../ans_subscriber_stub_unit_test.cpp | 490 ++++++++++++++++++ 3 files changed, 541 insertions(+) create mode 100644 frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 4b4e565eb..378e132d9 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -19,5 +19,6 @@ group("unittest") { "ans_callback_stub_test:unittest", "ans_manager_death_recipient_test:unittest", "ans_subscriber_proxy_test:unittest", + "ans_subscriber_stub_test:unittest", ] } diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn new file mode 100644 index 000000000..a94904050 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_subscriber_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_subscriber_stub_unit_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_subscriber_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp new file mode 100644 index 000000000..acf8e39a5 --- /dev/null +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp @@ -0,0 +1,490 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ans_subscriber_stub.h" +#include "ans_inner_errors.h" +#include "ans_notification.h" +#undef private +#undef protected + +#include "message_option.h" +#include "message_parcel.h" +#include "parcel.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class AnsSubscriberStubUnitTest : public testing::Test { +public: + AnsSubscriberStubUnitTest() {} + + virtual ~AnsSubscriberStubUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; + + sptr stub_; +}; + +void AnsSubscriberStubUnitTest::SetUpTestCase() +{ +} + +void AnsSubscriberStubUnitTest::TearDownTestCase() +{ +} + +void AnsSubscriberStubUnitTest::SetUp() +{ + stub_ = new AnsSubscriberStub(); +} + +void AnsSubscriberStubUnitTest::TearDown() +{ +} + +/** +* @tc.name: OnRemoteRequest01 +* @tc.desc: test descriptor check failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest01, Function | MediumTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool bRet = data.WriteInterfaceToken(u"error descriptor"); + EXPECT_TRUE(bRet) << "write token error"; + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_CONNECTED); + + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, OBJECT_NULL) << "descriptor error"; +} + +/** +* @tc.name: OnRemoteRequest02 +* @tc.desc: test code error +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + + + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED + 1); + + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_TRUE(res != NO_ERROR); +} + +/** +* @tc.name: OnRemoteRequest03 +* @tc.desc: test function error +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED); + stub_->interfaces_[AnsSubscriberInterface::TransactId::ON_ENABLED_NOTIFICATION_CHANGED] = nullptr; + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_TRUE(res != NO_ERROR); +} + +/** +* @tc.name: OnRemoteRequest04 +* @tc.desc: test ON_CONNECTED success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, OnRemoteRequest04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(AnsSubscriberStub::GetDescriptor()); + uint32_t code = static_cast(AnsSubscriberInterface::TransactId::ON_CONNECTED); + ErrCode res = stub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, NO_ERROR); +} + +/** +* @tc.name: HandleOnConnected +* @tc.desc: test HandleOnConnected success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConnected, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConnected(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnDisconnected +* @tc.desc: test HandleOnDisconnected success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDisconnected, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnDisconnected(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnConsumed01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumed01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumed(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumed02 +* @tc.desc: test notification success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumed02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + ErrCode res = stub_->HandleOnConsumed(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnConsumedMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedMap04 +* @tc.desc: test HandleOnConsumedMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnConsumedMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnCanceled01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceled01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnCanceled(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceled02 +* @tc.desc: test HandleOnCanceled success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceled02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnCanceled(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnCanceledMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap04 +* @tc.desc: test read reason failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnCanceledMap05 +* @tc.desc: test HandleOnCanceledMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnCanceledMap05, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + data.WriteParcelable(notification); + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + int32_t reason = 0; + data.WriteInt32(reason); + + ErrCode res = stub_->HandleOnCanceledMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnUpdated01 +* @tc.desc: test notificationMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnUpdated(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnUpdated02 +* @tc.desc: test HandleOnUpdated success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnUpdated02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notificationMap = new NotificationSortingMap(); + data.WriteParcelable(notificationMap); + + ErrCode res = stub_->HandleOnUpdated(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnDoNotDisturbDateChange01 +* @tc.desc: test callbackData failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnDoNotDisturbDateChange02 +* @tc.desc: test HandleOnDoNotDisturbDateChange success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnDoNotDisturbDateChange02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notifcallbackDataication = new EnabledNotificationCallbackData(); + data.WriteParcelable(notifcallbackDataication); + + ErrCode res = stub_->HandleOnDoNotDisturbDateChange(data, reply); + EXPECT_EQ(res, ERR_OK); +} + +/** +* @tc.name: HandleOnEnabledNotificationChanged01 +* @tc.desc: test callbackData failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnEnabledNotificationChanged02 +* @tc.desc: test HandleOnEnabledNotificationChanged success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnEnabledNotificationChanged02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notifcallbackDataication = new EnabledNotificationCallbackData(); + data.WriteParcelable(notifcallbackDataication); + + ErrCode res = stub_->HandleOnEnabledNotificationChanged(data, reply); + EXPECT_EQ(res, ERR_OK); +} +} +} -- Gitee From 6c50a3230ad733a7519d490a74ca0331b2074cc7 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Fri, 28 Oct 2022 15:43:35 +0800 Subject: [PATCH 26/44] add fuzz test Signed-off-by: liuyanzhi Change-Id: If3a02a73efca1fbf861c80fa497033f991a6e431 --- test/fuzztest/BUILD.gn | 2 + .../ansmanagerstubannexthree_fuzzer/BUILD.gn | 56 +++++++++++ .../ansmanagerstubannexthree_fuzzer.cpp | 87 +++++++++++++++++ .../ansmanagerstubannexthree_fuzzer.h | 23 +++++ .../corpus/init | 13 +++ .../project.xml | 25 +++++ .../ansmanagerstubannextwo_fuzzer/BUILD.gn | 56 +++++++++++ .../ansmanagerstubannextwo_fuzzer.cpp | 95 +++++++++++++++++++ .../ansmanagerstubannextwo_fuzzer.h | 23 +++++ .../ansmanagerstubannextwo_fuzzer/corpus/init | 13 +++ .../ansmanagerstubannextwo_fuzzer/project.xml | 25 +++++ 11 files changed, 418 insertions(+) create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 0091642d5..e1341def3 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -20,6 +20,8 @@ group("fuzztest") { "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", + "ansmanagerstubannexthree_fuzzer:AnsManagerStubAnnexThreeFuzzTest", + "ansmanagerstubannextwo_fuzzer:AnsManagerStubAnnexTwoFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn new file mode 100644 index 000000000..69d0849c6 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexThreeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannexthree_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannexthree_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexThreeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp new file mode 100644 index 000000000..e8fa6cd0f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannexthree_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + bool allow = *data % ENABLE; + ansManagerStub.GetPrivateNotificationsAllowed(allow); + sptr bundleOption = new Notification::NotificationBundleOption(); + int notificationId = 1; + std::string stringData(data); + int32_t removeReason = static_cast(GetU32Data(data)); + ansManagerStub.RemoveNotification(bundleOption, notificationId, stringData, removeReason); + ansManagerStub.RemoveAllNotifications(bundleOption); + ansManagerStub.Delete(stringData, removeReason); + ansManagerStub.DeleteByBundle(bundleOption); + ansManagerStub.DeleteAll(); + sptr slot = new Notification::NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + ansManagerStub.GetSlotsByBundle(bundleOption, slots); + ansManagerStub.SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, allow); + ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, allow); + ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, allow); + ansManagerStub.GetShowBadgeEnabled(allow); + ansManagerStub.AreNotificationsSuspended(allow); + sptr sortingMap = new Notification::NotificationSortingMap(); + ansManagerStub.GetCurrentAppSorting(sortingMap); + ansManagerStub.IsAllowedNotify(allow); + ansManagerStub.IsAllowedNotifySelf(allow); + ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allow); + ansManagerStub.CancelGroup(stringData); + ansManagerStub.RemoveGroupByBundle(bundleOption, stringData); + ansManagerStub.DoesSupportDoNotDisturbMode(allow); + ansManagerStub.IsDistributedEnabled(allow); + ansManagerStub.EnableDistributed(allow); + ansManagerStub.EnableDistributedByBundle(bundleOption, allow); + ansManagerStub.EnableDistributedSelf(allow); + ansManagerStub.IsDistributedEnableByBundle(bundleOption, allow); + int32_t remindType = static_cast(*data % SLOT_TYPE_NUM); + Notification::NotificationConstant::RemindType remind = + Notification::NotificationConstant::RemindType(remindType); + ansManagerStub.GetDeviceRemindType(remind); + sptr request = new Notification::NotificationRequest(); + ansManagerStub.PublishContinuousTaskNotification(request); + ansManagerStub.CancelContinuousTaskNotification(stringData, removeReason); + ansManagerStub.CancelReminder(removeReason); + return ansManagerStub.CancelAllReminders(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h new file mode 100644 index 000000000..ec514818a --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannexthree_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTHREE_FUZZER_ANSMANAGERSTUBANNEXTHREE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn new file mode 100644 index 000000000..ab0e817f3 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsManagerStubAnnexTwoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannextwo_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannextwo_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexTwoFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp new file mode 100644 index 000000000..e310e1843 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected +#include "ansmanagerstubannextwo_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::AnsManagerStub ansManagerStub; + MessageParcel datas; + MessageParcel reply; + ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply); + ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply); + std::string stringData(data); + sptr notification = new Notification::NotificationRequest(); + ansManagerStub.Publish(stringData, notification); + ansManagerStub.PublishToDevice(notification, stringData); + int notificationId = 1; + ansManagerStub.Cancel(notificationId, stringData); + ansManagerStub.CancelAll(); + int32_t notificationIds = static_cast(GetU32Data(data)); + int32_t userId = static_cast(GetU32Data(data)); + ansManagerStub.CancelAsBundle(notificationIds, stringData, userId); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + ansManagerStub.AddSlotByType(slotType); + sptr slot = new Notification::NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + ansManagerStub.AddSlots(slots); + ansManagerStub.RemoveSlotByType(slotType); + ansManagerStub.RemoveAllSlots(); + ansManagerStub.GetSlotByType(slotType, slot); + ansManagerStub.GetSlots(slots); + sptr bundleOption = new Notification::NotificationBundleOption(); + uint64_t num = 1; + ansManagerStub.GetSlotNumAsBundle(bundleOption, num); + sptr notificationer = new Notification::NotificationRequest(); + std::vector> notifications; + notifications.emplace_back(notificationer); + ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotificationNums(num); + sptr notificatione = new Notification::Notification(); + std::vector> notificationes; + notificationes.emplace_back(notificatione); + ansManagerStub.GetAllActiveNotifications(notificationes); + std::vector key; + key.emplace_back(stringData); + ansManagerStub.GetSpecialActiveNotifications(key, notificationes); + ansManagerStub.SetNotificationAgent(stringData); + ansManagerStub.GetNotificationAgent(stringData); + bool canPublish = *data % ENABLE; + ansManagerStub.CanPublishAsBundle(stringData, canPublish); + ansManagerStub.PublishAsBundle(notificationer, stringData); + ansManagerStub.SetNotificationBadgeNum(notificationId); + ansManagerStub.GetBundleImportance(notificationId); + ansManagerStub.HasNotificationPolicyAccessPermission(canPublish); + return ansManagerStub.SetPrivateNotificationsAllowed(canPublish); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h new file mode 100644 index 000000000..530222636 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannextwo_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From 16abd510d08650b5baf7db7e2c575dd0aff85e4f Mon Sep 17 00:00:00 2001 From: wangkailong Date: Fri, 28 Oct 2022 20:22:53 +0800 Subject: [PATCH 27/44] =?UTF-8?q?=E9=9D=99=E6=80=81=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkailong Change-Id: I483df608ca2b2d22918a2ae01f6bcdfa6fc424ac --- frameworks/js/napi/src/subscribe.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index c128d88c4..33948cdc2 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -232,7 +232,7 @@ void SubscriberInstance::OnCanceled(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnCanceled); if (ret != 0) { @@ -327,7 +327,7 @@ void SubscriberInstance::OnConsumed(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnConsumed); if (ret != 0) { @@ -406,7 +406,7 @@ void SubscriberInstance::OnUpdate(const std::shared_ptr return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnUpdate); if (ret != 0) { @@ -474,7 +474,7 @@ void SubscriberInstance::OnConnected() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnConnected); if (ret != 0) { @@ -545,7 +545,7 @@ void SubscriberInstance::OnDisconnected() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDisconnected); if (ret != 0) { @@ -613,7 +613,7 @@ void SubscriberInstance::OnDied() return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDied); if (ret != 0) { @@ -694,7 +694,7 @@ void SubscriberInstance::OnDoNotDisturbDateChange(const std::shared_ptrdata = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDoNotDisturbDateChange); if (ret != 0) { @@ -776,7 +776,7 @@ void SubscriberInstance::OnEnabledNotificationChanged( return; } - work->data = (void *)dataWorker; + work->data = reinterpret_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnEnabledNotificationChanged); if (ret != 0) { -- Gitee From 6ef40f4588c5575072e1cbf5bc99102c2f96773e Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Fri, 28 Oct 2022 20:01:26 +0800 Subject: [PATCH 28/44] static check modify Signed-off-by: fangJinliang1 Change-Id: I7aab026f473be3951545fd8afbc7d7ec2c844d14 Signed-off-by: fangJinliang1 --- frameworks/ans/src/notification.cpp | 2 +- frameworks/ans/src/notification_distributed_options.cpp | 4 ++-- frameworks/js/napi/include/subscribe.h | 2 +- frameworks/js/napi/src/reminder/publish.cpp | 2 +- frameworks/js/napi/src/reminder/reminder_common.cpp | 3 +-- frameworks/js/napi/src/subscribe.cpp | 2 +- services/ans/src/advanced_notification_service.cpp | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index f368a78c2..af1ca979b 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -486,7 +486,7 @@ void Notification::SetSourceType(NotificationConstant::SourceType sourceType) std::string Notification::Dump() const { std::string vibrationStyle = ""; - for (auto &style : vibrationStyle_) { + for (const auto &style : vibrationStyle_) { vibrationStyle += std::to_string(style); vibrationStyle += ", "; } diff --git a/frameworks/ans/src/notification_distributed_options.cpp b/frameworks/ans/src/notification_distributed_options.cpp index dbfb26a27..4f6349f67 100644 --- a/frameworks/ans/src/notification_distributed_options.cpp +++ b/frameworks/ans/src/notification_distributed_options.cpp @@ -56,13 +56,13 @@ std::vector NotificationDistributedOptions::GetDevicesSupportOperat std::string NotificationDistributedOptions::Dump() { std::string devicesSupportDisplay = ""; - for (auto &device : devicesSupportDisplay_) { + for (const auto &device : devicesSupportDisplay_) { devicesSupportDisplay += device; devicesSupportDisplay += ", "; } std::string devicesSupportOperate = ""; - for (auto &device : devicesSupportOperate_) { + for (const auto &device : devicesSupportOperate_) { devicesSupportOperate += device; devicesSupportOperate += ", "; } diff --git a/frameworks/js/napi/include/subscribe.h b/frameworks/js/napi/include/subscribe.h index 44b4a4eee..547107c67 100644 --- a/frameworks/js/napi/include/subscribe.h +++ b/frameworks/js/napi/include/subscribe.h @@ -167,7 +167,7 @@ static std::vector DeletingSubscriber; bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, SubscriberInstancesInfo &subscriberInfo); bool AddSubscriberInstancesInfo(const napi_env &env, const SubscriberInstancesInfo &subscriberInfo); -bool DelSubscriberInstancesInfo(const napi_env &env, SubscriberInstance *subscriber); +bool DelSubscriberInstancesInfo(const napi_env &env, const SubscriberInstance *subscriber); bool AddDeletingSubscriber(SubscriberInstance *subscriber); void DelDeletingSubscriber(SubscriberInstance *subscriber); diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 1d46fd682..f93810a8c 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -476,7 +476,7 @@ void ParseReminderCalendar(const napi_env &env, const ReminderRequest &reminder, } void ParseReminder( - const napi_env &env, const ReminderRequest::ReminderType &type, ReminderRequest &reminder, napi_value &result) + const napi_env &env, const ReminderRequest::ReminderType &type, const ReminderRequest &reminder, napi_value &result) { switch (type) { case ReminderRequest::ReminderType::TIMER: { diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 68642259b..0ca441b60 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -552,8 +552,7 @@ void ReminderCommon::HandleErrCode(const napi_env &env, int32_t errCode) if (errCode == ERR_OK) { return; } - std::string errCodeMsg = FindErrMsg(env, errCode); - errCodeMsg = reminderErrCodeMsgMap[errCode]; + std::string errCodeMsg = reminderErrCodeMsgMap[errCode]; napi_throw_error(env, std::to_string(errCode).c_str(), errCodeMsg.c_str()); } diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index c128d88c4..86cc4582e 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -1038,7 +1038,7 @@ bool AddSubscriberInstancesInfo(const napi_env &env, const SubscriberInstancesIn return true; } -bool DelSubscriberInstancesInfo(const napi_env &env, SubscriberInstance *subscriber) +bool DelSubscriberInstancesInfo(const napi_env &env, const SubscriberInstance *subscriber) { ANS_LOGI("enter"); if (subscriber == nullptr) { diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 971858661..9818b6fda 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2101,7 +2101,7 @@ ErrCode AdvancedNotificationService::FlowControl(const std::shared_ptr> sorted = notificationList_; sorted.sort(SortNotificationsByLevelAndTime); - recordToRemove = bundleList.front(); + recordToRemove = sorted.front(); SendFlowControlOccurHiSysEvent(recordToRemove); notificationList_.remove(sorted.front()); } -- Gitee From fb01981032c93eae1454073de0f9e7c7a79e04e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Sat, 29 Oct 2022 16:50:29 +0800 Subject: [PATCH 29/44] =?UTF-8?q?IssueNo:=20#I5YE46=20Description:=20?= =?UTF-8?q?=E5=81=B6=E7=8E=B0=E5=B4=A9=E6=BA=83=E5=A4=84=E7=90=86=20Sig:?= =?UTF-8?q?=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:=20Bugfix?= =?UTF-8?q?=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: I349984afc5794a298bee8ed71df4e4eff0409578 --- services/ans/src/notification_preferences_database.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 811dd544c..1f7a74bb6 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -674,15 +674,14 @@ bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreferencesInfo &info) { ANS_LOGD("%{public}s", __FUNCTION__); - ParseDoNotDisturbType(info); - ParseDoNotDisturbBeginDate(info); - ParseDoNotDisturbEndDate(info); - ParseEnableAllNotification(info); - if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); return false; } + ParseDoNotDisturbType(info); + ParseDoNotDisturbBeginDate(info); + ParseDoNotDisturbEndDate(info); + ParseEnableAllNotification(info); DistributedKv::Status status; std::vector entries; status = kvStorePtr_->GetEntries(DistributedKv::Key(KEY_BUNDLE_LABEL), entries); -- Gitee From 42526e7d9c1ebec16927605780f89c2effa97a61 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Sat, 29 Oct 2022 16:54:58 +0800 Subject: [PATCH 30/44] modify ut Signed-off-by: fangJinliang1 Change-Id: If9f43cbe9441b7b1dc958c0cc576efb7f53ded73 --- frameworks/ans/test/unittest/notification_helper_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index e7b70338e..5dda006cb 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -419,7 +419,7 @@ HWTEST_F(NotificationHelperTest, RequestEnableNotification_00001, Function | Sma NotificationHelper notificationHelper; bool needPop = true; ErrCode ret = notificationHelper.RequestEnableNotification(deviceId, needPop); - EXPECT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE); } /** @@ -883,7 +883,7 @@ HWTEST_F(NotificationHelperTest, IsAllowedNotify_00003, Function | SmallTest | L bool allowed = true; NotificationHelper notificationHelper; ErrCode ret = notificationHelper.IsAllowedNotify(userId, allowed); - EXPECT_EQ(ret, (int)ERR_OK); + EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } /** -- Gitee From 293d28bc0031dc19de75eb7f2ad50844b7a260d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Mon, 31 Oct 2022 09:59:16 +0800 Subject: [PATCH 31/44] =?UTF-8?q?IssueNo:=20#I5YHL9=20Description:=20?= =?UTF-8?q?=E5=81=B6=E7=8E=B0=E5=B4=A9=E6=BA=83=E5=A4=84=E7=90=86=20Sig:?= =?UTF-8?q?=20SIG=5FApplicationFramework=20Feature=20or=20Bugfix:=20Bugfix?= =?UTF-8?q?=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: Iecb248a5da03b34ce500ec8952245b5dea54ce65 --- .../ans/src/notification_preferences_database.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 1f7a74bb6..ddd71a199 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -313,13 +313,14 @@ DistributedKv::Status NotificationPreferencesDatabase::GetKvStore() if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Return error: %{public}d.", status); } else { - ANS_LOGD("Get kvStore success."); + ANS_LOGI("Get kvStore success."); } return status; } void NotificationPreferencesDatabase::CloseKvStore() { + ANS_LOGI("Close kvStore success."); dataManager_.CloseKvStore(appId_, kvStorePtr_); } @@ -674,14 +675,15 @@ bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreferencesInfo &info) { ANS_LOGD("%{public}s", __FUNCTION__); - if (!CheckKvStore()) { - ANS_LOGE("KvStore is nullptr."); - return false; - } ParseDoNotDisturbType(info); ParseDoNotDisturbBeginDate(info); ParseDoNotDisturbEndDate(info); ParseEnableAllNotification(info); + + if (!CheckKvStore()) { + ANS_LOGE("KvStore is nullptr."); + return false; + } DistributedKv::Status status; std::vector entries; status = kvStorePtr_->GetEntries(DistributedKv::Key(KEY_BUNDLE_LABEL), entries); -- Gitee From f672f6c1e44c7b06c0d0ea9553650eb100971313 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Mon, 31 Oct 2022 15:41:57 +0800 Subject: [PATCH 32/44] static check modify Signed-off-by: fangJinliang1 Change-Id: I8fd203fefd39c4b115ce08fec1ac3ec11dd5f73a --- frameworks/js/napi/src/subscribe.cpp | 2 +- services/ans/src/advanced_notification_service.cpp | 4 ++-- tools/dump/src/notification_shell_command.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index dfe646ee1..c3d9eef18 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -101,8 +101,8 @@ napi_value SetSubscribeCallbackData(const napi_env &env, // vibrationValues?: Array napi_value arr = nullptr; napi_create_array(env, &arr); - uint32_t count = 0; if (request->EnableVibrate()) { + uint32_t count = 0; for (auto vec : request->GetVibrationStyle()) { napi_value nVibrationValue = nullptr; napi_create_int64(env, vec, &nVibrationValue); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index c6d9f465d..0fc79793d 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -3687,7 +3687,7 @@ void AdvancedNotificationService::SendSubscribeHiSysEvent(int32_t pid, int32_t u eventInfo.userId = info->GetAppUserId(); std::vector appNames = info->GetAppNames(); eventInfo.bundleName = std::accumulate(appNames.begin(), appNames.end(), std::string(""), - [appNames](const std::string bundleName, const std::string &str) { + [appNames](const std::string &bundleName, const std::string &str) { return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); } @@ -3710,7 +3710,7 @@ void AdvancedNotificationService::SendUnSubscribeHiSysEvent(int32_t pid, int32_t eventInfo.userId = info->GetAppUserId(); std::vector appNames = info->GetAppNames(); eventInfo.bundleName = std::accumulate(appNames.begin(), appNames.end(), std::string(""), - [appNames](const std::string bundleName, const std::string &str) { + [appNames](const std::string &bundleName, const std::string &str) { return (str == appNames.front()) ? (bundleName + str) : (bundleName + "," + str); }); } diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index 0906e4684..1d4b04f71 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -244,7 +244,6 @@ void NotificationShellCommand::CheckDumpOpt() ErrCode NotificationShellCommand::RunAsSettingCommand() { - std::vector infos; int option = getopt_long(argc_, argv_, SETTING_SHORT_OPTIONS, SETTING_LONG_OPTIONS, nullptr); if (option == '?') { if (optopt == 'c') { @@ -264,6 +263,7 @@ ErrCode NotificationShellCommand::RunAsSettingCommand() resultReceiver_.append(SETTING_HELP_MSG); return ERR_INVALID_VALUE; } + std::vector infos; std::string cmd = COMMAND_SET_RECENT_COUNT; cmd.append(" ").append(std::string(optarg)); return RunDumpCmd(cmd, "", SUBSCRIBE_USER_INIT, infos); -- Gitee From ccd443e8a282d653c4326dcda4344ded6cc42027 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 1 Nov 2022 15:55:12 +0800 Subject: [PATCH 33/44] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BB=A7=E6=89=BFParce?= =?UTF-8?q?l=E7=9A=84Marshalling=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: htt1997 --- services/test/moduletest/mock/blob.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/services/test/moduletest/mock/blob.cpp b/services/test/moduletest/mock/blob.cpp index 540888d0f..9acb0f99d 100644 --- a/services/test/moduletest/mock/blob.cpp +++ b/services/test/moduletest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { -- Gitee From 7ddfb0caf553138c625c2e729df6bcf413bc48f8 Mon Sep 17 00:00:00 2001 From: renhw Date: Tue, 1 Nov 2022 16:59:00 +0800 Subject: [PATCH 34/44] modify image part so Signed-off-by: renhw --- frameworks/js/napi/BUILD.gn | 2 +- frameworks/js/napi/src/manager/BUILD.gn | 2 +- frameworks/js/napi/src/reminder/BUILD.gn | 4 ++-- frameworks/js/napi/src/subscribe/BUILD.gn | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index a1aa00bcb..bf8794ab1 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -76,7 +76,7 @@ ohos_shared_library("notification") { "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 074baef98..ad252fb33 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -66,7 +66,7 @@ ohos_shared_library("notificationmanager") { "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_path}/frameworks/native/appkit:app_context", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn index d116b4430..57b4ba33e 100644 --- a/frameworks/js/napi/src/reminder/BUILD.gn +++ b/frameworks/js/napi/src/reminder/BUILD.gn @@ -49,7 +49,7 @@ ohos_shared_library("reminderagent") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ @@ -94,7 +94,7 @@ ohos_shared_library("reminderagentmanager") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ diff --git a/frameworks/js/napi/src/subscribe/BUILD.gn b/frameworks/js/napi/src/subscribe/BUILD.gn index c18561fa6..6d1d3ecca 100644 --- a/frameworks/js/napi/src/subscribe/BUILD.gn +++ b/frameworks/js/napi/src/subscribe/BUILD.gn @@ -53,7 +53,7 @@ ohos_shared_library("notificationsubscribe") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${core_path}:ans_core", - "//foundation/multimedia/image_framework/interfaces/innerkits:image", + "//foundation/multimedia/image_framework/interfaces/kits/js/common:image", ] external_deps = [ -- Gitee From 54f46b752e85a4079b6af4ce437eaf1375a14102 Mon Sep 17 00:00:00 2001 From: liqiang Date: Mon, 31 Oct 2022 10:54:40 +0800 Subject: [PATCH 35/44] =?UTF-8?q?ans=5Fimage=5Futil=E5=A2=9E=E5=8A=A0tdd?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liqiang Change-Id: I09df7a4703dcf05a16b195f4f84dfc1678a09d77 --- frameworks/core/test/unittest/BUILD.gn | 1 + .../unittest/ans_image_util_test/BUILD.gn | 62 ++ .../ans_image_util_unit_test.cpp | 658 ++++++++++++++++++ .../test/unittest/mock/mock_i_remote_object.h | 160 ++--- .../test/unittest/mock/mock_image_packer.cpp | 139 ++++ .../unittest/mock/mock_image_related_class.h | 30 + .../test/unittest/mock/mock_image_source.cpp | 373 ++++++++++ .../test/unittest/mock/mock_pixel_map.cpp | 384 ++++++++++ 8 files changed, 1729 insertions(+), 78 deletions(-) create mode 100644 frameworks/core/test/unittest/ans_image_util_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_image_packer.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_image_related_class.h create mode 100644 frameworks/core/test/unittest/mock/mock_image_source.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_pixel_map.cpp diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 4b4e565eb..4d234bda8 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -17,6 +17,7 @@ group("unittest") { deps += [ "ans_callback_stub_test:unittest", + "ans_image_util_test:unittest", "ans_manager_death_recipient_test:unittest", "ans_subscriber_proxy_test:unittest", ] diff --git a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn new file mode 100644 index 000000000..366fadf47 --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_image_util_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "${core_path}/common/include", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + "../mock", + ] + + sources = [ + "${core_path}/common/src/ans_log_wrapper.cpp", + "${core_path}/src/ans_image_util.cpp", + "../mock/mock_image_packer.cpp", + "../mock/mock_image_source.cpp", + "../mock/mock_pixel_map.cpp", + "ans_image_util_unit_test.cpp", + ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_image_util_test" ] +} diff --git a/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp new file mode 100644 index 000000000..718f12727 --- /dev/null +++ b/frameworks/core/test/unittest/ans_image_util_test/ans_image_util_unit_test.cpp @@ -0,0 +1,658 @@ + /* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ans_image_util.h" +#include "image_packer.h" +#include "pixel_map.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; + +extern void MockImagePackerGetSupportedFormats(uint32_t mockRet); +extern void MockImagePackerStartPacking(const uint8_t* mockRet); +extern void MockImagePackerFinalizePacking(uint32_t mockRet); +extern void MockResetImagePackerState(); + +extern void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode); +extern void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode); +extern void MockImageSourceGetSupportedFormats(uint32_t mockRet); +extern void MockResetImageSourceState(); + +extern void MockPixelMapGetByteCount(int32_t mockRet); +extern void MockResetPixelMapState(); + +class AnsImageUtilUnitTest : public testing::Test { +public: + AnsImageUtilUnitTest() {} + + virtual ~AnsImageUtilUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsImageUtilUnitTest::SetUpTestCase() {} + +void AnsImageUtilUnitTest::TearDownTestCase() {} + +void AnsImageUtilUnitTest::SetUp() {} + +void AnsImageUtilUnitTest::TearDown() {} + +/* + * @tc.name: PackImageTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_FALSE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: PackImageTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string format = ":"; + std::string res = imageUtil->PackImage(nullptr, format); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string res = imageUtil->PackImage(pixelMap, ""); + EXPECT_TRUE(res.empty()); +} + +/* + * @tc.name: PackImageTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImageTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + const uint8_t testBitmap[16] = "101"; // 16 : size of testbitmap + MockImagePackerStartPacking(testBitmap); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + ASSERT_NE(nullptr, pixelMap); + std::string format = ":"; + std::string res = imageUtil->PackImage(pixelMap, format); + EXPECT_TRUE(res.empty()); + MockResetImagePackerState(); + MockResetPixelMapState(); +} + +/* + * @tc.name: UnPackImageTest_0100 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0200 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = ""; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0300 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0400 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0500 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: UnPackImageTest_0600 + * @tc.desc: test if AnsImageUtil's UnPackImage function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, UnPackImageTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, UnPackImageTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string pixelMapStr = "101"; + std::shared_ptr res = imageUtil->UnPackImage(pixelMapStr); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: PackImage2FileTest_0100 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0100, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_TRUE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0200 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0200, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = nullptr; + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0300 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0300, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = ""; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0400 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0400, TestSize.Level1"; + MockImagePackerGetSupportedFormats(0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = ""; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: PackImage2FileTest_0500 + * @tc.desc: test if AnsImageUtil's PackImage2File function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, PackImage2FileTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, PackImage2FileTest_0500, TestSize.Level1"; + MockImagePackerGetSupportedFormats(1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::shared_ptr pixelMap = std::make_shared(); + std::string outFilePath = "testPath"; + std::string format = "testFormat"; + bool res = imageUtil->PackImage2File(pixelMap, outFilePath, format); + EXPECT_FALSE(res); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0100 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0100, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_NE(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0200 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0200, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = ""; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0300 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0300, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = ""; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + + +/* + * @tc.name: CreatePixelMapTest_0400 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0400, TestSize.Level1"; + MockImageSourceCreateImageSource(false, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0500 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0500, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 1); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0600 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0600, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(1); + MockImageSourceCreatePixelMap(true, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); +} + +/* + * @tc.name: CreatePixelMapTest_0700 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0700, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(false, 0); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: CreatePixelMapTest_0800 + * @tc.desc: test if AnsImageUtil's CreatePixelMap function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, CreatePixelMapTest_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, CreatePixelMapTest_0800, TestSize.Level1"; + MockImageSourceCreateImageSource(true, 0); + MockImageSourceGetSupportedFormats(0); + MockImageSourceCreatePixelMap(true, 1); + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string inFilePath = "testInfile"; + std::string format = "testFormat"; + std::shared_ptr res = imageUtil->CreatePixelMap(inFilePath, format); + EXPECT_EQ(nullptr, res); + MockResetImageSourceState(); + MockResetImagePackerState(); +} + +/* + * @tc.name: BinToHexTest_0100 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = "12112221"; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_NE("", res); +} + +/* + * @tc.name: BinToHexTest_0200 + * @tc.desc: test if AnsImageUtil's BinToHex function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, BinToHexTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, BinToHexTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strBin = ""; + std::string res = imageUtil->HexToBin(strBin); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0100 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0100, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "12112221"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_NE("", res); +} + +/* + * @tc.name: HexToBinTest_0200 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0200, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = ""; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0300 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0300, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} + +/* + * @tc.name: HexToBinTest_0400 + * @tc.desc: test if AnsImageUtil's HexToBin function. + * @tc.type: FUNC + * @tc.require: #I5SJ62 + */ +HWTEST_F(AnsImageUtilUnitTest, HexToBinTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsImageUtilUnitTest, HexToBinTest_0400, TestSize.Level1"; + std::shared_ptr imageUtil = std::make_shared(); + ASSERT_NE(nullptr, imageUtil); + std::string strHex = "123x"; + std::string res = imageUtil->HexToBin(strHex); + EXPECT_EQ("", res); +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/mock/mock_i_remote_object.h b/frameworks/core/test/unittest/mock/mock_i_remote_object.h index d37235cd5..5a2392a1d 100644 --- a/frameworks/core/test/unittest/mock/mock_i_remote_object.h +++ b/frameworks/core/test/unittest/mock/mock_i_remote_object.h @@ -1,78 +1,82 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "gmock/gmock.h" - -#include "iremote_broker.h" -#include "iremote_object.h" - -namespace OHOS { -namespace Notification { -class MockIRemoteObject : public IRemoteObject { -public: - MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} - - ~MockIRemoteObject() {} - - int32_t GetObjectRefCount() override - { - return 0; - } - - MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - - bool IsProxyObject() const override - { - return true; - } - - bool CheckObjectLegality() const override - { - return true; - } - - bool AddDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool RemoveDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool Marshalling(Parcel &parcel) const override - { - return true; - } - - sptr AsInterface() override - { - return nullptr; - } - - int Dump(int fd, const std::vector &args) override - { - return 0; - } - - std::u16string GetObjectDescriptor() const - { - std::u16string descriptor = std::u16string(); - return descriptor; - } -}; -} // namespace Notification -} // namespace OHOS +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H +#define BASE_NOTIFICATION_MOCK_I_REMOTE_OBJECT_H + +#include "gmock/gmock.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Notification { +class MockIRemoteObject : public IRemoteObject { +public: + MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {} + + ~MockIRemoteObject() {} + + int32_t GetObjectRefCount() override + { + return 0; + } + + MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; +} // namespace Notification +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_packer.cpp b/frameworks/core/test/unittest/mock/mock_image_packer.cpp new file mode 100644 index 000000000..8063acfc9 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_packer.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "image_packer.h" +#include "mock_image_related_class.h" +#include "securec.h" + +namespace { +const uint8_t COUNT = 64; +uint32_t g_mockImagePackerGetSupportedFormatsRet = 0; +const uint8_t *g_mockImagePackerStartPackingRet = nullptr; +uint32_t g_mockImagePackerFinalizePackingRet = 16; +} + +void MockImagePackerGetSupportedFormats(uint32_t mockRet) +{ + g_mockImagePackerGetSupportedFormatsRet = mockRet; +} + +void MockImagePackerStartPacking(const uint8_t *mockRet) +{ + g_mockImagePackerStartPackingRet = mockRet; +} + +void MockImagePackerFinalizePacking(uint32_t mockRet) +{ + g_mockImagePackerFinalizePackingRet = mockRet; +} + +void MockResetImagePackerState() +{ + g_mockImagePackerGetSupportedFormatsRet = 0; + g_mockImagePackerStartPackingRet = nullptr; + g_mockImagePackerFinalizePackingRet = 16; // 16 :initial test result +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; +using namespace MultimediaPlugin; + +uint32_t ImagePacker::GetSupportedFormats(std::set &formats) +{ + return g_mockImagePackerGetSupportedFormatsRet; +} + +uint32_t ImagePacker::StartPackingImpl(const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(uint8_t *outputData, uint32_t maxSize, const PackOption &option) +{ + memcpy_s(outputData, COUNT, g_mockImagePackerStartPackingRet, COUNT); + return 0; +} + +uint32_t ImagePacker::StartPacking(const std::string &filePath, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(const int &fd, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPacking(std::ostream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::StartPackingAdapter(PackerStream &outputStream, const PackOption &option) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(PixelMap &pixelMap) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source) +{ + return 0; +} + +uint32_t ImagePacker::AddImage(ImageSource &source, uint32_t index) +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking() +{ + return 0; +} + +uint32_t ImagePacker::FinalizePacking(int64_t &packedSize) +{ + packedSize = g_mockImagePackerFinalizePackingRet; + return 0; +} + +bool ImagePacker::GetEncoderPlugin(const PackOption &option) +{ + return true; +} + +void ImagePacker::CopyOptionsToPlugin(const PackOption &opts, PlEncodeOptions &plOpts) +{} + +void ImagePacker::FreeOldPackerStream() +{} + +bool ImagePacker::IsPackOptionValid(const PackOption &option) +{ + return true; +} + +// class reference need explicit constructor and destructor, otherwise unique_ptr use unnormal +ImagePacker::ImagePacker() +{} + +ImagePacker::~ImagePacker() +{} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_image_related_class.h b/frameworks/core/test/unittest/mock/mock_image_related_class.h new file mode 100644 index 000000000..3d34c4cf7 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_related_class.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H +#define BASE_NOTIFICATION_MOCK_IMAGE_RELATED_CLASS_H + +namespace OHOS { +namespace Media { +class SourceStream {}; +class PackerStream {}; +} // namespace Media + +namespace ImagePlugin { +class AbsImageEncoder {}; +class AbsImageDecoder {}; +} // namespace Media +} // namespace OHOS +#endif diff --git a/frameworks/core/test/unittest/mock/mock_image_source.cpp b/frameworks/core/test/unittest/mock/mock_image_source.cpp new file mode 100644 index 000000000..57314557b --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_image_source.cpp @@ -0,0 +1,373 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "image_source.h" +#undef private +#undef protected +#include "mock_image_related_class.h" + +namespace { +bool g_mockImageSourceCreateImageSourceRet = true; +uint32_t g_mockImageSourceCreateImageSourceErrorCode = 0; +bool g_mockImageSourceCreatePixelMapRet = true; +uint32_t g_mockImageSourceCreatePixelMapErrorCode = 0; +uint32_t g_mockImageSourceGetSupportedFormatsRet = 0; +} + +void MockImageSourceCreateImageSource(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreateImageSourceRet = mockRet; + g_mockImageSourceCreateImageSourceErrorCode = errorCode; +} + +void MockImageSourceCreatePixelMap(bool mockRet, uint32_t errorCode) +{ + g_mockImageSourceCreatePixelMapRet = mockRet; + g_mockImageSourceCreatePixelMapErrorCode = errorCode; +} + +void MockImageSourceGetSupportedFormats(uint32_t mockRet) +{ + g_mockImageSourceGetSupportedFormatsRet = mockRet; +} + +void MockResetImageSourceState() +{ + g_mockImageSourceCreateImageSourceRet = true; + g_mockImageSourceCreateImageSourceErrorCode = 0; + g_mockImageSourceCreatePixelMapRet = true; + g_mockImageSourceCreatePixelMapErrorCode = 0; +} + +namespace OHOS { +namespace Media { +using namespace ImagePlugin; + +uint32_t ImageSource::GetSupportedFormats(std::set &formats) +{ + return g_mockImageSourceGetSupportedFormatsRet; +} + +std::unique_ptr ImageSource::CreateImageSource(std::unique_ptr is, + const SourceOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const uint8_t *data, uint32_t size, + const SourceOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const std::string &pathName, const SourceOptions &opts, + uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreateImageSourceErrorCode; + if (g_mockImageSourceCreateImageSourceRet) { + std::unique_ptr stream = nullptr; + OHOS::Media::SourceOptions opts; + ImageSource *sourcePtr = new (std::nothrow) ImageSource(std::move(stream), opts); + return std::unique_ptr(sourcePtr); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreateImageSource(const int fd, const SourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalImageSource(const IncrementalSourceOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +void ImageSource::Reset() +{} + +std::unique_ptr ImageSource::CreatePixelMapEx(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + errorCode = g_mockImageSourceCreatePixelMapErrorCode; + if (g_mockImageSourceCreatePixelMapRet) { + PixelMap *pixelMap = new (std::nothrow) PixelMap(); + return std::unique_ptr(pixelMap); + } + return nullptr; +} + +std::unique_ptr ImageSource::CreatePixelMap(uint32_t index, const DecodeOptions &opts, uint32_t &errorCode) +{ + return nullptr; +} + +std::unique_ptr ImageSource::CreateIncrementalPixelMap(uint32_t index, const DecodeOptions &opts, + uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::PromoteDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + ImageDecodingState &state, uint8_t &decodeProgress) +{ + return 0; +} + +void ImageSource::DetachIncrementalDecoding(PixelMap &pixelMap) +{} + +uint32_t ImageSource::UpdateData(const uint8_t *data, uint32_t size, bool isCompleted) +{ + return 0; +} + +DecodeEvent ImageSource::GetDecodeEvent() +{ + return decodeEvent_; +} + +uint32_t ImageSource::GetImageInfo(uint32_t index, ImageInfo &imageInfo) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const std::string &path) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, const int fd) +{ + return 0; +} + +uint32_t ImageSource::ModifyImageProperty(uint32_t index, const std::string &key, + const std::string &value, uint8_t *data, uint32_t size) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value) +{ + return 0; +} + +uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string &key, std::string &value) +{ + return 0; +} + +const SourceInfo &ImageSource::GetSourceInfo(uint32_t &errorCode) +{ + return sourceInfo_; +} + +void ImageSource::RegisterListener(PeerListener *listener) +{} + +void ImageSource::UnRegisterListener(PeerListener *listener) +{} + +void ImageSource::AddDecodeListener(DecodeListener *listener) +{} + +void ImageSource::RemoveDecodeListener(DecodeListener *listener) +{} + +ImageSource::~ImageSource() +{} + +bool ImageSource::IsStreamCompleted() +{ + return true; +} + +ImageSource::ImageSource(std::unique_ptr &&stream, const SourceOptions &opts) +{} + +ImageSource::FormatAgentMap ImageSource::InitClass() +{ + FormatAgentMap tempAgentMap; + return tempAgentMap; +} + +uint32_t ImageSource::CheckEncodedFormat(AbsImageFormatAgent &agent) +{ + return 0; +} + +uint32_t ImageSource::CheckFormatHint(const std::string &formatHint, FormatAgentMap::iterator &formatIter) +{ + return 0; +} + +uint32_t ImageSource::GetEncodedFormat(const std::string &formatHint, std::string &format) +{ + return 0; +} + +uint32_t ImageSource::OnSourceRecognized(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::OnSourceUnresolved() +{ + return 0; +} + +uint32_t ImageSource::DecodeSourceInfo(bool isAcquiredImageNum) +{ + return 0; +} + +uint32_t ImageSource::DecodeImageInfo(uint32_t index, ImageStatusMap::iterator &iter) +{ + return 0; +} + +uint32_t ImageSource::InitMainDecoder() +{ + return 0; +} + +AbsImageDecoder *ImageSource::CreateDecoder(uint32_t &errorCode) +{ + return nullptr; +} + +uint32_t ImageSource::SetDecodeOptions(std::unique_ptr &decoder, uint32_t index, + const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo) +{ + return 0; +} + +uint32_t ImageSource::UpdatePixelMapInfo(const DecodeOptions &opts, ImagePlugin::PlImageInfo &plInfo, + PixelMap &pixelMap) +{ + return 0; +} + +void ImageSource::CopyOptionsToPlugin(const DecodeOptions &opts, PixelDecodeOptions &plOpts) +{} + +void ImageSource::CopyOptionsToProcOpts(const DecodeOptions &opts, DecodeOptions &procOpts, PixelMap &pixelMap) +{} + +ImageSource::ImageStatusMap::iterator ImageSource::GetValidImageStatus(uint32_t index, uint32_t &errorCode) +{ + return imageStatusMap_.find(index); +} + +uint32_t ImageSource::AddIncrementalContext(PixelMap &pixelMap, IncrementalRecordMap::iterator &iterator) +{ + return 0; +} + +uint32_t ImageSource::DoIncrementalDecoding(uint32_t index, const DecodeOptions &opts, PixelMap &pixelMap, + IncrementalDecodingContext &recordContext) +{ + return 0; +} + +const NinePatchInfo &ImageSource::GetNinePatchInfo() const +{ + return ninePatchInfo_; +} + +void ImageSource::SetMemoryUsagePreference(const MemoryUsagePreference preference) +{} + +MemoryUsagePreference ImageSource::GetMemoryUsagePreference() +{ + return preference_; +} + +uint32_t ImageSource::GetRedactionArea(const int &fd, const int &redactionType, + std::vector> &ranges) +{ + return 0; +} + +void ImageSource::SetIncrementalSource(const bool isIncrementalSource) +{ + isIncrementalSource_ = isIncrementalSource; +} + +bool ImageSource::IsIncrementalSource() +{ + return isIncrementalSource_; +} + +FinalOutputStep ImageSource::GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch) +{ + return FinalOutputStep::NO_CHANGE; +} + +bool ImageSource::HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch) +{ + return true; +} + +bool ImageSource::ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight) +{ + return false; +} + +bool ImageSource::ImageConverChange(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo) +{ + return true; +} + +std::unique_ptr ImageSource::DecodeBase64(const uint8_t *data, uint32_t size) +{ + return DecodeBase64(""); +} + +std::unique_ptr ImageSource::DecodeBase64(const std::string &data) +{ + return nullptr; +} + +bool ImageSource::IsSpecialYUV() +{ + return true; +} + +bool ImageSource::ConvertYUV420ToRGBA(uint8_t *data, uint32_t size, + bool isSupportOdd, bool isAddUV, uint32_t &errorCode) +{ + return true; +} + +std::unique_ptr ImageSource::CreatePixelMapForYUV(uint32_t &errorCode) +{ + return nullptr; +} +} // namespace Media +} // namespace OHOS diff --git a/frameworks/core/test/unittest/mock/mock_pixel_map.cpp b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp new file mode 100644 index 000000000..1bd9daa2a --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_pixel_map.cpp @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pixel_map.h" + +namespace { +int32_t g_mockPixelMapGetByteCountRet = 128; +} + +void MockPixelMapGetByteCount(int32_t mockRet) +{ + g_mockPixelMapGetByteCountRet = mockRet; +} + +void MockResetPixelMapState() +{ + g_mockPixelMapGetByteCountRet = 128; // 128 :initial test result +} +namespace OHOS { +namespace Media { +PixelMap::~PixelMap() +{} + +void PixelMap::FreePixelMap() __attribute__((no_sanitize("cfi"))) +{} + +void PixelMap::ReleaseSharedMemory(void *addr, void *context, uint32_t size) +{} + +void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, AllocatorType type, CustomFreePixelMap func) +{} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, + const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, int32_t offset, + int32_t stride, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::CheckParams(const uint32_t *colors, uint32_t colorLength, int32_t offset, int32_t stride, + const InitializationOptions &opts) +{ + return true; +} + +std::unique_ptr PixelMap::Create(const InitializationOptions &opts) +{ + return nullptr; +} + +void PixelMap::UpdatePixelsAlpha(const AlphaType &alphaType, const PixelFormat &pixelFormat, uint8_t *dstPixels, + PixelMap dstPixelMap) +{} + +std::unique_ptr PixelMap::Create(PixelMap &source, const InitializationOptions &opts) +{ + return nullptr; +} + +std::unique_ptr PixelMap::Create(PixelMap &source, const Rect &srcRect, const InitializationOptions &opts) +{ + return nullptr; +} + +bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageInfo, const ImageInfo &dstImageInfo, + const Rect &srcRect, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::ScalePixelMap(const Size &targetSize, const Size &dstSize, const ScaleMode &scaleMode, + PixelMap &dstPixelMap) +{ + return true; +} + +void PixelMap::InitDstImageInfo(const InitializationOptions &opts, const ImageInfo &srcImageInfo, + ImageInfo &dstImageInfo) +{} + +bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap) +{ + return true; +} + +bool PixelMap::IsSameSize(const Size &src, const Size &dst) +{ + return true; +} + +bool PixelMap::GetPixelFormatDetail(const PixelFormat format) +{ + return true; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info) +{ + return 0; +} + +uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused) +{ + return 0; +} + +const uint8_t *PixelMap::GetPixel8(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint16_t *PixelMap::GetPixel16(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint32_t *PixelMap::GetPixel32(int32_t x, int32_t y) +{ + return nullptr; +} + +const uint8_t *PixelMap::GetPixel(int32_t x, int32_t y) +{ + return nullptr; +} + +bool PixelMap::GetARGB32Color(int32_t x, int32_t y, uint32_t &color) +{ + return true; +} + +bool PixelMap::ALPHA8ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB565ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::ARGB8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGBA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::BGRA8888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +bool PixelMap::RGB888ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount) +{ + return true; +} + +int32_t PixelMap::GetPixelBytes() +{ + return 0; +} + +int32_t PixelMap::GetRowBytes() +{ + return 0; +} + +int32_t PixelMap::GetByteCount() +{ + return g_mockPixelMapGetByteCountRet; +} + +int32_t PixelMap::GetWidth() +{ + return 0; +} + +int32_t PixelMap::GetHeight() +{ + return 0; +} + +int32_t PixelMap::GetBaseDensity() +{ + return 0; +} + +void PixelMap::GetImageInfo(ImageInfo &imageInfo) +{} + +PixelFormat PixelMap::GetPixelFormat() +{ + return imageInfo_.pixelFormat; +} + +ColorSpace PixelMap::GetColorSpace() +{ + return imageInfo_.colorSpace; +} + +AlphaType PixelMap::GetAlphaType() +{ + return imageInfo_.alphaType; +} + +const uint8_t *PixelMap::GetPixels() +{ + return data_; +} + +uint8_t PixelMap::GetARGB32ColorA(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorR(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorG(uint32_t color) +{ + return 0; +} + +uint8_t PixelMap::GetARGB32ColorB(uint32_t color) +{ + return 0; +} + +bool PixelMap::IsSameImage(const PixelMap &other) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, uint8_t *dst) +{ + return 0; +} + +bool PixelMap::CheckPixelsInput(const uint8_t *dst, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return true; +} + +uint32_t PixelMap::ReadPixels(const uint64_t &bufferSize, const uint32_t &offset, const uint32_t &stride, + const Rect ®ion, uint8_t *dst) +{ + return 0; +} + +uint32_t PixelMap::ReadPixel(const Position &pos, uint32_t &dst) +{ + return 0; +} + +uint32_t PixelMap::ResetConfig(const Size &size, const PixelFormat &format) +{ + return 0; +} + +bool PixelMap::SetAlphaType(const AlphaType &alphaType) +{ + return true; +} + +uint32_t PixelMap::WritePixel(const Position &pos, const uint32_t &color) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize, const uint32_t &offset, + const uint32_t &stride, const Rect ®ion) +{ + return 0; +} + +uint32_t PixelMap::WritePixels(const uint8_t *source, const uint64_t &bufferSize) +{ + return 0; +} + +bool PixelMap::WritePixels(const uint32_t &color) +{ + return true; +} + +AllocatorType PixelMap::GetAllocatorType() +{ + return allocatorType_; +} + +void *PixelMap::GetFd() const +{ + return context_; +} + +void PixelMap::ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size) +{} + +bool PixelMap::WriteImageData(Parcel &parcel, size_t size) const +{ + return true; +} + +uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) +{ + return nullptr; +} + +bool PixelMap::WriteFileDescriptor(Parcel &parcel, int fd) +{ + return true; +} + +int PixelMap::ReadFileDescriptor(Parcel &parcel) +{ + return 0; +} + +bool PixelMap::WriteImageInfo(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::Marshalling(Parcel &parcel) const +{ + return true; +} + +bool PixelMap::ReadImageInfo(Parcel &parcel, ImageInfo &imgInfo) +{ + return true; +} + +PixelMap *PixelMap::Unmarshalling(Parcel &parcel) +{ + return nullptr; +} + +uint32_t PixelMap::SetAlpha(const float percent) +{ + return 0; +} + +void PixelMap::scale(float xAxis, float yAxis) +{} + +void PixelMap::translate(float xAxis, float yAxis) +{} + +void PixelMap::rotate(float degrees) +{} + +void PixelMap::flip(bool xAxis, bool yAxis) +{} + +uint32_t PixelMap::crop(const Rect &rect) +{ + return 0; +} +} // namespace Media +} // namespace OHOS -- Gitee From ab22d36fcf1c5b1c5172e577f5a9ec6764455921 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 1 Nov 2022 22:07:09 +0800 Subject: [PATCH 36/44] notification enable modify Signed-off-by: fangJinliang1 Change-Id: I7e27f4f615c884fbfb96511235059447a0b999d3 Signed-off-by: fangJinliang1 --- .../ans/include/notification_preferences.h | 1 + .../notification_preferences_database.h | 1 + .../include/notification_preferences_info.h | 1 + .../ans/src/advanced_notification_service.cpp | 3 +++ services/ans/src/notification_preferences.cpp | 9 +++++++ .../src/notification_preferences_database.cpp | 24 ++++++++++++++++++- .../ans/src/notification_preferences_info.cpp | 5 ++++ 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 7548eb5f7..da1f339f1 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -261,6 +261,7 @@ public: void OnDistributedKvStoreDeathRecipient(); void InitSettingFromDisturbDB(); void RemoveSettings(int32_t userId); + void RemoveAnsBundleDbInfo(const sptr &bundleOption); private: ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 6aee6f7c3..e2123a89e 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -163,6 +163,7 @@ public: bool RemoveNotificationEnable(const int32_t userId); bool RemoveDoNotDisturbDate(const int32_t userId); + bool RemoveAnsBundleDbInfo(std::string bundleName, int32_t uid); private: void TryTwice(const std::function &func) const; diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 450655e8d..895c80478 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -287,6 +287,7 @@ public: bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; void RemoveNotificationEnable(const int32_t userId); void RemoveDoNotDisturbDate(const int32_t userId); + void SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey); private: std::map isEnabledAllNotification_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 0fc79793d..aef1db173 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1584,6 +1584,7 @@ ErrCode AdvancedNotificationService::IsAllowedNotifySelf(bool &allowed) ErrCode AdvancedNotificationService::IsAllowedNotifySelf(const sptr &bundleOption, bool &allowed) { + ANS_LOGD("%{public}s", __FUNCTION__); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } @@ -2139,6 +2140,8 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrCheckApiCompatibility(bundleOption); } + +void NotificationPreferences::RemoveAnsBundleDbInfo(const sptr &bundleOption) +{ + ANS_LOGE("%{public}s", __FUNCTION__); + if (preferncesDB_ != nullptr && bundleOption != nullptr) { + preferncesDB_->RemoveAnsBundleDbInfo(bundleOption->GetBundleName(), bundleOption->GetUid()); + } +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 811dd544c..e65518d4e 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -471,6 +471,7 @@ bool NotificationPreferencesDatabase::PutPrivateNotificationsAllowed( bool NotificationPreferencesDatabase::PutNotificationsEnabledForBundle( const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &enabled) { + ANS_LOGD("%{public}s, enabled[%{public}d]", __FUNCTION__, enabled); if (bundleInfo.GetBundleName().empty()) { ANS_LOGE("Bundle name is null."); return false; @@ -961,7 +962,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( } } - info.SetBundleInfo(bunldeInfo); + info.SetBundleInfoFromDb(bunldeInfo, bundleKey); } } @@ -1115,6 +1116,7 @@ std::string NotificationPreferencesDatabase::GenerateBundleKey( * KEY_ANS_BUNDLE_bundlename_ * */ + ANS_LOGD("%{public}s, bundleKey[%{public}s] type[%{public}s]", __FUNCTION__, bundleKey.c_str(), type.c_str()); std::string key = std::string().append(KEY_ANS_BUNDLE).append(KEY_UNDER_LINE).append(bundleKey).append(KEY_UNDER_LINE); if (!type.empty()) { @@ -1475,5 +1477,25 @@ bool NotificationPreferencesDatabase::RemoveDoNotDisturbDate(const int32_t userI ANS_LOGD("%{public}s remove DoNotDisturb date, userId : %{public}d", __FUNCTION__, userId); return true; } + +bool NotificationPreferencesDatabase::RemoveAnsBundleDbInfo(std::string bundleName, int32_t uid) +{ + if (!CheckKvStore()) { + ANS_LOGE("KvStore is nullptr."); + return false; + } + + std::string key = KEY_BUNDLE_LABEL + bundleName + std::to_string(uid); + DistributedKv::Key enableKey(key); + DistributedKv::Status status = kvStorePtr_->Delete(enableKey); + CloseKvStore(); + if (status != DistributedKv::Status::SUCCESS) { + ANS_LOGE("Delete ans bundle db info failed, bundle[%{public}s:%{public}d]", bundleName.c_str(), uid); + return false; + } + + ANS_LOGE("Remove ans bundle db info, bundle[%{public}s:%{public}d]", bundleName.c_str(), uid); + return true; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 2ab4e39f8..b0cb322b4 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -240,5 +240,10 @@ void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId) { doNotDisturbDate_.erase(userId); } + +void NotificationPreferencesInfo::SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey) +{ + infos_.insert_or_assign(bundleKey, info); +} } // namespace Notification } // namespace OHOS -- Gitee From cfe1861de6ac776bcfc4d13ac9fcd80d5f5fba63 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 2 Nov 2022 12:31:23 +0800 Subject: [PATCH 37/44] =?UTF-8?q?=E5=88=A0=E9=99=A4Blob=E7=BB=A7=E6=89=BFP?= =?UTF-8?q?arcel=E7=9A=84Marshalling=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: htt1997 --- frameworks/test/moduletest/mock/blob.cpp | 14 -------------- services/ans/test/unittest/mock/blob.cpp | 14 -------------- .../distributed/test/unittest/mock/mock_blob.cpp | 13 ------------- 3 files changed, 41 deletions(-) diff --git a/frameworks/test/moduletest/mock/blob.cpp b/frameworks/test/moduletest/mock/blob.cpp index 540888d0f..9acb0f99d 100644 --- a/frameworks/test/moduletest/mock/blob.cpp +++ b/frameworks/test/moduletest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { diff --git a/services/ans/test/unittest/mock/blob.cpp b/services/ans/test/unittest/mock/blob.cpp index 540888d0f..9acb0f99d 100644 --- a/services/ans/test/unittest/mock/blob.cpp +++ b/services/ans/test/unittest/mock/blob.cpp @@ -157,20 +157,6 @@ bool Blob::StartsWith(const Blob &blob) const return true; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} - /* write blob size and data to memory buffer. return error when bufferLeftSize not enough. */ bool Blob::WriteToBuffer(uint8_t *&cursorPtr, int &bufferLeftSize) const { diff --git a/services/distributed/test/unittest/mock/mock_blob.cpp b/services/distributed/test/unittest/mock/mock_blob.cpp index d55add0bd..490a66758 100644 --- a/services/distributed/test/unittest/mock/mock_blob.cpp +++ b/services/distributed/test/unittest/mock/mock_blob.cpp @@ -90,18 +90,5 @@ std::string Blob::ToString() const return str; } -bool Blob::Marshalling(Parcel &parcel) const -{ - return parcel.WriteUInt8Vector(this->blob_); -} - -Blob *Blob::Unmarshalling(Parcel &parcel) -{ - std::vector blobData; - if (!parcel.ReadUInt8Vector(&blobData)) { - return nullptr; - } - return new Blob(blobData); -} } // namespace DistributedKv } // namespace OHOS \ No newline at end of file -- Gitee From 448abcb5877caab73b987a5766a86f120c802cdd Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 2 Nov 2022 17:34:36 +0800 Subject: [PATCH 38/44] remove function Signed-off-by: fangJinliang1 Change-Id: Ia356f08c63b755622a023ec1e025cb26f094cc6f --- services/ans/src/notification_preferences.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 34f38a5d3..19e7daaa0 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -365,7 +365,6 @@ ErrCode NotificationPreferences::SetNotificationsEnabledForBundle( ErrCode NotificationPreferences::GetNotificationsEnabled(const int32_t &userId, bool &enabled) { - InitSettingFromDisturbDB(); if (userId <= SUBSCRIBE_USER_INIT) { return ERR_ANS_INVALID_PARAM; } -- Gitee From 564ed38bb5762e14602b1b8b233d350264ec98ce Mon Sep 17 00:00:00 2001 From: wujiqin Date: Fri, 4 Nov 2022 17:56:34 +0800 Subject: [PATCH 39/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I5ZJTE?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:tdd=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E6=8F=90=E5=8D=8708=20Sig:SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: Ifa2a5d66c5064130154743b3e6e1286ed940563c --- frameworks/ans/test/unittest/BUILD.gn | 1 + .../unittest/notification_user_input_test.cpp | 133 ++++++++++++++ .../unittest/reminder_request_alarm_test.cpp | 167 +++++++++++++++++- .../reminder_request_calendar_test.cpp | 156 +++++++++++++++- 4 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 frameworks/ans/test/unittest/notification_user_input_test.cpp diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index a952eb31c..c9e5e0525 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -49,6 +49,7 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/notification_subscribe_info_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_template_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_user_input_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_helper_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_alarm_test.cpp", "${frameworks_module_ans_path}/test/unittest/reminder_request_calendar_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_user_input_test.cpp b/frameworks/ans/test/unittest/notification_user_input_test.cpp new file mode 100644 index 000000000..fa7a7098d --- /dev/null +++ b/frameworks/ans/test/unittest/notification_user_input_test.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "notification_user_input.h" +#undef private +#undef protected + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationUserInputTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: NotificationUserInput_00001 + * @tc.desc: Test NotificationUserInput parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Dump_00001, Function | SmallTest | Level1) +{ + std::string inputKey = "InputKey"; + std::string tag = "Tag"; + std::vector options; + bool permitFreeFormInput = true; + std::set permitMimeTypes; + std::shared_ptr additional = nullptr; + Notification::NotificationConstant::InputEditType editType = + Notification::NotificationConstant::InputEditType(1); + auto rrc = std::make_shared(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, + additional, editType); + std::string ret = rrc->GetInputKey(); + EXPECT_EQ(ret, inputKey); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, FromJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + std::shared_ptr userInput = nullptr; + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationUserInputTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp index 4c0389860..77097c01a 100644 --- a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp @@ -15,8 +15,13 @@ #include -#include "ans_log_wrapper.h" +#define private public +#define protected public #include "reminder_request_alarm.h" +#undef private +#undef protected + +#include "ans_log_wrapper.h" #include "reminder_helper.h" using namespace testing::ext; @@ -131,5 +136,165 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | uint8_t expectedVal = 0; EXPECT_TRUE(rrc->GetRepeatDay() == expectedVal) << "repeatDays () should be 0"; } + +/** + * @tc.name: IsRepeatReminder_00100 + * @tc.desc: Test IsRepeatReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, IsRepeatReminder_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->IsRepeatReminder(), false); + EXPECT_EQ(rrc->UpdateNextReminder(), false); +} + +/** + * @tc.name: IsRepeatReminder_00200 + * @tc.desc: Test IsRepeatReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, IsRepeatReminder_00200, Function | SmallTest | Level1) +{ + uint8_t arr[] = {1, 1, 5, 5, 7, 7, 7}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 1, daysOfWeek); + EXPECT_EQ(rrc->IsRepeatReminder(), true); + EXPECT_EQ(rrc->UpdateNextReminder(), true); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_00100 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, PreGetNextTriggerTimeIgnoreSnooze_00100, Function | SmallTest | Level1) +{ + bool ignoreRepeat = true; + bool forceToGetNext = true; + uint8_t arr[] = {1, 1, 5, 5, 7, 7, 7}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 1, daysOfWeek); + rrc->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext); + EXPECT_EQ(rrc->GetNextTriggerTime(forceToGetNext), + rrc->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext)); +} + +/** + * @tc.name: GetDaysOfWeek_00100 + * @tc.desc: Test GetDaysOfWeek parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, GetDaysOfWeek_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + auto ret = rrc->GetDaysOfWeek(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.name: OnDateTimeChange_00100 + * @tc.desc: Test OnDateTimeChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, OnDateTimeChange_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->OnDateTimeChange(), false); +} + +/** + * @tc.name: OnTimeZoneChange_00100 + * @tc.desc: Test OnTimeZoneChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, OnTimeZoneChange_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->OnTimeZoneChange(), false); +} + +/** + * @tc.name: RecoverFromDb_00100 + * @tc.desc: Test RecoverFromDb parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, RecoverFromDb_00100, Function | SmallTest | Level1) +{ + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + std::shared_ptr resultSet = nullptr; + rrc->RecoverFromDb(resultSet); + uint8_t ret = rrc->GetRepeatDay(); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestAlarmTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + std::shared_ptr result = + std::make_shared(0, 0, daysOfWeek); + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI + */ +HWTEST_F(ReminderRequestAlarmTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + uint8_t arr[] = {}; + std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); + auto rrc = std::make_shared(0, 0, daysOfWeek); + EXPECT_EQ(rrc->ReadFromParcel(parcel), false); +} } } \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index 33a51584b..2195a5dd4 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -15,8 +15,13 @@ #include -#include "ans_log_wrapper.h" +#define private public +#define protected public #include "reminder_request_calendar.h" +#undef private +#undef protected + +#include "ans_log_wrapper.h" #include "reminder_helper.h" using namespace testing::ext; @@ -299,5 +304,154 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00900, Function | SmallTest | EXPECT_TRUE(1 == calendar->GetMinute()) << "Set minute error."; EXPECT_TRUE(0 == calendar->GetSecond()) << "Set seconds error."; } + +/** + * @tc.name: initDateTime_01000 + * @tc.desc: Test InitDateTime parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, initDateTime_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + calendar->InitDateTime(); + EXPECT_EQ(calendar->IsRepeatReminder(), true); +} + +/** + * @tc.name: OnDateTimeChange_01000 + * @tc.desc: Test OnDateTimeChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, OnDateTimeChange_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->OnDateTimeChange(), false); +} + +/** + * @tc.name: OnTimeZoneChange_01000 + * @tc.desc: Test OnTimeZoneChange parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, OnTimeZoneChange_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->OnTimeZoneChange(), false); +} + +/** + * @tc.name: UpdateNextReminder_01000 + * @tc.desc: Test UpdateNextReminder parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_01000, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->UpdateNextReminder(), true); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_01000 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, PreGetNextTriggerTimeIgnoreSnooze_01000, Function | SmallTest | Level1) +{ + bool ignoreRepeat = true; + bool forceToGetNext = true; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext), + calendar->GetNextTriggerTime()); +} + +/** + * @tc.name: PreGetNextTriggerTimeIgnoreSnooze_02000 + * @tc.desc: Test PreGetNextTriggerTimeIgnoreSnooze parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, PreGetNextTriggerTimeIgnoreSnooze_02000, Function | SmallTest | Level1) +{ + bool ignoreRepeat = false; + bool forceToGetNext = true; + time_t now; + time(&now); // unit is seconds. + tm *tmp = localtime(&now); + EXPECT_NE(nullptr, tmp); + tm nowTime = *tmp; + nowTime.tm_year += 1; + std::vector repeatMonths; + std::vector repeatDays; + repeatMonths.push_back(-1); + repeatDays.push_back(1); + auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + EXPECT_EQ(calendar->PreGetNextTriggerTimeIgnoreSnooze(ignoreRepeat, forceToGetNext), 0); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(ReminderRequestCalendarTest, Unmarshalling_001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + if (nullptr != calendar) { + if (nullptr == calendar->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: ReadFromParcel_00001 + * @tc.desc: Test ReadFromParcel parameters. + * @tc.type: FUNC + * @tc.require: issueI + */ +HWTEST_F(ReminderRequestCalendarTest, ReadFromParcel_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + EXPECT_EQ(calendar->ReadFromParcel(parcel), false); +} } } \ No newline at end of file -- Gitee From 6f65762ee87d9463e7ffb2c9c1a65ad093589b28 Mon Sep 17 00:00:00 2001 From: MangTsang Date: Mon, 7 Nov 2022 17:16:18 +0800 Subject: [PATCH 40/44] replace time_service with time_client Signed-off-by: MangTsang --- frameworks/core/BUILD.gn | 2 +- services/ans/BUILD.gn | 2 +- services/ans/test/unittest/BUILD.gn | 2 +- services/test/moduletest/BUILD.gn | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 35b830b1b..606ba3b08 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -94,7 +94,7 @@ ohos_shared_library("ans_core") { "os_account:os_account_innerkits", "relational_store:native_rdb", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] install_images = [ system_base_dir ] relative_install_dir = "platformsdk" diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 7843be17f..825672e2a 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -76,7 +76,7 @@ ohos_shared_library("libans") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", - "time_service:time_service", + "time_service:time_client", "window_manager:libdm", ] external_deps += component_external_deps diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 1b55a7c8d..e06486e8c 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -100,7 +100,7 @@ ohos_unittest("ans_unit_test") { "os_account:os_account_innerkits", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] if (device_usage) { diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index f61ff5073..d0f09c4d1 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -86,7 +86,7 @@ ohos_moduletest("ans_module_test") { "os_account:os_account_innerkits", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "time_service:time_service", + "time_service:time_client", ] if (device_usage) { -- Gitee From f4cb027ca675a88ad71743a90a60a432d94986bd Mon Sep 17 00:00:00 2001 From: MangTsang Date: Mon, 7 Nov 2022 10:36:56 +0000 Subject: [PATCH 41/44] add deps: native_rdb Signed-off-by: MangTsang --- services/ans/BUILD.gn | 1 + services/ans/test/unittest/BUILD.gn | 1 + services/test/moduletest/BUILD.gn | 1 + 3 files changed, 3 insertions(+) diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 825672e2a..c76765868 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -76,6 +76,7 @@ ohos_shared_library("libans") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", + "relational_store:native_rdb", "time_service:time_client", "window_manager:libdm", ] diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index e06486e8c..d017bfdbb 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -98,6 +98,7 @@ ohos_unittest("ans_unit_test") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index d0f09c4d1..553b20c74 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -84,6 +84,7 @@ ohos_moduletest("ans_module_test") { "multimedia_image_framework:image_native", "multimedia_player_framework:media_client", "os_account:os_account_innerkits", + "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", "time_service:time_client", -- Gitee From 7d69121788c4a7701fc84d118f1529fb3b6cc487 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Tue, 8 Nov 2022 15:39:51 +0800 Subject: [PATCH 42/44] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I602CC?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:tdd=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E6=8F=90=E5=8D=87fuzz=20Sig:SIG=5FApplicationFramewor?= =?UTF-8?q?k=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wujiqin Change-Id: Ifc03ede40845a549479ade8f90984ea68850ffb0 --- test/fuzztest/BUILD.gn | 4 + .../BUILD.gn | 55 +++++++++ .../corpus/init | 13 ++ ...enablednotificationcallbackdata_fuzzer.cpp | 66 ++++++++++ .../enablednotificationcallbackdata_fuzzer.h | 23 ++++ .../project.xml | 25 ++++ .../notificationmediacontent_fuzzer/BUILD.gn | 55 +++++++++ .../corpus/init | 13 ++ .../notificationmediacontent_fuzzer.cpp | 58 +++++++++ .../notificationmediacontent_fuzzer.h | 23 ++++ .../project.xml | 25 ++++ .../reminderrequestalarm_fuzzer/BUILD.gn | 56 +++++++++ .../reminderrequestalarm_fuzzer/corpus/init | 13 ++ .../reminderrequestalarm_fuzzer/project.xml | 25 ++++ .../reminderrequestalarm_fuzzer.cpp | 94 ++++++++++++++ .../reminderrequestalarm_fuzzer.h | 23 ++++ .../reminderrequestcalendar_fuzzer/BUILD.gn | 56 +++++++++ .../corpus/init | 13 ++ .../project.xml | 25 ++++ .../reminderrequestcalendar_fuzzer.cpp | 115 ++++++++++++++++++ .../reminderrequestcalendar_fuzzer.h | 23 ++++ 21 files changed, 803 insertions(+) create mode 100644 test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn create mode 100644 test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init create mode 100644 test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp create mode 100644 test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h create mode 100644 test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml create mode 100644 test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationmediacontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h create mode 100644 test/fuzztest/notificationmediacontent_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestalarm_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestalarm_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h create mode 100644 test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestcalendar_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index e1341def3..3b674d09c 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -26,6 +26,7 @@ group("fuzztest") { "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", "enabledistributed_fuzzer:EnableDistributedFuzzTest", + "enablednotificationcallbackdata_fuzzer:EnabledNotificationCallbackDataFuzzTest", "getactivenotificationnums_fuzzer:GetActiveNotificationNumsFuzzTest", "getallactivenotifications_fuzzer:GetAllActiveNotificationsFuzzTest", "getbundleimportance_fuzzer:GetBundleImportanceFuzzTest", @@ -37,6 +38,7 @@ group("fuzztest") { "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", + "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", @@ -50,7 +52,9 @@ group("fuzztest") { "readfromparcel_fuzzer:ReadFromParcelFuzzTest", "reminderhelper_fuzzer:ReminderHelperFuzzTest", "reminderrequest_fuzzer:ReminderRequestFuzzTest", + "reminderrequestalarm_fuzzer:ReminderRequestAlarmFuzzTest", "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestcalendar_fuzzer:ReminderRequestCalendarFuzzTest", "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", "reminderstore_fuzzer:ReminderStoreFuzzTest", diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn b/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn new file mode 100644 index 000000000..354fe3dce --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("EnabledNotificationCallbackDataFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/enablednotificationcallbackdata_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "enablednotificationcallbackdata_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":EnabledNotificationCallbackDataFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init b/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp new file mode 100644 index 000000000..fd2f68323 --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "enabled_notification_callback_data.h" +#undef private +#undef protected +#include "enablednotificationcallbackdata_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + uid_t uid = static_cast(GetU32Data(data)); + bool enabled = *data % ENABLE; + Notification::EnabledNotificationCallbackData enabledNotificationCallbackData(stringData, uid, enabled); + // test SetBundle function + enabledNotificationCallbackData.SetBundle(stringData); + // test SetUid function + enabledNotificationCallbackData.SetUid(uid); + // test SetEnable function + enabledNotificationCallbackData.SetEnable(enabled); + // test GetBundle function + enabledNotificationCallbackData.GetBundle(); + // test GetUid function + enabledNotificationCallbackData.GetUid(); + // test GetEnable function + enabledNotificationCallbackData.GetEnable(); + // test Dump function + enabledNotificationCallbackData.Dump(); + // test Unmarshalling function + Parcel parcel; + enabledNotificationCallbackData.Unmarshalling(parcel); + enabledNotificationCallbackData.ReadFromParcel(parcel); + return enabledNotificationCallbackData.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h new file mode 100644 index 000000000..8553a05fa --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/enablednotificationcallbackdata_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H +#define TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "enablednotificationcallbackdata_fuzzer" + +#endif // TEST_FUZZTEST_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_ENABLEDNOTIFICATIONCALLBACKDATA_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml b/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/enablednotificationcallbackdata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn b/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..88e74fbda --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationMediaContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationmediacontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationmediacontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationMediaContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationmediacontent_fuzzer/corpus/init b/test/fuzztest/notificationmediacontent_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp new file mode 100644 index 000000000..308d7c700 --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_media_content.h" +#undef private +#undef protected +#include "notificationmediacontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationMediaContent notificationMediaContent; + // test SetAVToken function + std::shared_ptr avToken = nullptr; + notificationMediaContent.SetAVToken(avToken); + // test SetShownActions function + std::vector actions; + notificationMediaContent.SetShownActions(actions); + // test GetAVToken function + notificationMediaContent.GetAVToken(); + // test GetShownActions function + notificationMediaContent.GetShownActions(); + // test Dump function + notificationMediaContent.Dump(); + // test Unmarshalling function + Parcel parcel; + notificationMediaContent.Unmarshalling(parcel); + notificationMediaContent.ReadFromParcel(parcel); + return notificationMediaContent.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h new file mode 100644 index 000000000..a6594080c --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationmediacontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONMEDIACONTENT_FUZZER_NOTIFICATIONMEDIACONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationmediacontent_fuzzer/project.xml b/test/fuzztest/notificationmediacontent_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationmediacontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn new file mode 100644 index 000000000..5648157aa --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestAlarmFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestalarm_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestalarm_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestAlarmFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/project.xml b/test/fuzztest/reminderrequestalarm_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp new file mode 100644 index 000000000..e36cfa81a --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_request_alarm.h" +#undef private +#undef protected +#include "reminderrequestalarm_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t HOUR = 24; + constexpr uint8_t MINUTE = 60; + constexpr uint8_t WEEK = 7; + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + uint8_t hour = *data % HOUR; + uint8_t minute = *data % MINUTE; + uint8_t week = *data % WEEK; + std::vector daysOfWeek; + daysOfWeek.push_back(week); + auto rrc = std::make_shared(hour, minute, daysOfWeek); + // test SetDaysOfWeek function + bool enabled = *data % ENABLE; + rrc->SetDaysOfWeek(enabled, daysOfWeek); + // test GetDaysOfWeek function + rrc->GetDaysOfWeek(); + // test CheckParamValid function + rrc->CheckParamValid(); + // test IsRepeatReminder function + rrc->IsRepeatReminder(); + // test PreGetNextTriggerTimeIgnoreSnooze function + rrc->PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + // test GetNextTriggerTime function + rrc->GetNextTriggerTime(enabled); + // test GetNextAlarm function + time_t now; + (void)time(&now); // unit is seconds. + time_t target = *data % ENABLE; + rrc->GetNextAlarm(now, target); + // test IsRepeatDay function + int32_t day = static_cast(GetU32Data(data)); + rrc->IsRepeatDay(day); + // test GetHour function + rrc->GetHour(); + // test GetMinute function + rrc->GetMinute(); + // test GetRepeatDay function + rrc->GetRepeatDay(); + // test OnDateTimeChange function + rrc->OnDateTimeChange(); + // test OnTimeZoneChange function + rrc->OnTimeZoneChange(); + // test UpdateNextReminder function + rrc->UpdateNextReminder(); + // test Unmarshalling function + Parcel parcel; + rrc->Unmarshalling(parcel); + rrc->ReadFromParcel(parcel); + // test RecoverFromDb function + std::shared_ptr resultSet = + std::make_shared(); + rrc->RecoverFromDb(resultSet); + return rrc->Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h new file mode 100644 index 000000000..3b5e31f18 --- /dev/null +++ b/test/fuzztest/reminderrequestalarm_fuzzer/reminderrequestalarm_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestalarm_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTALARM_FUZZER_REMINDERREQUESTALARM_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn new file mode 100644 index 000000000..645f13462 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestCalendarFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestcalendar_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestcalendar_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestCalendarFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml b/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp new file mode 100644 index 000000000..c9b914de2 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_request_calendar.h" +#undef private +#undef protected +#include "reminderrequestcalendar_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t MONTHS = 12; + constexpr uint8_t DAYS = 31; + constexpr uint16_t YEAR = 365; + constexpr uint16_t HOURS = 24; + constexpr uint16_t MINUTES = 60; + constexpr uint16_t SECONDS = 60; + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + struct tm nowTime; + uint8_t months = *data % MONTHS; + uint8_t days = *data % DAYS; + std::vector repeatMonths; + std::vector repeatDays; + repeatMonths.push_back(months); + repeatDays.push_back(days); + Notification::ReminderRequestCalendar reminderRequestCalendar(nowTime, repeatMonths, repeatDays); + // test SetNextTriggerTime function + reminderRequestCalendar.SetNextTriggerTime(); + // test InitDateTime function + reminderRequestCalendar.InitDateTime(); + // test InitDateTime function + reminderRequestCalendar.InitDateTime(nowTime); + // test SetDay function + bool enabled = *data % ENABLE; + reminderRequestCalendar.SetDay(days, enabled); + // test SetMonth function + reminderRequestCalendar.SetMonth(months, enabled); + // test SetRepeatMonths function + reminderRequestCalendar.SetRepeatMonths(repeatMonths); + // test SetRepeatDaysOfMonth function + reminderRequestCalendar.SetRepeatDaysOfMonth(repeatDays); + // test GetRepeatMonths function + reminderRequestCalendar.GetRepeatMonths(); + // test GetRepeatDays function + reminderRequestCalendar.GetRepeatDays(); + // test GetDaysOfMonth function + uint16_t year = *data % YEAR; + reminderRequestCalendar.GetDaysOfMonth(year, months); + // test GetNextDay function + struct tm target; + reminderRequestCalendar.GetNextDay(year, months, nowTime, target); + // test GetNextTriggerTime function + reminderRequestCalendar.GetNextTriggerTime(); + // test GetNextTriggerTimeAsRepeatReminder function + struct tm tarTime; + reminderRequestCalendar.GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime); + // test GetTimeInstantMilli function + uint8_t hour = *data % HOURS; + uint8_t minute = *data % MINUTES; + uint8_t second = *data % SECONDS; + reminderRequestCalendar.GetTimeInstantMilli(year, months, days, hour, minute, second); + // test IsRepeatReminder function + reminderRequestCalendar.IsRepeatReminder(); + // test IsRepeatMonth function + reminderRequestCalendar.IsRepeatMonth(months); + // test IsRepeatDay function + reminderRequestCalendar.IsRepeatDay(days); + // test OnDateTimeChange function + reminderRequestCalendar.OnDateTimeChange(); + // test OnTimeZoneChange function + reminderRequestCalendar.OnTimeZoneChange(); + // test UpdateNextReminder function + reminderRequestCalendar.UpdateNextReminder(); + // test PreGetNextTriggerTimeIgnoreSnooze function + reminderRequestCalendar.PreGetNextTriggerTimeIgnoreSnooze(enabled, enabled); + // test RecoverFromDb function + std::shared_ptr resultSet = + std::make_shared(); + reminderRequestCalendar.RecoverFromDb(resultSet); + // test Unmarshalling function + Parcel parcel; + reminderRequestCalendar.Unmarshalling(parcel); + reminderRequestCalendar.ReadFromParcel(parcel); + return reminderRequestCalendar.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h new file mode 100644 index 000000000..12064cc93 --- /dev/null +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/reminderrequestcalendar_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcalendar_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTCALENDAR_FUZZER_REMINDERREQUESTCALENDAR_FUZZER_H \ No newline at end of file -- Gitee From a7668d3e7cb6c1c506b91bd170c04102aca1618b Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Wed, 9 Nov 2022 11:46:08 +0800 Subject: [PATCH 43/44] =?UTF-8?q?ans=5Fmanager=5Fstub=E6=96=B0=E5=A2=9ETDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: I81a9cd8c992861fc5a180d7e3fc8bf683db9b4f7 --- frameworks/core/test/unittest/BUILD.gn | 1 + .../unittest/ans_manager_stub_test/BUILD.gn | 50 ++ .../ans_manager_stub_test.cpp | 694 ++++++++++++++++++ 3 files changed, 745 insertions(+) create mode 100644 frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 701d7950b..4176836bf 100644 --- a/frameworks/core/test/unittest/BUILD.gn +++ b/frameworks/core/test/unittest/BUILD.gn @@ -19,6 +19,7 @@ group("unittest") { "ans_callback_stub_test:unittest", "ans_image_util_test:unittest", "ans_manager_death_recipient_test:unittest", + "ans_manager_stub_test:unittest", "ans_subscriber_proxy_test:unittest", "ans_subscriber_stub_test:unittest", ] diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn new file mode 100644 index 000000000..f0b1edc23 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_stub_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("ans_manager_stub_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "ans_manager_stub_test.cpp" ] + + deps = [ "${core_path}:ans_core" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_stub_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp new file mode 100644 index 000000000..03e4a7633 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -0,0 +1,694 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "ans_manager_stub.h" +#undef private +#undef protected + +#include "ans_inner_errors.h" + + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class AnsManagerStubTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() + { + ansManagerStub_ = new AnsManagerStub(); + } + void TearDown() {} + sptr ansManagerStub_; +}; + +/** + * @tc.name: OnRemoteRequest01 + * @tc.desc: Test if get the wrong descriptor. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0001, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(u"error.GetDescriptor"); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)OBJECT_NULL); +} + +/** + * @tc.name: OnRemoteRequest02 + * @tc.desc: Test if get the wrong code. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, OnRemoteRequest0002, Function | SmallTest | Level1) +{ + uint32_t code = 267; + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: HandlePublish01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublish02 + * @tc.desc: Test if the label is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublish03 + * @tc.desc: Test if the notification is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublish03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishToDevice01 + * @tc.desc: Test HandlePublishToDevice succeeds; + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishToDevice02 + * @tc.desc: Test if the notification is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishToDevice03 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishToDevice03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_NOTIFICATION_TO_DEVICE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel01 + * @tc.desc: Test HandleCancel succeeds + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancel02 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a notification label"; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancel03 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancel03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAll01 + * @tc.desc: Test HandleCancelAll succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle01 + * @tc.desc: Test HandlePublish succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelAsBundle02 + * @tc.desc: Test if the notificationId in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelAsBundle04 + * @tc.desc: Test if the userId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelAsBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleAddSlotByType01 + * @tc.desc: Test HandleAddSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleAddSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::ADD_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveSlotByType01 + * @tc.desc: Test HandleRemoveSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllSlots01 + * @tc.desc: Test HandleRemoveAllSlots succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotByType01 + * @tc.desc: Test HandleGetSlotByType succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotByType01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_BY_TYPE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle01 + * @tc.desc: Test HandleGetSlotNumAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotNumAsBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotNumAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOT_NUM_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetActiveNotifications01 + * @tc.desc: Test HandleGetActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetActiveNotificationNums01 + * @tc.desc: Test HandleGetActiveNotificationNums succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetActiveNotificationNums01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ACTIVE_NOTIFICATION_NUMS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetAllActiveNotifications01 + * @tc.desc: Test HandleGetAllActiveNotifications succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetAllActiveNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_ALL_ACTIVE_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationAgent01 + * @tc.desc: Test HandleSetNotificationAgent succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationAgent01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string agent = "this is a agent"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(agent); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationAgent02 + * @tc.desc: Test if the agent in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationAgent02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetNotificationAgent01 + * @tc.desc: Test HandleGetNotificationAgent succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetNotificationAgent01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_NOTIFICATION_AGENT); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCanPublishAsBundle01 + * @tc.desc: Test HandleCanPublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCanPublishAsBundle02 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CAN_PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle01 + * @tc.desc: Test HandlePublishAsBundle succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + std::string representativeBundle = "this is a representativeBundle"; + int32_t userId = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(representativeBundle); + data.WriteInt32(userId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +} +} \ No newline at end of file -- Gitee From 552e5ddaf8af26bd8d26a63357ecb461dde29ea6 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Thu, 10 Nov 2022 10:59:23 +0800 Subject: [PATCH 44/44] =?UTF-8?q?ans=5Fmanager=5Fstub=5Ftest=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyuyan Change-Id: I2be70c4459f1137ee04a21da1362205298d572ab --- .../ans_manager_stub_test.cpp | 1113 ++++++++++++++++- 1 file changed, 1108 insertions(+), 5 deletions(-) diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index 03e4a7633..357b5ef74 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -672,23 +672,1126 @@ HWTEST_F(AnsManagerStubTest, HandleCanPublishAsBundle02, Function | SmallTest | */ HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle01, Function | SmallTest | Level1) { - uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_AS_BUNDLE); + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); MessageParcel data; MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; - int32_t notificationId = 3; + sptr notification = new NotificationRequest(); + std::string representativeBundle = "this is a representativeBundle"; - int32_t userId = 4; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteInt32(notificationId); + data.WriteParcelable(notification); data.WriteString(representativeBundle); - data.WriteInt32(userId); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)NO_ERROR); } +/** + * @tc.name: HandlePublishAsBundle02 + * @tc.desc: Test if the notification in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string representativeBundle = "this is a representativeBundle"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(representativeBundle); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandlePublishAsBundle03 + * @tc.desc: Test if the representativeBundle in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishAsBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_AS_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr notification = new NotificationRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(notification); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum01 + * @tc.desc: Test HandleSetNotificationBadgeNum succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t num = 4; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(num); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationBadgeNum02 + * @tc.desc: Test if the num in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationBadgeNum02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_BADGE_NUM); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetBundleImportance01 + * @tc.desc: Test HandleGetBundleImportance succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetBundleImportance01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_BUNDLE_IMPORTANCE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate01 + * @tc.desc: Test HandleSetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr date = new NotificationDoNotDisturbDate(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(date); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetDoNotDisturbDate02 + * @tc.desc: Test if the date in data is null.. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetDoNotDisturbDate02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetDoNotDisturbDate01 + * @tc.desc: Test HandleGetDoNotDisturbDate succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetDoNotDisturbDate01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_DO_NOT_DISTURB_DATE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDoesSupportDoNotDisturbMode01 + * @tc.desc: Test HandleDoesSupportDoNotDisturbMode01 succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDoesSupportDoNotDisturbMode01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DOES_SUPPORT_DO_NOT_DISTURB_MODE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification01 + * @tc.desc: Test HandlePublishContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr request = new NotificationRequest(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(request); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandlePublishContinuousTaskNotification02 + * @tc.desc: Test if the request in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandlePublishContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::PUBLISH_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification01 + * @tc.desc: Test HandleCancelContinuousTaskNotification succeeds. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification02 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleCancelContinuousTaskNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleCancelContinuousTaskNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::CANCEL_CONTINUOUS_TASK_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleIsNotificationPolicyAccessGranted01 + * @tc.desc: Test HandleIsNotificationPolicyAccessGranted succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleIsNotificationPolicyAccessGranted01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::IS_NOTIFICATION_POLICY_ACCESS_GRANTED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetPrivateNotificationsAllowed02 + * @tc.desc: Test if the allow in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetPrivateNotificationsAllowed02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_PRIVATIVE_NOTIFICATIONS_ALLOWED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleGetPrivateNotificationsAllowed01 + * @tc.desc: Test HandleGetPrivateNotificationsAllowed succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetPrivateNotificationsAllowed01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_PRIVATIVE_NOTIFICATIONS_ALLOWED); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification01 + * @tc.desc: Test HandleRemoveNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveNotification02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t notificationId = 1; + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(notificationId); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification03 + * @tc.desc: Test if the notificationId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + std::string label = "this is a label"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteString(label); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification04 + * @tc.desc: Test if the label in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveNotification05 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveNotification05, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t notificationId = 1; + std::string label = "this is a label"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + data.WriteInt32(notificationId); + data.WriteString(label); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRemoveAllNotifications01 + * @tc.desc: Test HandleRemoveAllNotifications succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleRemoveAllNotifications02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRemoveAllNotifications02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REMOVE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete01 + * @tc.desc: Test HandleDelete succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDelete02 + * @tc.desc: Test if the key in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + int32_t removeReason = 2; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(removeReason); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDelete03 + * @tc.desc: Test if the removeReason in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDelete03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string key = "this is a key"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(key); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteByBundle01 + * @tc.desc: Test HandleDeleteByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteStrongParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleDeleteByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_NOTIFICATION_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleDeleteAll01 + * @tc.desc: Test HandleDeleteAll succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleDeleteAll01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::DELETE_ALL_NOTIFICATIONS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle01 + * @tc.desc: Test HandleGetSlotsByBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleGetSlotsByBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleGetSlotsByBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::GET_SLOTS_BY_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots01 + * @tc.desc: Test HandleUpdateSlots succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + sptr slot1 = new NotificationSlot(); + sptr slot2 = new NotificationSlot(); + sptr slot3 = new NotificationSlot(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + data.WriteStrongParcelable(slot1); + data.WriteStrongParcelable(slot2); + data.WriteStrongParcelable(slot3); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleUpdateSlots02 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + int32_t infoSize = 3; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(infoSize); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleUpdateSlots03 + * @tc.desc: Test if the StrongParcelable:info in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleUpdateSlots03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::UPDATE_SLOTS); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleRequestEnableNotification01 + * @tc.desc: Test HandleRequestEnableNotification succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.name: HandleRequestEnableNotification02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleRequestEnableNotification02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::REQUEST_ENABLE_NOTIFICATION); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = false; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles01 + * @tc.desc: Test HandleSetNotificationsEnabledForAllBundles succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForAllBundles03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForAllBundles03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle01 + * @tc.desc: Test HandleSetNotificationsEnabledForSpecialBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle02 + * @tc.desc: Test if the deviceId in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle03 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetNotificationsEnabledForSpecialBundle04 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetNotificationsEnabledForSpecialBundle04, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + std::string deviceId = "this is a deviceId"; + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteString(deviceId); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle01 + * @tc.desc: Test HandleSetShowBadgeEnabledForBundle succeed. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle01, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)NO_ERROR); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle02 + * @tc.desc: Test if the bundleOption in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle02, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + bool enabled = true; + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteBool(enabled); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} + +/** + * @tc.name: HandleSetShowBadgeEnabledForBundle03 + * @tc.desc: Test if the enabled in data is null. + * @tc.type: FUNC + * @tc.require: issueI5XQ4E + */ +HWTEST_F(AnsManagerStubTest, HandleSetShowBadgeEnabledForBundle03, Function | SmallTest | Level1) +{ + uint32_t code = static_cast(AnsManagerInterface::TransactId::SET_SHOW_BADGE_ENABLED_FOR_BUNDLE); + MessageParcel data; + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + + sptr bundleOption = new NotificationBundleOption(); + + data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteParcelable(bundleOption); + + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); +} } } \ No newline at end of file -- Gitee