From 3d301c903f9c9e65d31a921f2dec45d98c647115 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Tue, 18 Oct 2022 14:36:19 +0800 Subject: [PATCH 01/61] =?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/61] 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/61] 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/61] 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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] 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/61] 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/61] 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/61] =?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/61] =?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/61] =?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/61] =?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/61] 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/61] =?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/61] 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/61] 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/61] =?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/61] 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/61] =?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/61] =?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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] =?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/61] 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/61] 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/61] =?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/61] =?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 54e4eb8b0816b4d1eb9a83abb16c289f41d816a4 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 9 Nov 2022 20:01:33 +0800 Subject: [PATCH 44/61] add ut Signed-off-by: fangJinliang1 Change-Id: Icf7c59ca6e377fce7a0d9457a5bc2153e1f32b27 Signed-off-by: fangJinliang1 --- frameworks/core/test/unittest/BUILD.gn | 1 + .../unittest/ans_manager_proxy_test/BUILD.gn | 62 + .../ans_manager_proxy_unit_test.cpp | 1099 +++++++++++++++++ .../test/unittest/mock/mock_i_remote_object.h | 2 +- .../unittest/mock/mock_message_parcel.cpp | 148 +++ 5 files changed, 1311 insertions(+), 1 deletion(-) create mode 100644 frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn create mode 100644 frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp create mode 100644 frameworks/core/test/unittest/mock/mock_message_parcel.cpp diff --git a/frameworks/core/test/unittest/BUILD.gn b/frameworks/core/test/unittest/BUILD.gn index 701d7950b..4088812ba 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_proxy_test:unittest", "ans_subscriber_proxy_test:unittest", "ans_subscriber_stub_test:unittest", ] diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn new file mode 100644 index 000000000..d5d35af52 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_proxy_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_manager_proxy_test") { + module_out_path = module_output_path + include_dirs = [ + "${core_path}/include", + "//commonlibrary/c_utils/base/include", + "../mock/", + # "${core_path}/common/include", + # "${core_path}/include", + "${inner_api_path}", + ] + + sources = [ + "ans_manager_proxy_unit_test.cpp", + "../mock/mock_message_parcel.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", + "ipc:ipc_core", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [] + + deps += [ ":ans_manager_proxy_test" ] +} diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp new file mode 100644 index 000000000..1734784e1 --- /dev/null +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -0,0 +1,1099 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "ans_manager_proxy.h" +#undef private +#undef protected +#include "ans_const_define.h" +#include "ans_manager_interface.h" +#include "ans_inner_errors.h" +#include "message_parcel.h" +#include "mock_i_remote_object.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Notification; +using namespace std::placeholders; + +extern void MockWriteInterfaceToken(bool mockRet); + +class AnsManagerProxyUnitTest : public testing::Test { +public: + AnsManagerProxyUnitTest() {} + + virtual ~AnsManagerProxyUnitTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AnsManagerProxyUnitTest::SetUpTestCase() +{ + MockWriteInterfaceToken(true); +} + +void AnsManagerProxyUnitTest::TearDownTestCase() {} + +void AnsManagerProxyUnitTest::SetUp() {} + +void AnsManagerProxyUnitTest::TearDown() {} + +int SendRequestReplace(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, bool retBool, bool setRetBool) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetBool) { + reply.WriteBool(retBool); + } + return 0; +} + +/* + * @tc.name: InnerTransactTest_0100 + * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_OK, res); +} + +/* + * @tc.name: InnerTransactTest_0200 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: InnerTransactTest_0300 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).WillOnce(DoAll(Return(-1))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, res); +} + +/* + * @tc.name: InnerTransactTest_0400 + * @tc.desc: test AnsManagerProxy's InnerTransact function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, InnerTransactTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, InnerTransactTest_0400, TestSize.Level1"; + std::shared_ptr proxy = std::make_shared(nullptr); + ASSERT_NE(nullptr, proxy); + uint32_t code = 0; + MessageOption flags; + MessageParcel data; + MessageParcel reply; + ErrCode res = proxy->InnerTransact(code, flags, data, reply); + EXPECT_EQ(ERR_DEAD_OBJECT, res); +} + +/* + * @tc.name: PublishTest_0100 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + sptr notification = nullptr; + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishTest_0200 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0300 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = ""; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishTest_0400 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishTest_0500 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishTest_0600 + * @tc.desc: test Publish function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string label = "label"; + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + int32_t result = proxy->Publish(label, notification); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0100 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishToDeviceTest_0200 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0300 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = ""; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0400 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: PublishToDeviceTest_0500 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishToDeviceTest_0600 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishToDeviceTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishToDeviceTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + ASSERT_NE(nullptr, notification); + std::string deviceId = "Device"; + int32_t result = proxy->PublishToDevice(notification, deviceId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0100 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0200 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = ""; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelTest_0300 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelTest_0400 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelTest_0500 + * @tc.desc: test Cancel function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string label = "label"; + int32_t result = proxy->Cancel(notificationId, label); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0100 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0200 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAllTest_0300 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAllTest_0400 + * @tc.desc: test CancelAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->CancelAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0100 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0200 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = ""; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0300 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: CancelAsBundleTest_0400 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CancelAsBundleTest_0500 + * @tc.desc: test CancelAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CancelAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CancelAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t notificationId = 0; + std::string representativeBundle = "Bundle"; + int32_t userId = 0; + int32_t result = proxy->CancelAsBundle(notificationId, representativeBundle, userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0100 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0200 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotByTypeTest_0300 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotByTypeTest_0400 + * @tc.desc: test AddSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->AddSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0100 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0200 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0300 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AddSlotsTest_0400 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: AddSlotsTest_0500 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AddSlotsTest_0600 + * @tc.desc: test AddSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AddSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AddSlotsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->AddSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0100 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0200 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = ""; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0300 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, popFlag); +} + +/* + * @tc.name: RequestEnableNotificationTest_0400 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0500 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RequestEnableNotificationTest_0600 + * @tc.desc: test RequestEnableNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string deviceId = "Device"; + bool popFlag = false; + int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} 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 5a2392a1d..769c32e8d 100644 --- a/frameworks/core/test/unittest/mock/mock_i_remote_object.h +++ b/frameworks/core/test/unittest/mock/mock_i_remote_object.h @@ -34,7 +34,7 @@ public: return 0; } - MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + MOCK_METHOD(int, SendRequest, (uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); bool IsProxyObject() const override { diff --git a/frameworks/core/test/unittest/mock/mock_message_parcel.cpp b/frameworks/core/test/unittest/mock/mock_message_parcel.cpp new file mode 100644 index 000000000..ba501f6f9 --- /dev/null +++ b/frameworks/core/test/unittest/mock/mock_message_parcel.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "message_parcel.h" +#include "iremote_object.h" + +namespace { + bool g_mockWriteInterfaceTokenRet = true; +} + +void MockWriteInterfaceToken(bool mockRet) +{ + g_mockWriteInterfaceTokenRet = mockRet; +} + +namespace OHOS { + +MessageParcel::MessageParcel() +{} + +MessageParcel::MessageParcel(Allocator *allocator) + : Parcel(allocator) +{ + writeRawDataFd_ = -1; + readRawDataFd_ = -1; + kernelMappedWrite_ = nullptr; + kernelMappedRead_ = nullptr; + rawData_ = nullptr; + rawDataSize_ = 0; +} + +MessageParcel::~MessageParcel() +{} + + +#ifndef CONFIG_IPC_SINGLE +bool MessageParcel::WriteDBinderProxy(const sptr &object, uint32_t handle, uint64_t stubIndex) +{ + return true; +} +#endif + +bool MessageParcel::WriteRemoteObject(const sptr &object) +{ + return true; +} + +sptr MessageParcel::ReadRemoteObject() +{ + sptr temp = ReadObject(); + return temp; +} + +bool MessageParcel::WriteFileDescriptor(int fd) +{ + return true; +} + +int MessageParcel::ReadFileDescriptor() +{ + return 0; +} + +void MessageParcel::ClearFileDescriptor() +{} + +bool MessageParcel::ContainFileDescriptors() const +{ + return true; +} + +bool MessageParcel::WriteInterfaceToken(std::u16string name) +{ + return g_mockWriteInterfaceTokenRet; +} + +std::u16string MessageParcel::ReadInterfaceToken() +{ + return ReadString16(); +} + +bool MessageParcel::WriteRawData(const void *data, size_t size) +{ + return true; +} + +bool MessageParcel::RestoreRawData(std::shared_ptr rawData, size_t size) +{ + return true; +} + +const void *MessageParcel::ReadRawData(size_t size) +{ + return nullptr; +} + +const void *MessageParcel::GetRawData() const +{ + return nullptr; +} + +size_t MessageParcel::GetRawDataSize() const +{ + return 0; +} + +size_t MessageParcel::GetRawDataCapacity() const +{ + return 0; +} + +void MessageParcel::WriteNoException() +{ + WriteInt32(0); +} + +int32_t MessageParcel::ReadException() +{ + return 0; +} + +bool MessageParcel::WriteAshmem(sptr ashmem) +{ + return true; +} + +sptr MessageParcel::ReadAshmem() +{ + return nullptr; +} + +bool MessageParcel::Append(MessageParcel &data) +{ + return true; +} +} // namespace OHOS -- Gitee From 552e5ddaf8af26bd8d26a63357ecb461dde29ea6 Mon Sep 17 00:00:00 2001 From: chenyuyan Date: Thu, 10 Nov 2022 10:59:23 +0800 Subject: [PATCH 45/61] =?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 From ffe78192e332550bae5630bb820fd2ee9d59e859 Mon Sep 17 00:00:00 2001 From: wangkailong Date: Thu, 10 Nov 2022 17:53:23 +0800 Subject: [PATCH 46/61] =?UTF-8?q?tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkailong Change-Id: I4aa49ee7ad4e5d54a429000ca7fd82641574bde6 --- services/ans/test/unittest/BUILD.gn | 4 +- .../unittest/access_token_helper_test.cpp | 129 ++++++++++++++++++ .../unittest/mock/mock_accesstoken_kit.cpp | 60 ++++++++ .../notification_slot_filter_test.cpp | 15 ++ .../unittest/system_event_observer_test.cpp | 112 +++++++++++++++ 5 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 services/ans/test/unittest/access_token_helper_test.cpp create mode 100644 services/ans/test/unittest/mock/mock_accesstoken_kit.cpp create mode 100644 services/ans/test/unittest/system_event_observer_test.cpp diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 1b55a7c8d..2eb1eb076 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -47,13 +47,13 @@ ohos_unittest("ans_unit_test") { "advanced_notification_service_ability_test.cpp", "advanced_notification_service_test.cpp", "bundle_manager_helper_test.cpp", - "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_access_token_helper.cpp", "mock/mock_bundle_manager_helper.cpp", "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/mock_accesstoken_kit.cpp", "notification_hisysevent_test.cpp", "notification_preferences_database_test.cpp", "notification_preferences_test.cpp", @@ -61,6 +61,8 @@ ohos_unittest("ans_unit_test") { "notification_subscriber_manager_test.cpp", "permission_filter_test.cpp", "reminder_data_manager_test.cpp", + "system_event_observer_test.cpp", + "access_token_helper_test.cpp", ] configs = [ "//commonlibrary/c_utils/base:utils_config" ] diff --git a/services/ans/test/unittest/access_token_helper_test.cpp b/services/ans/test/unittest/access_token_helper_test.cpp new file mode 100644 index 000000000..37324132f --- /dev/null +++ b/services/ans/test/unittest/access_token_helper_test.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "accesstoken_kit.h" +#define private public +#define protected public +#include "access_token_helper.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +#undef private +#undef protected +using namespace testing::ext; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace Notification { + +extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); + +class AccessTokenHelperTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr stub_; +}; + +void AccessTokenHelperTest::SetUpTestCase() +{ +} + +void AccessTokenHelperTest::TearDownTestCase() +{ +} + +void AccessTokenHelperTest::SetUp() +{ + stub_ = std::make_shared(); +} + +void AccessTokenHelperTest::TearDown() +{ +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : VerifyCallerPermission_00100 + * @tc.desc : VerifyCallerPermission success + */ +HWTEST_F(AccessTokenHelperTest, VerifyCallerPermission_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + string permission; + EXPECT_TRUE(stub_->VerifyCallerPermission(tokenID, permission)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : VerifyNativeToken_00100 + * @tc.desc : VerifyNativeToken success + */ +HWTEST_F(AccessTokenHelperTest, VerifyNativeToken_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_TRUE(stub_->VerifyNativeToken(tokenID)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00100 + * @tc.desc : IsSystemHap Token Type TOKEN_NATIVE + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00100, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_TRUE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00200 + * @tc.desc : IsSystemHap Token Type TOKEN_HAP + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00200, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + EXPECT_TRUE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemHap_00300 + * @tc.desc : IsSystemHap false + */ +HWTEST_F(AccessTokenHelperTest, IsSystemHap_00300, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_SHELL); + EXPECT_FALSE(stub_->IsSystemHap()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsDlpHap_00100 + * @tc.desc : IsDlpHap Token Type TOKEN_NATIVE + */ +HWTEST_F(AccessTokenHelperTest, IsDlpHap_00100, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + EXPECT_FALSE(stub_->IsSystemHap()); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp new file mode 100644 index 000000000..b7f41dca0 --- /dev/null +++ b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp @@ -0,0 +1,60 @@ +/* + * @Author: wangkailong wangkailong6@huawei.com + * @Date: 2022-11-08 10:44:55 + * @LastEditors: wangkailong wangkailong6@huawei.com + * @LastEditTime: 2022-11-10 11:57:12 + * @FilePath: /distributed_notification_service/services/ans/test/unittest/mock_accesstoken_kit.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "accesstoken_kit.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" + +using namespace OHOS::Security::AccessToken; +namespace OHOS { +namespace Notification { +namespace { +ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID; +} + +void MockGetTokenTypeFlag(ATokenTypeEnum mockRet) +{ + g_mockGetTokenTypeFlagRet = mockRet; +} +} +} +namespace OHOS { +namespace Security { +namespace AccessToken { +int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) +{ + return PERMISSION_GRANTED; +} + +ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) +{ + return Notification::g_mockGetTokenTypeFlagRet; +} + +int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& info) +{ + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/ans/test/unittest/notification_slot_filter_test.cpp b/services/ans/test/unittest/notification_slot_filter_test.cpp index 90e5730dc..f08f6978a 100644 --- a/services/ans/test/unittest/notification_slot_filter_test.cpp +++ b/services/ans/test/unittest/notification_slot_filter_test.cpp @@ -21,6 +21,7 @@ #include "notification_slot.h" #undef private #undef protected +#include "ans_inner_errors.h" #include "notification_slot_filter.h" #include "notification_subscribe_info.h" @@ -77,6 +78,20 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00200, Function * @tc.desc : Test OnPublish function */ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00300, Function | SmallTest | Level1) +{ + NotificationSlotFilter notificationSlotFilter; + std::shared_ptr record = std::make_shared(); + ErrCode result = notificationSlotFilter.OnPublish(record); + EXPECT_EQ(result, ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST); +} + + +/** + * @tc.number : NotificationSlotFilterTest_00400 + * @tc.name : ANS_OnPublish_0200 + * @tc.desc : Test OnPublish function + */ +HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00400, Function | SmallTest | Level1) { NotificationSlotFilter notificationSlotFilter; std::shared_ptr record = std::make_shared(); diff --git a/services/ans/test/unittest/system_event_observer_test.cpp b/services/ans/test/unittest/system_event_observer_test.cpp new file mode 100644 index 000000000..7b0baeda3 --- /dev/null +++ b/services/ans/test/unittest/system_event_observer_test.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define private public +#define protected public +#include "system_event_observer.h" +#undef private +#undef protected +#include "ans_inner_errors.h" +#include "common_event_support.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class SystemEventObserverTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr stub_; +}; + +void SystemEventObserverTest::SetUpTestCase() +{ +} + +void SystemEventObserverTest::TearDownTestCase() +{ +} + +void SystemEventObserverTest::SetUp() +{ + ISystemEvent iSystemEvent; + stub_ = std::make_shared(iSystemEvent); +} + +void SystemEventObserverTest::TearDown() +{ +} + +/** + * @tc.number : OnReceiveEvent_001 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_001, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED)); + + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_002 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_002, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED)); + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_003 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_003, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + stub_->OnReceiveEvent(data); +} + +/** + * @tc.number : OnReceiveEvent_004 + * @tc.name : + * @tc.desc : Test OnReceiveEvent function, return is void. + */ +HWTEST_F(SystemEventObserverTest, OnReceiveEvent_004, Function | SmallTest | Level1) +{ + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED)); + stub_->OnReceiveEvent(data); +} + +} // namespace Notification +} // namespace OHOS \ No newline at end of file -- Gitee From 691886a69dc90c1ab15c3ace94ed422abf139b4c Mon Sep 17 00:00:00 2001 From: wujiqin Date: Thu, 10 Nov 2022 18:11:45 +0800 Subject: [PATCH 47/61] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I60KBQ?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5fuzz=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=8702=20Sig:SIG=5FApplicationFramework=20Feature=20or=20B?= =?UTF-8?q?ugfix: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: Ida7c26563f244114900ed0ff84e5b7da33b7f926 --- test/fuzztest/BUILD.gn | 7 ++ test/fuzztest/messageuser_fuzzer/BUILD.gn | 54 ++++++++++++ test/fuzztest/messageuser_fuzzer/corpus/init | 13 +++ .../messageuser_fuzzer/messageuser_fuzzer.cpp | 78 ++++++++++++++++ .../messageuser_fuzzer/messageuser_fuzzer.h | 23 +++++ test/fuzztest/messageuser_fuzzer/project.xml | 25 ++++++ .../notificationactionbutton_fuzzer/BUILD.gn | 56 ++++++++++++ .../corpus/init | 13 +++ .../notificationactionbutton_fuzzer.cpp | 88 +++++++++++++++++++ .../notificationactionbutton_fuzzer.h | 23 +++++ .../project.xml | 25 ++++++ .../notificationcontent_fuzzer/BUILD.gn | 55 ++++++++++++ .../notificationcontent_fuzzer/corpus/init | 13 +++ .../notificationcontent_fuzzer.cpp | 77 ++++++++++++++++ .../notificationcontent_fuzzer.h | 23 +++++ .../notificationcontent_fuzzer/project.xml | 25 ++++++ .../BUILD.gn | 55 ++++++++++++ .../corpus/init | 13 +++ .../notificationdistributedoptions_fuzzer.cpp | 63 +++++++++++++ .../notificationdistributedoptions_fuzzer.h | 23 +++++ .../project.xml | 25 ++++++ .../notificationflags_fuzzer/BUILD.gn | 54 ++++++++++++ .../notificationflags_fuzzer/corpus/init | 13 +++ .../notificationflags_fuzzer.cpp | 59 +++++++++++++ .../notificationflags_fuzzer.h | 23 +++++ .../notificationflags_fuzzer/project.xml | 25 ++++++ .../notificationnormalcontent_fuzzer/BUILD.gn | 55 ++++++++++++ .../corpus/init | 13 +++ .../notificationnormalcontent_fuzzer.cpp | 52 +++++++++++ .../notificationnormalcontent_fuzzer.h | 23 +++++ .../project.xml | 25 ++++++ .../reminderstoreannex_fuzzer/BUILD.gn | 55 ++++++++++++ .../reminderstoreannex_fuzzer/corpus/init | 13 +++ .../reminderstoreannex_fuzzer/project.xml | 25 ++++++ .../reminderstoreannex_fuzzer.cpp | 62 +++++++++++++ .../reminderstoreannex_fuzzer.h | 23 +++++ 36 files changed, 1297 insertions(+) create mode 100644 test/fuzztest/messageuser_fuzzer/BUILD.gn create mode 100644 test/fuzztest/messageuser_fuzzer/corpus/init create mode 100644 test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp create mode 100644 test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h create mode 100644 test/fuzztest/messageuser_fuzzer/project.xml create mode 100644 test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationactionbutton_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp create mode 100644 test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h create mode 100644 test/fuzztest/notificationactionbutton_fuzzer/project.xml create mode 100644 test/fuzztest/notificationcontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationcontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h create mode 100644 test/fuzztest/notificationcontent_fuzzer/project.xml create mode 100644 test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp create mode 100644 test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h create mode 100644 test/fuzztest/notificationdistributedoptions_fuzzer/project.xml create mode 100644 test/fuzztest/notificationflags_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationflags_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp create mode 100644 test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h create mode 100644 test/fuzztest/notificationflags_fuzzer/project.xml create mode 100644 test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationnormalcontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h create mode 100644 test/fuzztest/notificationnormalcontent_fuzzer/project.xml create mode 100644 test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderstoreannex_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderstoreannex_fuzzer/project.xml create mode 100644 test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp create mode 100644 test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 3b674d09c..68e8077f3 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -33,13 +33,19 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "messageuser_fuzzer:MessageUserFuzzTest", "notification_fuzzer:NotificationFuzzTest", + "notificationactionbutton_fuzzer:NotificationActionButtonFuzzTest", + "notificationcontent_fuzzer:NotificationContentFuzzTest", "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationdistributedoptions_fuzzer:NotificationDistributedOptionsFuzzTest", "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", + "notificationflags_fuzzer:NotificationFlagsFuzzTest", "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", + "notificationnormalcontent_fuzzer:NotificationNormalContentFuzzTest", "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", "notificationsorting_fuzzer:NotificationSortingFuzzTest", @@ -58,6 +64,7 @@ group("fuzztest") { "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", "reminderstore_fuzzer:ReminderStoreFuzzTest", + "reminderstoreannex_fuzzer:ReminderStoreAnnexFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/messageuser_fuzzer/BUILD.gn b/test/fuzztest/messageuser_fuzzer/BUILD.gn new file mode 100644 index 000000000..743510799 --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("MessageUserFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/messageuser_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "messageuser_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":MessageUserFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/messageuser_fuzzer/corpus/init b/test/fuzztest/messageuser_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp new file mode 100644 index 000000000..47210c4a2 --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "message_user.h" +#undef private +#undef protected +#include "messageuser_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string key(data); + Notification::MessageUser messageUser; + // test SetKey function + messageUser.SetKey(key); + // test SetName function + std::string name(data); + messageUser.SetName(name); + // test SetPixelMap function + std::shared_ptr pixelMap = std::make_shared(); + messageUser.SetPixelMap(pixelMap); + // test SetUri function + Uri uri(key); + messageUser.SetUri(uri); + // test SetMachine function + bool enabled = *data % ENABLE; + messageUser.SetMachine(enabled); + // test SetUserAsImportant function + messageUser.SetUserAsImportant(enabled); + // test GetKey function + messageUser.GetKey(); + // test GetName function + messageUser.GetName(); + // test GetPixelMap function + messageUser.GetPixelMap(); + // test GetUri function + messageUser.GetUri(); + // test IsMachine function + messageUser.IsMachine(); + // test IsUserImportant function + messageUser.IsUserImportant(); + // test ToJson function + nlohmann::json jsonObject; + messageUser.ToJson(jsonObject); + messageUser.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h new file mode 100644 index 000000000..8e6a27836 --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/messageuser_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H +#define TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "messageuser_fuzzer" + +#endif // TEST_FUZZTEST_MESSAGEUSER_FUZZER_MESSAGEUSER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/messageuser_fuzzer/project.xml b/test/fuzztest/messageuser_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/messageuser_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn new file mode 100644 index 000000000..990c9dba2 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationActionButtonFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationactionbutton_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationactionbutton_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationActionButtonFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationactionbutton_fuzzer/corpus/init b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp new file mode 100644 index 000000000..10982a6b7 --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_action_button.h" +#undef private +#undef protected +#include "notificationactionbutton_fuzzer.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" +#include "want_params.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + std::string title(data); + std::shared_ptr actionButton = + Notification::NotificationActionButton::Create(nullptr, title, wantAgent); + if (actionButton == nullptr) { + return false; + } + // test AddAdditionalData function + AAFwk::WantParams extras; + actionButton->AddAdditionalData(extras); + // test AddMimeTypeOnlyUserInput function + std::shared_ptr userInput = + std::make_shared(); + actionButton->AddMimeTypeOnlyUserInput(userInput); + actionButton->AddNotificationUserInput(userInput); + // test GetMimeTypeOnlyUserInputs function + actionButton->GetMimeTypeOnlyUserInputs(); + // test GetUserInput function + actionButton->GetUserInput(); + // test IsAutoCreatedReplies function + actionButton->IsAutoCreatedReplies(); + // test IsContextDependent function + actionButton->IsContextDependent(); + // test GetSemanticActionButton function + actionButton->GetSemanticActionButton(); + // test GetIcon function + actionButton->GetIcon(); + // test GetTitle function + actionButton->GetTitle(); + // test GetWantAgent function + actionButton->GetWantAgent(); + // test Dump function + actionButton->Dump(); + // test ToJson function + nlohmann::json jsonObject; + actionButton->ToJson(jsonObject); + actionButton->FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + actionButton->Marshalling(parcel); + actionButton->Unmarshalling(parcel); + actionButton->ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h new file mode 100644 index 000000000..32b8806cc --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/notificationactionbutton_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationactionbutton_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONACTIONBUTTON_FUZZER_NOTIFICATIONACTIONBUTTON_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationactionbutton_fuzzer/project.xml b/test/fuzztest/notificationactionbutton_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationactionbutton_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..f093ca3f1 --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationcontent_fuzzer/corpus/init b/test/fuzztest/notificationcontent_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp new file mode 100644 index 000000000..2b913e0a6 --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_content.h" +#undef private +#undef protected +#include "notificationcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::shared_ptr normalContent = + std::make_shared(); + std::shared_ptr longTextContent = + std::make_shared(); + std::shared_ptr pictureContent = + std::make_shared(); + std::shared_ptr conversationContent = + std::make_shared(); + std::shared_ptr multiLineContent = + std::make_shared(); + std::shared_ptr mediaContent = + std::make_shared(); + if ((normalContent == nullptr) || (longTextContent == nullptr) || (pictureContent == nullptr) || + (conversationContent == nullptr) || (multiLineContent == nullptr) || (mediaContent == nullptr)) { + return false; + } + Notification::NotificationContent notificationContent(normalContent); + Notification::NotificationContent notificationLongTextContent(longTextContent); + Notification::NotificationContent notificationPictureContent(pictureContent); + Notification::NotificationContent notificationConversationContent(conversationContent); + Notification::NotificationContent notificationMultiLineContent(multiLineContent); + Notification::NotificationContent notificationMediaContent(mediaContent); + // test Dump function + notificationContent.GetContentType(); + // test Dump function + notificationContent.GetNotificationContent(); + // test Dump function + notificationContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationContent.ToJson(jsonObject); + notificationContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationContent.Unmarshalling(parcel); + notificationContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h new file mode 100644 index 000000000..f38e46696 --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/notificationcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONTENT_FUZZER_NOTIFICATIONCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationcontent_fuzzer/project.xml b/test/fuzztest/notificationcontent_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn new file mode 100644 index 000000000..559ffbc70 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationDistributedOptionsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationdistributedoptions_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationdistributedoptions_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationDistributedOptionsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp new file mode 100644 index 000000000..0750e4835 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_distributed_options.h" +#include "notificationdistributedoptions_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + bool distribute = *data % ENABLE; + std::vector dvsDisplay; + std::vector dvsOperate; + dvsDisplay.emplace_back(stringData); + dvsOperate.emplace_back(stringData); + Notification::NotificationDistributedOptions notificationDistributedOptions(distribute, dvsDisplay, dvsOperate); + // test IsDistributed function + notificationDistributedOptions.IsDistributed(); + // test GetDevicesSupportDisplay function + notificationDistributedOptions.GetDevicesSupportDisplay(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test GetDevicesSupportOperate function + notificationDistributedOptions.GetDevicesSupportOperate(); + // test Dump function + notificationDistributedOptions.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationDistributedOptions.ToJson(jsonObject); + notificationDistributedOptions.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + return notificationDistributedOptions.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h new file mode 100644 index 000000000..083e19669 --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/notificationdistributedoptions_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationdistributedoptions_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_NOTIFICATIONDISTRIBUTEDOPTIONS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationdistributedoptions_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationflags_fuzzer/BUILD.gn b/test/fuzztest/notificationflags_fuzzer/BUILD.gn new file mode 100644 index 000000000..447895fb7 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationFlagsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationflags_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationflags_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationFlagsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationflags_fuzzer/corpus/init b/test/fuzztest/notificationflags_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp new file mode 100644 index 000000000..40ddcc291 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_flags.h" +#undef private +#undef protected +#include "notificationflags_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationFlags notificationFlags; + // test IsSoundEnabled function + notificationFlags.IsSoundEnabled(); + // test IsVibrationEnabled function + notificationFlags.IsVibrationEnabled(); + // test Dump function + notificationFlags.Dump(); + // test ToJson function + nlohmann::json jsonObject; + if (jsonObject.is_null() or !jsonObject.is_object()) { + return false; + } + notificationFlags.ToJson(jsonObject); + notificationFlags.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationFlags.Unmarshalling(parcel); + notificationFlags.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h new file mode 100644 index 000000000..9c68c8131 --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/notificationflags_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationflags_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONFLAGS_FUZZER_NOTIFICATIONFLAGS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationflags_fuzzer/project.xml b/test/fuzztest/notificationflags_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationflags_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..dab3a817d --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationNormalContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationnormalcontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationnormalcontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationNormalContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp new file mode 100644 index 000000000..5a81c96f8 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_normal_content.h" +#undef private +#undef protected +#include "notificationnormalcontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationNormalContent notificationNormalContent; + // test Dump function + notificationNormalContent.Dump(); + // test ToJson function + nlohmann::json jsonObject; + notificationNormalContent.ToJson(jsonObject); + notificationNormalContent.FromJson(jsonObject); + // test Unmarshalling function + Parcel parcel; + notificationNormalContent.Unmarshalling(parcel); + notificationNormalContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h new file mode 100644 index 000000000..8033ab597 --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/notificationnormalcontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationnormalcontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONNORMALCONTENT_FUZZER_NOTIFICATIONNORMALCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationnormalcontent_fuzzer/project.xml b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationnormalcontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..edfc9cfd4 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstoreannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderstoreannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstoreannex_fuzzer/corpus/init b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderstoreannex_fuzzer/project.xml b/test/fuzztest/reminderstoreannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp new file mode 100644 index 000000000..99e1ef7c0 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_store.h" +#undef private +#undef protected +#include "reminderstoreannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::ReminderStore reminderStore; + // test GetReminders function + std::string queryCondition(data); + reminderStore.GetReminders(queryCondition); + // test GetAllValidReminders function + reminderStore.GetAllValidReminders(); + // test Query function + reminderStore.Query(queryCondition); + // test GetBundleOption function + sptr bundleOption; + int32_t reminderId = static_cast(GetU32Data(data)); + reminderStore.GetBundleOption(reminderId, bundleOption); + // test GetInt32Val function + std::shared_ptr resultSet = std::make_shared(); + std::string name(data); + int32_t value = static_cast(GetU32Data(data)); + reminderStore.GetInt32Val(resultSet, name, value); + std::string value1(data); + reminderStore.GetStringVal(resultSet, name, value1); + // test BuildReminder function + reminderStore.BuildReminder(resultSet); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h new file mode 100644 index 000000000..590bc3f13 --- /dev/null +++ b/test/fuzztest/reminderstoreannex_fuzzer/reminderstoreannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstoreannex_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTOREANNEX_FUZZER_REMINDERSTOREANNEX_FUZZER_H \ No newline at end of file -- Gitee From f327e895419137cea2df7cb960b5197958b626cc Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 9 Nov 2022 15:54:53 +0800 Subject: [PATCH 48/61] notification_preferences add TDD testcase Signed-off-by: raul Change-Id: If30c0e32be03f4421d44b16036bf387407b431e0 --- services/ans/test/unittest/ans_ut_constant.h | 1 + .../notification_preferences_test.cpp | 457 +++++++++++++++++- 2 files changed, 436 insertions(+), 22 deletions(-) diff --git a/services/ans/test/unittest/ans_ut_constant.h b/services/ans/test/unittest/ans_ut_constant.h index 2e8a9b906..c13d7d004 100644 --- a/services/ans/test/unittest/ans_ut_constant.h +++ b/services/ans/test/unittest/ans_ut_constant.h @@ -27,6 +27,7 @@ constexpr int32_t SYSTEM_APP_UID = 100; constexpr int32_t NON_SYSTEM_APP_UID = 1000; constexpr int32_t NON_BUNDLE_NAME_UID = 2000; const std::string TEST_DEFUALT_BUNDLE = "bundleName"; +constexpr int32_t TEST_SUBSCRIBE_USER_INIT = -1; } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index fed80303f..33bd1bcdd 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -17,7 +17,11 @@ #include "ans_inner_errors.h" #include "ans_ut_constant.h" +#define private public +#define protected public #include "notification_preferences.h" +#undef private +#undef protected using namespace testing::ext; namespace OHOS { @@ -127,6 +131,21 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | Sma EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK); } +/** + * @tc.number : AddNotificationSlots_00600 + * @tc.name : + * @tc.desc : Add a notification slot into distrube DB , return is ERR_OK. + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(nullptr, slots), (int)ERR_OK); +} + + + /** * @tc.number : RemoveNotificationSlot_00100 * @tc.name : @@ -180,6 +199,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00400, Function | S (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationSlot_00500 + * @tc.name : + * @tc.desc : Remove a notification slot from disturbe DB , return is ERR_OK + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER), + (int)ERR_OK); +} + /** * @tc.number : RemoveNotificationForBundle_00100 * @tc.name : @@ -215,6 +247,18 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00300, Functio (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationForBundle_00400 + * @tc.name : + * @tc.desc : Remove notification for bundle from disturbe DB when bundle name is null, return is + * ERR_ANS_INVALID_PARAM; + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : UpdateNotificationSlots_00100 * @tc.name : @@ -289,6 +333,20 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : UpdateNotificationSlots_00600 + * @tc.name : + * @tc.desc : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(nullptr, slots), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlot_00100 * @tc.name : @@ -347,6 +405,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | Smal (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : GetNotificationSlot_00500 + * @tc.name : + * @tc.desc : Update notification slot group into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | SmallTest | Level1) +{ + sptr slot; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER, slot), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationAllSlots_00100 * @tc.name : @@ -411,6 +483,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00400, Function | EXPECT_EQ((int)slotsResult.size(), 0); } +/** + * @tc.number : GetNotificationAllSlots_00500 + * @tc.name : + * @tc.desc : Get all notification slots from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00500, Function | SmallTest | Level1) +{ + std::vector> slotsResult; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(nullptr, slotsResult), + (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ((int)slotsResult.size(), 0); +} + /** * @tc.number : SetShowBadge_00100 * @tc.name : @@ -458,6 +544,18 @@ HWTEST_F(NotificationPreferencesTest, IsShowBadge_00200, Function | SmallTest | (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : IsShowBadge_00300 + * @tc.name : + * @tc.desc : Get bunlde show badge from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, IsShowBadge_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(nullptr, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetImportance_00100 * @tc.name : @@ -481,6 +579,18 @@ HWTEST_F(NotificationPreferencesTest, SetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetImportance_00300 + * @tc.name : + * @tc.desc : Set bundle importance into disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetImportance_00300, Function | SmallTest | Level1) +{ + int importance = 1; + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(nullptr, importance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetImportance_00100 * @tc.name : @@ -508,6 +618,18 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetImportance_00300 + * @tc.name : + * @tc.desc : Get bundle importance from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetImportance_00300, Function | SmallTest | Level1) +{ + int getImportance = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(nullptr, getImportance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetTotalBadgeNums_00100 * @tc.name : @@ -557,6 +679,18 @@ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallT (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetTotalBadgeNums_00300 + * @tc.name : + * @tc.desc : Get total badge nums from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00300, Function | SmallTest | Level1) +{ + int totalBadgeNum = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(nullptr, totalBadgeNum), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetPrivateNotificationsAllowed_00100 * @tc.name : @@ -580,6 +714,18 @@ HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Set private notification allowed badge nums into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetPrivateNotificationsAllowed(nullptr, true), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetPrivateNotificationsAllowed_00100 * @tc.name : @@ -608,6 +754,19 @@ HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Get private notification allowed badge nums from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + bool allow = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetPrivateNotificationsAllowed(nullptr, allow), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabledForBundle_00100 * @tc.name : @@ -631,12 +790,24 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00200, Fu (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Set notification enable for bundle into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(nullptr, false), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationsEnabledForBundle_00100 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB, return is ERR_OK. */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1) { EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleOption_, false), (int)ERR_OK); @@ -647,18 +818,31 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Fu } /** - * @tc.number : GetNotificationsEnabledForBundle_00100 + * @tc.number : GetNotificationsEnabledForBundle_00200 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB when bundle name is null, return is * ERR_ANS_INVALID_PARAM. */ -HWTEST_F(NotificationPreferencesTest, NotificationPreferencesTest_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1) { bool enabled = false; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleEmptyOption_, enabled), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Get notification enable for bundle from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + bool enabled = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(nullptr, enabled), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabled_00100 * @tc.name : @@ -670,7 +854,18 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00100, Function | } /** - * @tc.number : GetNotificationsEnabled + * @tc.number : SetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Set enable notification into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, true), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : GetNotificationsEnabled_00100 * @tc.name : * @tc.desc : Get enable notification from disturbe DB, return is ERR_OK */ @@ -682,6 +877,36 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | EXPECT_TRUE(enable); } +/** + * @tc.number : GetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Same user can get enable setting, different user can not get. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); + EXPECT_TRUE(enable); + + enable = false; + EXPECT_EQ( + (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); + EXPECT_FALSE(enable); +} + +/** + * @tc.number : GetNotificationsEnabled_00300 + * @tc.name : + * @tc.desc : Get enable notification from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetDoNotDisturbDate_00100 * @tc.name : @@ -701,6 +926,26 @@ HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK); } +/** + * @tc.number : SetDoNotDisturbDate_00200 + * @tc.name : + * @tc.desc : Set disturbe mode into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00200, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, date), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetDoNotDisturbDate_00100 * @tc.name : @@ -725,24 +970,6 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ(getDate->GetEndDate(), endDate); } -/** - * @tc.number : GetNotificationsEnabled_00200 - * @tc.name : - * @tc.desc : Same user can get enable setting, different user can not get. - */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) -{ - EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); - bool enable = false; - EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); - EXPECT_TRUE(enable); - - enable = false; - EXPECT_EQ( - (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); - EXPECT_FALSE(enable); -} - /** * @tc.number : GetDoNotDisturbDate_00200 * @tc.name : @@ -771,6 +998,18 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00200, Function | Smal NON_SYSTEM_APP_UID, getExsitDate), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetDoNotDisturbDate_00300 + * @tc.name : + * @tc.desc : Get disturbe mode from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00300, Function | SmallTest | Level1) +{ + sptr getDate; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, getDate), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetHasPoppedDialog_00100 * @tc.name : @@ -825,6 +1064,19 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00200, Funct (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : AddNotificationBundleProperty_00300 + * @tc.name : AddNotificationBundleProperty + * @tc.desc : Add a notification BundleProperty into distrube DB when bundlename is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : RemoveNotificationAllSlots_00100 * @tc.name : RemoveNotificationAllSlots @@ -851,6 +1103,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00200, Function (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : RemoveNotificationAllSlots_00300 + * @tc.name : RemoveNotificationAllSlots + * @tc.desc : Test RemoveNotificationAllSlots function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlotsNumForBundle_00100 * @tc.name : GetNotificationSlotsNumForBundle @@ -878,5 +1143,153 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00200, Fu EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundleEmptyOption_, num), (int)ERR_ANS_INVALID_PARAM); } + +/** + * @tc.number : GetNotificationSlotsNumForBundle_00300 + * @tc.name : GetNotificationSlotsNumForBundle + * @tc.desc : Test GetNotificationSlotsNumForBundle function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Function | SmallTest | Level1) +{ + uint64_t num = 2; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(nullptr, num), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00100 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00200 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function, return ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00100 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00200 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function, return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00300 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00100 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00200 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when bundle not existed, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00300 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is different type, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00400 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function after add notification slot, return is ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} } // namespace Notification } // namespace OHOS -- Gitee From 0f6b77c44211ad0734c3be9c1532b6e198417577 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Thu, 10 Nov 2022 23:42:44 +0800 Subject: [PATCH 49/61] add ut Signed-off-by: fangJinliang1 Change-Id: I02713130c85a2b0d4380d17c8b4e9a2bef2c68ca --- .../ans_manager_proxy_unit_test.cpp | 1210 +++++++++++++++++ 1 file changed, 1210 insertions(+) diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index 1734784e1..d7b4cd09f 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -73,6 +73,18 @@ int SendRequestReplace(uint32_t code, MessageParcel &data, MessageParcel &reply, return 0; } +int SendRequestReplaceNum(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, uint64_t retNum, bool setRetNum) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetNum) { + reply.WriteUint64(retNum); + } + return 0; +} + /* * @tc.name: InnerTransactTest_0100 * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. @@ -1097,3 +1109,1201 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, Function | int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } + +/* + * @tc.name: RemoveSlotByTypeTest_0100 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0200 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveSlotByTypeTest_0300 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0400 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0100 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0200 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveAllSlotsTest_0300 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0400 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceSlot(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t slotNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (slotNum == 1) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteParcelable(slot); + } + if (slotNum > 1) { + reply.WriteInt32(slotNum); + for (size_t i = 0; i < slotNum; i++) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteStrongParcelable(slot); + } + } + return 0; +} + +/* + * @tc.name: GetSlotByTypeTest_0100 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0200 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_OK, result); + EXPECT_NE(nullptr, slot); +} +/* + * @tc.name: GetSlotByTypeTest_0300 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0400 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0100 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0200 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsTest_0300 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0400 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0100 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0200 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0300 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0400 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0500 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0600 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceNotifications(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t notificationNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (notificationNum > 0) { + reply.WriteInt32(notificationNum); + for (size_t i = 0; i < notificationNum; i++) { + sptr request = new (std::nothrow) NotificationRequest(0); + reply.WriteStrongParcelable(request); + } + } + + return 0; +} +/* + * @tc.name: GetActiveNotificationsTest_0100 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0200 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); +} +/* + * @tc.name: GetActiveNotificationsTest_0300 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0400 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0500 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0100 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0200 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0300 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0400 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0500 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0100 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0200 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0300 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, support); +} + +/* + * @tc.name: IsSupportTemplateTest_0400 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0500 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0600 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0100 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0200 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledByUserTest_0300 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0400 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0100 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0200 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllByUserTest_0300 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0400 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} \ No newline at end of file -- Gitee From f30712d08316f595d8b909e375abca89752d5cb8 Mon Sep 17 00:00:00 2001 From: liyanzhi Date: Fri, 11 Nov 2022 08:24:30 +0800 Subject: [PATCH 50/61] add fuzz Signed-off-by: liyanzhi Change-Id: Iea694e538b1ad45eb415ac2bb261b5dabe1bde9f --- .../notificationconversationalcontent_fuzzer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp index d84384286..1139f3189 100644 --- a/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp +++ b/test/fuzztest/notificationconversationalcontent_fuzzer/notificationconversationalcontent_fuzzer.cpp @@ -20,6 +20,7 @@ #undef protected #include "notificationconversationalcontent_fuzzer.h" +#define DISABLE_FUZZ namespace OHOS { namespace { constexpr uint8_t ENABLE = 2; @@ -54,7 +55,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ char *ch = ParseData(data, size); if (ch != nullptr && size >= GetU32Size()) { +#ifndef DISABLE_FUZZ OHOS::DoSomethingInterestingWithMyAPI(ch, size); +#endif free(ch); ch = nullptr; } -- Gitee From 5b61003b74ee88f392457de55c28a22bcde39d0f Mon Sep 17 00:00:00 2001 From: sunbingxin Date: Fri, 11 Nov 2022 15:35:49 +0800 Subject: [PATCH 51/61] add new tdd cases for ans Signed-off-by: sunbingxin --- .../ans_manager_proxy_unit_test.cpp | 1210 +++++++++++++++++ 1 file changed, 1210 insertions(+) diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index 1734784e1..d7b4cd09f 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -73,6 +73,18 @@ int SendRequestReplace(uint32_t code, MessageParcel &data, MessageParcel &reply, return 0; } +int SendRequestReplaceNum(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, uint64_t retNum, bool setRetNum) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetNum) { + reply.WriteUint64(retNum); + } + return 0; +} + /* * @tc.name: InnerTransactTest_0100 * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. @@ -1097,3 +1109,1201 @@ HWTEST_F(AnsManagerProxyUnitTest, RequestEnableNotificationTest_0600, Function | int32_t result = proxy->RequestEnableNotification(deviceId, popFlag); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } + +/* + * @tc.name: RemoveSlotByTypeTest_0100 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0200 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveSlotByTypeTest_0300 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveSlotByTypeTest_0400 + * @tc.desc: test RemoveSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + int32_t result = proxy->RemoveSlotByType(slotType); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0100 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0200 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: RemoveAllSlotsTest_0300 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllSlotsTest_0400 + * @tc.desc: test RemoveAllSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->RemoveAllSlots(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceSlot(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t slotNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (slotNum == 1) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteParcelable(slot); + } + if (slotNum > 1) { + reply.WriteInt32(slotNum); + for (size_t i = 0; i < slotNum; i++) { + sptr slot = new (std::nothrow) NotificationSlot(); + reply.WriteStrongParcelable(slot); + } + } + return 0; +} + +/* + * @tc.name: GetSlotByTypeTest_0100 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0200 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_OK, result); + EXPECT_NE(nullptr, slot); +} +/* + * @tc.name: GetSlotByTypeTest_0300 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0400 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotByTypeTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotByTypeTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationConstant::SlotType slotType = NotificationConstant::SOCIAL_COMMUNICATION; + sptr slot = nullptr; + int32_t result = proxy->GetSlotByType(slotType, slot); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0100 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0200 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsTest_0300 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0400 + * @tc.desc: test GetSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsTest_0500 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + int32_t result = proxy->GetSlots(slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0100 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0200 + * @tc.desc: test PublishToDevice function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0300 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0400 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0500 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotNumAsBundleTest_0600 + * @tc.desc: test GetSlotNumAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotNumAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + uint64_t num = 0; + int32_t result = proxy->GetSlotNumAsBundle(bundleOption, num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +int SendRequestReplaceNotifications(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, int32_t notificationNum) +{ + if (setError) { + reply.WriteInt32(error); + } + + if (notificationNum > 0) { + reply.WriteInt32(notificationNum); + for (size_t i = 0; i < notificationNum; i++) { + sptr request = new (std::nothrow) NotificationRequest(0); + reply.WriteStrongParcelable(request); + } + } + + return 0; +} +/* + * @tc.name: GetActiveNotificationsTest_0100 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0200 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); +} +/* + * @tc.name: GetActiveNotificationsTest_0300 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0400 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationsTest_0500 + * @tc.desc: test GetActiveNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + int32_t result = proxy->GetActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0100 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0200 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0300 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0400 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetActiveNotificationNumsTest_0500 + * @tc.desc: test GetActiveNotificationNums function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + uint64_t num = 0; + int32_t result = proxy->GetActiveNotificationNums(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0100 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0200 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0300 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, support); +} + +/* + * @tc.name: IsSupportTemplateTest_0400 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0500 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0600 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0100 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0200 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledByUserTest_0300 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0400 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0100 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0200 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllByUserTest_0300 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0400 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} \ No newline at end of file -- Gitee From 3098d8647578a8e10bdbc5b0c2d6379632182302 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Thu, 10 Nov 2022 20:06:00 +0800 Subject: [PATCH 52/61] tdd cover Signed-off-by: zhuhan Change-Id: I4d921eff36458b200fd4ef18f9a19ed8d2f1db03 --- .../advanced_notification_service_test.cpp | 496 +++++++++++++++++- .../mock/mock_bundle_manager_helper.cpp | 8 +- 2 files changed, 501 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 505ffe42b..4e013eba4 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -56,24 +56,36 @@ sptr AdvancedNotificationServiceTest::advancedNotif void AdvancedNotificationServiceTest::SetUpTestCase() { + GTEST_LOG_(INFO) << "SetUpTestCase start"; advancedNotificationService_ = AdvancedNotificationService::GetInstance(); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + GTEST_LOG_(INFO) << "SetUpTestCase end"; } void AdvancedNotificationServiceTest::TearDownTestCase() { + GTEST_LOG_(INFO) << "TearDownTestCase start"; advancedNotificationService_ = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase end"; } void AdvancedNotificationServiceTest::SetUp() { + GTEST_LOG_(INFO) << "SetUp start"; + NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); advancedNotificationService_->CancelAll(); + + GTEST_LOG_(INFO) << "SetUp end"; } void AdvancedNotificationServiceTest::TearDown() -{} +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + GTEST_LOG_(INFO) << "TearDown"; +} inline void SleepForFC() { @@ -2092,5 +2104,487 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); } + +/** + * @tc.number : AdvancedNotificationServiceTest_15700 + * @tc.name : PrepareNotificationRequest_0100 + * @tc.desc : Test PrepareNotificationRequest function when notification is agent. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test start"; + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + + req->SetContent(content); + req->SetIsAgentNotification(true); + EXPECT_EQ(advancedNotificationService_->PrepareNotificationRequest(req), ERR_ANS_NON_SYSTEM_APP); + GTEST_LOG_(INFO) << "PrepareNotificationRequest_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_15800 + * @tc.name : GenerateBundleOption_0100 + * @tc.desc : Test GenerateBundleOption function when bundle name is null. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + EXPECT_EQ(advancedNotificationService_->GenerateBundleOption(), nullptr); + GTEST_LOG_(INFO) << "GenerateBundleOption_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16000 + * @tc.name : CancelPreparedNotification_1000 + * @tc.desc : Test CancelPreparedNotification function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start"; + + int32_t notificationId = 0; + std::string label = "testLabel"; + sptr bundleOption = nullptr; + EXPECT_EQ(advancedNotificationService_->CancelPreparedNotification(notificationId, label, bundleOption), + ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16100 + * @tc.name : PrepareNotificationInfo_1000 + * @tc.desc : Test PrepareNotificationInfo function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test start"; + + sptr req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + req->SetCreatorUserId(DEFAULT_USER_ID); + req->SetIsAgentNotification(true); + advancedNotificationService_->Publish(label, req); + SleepForFC(); + + GTEST_LOG_(INFO) << "CancelPreparedNotification_1000 test end"; +} + + +/** + * @tc.number : AdvancedNotificationServiceTest_16200 + * @tc.name : ANS_CancelAsBundle_0200 + * @tc.desc : Test CancelAsBundle function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + int32_t notificationId = 1; + std::string representativeBundle = "RepresentativeBundle"; + int32_t userId = 1; + int result = ERR_ANS_NON_SYSTEM_APP; + EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result); + + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16300 + * @tc.name : ANS_CancelAsBundle_0300 + * @tc.desc : Test CancelAsBundle function when uid is less than 0. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + int32_t notificationId = 1; + std::string representativeBundle = "RepresentativeBundle"; + int32_t userId = 0; + int result = ERR_ANS_INVALID_UID; + EXPECT_EQ(advancedNotificationService_->CancelAsBundle(notificationId, representativeBundle, userId), result); + + GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16400 + * @tc.name : ANS_AddSlots_0100 + * @tc.desc : Test AddSlots function whith not system app + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16600 + * @tc.name : ANS_AddSlots_0300 + * @tc.desc : Test AddSlots function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0300 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16700 + * @tc.name : ANS_AddSlots_0400 + * @tc.desc : Test AddSlots function with invalid bundle option + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test start"; + + std::vector> slots; + EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "ANS_AddSlots_0400 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16800 + * @tc.name : ANS_GetSlots_0100 + * @tc.desc : Test GetSlots function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test start"; + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + + std::vector> slots; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slots.push_back(slot); + EXPECT_EQ(advancedNotificationService_->GetSlots(slots), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "ANS_GetSlots_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_16900 + * @tc.name : ANS_GetActiveNotifications_0100 + * @tc.desc : Test function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + std::vector> notifications; + EXPECT_EQ(advancedNotificationService_->GetActiveNotifications(notifications), ERR_ANS_INVALID_BUNDLE); + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetActiveNotificationNums(num), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->SetNotificationBadgeNum(num), ERR_ANS_INVALID_BUNDLE); + int32_t importance = 2; + EXPECT_EQ(advancedNotificationService_->GetBundleImportance(importance), ERR_ANS_INVALID_BUNDLE); + bool allow = true; + EXPECT_EQ(advancedNotificationService_->SetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->GetPrivateNotificationsAllowed(allow), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabled(allow), ERR_ANS_INVALID_BUNDLE); + + sptr slot = new NotificationSlot(NotificationConstant::OTHER); + EXPECT_EQ(advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->RemoveSlotByType(NotificationConstant::OTHER), ERR_ANS_INVALID_BUNDLE); + + std::string deviceId = "DeviceId"; + bool needPop = false; + EXPECT_EQ(advancedNotificationService_->RequestEnableNotification(deviceId, needPop), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(needPop), ERR_ANS_INVALID_BUNDLE); + sptr bundleOption; + EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(bundleOption, needPop), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_ANS_INVALID_BUNDLE); + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17000 + * @tc.name : ANS_GetSetActiveNotifications_0100 + * @tc.desc : Test SetNotificationAgent and GetNotificationAgent function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + std::string agent = "agent"; + EXPECT_EQ(advancedNotificationService_->SetNotificationAgent(agent), ERR_INVALID_OPERATION); + EXPECT_EQ(advancedNotificationService_->GetNotificationAgent(agent), ERR_INVALID_OPERATION); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17100 + * @tc.name : ANS_GetSetActiveNotifications_0100 + * @tc.desc : Test function with NON_SYSTEM_APP_UID + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + std::string key = "key"; + int32_t removeReason = 0; + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + EXPECT_EQ(advancedNotificationService_->Delete(key, removeReason), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteByBundle(bundleOption), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_ANS_NON_SYSTEM_APP); + + bool enable = true; + EXPECT_EQ(advancedNotificationService_->SetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetShowBadgeEnabledForBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + std::vector> notifications; + EXPECT_EQ(advancedNotificationService_->GetAllActiveNotifications(notifications), ERR_ANS_NON_SYSTEM_APP); + + std::vector keys; + EXPECT_EQ(advancedNotificationService_->GetSpecialActiveNotifications(keys, notifications), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForAllBundles(key, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( + std::string(), bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->IsAllowedNotify(enable), ERR_ANS_NON_SYSTEM_APP); + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17200 + * @tc.name : ANS_DeleteAll_0100 + * @tc.desc : Test DeleteAll function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; + + TestAddSlot(NotificationConstant::SlotType::OTHER); + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK); + SleepForFC(); + req->SetCreatorUserId(SUBSCRIBE_USER_INIT); + std::shared_ptr notification = std::make_shared(req); + EXPECT_EQ(advancedNotificationService_->DeleteAll(), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17300 + * @tc.name : ANS_GetSlotsByBundle_0100 + * @tc.desc : Test GetSlotsByBundle function + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test start"; + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + + std::vector> slots; + EXPECT_EQ(advancedNotificationService_->GetSlotsByBundle( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->UpdateSlots( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), slots), + ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17400 + * @tc.name : CancelPreparedNotification_1000 + * @tc.desc : Test CancelPreparedNotification function. + * @tc.require : #I60KYN + */ +// HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, Function | SmallTest | Level1) +// { +// GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_17400 test start"; + +// int32_t notificationId = 0; +// std::string label = "testLabel"; +// sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); +// sptr notification = nullptr; +// bool isCancel = false; +// EXPECT_EQ(advancedNotificationService_->RemoveFromNotificationList(bundleOption, label, notificationId, +// notification, isCancel), ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED); + +// EXPECT_EQ(advancedNotificationService_->RemoveFromNotificationList(label, notification, isCancel, +// NotificationConstant::CANCEL_REASON_DELETE), ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED); + +// GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_17400 test end"; +// } + +/** + * @tc.number : AdvancedNotificationServiceTest_17400 + * @tc.name : Subscribe_1000 + * @tc.desc : Test Subscribe function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "Subscribe_1000 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "Subscribe_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17500 + * @tc.name : Unsubscribe_1000 + * @tc.desc : Test Subscribe function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "Unsubscribe_1000 test start"; + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "Unsubscribe_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17600 + * @tc.name : GetAppTargetBundle_1000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; + + sptr bundleOption = nullptr; + + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_OK); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17700 + * @tc.name : GetAppTargetBundle_2000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; + + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); + sptr targetBundle = nullptr; + bundleOption->SetBundleName("test"); + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_ANS_NON_SYSTEM_APP); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_17800 + * @tc.name : GetAppTargetBundle_2000 + * @tc.desc : Test GetAppTargetBundle function. + * @tc.require : #I60KYN + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + sptr targetBundle = nullptr; + bundleOption->SetBundleName("test"); + EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, targetBundle), ERR_OK); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test end"; +} + } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp index fa0d3eb61..501bf9e10 100644 --- a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp +++ b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -38,12 +38,16 @@ std::string BundleManagerHelper::GetBundleNameByUid(int uid) int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) { - return NON_SYSTEM_APP_UID; + if (userId == 0) { + return -1; + } else { + return NON_SYSTEM_APP_UID; + } } bool BundleManagerHelper::IsSystemApp(int uid) { - return (uid == SYSTEM_APP_UID); + return (uid == SYSTEM_APP_UID || uid == NON_BUNDLE_NAME_UID); } bool BundleManagerHelper::CheckApiCompatibility(const sptr &bundleOption) -- Gitee From 1520ad48d29157f3bcdebc9554f3b808544e9175 Mon Sep 17 00:00:00 2001 From: yuyaozhi Date: Sat, 12 Nov 2022 11:40:46 +0800 Subject: [PATCH 53/61] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuyaozhi Change-Id: I6021806fd8e01b8f929d63383680446bdea4e46d Signed-off-by: yuyaozhi --- test/fuzztest/BUILD.gn | 3 + test/fuzztest/anscallbackstub_fuzzer/BUILD.gn | 55 ++++++++++++ .../anscallbackstub_fuzzer.cpp | 60 +++++++++++++ .../anscallbackstub_fuzzer.h | 23 +++++ .../anscallbackstub_fuzzer/corpus/init | 13 +++ .../anscallbackstub_fuzzer/project.xml | 25 ++++++ .../ansmanagerstub_fuzzer.cpp | 68 +++++++++++++- .../anssubscriberproxy_fuzzer/BUILD.gn | 55 ++++++++++++ .../anssubscriberproxy_fuzzer.cpp | 75 ++++++++++++++++ .../anssubscriberproxy_fuzzer.h | 23 +++++ .../anssubscriberproxy_fuzzer/corpus/init | 13 +++ .../anssubscriberproxy_fuzzer/project.xml | 25 ++++++ .../anssubscriberstub_fuzzer/BUILD.gn | 55 ++++++++++++ .../anssubscriberstub_fuzzer.cpp | 90 +++++++++++++++++++ .../anssubscriberstub_fuzzer.h | 23 +++++ .../anssubscriberstub_fuzzer/corpus/init | 13 +++ .../anssubscriberstub_fuzzer/project.xml | 25 ++++++ 17 files changed, 643 insertions(+), 1 deletion(-) create mode 100644 test/fuzztest/anscallbackstub_fuzzer/BUILD.gn create mode 100644 test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp create mode 100644 test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h create mode 100644 test/fuzztest/anscallbackstub_fuzzer/corpus/init create mode 100644 test/fuzztest/anscallbackstub_fuzzer/project.xml create mode 100644 test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn create mode 100644 test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp create mode 100644 test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h create mode 100644 test/fuzztest/anssubscriberproxy_fuzzer/corpus/init create mode 100644 test/fuzztest/anssubscriberproxy_fuzzer/project.xml create mode 100644 test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn create mode 100644 test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp create mode 100644 test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h create mode 100644 test/fuzztest/anssubscriberstub_fuzzer/corpus/init create mode 100644 test/fuzztest/anssubscriberstub_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 3b674d09c..db481e85b 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,10 +18,13 @@ group("fuzztest") { "addnotificationslot_fuzzer:AddNotificationSlotFuzzTest", "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", + "anscallbackstub_fuzzer:AnsCallbackStubFuzzTest", "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", "ansmanagerstubannexthree_fuzzer:AnsManagerStubAnnexThreeFuzzTest", "ansmanagerstubannextwo_fuzzer:AnsManagerStubAnnexTwoFuzzTest", + "anssubscriberproxy_fuzzer:AnsSubscriberProxyFuzzTest", + "anssubscriberstub_fuzzer:AnsSubscriberStubFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", diff --git a/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn b/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn new file mode 100644 index 000000000..f83638039 --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsCallbackStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anscallbackstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anscallbackstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsCallbackStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp new file mode 100644 index 000000000..17d19877d --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_callback_stub.h" +#undef private +#undef protected +#include "anscallbackstub_fuzzer.h" +#include "notification_request.h" + +using namespace OHOS::Notification; + +namespace OHOS { +class AnsCallbackStubImpl : public AnsCallbackStub { + bool OnEnableNotification(bool isAllow) override + { + return false; + } +}; + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + std::string stringData(data); + std::shared_ptr ansCallbackStub = + std::make_shared(); + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test OnRemoteRequest function + ansCallbackStub->OnRemoteRequest(code, datas, reply, flags); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h new file mode 100644 index 000000000..1acf06ab4 --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/anscallbackstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anscallbackstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSCALLBACKSTUB_FUZZER_ANSCALLBACKSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/corpus/init b/test/fuzztest/anscallbackstub_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anscallbackstub_fuzzer/project.xml b/test/fuzztest/anscallbackstub_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/anscallbackstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 36a919d2d..f0399517c 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -19,6 +19,9 @@ #undef private #undef protected #include "ansmanagerstub_fuzzer.h" +#include "notification_request.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; namespace OHOS { bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) @@ -61,7 +64,70 @@ namespace OHOS { ansManagerStub.HandleSetPrivateNotificationsAllowed(datas, reply); ansManagerStub.HandleGetPrivateNotificationsAllowed(datas, reply); ansManagerStub.HandleRemoveNotification(datas, reply); - return ansManagerStub.HandleRemoveAllNotifications(datas, reply); + ansManagerStub.HandleRemoveAllNotifications(datas, reply); + ansManagerStub.HandleDelete(datas, reply); + ansManagerStub.HandleDeleteByBundle(datas, reply); + ansManagerStub.HandleDeleteAll(datas, reply); + ansManagerStub.HandleGetSlotsByBundle(datas, reply); + ansManagerStub.HandleUpdateSlots(datas, reply); + ansManagerStub.HandleRequestEnableNotification(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForBundle(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForAllBundles(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledForSpecialBundle(datas, reply); + ansManagerStub.HandleSetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply); + ansManagerStub.HandleGetShowBadgeEnabled(datas, reply); + ansManagerStub.HandleSubscribe(datas, reply); + ansManagerStub.HandleUnsubscribe(datas, reply); + ansManagerStub.HandleAreNotificationsSuspended(datas, reply); + ansManagerStub.HandleGetCurrentAppSorting(datas, reply); + ansManagerStub.HandleIsAllowedNotify(datas, reply); + ansManagerStub.HandleIsAllowedNotifySelf(datas, reply); + ansManagerStub.HandleIsSpecialBundleAllowedNotify(datas, reply); + ansManagerStub.HandleCancelGroup(datas, reply); + ansManagerStub.HandleRemoveGroupByBundle(datas, reply); + ansManagerStub.HandleIsDistributedEnabled(datas, reply); + ansManagerStub.HandleEnableDistributed(datas, reply); + ansManagerStub.HandleEnableDistributedByBundle(datas, reply); + ansManagerStub.HandleEnableDistributedSelf(datas, reply); + ansManagerStub.HandleIsDistributedEnableByBundle(datas, reply); + ansManagerStub.HandleGetDeviceRemindType(datas, reply); + ansManagerStub.HandleShellDump(datas, reply); + ansManagerStub.HandlePublishReminder(datas, reply); + ansManagerStub.HandleCancelReminder(datas, reply); + ansManagerStub.HandleCancelAllReminders(datas, reply); + ansManagerStub.HandleGetValidReminders(datas, reply); + ansManagerStub.HandleIsSupportTemplate(datas, reply); + ansManagerStub.HandleIsSpecialUserAllowedNotifyByUser(datas, reply); + ansManagerStub.HandleSetNotificationsEnabledByUser(datas, reply); + ansManagerStub.HandleDeleteAllByUser(datas, reply); + ansManagerStub.HandleSetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleGetDoNotDisturbDateByUser(datas, reply); + ansManagerStub.HandleSetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply); + ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply); + ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply); + sptr notification = new Notification::NotificationRequest(); + const std::string label = "this is a notification label"; + ansManagerStub.Publish(label, notification); + const std::string deviceId = "this is a notification deviceId"; + ansManagerStub.PublishToDevice(notification, deviceId); + int notificationId = 1; + ansManagerStub.Cancel(notificationId, label); + ansManagerStub.CancelAll(); + const std::string representativeBundle ="this is a notification representativeBundle"; + int32_t userId = 1; + ansManagerStub.CancelAsBundle(notificationId, representativeBundle, userId); + uint8_t type = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + ansManagerStub.AddSlotByType(slotType); + ansManagerStub.RemoveSlotByType(slotType); + sptr slot = new Notification::NotificationSlot(); + ansManagerStub.GetSlotByType(slotType, slot); + sptr bundleOption = new Notification::NotificationBundleOption(); + uint64_t num = 1; + ansManagerStub.GetSlotNumAsBundle(bundleOption, num); + return true; } } diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn b/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn new file mode 100644 index 000000000..d2ddb41dc --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsSubscriberProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anssubscriberproxy_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anssubscriberproxy_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsSubscriberProxyFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp new file mode 100644 index 000000000..85ee11544 --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_subscriber_proxy.h" +#undef private +#undef protected +#include "anssubscriberproxy_fuzzer.h" +#include "notification_request.h" +#include "notification_subscriber.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr impl; + Notification::AnsSubscriberProxy ansSubscriberProxy(impl); + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test InnerTransact function + ansSubscriberProxy.InnerTransact(code, flags, datas, reply); + // test InnerTransact function + ansSubscriberProxy.OnConnected(); + // test InnerTransact function + ansSubscriberProxy.OnDisconnected(); + // test InnerTransact function + sptr notification = new Notification::Notification(); + ansSubscriberProxy.OnConsumed(notification); + // test InnerTransact function + sptr notificationMap = new Notification::NotificationSortingMap(); + ansSubscriberProxy.OnConsumed(notification, notificationMap); + // test OnCanceled function + ansSubscriberProxy.OnCanceled(notification); + // test OnCanceled function + int32_t deleteReason = 1; + ansSubscriberProxy.OnCanceled(notification, notificationMap, deleteReason); + // test OnCanceled function + ansSubscriberProxy.OnUpdated(notificationMap); + // test OnCanceled function + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansSubscriberProxy.OnDoNotDisturbDateChange(date); + // test OnEnabledNotificationChanged function + sptr callbackData = new Notification::EnabledNotificationCallbackData(); + ansSubscriberProxy.OnEnabledNotificationChanged(callbackData); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h new file mode 100644 index 000000000..0cdd0af12 --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/anssubscriberproxy_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H +#define TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anssubscriberproxy_fuzzer" + +#endif // TEST_FUZZTEST_ANSSUBSCRIBERPROXY_FUZZER_ANSSUBSCRIBERPROXY_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init b/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anssubscriberproxy_fuzzer/project.xml b/test/fuzztest/anssubscriberproxy_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/anssubscriberproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn b/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn new file mode 100644 index 000000000..2d73d3f05 --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("AnsSubscriberStubFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/anssubscriberstub_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anssubscriberstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "//base\notification\distributed_notification_service\frameworks\core:ans_core", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsSubscriberStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp new file mode 100644 index 000000000..25e72818e --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "ans_subscriber_stub.h" +#undef private +#undef protected +#include "anssubscriberstub_fuzzer.h" +#include "notification_request.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::AnsSubscriberStub ansSubscriberStub; + uint32_t code = GetU32Data(data); + MessageParcel datas; + MessageParcel reply; + MessageOption flags; + // test OnRemoteRequest function + ansSubscriberStub.OnRemoteRequest(code, datas, reply, flags); + // test HandleOnConnected function + ansSubscriberStub.HandleOnConnected(datas, reply); + // test HandleOnDisconnected function + ansSubscriberStub.HandleOnDisconnected(datas, reply); + // test HandleOnConsumed function + ansSubscriberStub.HandleOnConsumed(datas, reply); + // test HandleOnConsumedMap function + ansSubscriberStub.HandleOnConsumedMap(datas, reply); + // test HandleOnCanceled function + ansSubscriberStub.HandleOnCanceled(datas, reply); + // test HandleOnCanceledMap function + ansSubscriberStub.HandleOnCanceledMap(datas, reply); + // test HandleOnUpdated function + ansSubscriberStub.HandleOnUpdated(datas, reply); + // test HandleOnDoNotDisturbDateChange function + ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply); + // test HandleOnEnabledNotificationChanged function + ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply); + // test OnConnected function + ansSubscriberStub.OnConnected(); + // test OnDisconnected function + ansSubscriberStub.OnDisconnected(); + // test OnConsumed function + sptr notification = new Notification::Notification(); + ansSubscriberStub.OnConsumed(notification); + // test OnConsumed function + sptr notificationMap = new Notification::NotificationSortingMap(); + ansSubscriberStub.OnConsumed(notification, notificationMap); + // test OnCanceled function + ansSubscriberStub.OnCanceled(notification); + // test OnCanceled function + int32_t deleteReason = 1; + ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason); + // test OnUpdated function + ansSubscriberStub.OnUpdated(notificationMap); + // test OnDoNotDisturbDateChange function + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansSubscriberStub.OnDoNotDisturbDateChange(date); + // test OnEnabledNotificationChanged function + sptr callbackData = new Notification::EnabledNotificationCallbackData(); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h new file mode 100644 index 000000000..ec87efa9b --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/anssubscriberstub_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "anssubscriberstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSSUBSCRIBERSTUB_FUZZER_ANSSUBSCRIBERSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/anssubscriberstub_fuzzer/corpus/init b/test/fuzztest/anssubscriberstub_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/anssubscriberstub_fuzzer/project.xml b/test/fuzztest/anssubscriberstub_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/anssubscriberstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From 06d6d352dee6c6e0cf75a3e4942025d307aab559 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Mon, 14 Nov 2022 10:23:56 +0800 Subject: [PATCH 54/61] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I60XZ5?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5fuzz=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=8703=20Sig:SIG=5FApplicationFramework=20Feature=20or=20B?= =?UTF-8?q?ugfix: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: I68345178084c56d890f9d127ca1a0134f0c8f334 --- test/fuzztest/BUILD.gn | 10 +++ .../notificationdonotdisturbdate_fuzzer.cpp | 1 + .../notificationhelper_fuzzer/BUILD.gn | 54 ++++++++++++++ .../notificationhelper_fuzzer/corpus/init | 13 ++++ .../notificationhelper_fuzzer.cpp | 53 ++++++++++++++ .../notificationhelper_fuzzer.h | 23 ++++++ .../notificationhelper_fuzzer/project.xml | 25 +++++++ .../BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ ...tificationmultilinecontentannex_fuzzer.cpp | 48 +++++++++++++ ...notificationmultilinecontentannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ ...notificationpicturecontentannex_fuzzer.cpp | 48 +++++++++++++ .../notificationpicturecontentannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../notificationrequestannex_fuzzer/BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ .../notificationrequestannex_fuzzer.cpp | 61 ++++++++++++++++ .../notificationrequestannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../fuzztest/notificationslot_fuzzer/BUILD.gn | 54 ++++++++++++++ .../notificationslot_fuzzer/corpus/init | 13 ++++ .../notificationslot_fuzzer.cpp | 66 +++++++++++++++++ .../notificationslot_fuzzer.h | 23 ++++++ .../notificationslot_fuzzer/project.xml | 25 +++++++ .../notificationsortingannex_fuzzer/BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ .../notificationsortingannex_fuzzer.cpp | 46 ++++++++++++ .../notificationsortingannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ .../notificationsortingmapannex_fuzzer.cpp | 45 ++++++++++++ .../notificationsortingmapannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../notificationtemplateannex_fuzzer/BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ .../notificationtemplateannex_fuzzer.cpp | 51 ++++++++++++++ .../notificationtemplateannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 55 +++++++++++++++ .../corpus/init | 13 ++++ .../notificationuserinputannex_fuzzer.cpp | 70 +++++++++++++++++++ .../notificationuserinputannex_fuzzer.h | 23 ++++++ .../project.xml | 25 +++++++ .../reminderrequestannexthree_fuzzer/BUILD.gn | 56 +++++++++++++++ .../corpus/init | 13 ++++ .../project.xml | 25 +++++++ .../reminderrequestannexthree_fuzzer.cpp | 53 ++++++++++++++ .../reminderrequestannexthree_fuzzer.h | 23 ++++++ .../reminderrequesttimer_fuzzer.cpp | 1 + 53 files changed, 1712 insertions(+) create mode 100644 test/fuzztest/notificationhelper_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationhelper_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp create mode 100644 test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h create mode 100644 test/fuzztest/notificationhelper_fuzzer/project.xml create mode 100644 test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h create mode 100644 test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h create mode 100644 test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationrequestannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h create mode 100644 test/fuzztest/notificationrequestannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationslot_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationslot_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp create mode 100644 test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h create mode 100644 test/fuzztest/notificationslot_fuzzer/project.xml create mode 100644 test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationsortingannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h create mode 100644 test/fuzztest/notificationsortingannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h create mode 100644 test/fuzztest/notificationsortingmapannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationtemplateannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h create mode 100644 test/fuzztest/notificationtemplateannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationuserinputannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h create mode 100644 test/fuzztest/notificationuserinputannex_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestannexthree_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index dc397c3e4..0f9028eb6 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -45,17 +45,26 @@ group("fuzztest") { "notificationdistributedoptions_fuzzer:NotificationDistributedOptionsFuzzTest", "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", "notificationflags_fuzzer:NotificationFlagsFuzzTest", + "notificationhelper_fuzzer:NotificationHelperFuzzTest", "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", + "notificationmultilinecontentannex_fuzzer:NotificationMultiLineContentAnnexFuzzTest", "notificationnormalcontent_fuzzer:NotificationNormalContentFuzzTest", "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", + "notificationpicturecontentannex_fuzzer:NotificationPictureContentAnnexFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", + "notificationrequestannex_fuzzer:NotificationRequestAnnexFuzzTest", + "notificationslot_fuzzer:NotificationSlotFuzzTest", "notificationsorting_fuzzer:NotificationSortingFuzzTest", + "notificationsortingannex_fuzzer:NotificationSortingAnnexFuzzTest", "notificationsortingmap_fuzzer:NotificationSortingMapFuzzTest", + "notificationsortingmapannex_fuzzer:NotificationSortingMapAnnexFuzzTest", "notificationsubscribeInfo_fuzzer:NotificationSubscribeInfoFuzzTest", "notificationtemplate_fuzzer:NotificationTemplateFuzzTest", + "notificationtemplateannex_fuzzer:NotificationTemplateAnnexFuzzTest", "notificationuserinput_fuzzer:NotificationUserInputFuzzTest", + "notificationuserinputannex_fuzzer:NotificationUserInputAnnexFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", "readfromparcel_fuzzer:ReadFromParcelFuzzTest", @@ -63,6 +72,7 @@ group("fuzztest") { "reminderrequest_fuzzer:ReminderRequestFuzzTest", "reminderrequestalarm_fuzzer:ReminderRequestAlarmFuzzTest", "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestannexthree_fuzzer:ReminderRequestAnnexThreeFuzzTest", "reminderrequestcalendar_fuzzer:ReminderRequestCalendarFuzzTest", "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", diff --git a/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp index 8641146ba..6503996dd 100644 --- a/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp +++ b/test/fuzztest/notificationdonotdisturbdate_fuzzer/notificationdonotdisturbdate_fuzzer.cpp @@ -31,6 +31,7 @@ namespace OHOS { notificationDoNotDisturbDate.SetBeginDate(beginDate); notificationDoNotDisturbDate.GetBeginDate(); notificationDoNotDisturbDate.SetEndDate(endDate); + notificationDoNotDisturbDate.Dump(); return notificationDoNotDisturbDate.GetEndDate(); } } diff --git a/test/fuzztest/notificationhelper_fuzzer/BUILD.gn b/test/fuzztest/notificationhelper_fuzzer/BUILD.gn new file mode 100644 index 000000000..608cc9ae5 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationHelperFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationhelper_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationhelper_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationHelperFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationhelper_fuzzer/corpus/init b/test/fuzztest/notificationhelper_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp new file mode 100644 index 000000000..ff1f5e769 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_helper.h" +#undef private +#undef protected +#include "notificationhelper_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationHelper notificationHelper; + // test IsSoundEnabled function + std::string representativeBundle(data); + Notification::NotificationRequest request; + notificationHelper.PublishNotificationAsBundle(representativeBundle, request); + notificationHelper.RemoveNotifications(); + int32_t userId = static_cast(GetU32Data(data)); + bool enabled = *data % ENABLE; + notificationHelper.SetNotificationsEnabledForAllBundles(userId, enabled); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h new file mode 100644 index 000000000..b95e3f322 --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/notificationhelper_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationhelper_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONHELPER_FUZZER_NOTIFICATIONHELPER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationhelper_fuzzer/project.xml b/test/fuzztest/notificationhelper_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..d18e78d23 --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationMultiLineContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationmultilinecontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationmultilinecontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationMultiLineContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init b/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp new file mode 100644 index 000000000..223cd379f --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_multiline_content.h" +#undef private +#undef protected +#include "notificationmultilinecontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationMultiLineContent notificationMultiLineContent; + nlohmann::json jsonObject; + notificationMultiLineContent.ToJson(jsonObject); + notificationMultiLineContent.FromJson(jsonObject); + Parcel parcel; + notificationMultiLineContent.Unmarshalling(parcel); + notificationMultiLineContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h new file mode 100644 index 000000000..e3d596d6c --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/notificationmultilinecontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationmultilinecontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_NOTIFICATIONMULTILINECONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml b/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationmultilinecontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..0defda831 --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationPictureContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationpicturecontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationpicturecontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationPictureContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init b/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp new file mode 100644 index 000000000..0ecb02f79 --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_picture_content.h" +#undef private +#undef protected +#include "notificationpicturecontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationPictureContent notificationPictureContent; + nlohmann::json jsonObject; + notificationPictureContent.ToJson(jsonObject); + notificationPictureContent.FromJson(jsonObject); + Parcel parcel; + notificationPictureContent.Unmarshalling(parcel); + notificationPictureContent.ReadFromParcel(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h new file mode 100644 index 000000000..680d2a79a --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/notificationpicturecontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationpicturecontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_NOTIFICATIONPICTURECONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml b/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationpicturecontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn b/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..e6dcd86ad --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationRequestAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationrequestannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationrequestannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationRequestAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationrequestannex_fuzzer/corpus/init b/test/fuzztest/notificationrequestannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp new file mode 100644 index 000000000..9fae7ec24 --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_request.h" +#undef private +#undef protected +#include "notificationrequestannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + int32_t notificationId = static_cast(GetU32Data(data)); + Notification::NotificationRequest request(notificationId); + pid_t pid = *data; + request.SetCreatorPid(pid); + request.Dump(); + nlohmann::json jsonObject; + request.ToJson(jsonObject); + request.FromJson(jsonObject); + request.ConvertObjectsToJson(jsonObject); + request.ConvertObjectsToJson(jsonObject); + Notification::NotificationRequest* target = new Notification::NotificationRequest(notificationId); + request.ConvertJsonToNum(target, jsonObject); + request.ConvertJsonToString(target, jsonObject); + request.ConvertJsonToEnum(target, jsonObject); + request.ConvertJsonToBool(target, jsonObject); + request.ConvertJsonToPixelMap(target, jsonObject); + request.ConvertJsonToNotificationContent(target, jsonObject); + request.ConvertJsonToNotificationActionButton(target, jsonObject); + request.ConvertJsonToNotificationDistributedOptions(target, jsonObject); + request.ConvertJsonToNotificationFlags(target, jsonObject); + return request.IsAgentNotification(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h new file mode 100644 index 000000000..f264ff8f3 --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/notificationrequestannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationrequestannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONREQUESTANNEX_FUZZER_NOTIFICATIONREQUESTANNEX_FUZZER_H diff --git a/test/fuzztest/notificationrequestannex_fuzzer/project.xml b/test/fuzztest/notificationrequestannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationrequestannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationslot_fuzzer/BUILD.gn b/test/fuzztest/notificationslot_fuzzer/BUILD.gn new file mode 100644 index 000000000..af8ba11b9 --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSlotFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationslot_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationslot_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSlotFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationslot_fuzzer/corpus/init b/test/fuzztest/notificationslot_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp new file mode 100644 index 000000000..5148f2211 --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_slot.h" +#undef private +#undef protected +#include "notificationslot_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSlot notificationSlot; + bool enabled = *data % ENABLE; + notificationSlot.CanEnableLight(); + notificationSlot.CanVibrate(); + notificationSlot.GetDescription(); + notificationSlot.GetId(); + notificationSlot.GetLedLightColor(); + notificationSlot.GetLevel(); + notificationSlot.GetType(); + notificationSlot.GetLockScreenVisibleness(); + notificationSlot.GetName(); + notificationSlot.GetSound(); + notificationSlot.GetVibrationStyle(); + notificationSlot.IsEnableBypassDnd(); + notificationSlot.EnableBypassDnd(enabled); + notificationSlot.IsShowBadge(); + notificationSlot.EnableBadge(enabled); + notificationSlot.SetEnable(enabled); + notificationSlot.GetEnable(); + Parcel parcel; + notificationSlot.ReadFromParcel(parcel); + notificationSlot.Unmarshalling(parcel); + return notificationSlot.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h new file mode 100644 index 000000000..4a3f47bde --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/notificationslot_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationslot_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSLOT_FUZZER_NOTIFICATIONSLOT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationslot_fuzzer/project.xml b/test/fuzztest/notificationslot_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationslot_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn b/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..396489de5 --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsortingannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsortingannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsortingannex_fuzzer/corpus/init b/test/fuzztest/notificationsortingannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp new file mode 100644 index 000000000..6be90e7ed --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#undef private +#undef protected +#include "notificationsortingannex_fuzzer.h" + +namespace OHOS { + + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSorting notificationSorting; + Parcel parcel; + notificationSorting.ReadFromParcel(parcel); + notificationSorting.Unmarshalling(parcel); + return notificationSorting.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h new file mode 100644 index 000000000..7cb527a2d --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/notificationsortingannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsortingannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTINGANNEX_FUZZER_NOTIFICATIONSORTINGANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsortingannex_fuzzer/project.xml b/test/fuzztest/notificationsortingannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationsortingannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn b/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..f449870f6 --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationSortingMapAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationsortingmapannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationsortingmapannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationSortingMapAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init b/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp new file mode 100644 index 000000000..4830a47aa --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_sorting.h" +#include "notification_sorting_map.h" +#undef private +#undef protected +#include "notificationsortingmapannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationSortingMap notificationSortingMap; + Parcel parcel; + notificationSortingMap.Unmarshalling(parcel); + return notificationSortingMap.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h new file mode 100644 index 000000000..dd76b2481 --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/notificationsortingmapannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationsortingmapannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONSORTINGMAPANNEX_FUZZER_NOTIFICATIONSORTINGMAPANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml b/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationsortingmapannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn b/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..262ac70cd --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationTemplateAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationtemplateannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationtemplateannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationTemplateAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init b/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp new file mode 100644 index 000000000..98a8fc8f7 --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_template.h" +#include "notification_conversational_content.h" +#undef private +#undef protected +#include "notificationtemplateannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + Notification::NotificationTemplate notificationTemplate; + Parcel parcel; + notificationTemplate.Unmarshalling(parcel); + notificationTemplate.ReadFromParcel(parcel); + Notification::MessageUser messageUser; + Notification::NotificationConversationalContent NotificationConversationalContent(messageUser); + nlohmann::json jsonObject; + NotificationConversationalContent.ToJson(jsonObject); + NotificationConversationalContent.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h new file mode 100644 index 000000000..50b6df6e8 --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/notificationtemplateannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationtemplateannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONTEMPLATEANNEX_FUZZER_NOTIFICATIONTEMPLATEANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationtemplateannex_fuzzer/project.xml b/test/fuzztest/notificationtemplateannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationtemplateannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn b/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..db8a5f6fd --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationUserInputAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationuserinputannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationuserinputannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationUserInputAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init b/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp new file mode 100644 index 000000000..3b9fc30ea --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_user_input.h" +#undef private +#undef protected +#include "notificationuserinputannex_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t INPUT_EDIT_TYPE = 3; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationUserInput notificationUserInput(stringData); + AAFwk::Want want; + Notification::NotificationUserInput userInput(stringData); + std::map> results; + notificationUserInput.AddMimeInputToWant(userInput, want, results); + std::string inputKey(data); + std::string tag(data); + std::vector options; + options.emplace_back(stringData); + bool permitFreeFormInput = *data % ENABLE; + std::set permitMimeTypes; + std::shared_ptr additional; + uint8_t inputEditTypes = *data % INPUT_EDIT_TYPE; + Notification::NotificationConstant::InputEditType inputEditType = + Notification::NotificationConstant::InputEditType(inputEditTypes); + std::shared_ptr notificationUserInputs = + Notification::NotificationUserInput::Create(inputKey, tag, options, permitFreeFormInput, + permitMimeTypes, additional, inputEditType); + Notification::NotificationUserInput notificationUserInputannex + (inputKey, tag, options, permitFreeFormInput, permitMimeTypes, additional, inputEditType); + nlohmann::json jsonObject; + notificationUserInputannex.ToJson(jsonObject); + notificationUserInputannex.FromJson(jsonObject); + Parcel parcel; + return notificationUserInput.Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h new file mode 100644 index 000000000..03d07efec --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationuserinputannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONUSERINPUTANNEX_FUZZER_NOTIFICATIONUSERINPUTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/project.xml b/test/fuzztest/notificationuserinputannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationuserinputannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn new file mode 100644 index 000000000..bea9b9743 --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestAnnexThreeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestannexthree_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestannexthree_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestAnnexThreeFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml b/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp new file mode 100644 index 000000000..8e0a45d9d --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "reminder_request.h" +#undef private +#undef protected +#include "reminderrequestannexthree_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.GetTitle(); + uint64_t showTime = 2; + reminderRequest.ReminderRequest::GetShowTime(showTime); + Notification::ReminderRequest::TimeTransferType type = Notification::ReminderRequest::TimeTransferType::YEAR; + int32_t cTime = static_cast(GetU32Data(data)); + reminderRequest.GetActualTime(type, cTime); + reminderRequest.GetCTime(type, cTime); + int32_t uid = static_cast(GetU32Data(data)); + reminderRequest.GetUserId(uid); + return reminderRequest.IsAlerting(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h new file mode 100644 index 000000000..cee6c1ae2 --- /dev/null +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestannexthree_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTANNEXTHREE_FUZZER_REMINDERREQUESTANNEXTHREE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp index 1b9d9365c..7ede3ee51 100644 --- a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp @@ -38,6 +38,7 @@ namespace OHOS { reminderRequestTimer.CheckParamsValid(countDownTimeInSeconds); reminderRequestTimer.UpdateTimeInfo(stringData); Parcel parcel; + reminderRequestTimer.Unmarshalling(parcel); reminderRequestTimer.Marshalling(parcel); return reminderRequestTimer.ReadFromParcel(parcel); } -- Gitee From 49f05b5515bf7ce821499d94ae3eee240a17c285 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Mon, 14 Nov 2022 17:33:27 +0800 Subject: [PATCH 55/61] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I613BC?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5fuzz=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=8704=20Sig:SIG=5FApplicationFramework=20Feature=20or=20B?= =?UTF-8?q?ugfix: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: Ibfa4a41a2ae4f831423a615efcca5d33cd94c6d0 --- test/fuzztest/BUILD.gn | 5 ++ .../notificationannex_fuzzer/BUILD.gn | 54 ++++++++++++++++++ .../notificationannex_fuzzer/corpus/init | 13 +++++ .../notificationannex_fuzzer.cpp | 52 +++++++++++++++++ .../notificationannex_fuzzer.h | 23 ++++++++ .../notificationannex_fuzzer/project.xml | 25 +++++++++ .../notificationbasiccontent_fuzzer/BUILD.gn | 56 +++++++++++++++++++ .../corpus/init | 13 +++++ .../notificationbasiccontent_fuzzer.cpp | 54 ++++++++++++++++++ .../notificationbasiccontent_fuzzer.h | 23 ++++++++ .../project.xml | 25 +++++++++ .../notificationbundleoption_fuzzer/BUILD.gn | 56 +++++++++++++++++++ .../corpus/init | 13 +++++ .../notificationbundleoption_fuzzer.cpp | 53 ++++++++++++++++++ .../notificationbundleoption_fuzzer.h | 23 ++++++++ .../project.xml | 25 +++++++++ .../BUILD.gn | 54 ++++++++++++++++++ .../corpus/init | 13 +++++ ...ationconversationalmessageannex_fuzzer.cpp | 52 +++++++++++++++++ ...icationconversationalmessageannex_fuzzer.h | 23 ++++++++ .../project.xml | 25 +++++++++ .../BUILD.gn | 55 ++++++++++++++++++ .../corpus/init | 13 +++++ ...otificationlongtextcontentannex_fuzzer.cpp | 48 ++++++++++++++++ .../notificationlongtextcontentannex_fuzzer.h | 23 ++++++++ .../project.xml | 25 +++++++++ 26 files changed, 844 insertions(+) create mode 100644 test/fuzztest/notificationannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h create mode 100644 test/fuzztest/notificationannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationbasiccontent_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp create mode 100644 test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h create mode 100644 test/fuzztest/notificationbasiccontent_fuzzer/project.xml create mode 100644 test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationbundleoption_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp create mode 100644 test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h create mode 100644 test/fuzztest/notificationbundleoption_fuzzer/project.xml create mode 100644 test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h create mode 100644 test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml create mode 100644 test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init create mode 100644 test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp create mode 100644 test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h create mode 100644 test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 0f9028eb6..2871d134d 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -39,14 +39,19 @@ group("fuzztest") { "messageuser_fuzzer:MessageUserFuzzTest", "notification_fuzzer:NotificationFuzzTest", "notificationactionbutton_fuzzer:NotificationActionButtonFuzzTest", + "notificationannex_fuzzer:NotificationAnnexFuzzTest", + "notificationbasiccontent_fuzzer:NotificationBasicContentFuzzTest", + "notificationbundleoption_fuzzer:NotificationBundleOptionFuzzTest", "notificationcontent_fuzzer:NotificationContentFuzzTest", "notificationconversationalcontent_fuzzer:NotificationConversationalContentFuzzTest", "notificationconversationalmessage_fuzzer:NotificationConversationalMessageFuzzTest", + "notificationconversationalmessageannex_fuzzer:NotificationConversationalMessageAnnexFuzzTest", "notificationdistributedoptions_fuzzer:NotificationDistributedOptionsFuzzTest", "notificationdonotdisturbdate_fuzzer:NotificationDoNotDisturbDateFuzzTest", "notificationflags_fuzzer:NotificationFlagsFuzzTest", "notificationhelper_fuzzer:NotificationHelperFuzzTest", "notificationlongtextcontent_fuzzer:NotificationLongTextContentFuzzTest", + "notificationlongtextcontentannex_fuzzer:NotificationLongTextContentAnnexFuzzTest", "notificationmediacontent_fuzzer:NotificationMediaContentFuzzTest", "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", "notificationmultilinecontentannex_fuzzer:NotificationMultiLineContentAnnexFuzzTest", diff --git a/test/fuzztest/notificationannex_fuzzer/BUILD.gn b/test/fuzztest/notificationannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..44d67fcb9 --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationannex_fuzzer/corpus/init b/test/fuzztest/notificationannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp new file mode 100644 index 000000000..453e0059e --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification.h" +#undef private +#undef protected +#include "notificationannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(stringData, request); + notification.GetSourceType(); + notification.GetDeviceId(); + Uri sound(stringData); + notification.SetSound(sound); + Parcel parcel; + return notification.MarshallingBool(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h new file mode 100644 index 000000000..6b9608293 --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/notificationannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONANNEX_FUZZER_NOTIFICATIONANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationannex_fuzzer/project.xml b/test/fuzztest/notificationannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn b/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn new file mode 100644 index 000000000..13e4c6634 --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationBasicContentFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationbasiccontent_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationbasiccontent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationBasicContentFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init b/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp new file mode 100644 index 000000000..2b05ab2ab --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_basic_content.h" +#undef private +#undef protected +#include "notificationbasiccontent_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::shared_ptr notificationBasicContent = + std::make_shared(); + // test GetAdditionalText function + notificationBasicContent->GetAdditionalText(); + // test GetText function + notificationBasicContent->GetText(); + // test GetTitle function + notificationBasicContent->GetTitle(); + // test GetTitle function + notificationBasicContent->GetTitle(); + // test ReadFromJson function + nlohmann::json jsonObject; + notificationBasicContent->ReadFromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h new file mode 100644 index 000000000..7dcf5e00a --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/notificationbasiccontent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationbasiccontent_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONBASICCONTENT_FUZZER_NOTIFICATIONBASICCONTENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationbasiccontent_fuzzer/project.xml b/test/fuzztest/notificationbasiccontent_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationbasiccontent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn b/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn new file mode 100644 index 000000000..f28fb32ff --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationBundleOptionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationbundleoption_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationbundleoption_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationBundleOptionFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationbundleoption_fuzzer/corpus/init b/test/fuzztest/notificationbundleoption_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp new file mode 100644 index 000000000..882e445e3 --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_bundle_option.h" +#undef private +#undef protected +#include "notificationbundleoption_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string bundleNametitle(data); + int32_t uid = static_cast(GetU32Data(data)); + std::shared_ptr notificationBundleOption = + std::make_shared(bundleNametitle, uid); + // test GetUid function + notificationBundleOption->GetUid(); + // test Dump function + notificationBundleOption->Dump(); + // test Unmarshalling function + Parcel parcel; + notificationBundleOption->Unmarshalling(parcel); + notificationBundleOption->ReadFromParcel(parcel); + return notificationBundleOption->Marshalling(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h new file mode 100644 index 000000000..ff6ffcdc8 --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/notificationbundleoption_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationbundleoption_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONBUNDLEOPTION_FUZZER_NOTIFICATIONBUNDLEOPTION_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationbundleoption_fuzzer/project.xml b/test/fuzztest/notificationbundleoption_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationbundleoption_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn b/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..1a63c08b7 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationConversationalMessageAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationconversationalmessageannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationconversationalmessageannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationConversationalMessageAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init b/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp new file mode 100644 index 000000000..1ab2e76fa --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_conversational_message.h" +#undef private +#undef protected +#include "notificationconversationalmessageannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int64_t timestamp = 1; + Notification::MessageUser sender; + Notification::NotificationConversationalMessage notificationConversationalMessage( + stringData, timestamp, sender); + std::string uri(data); + std::shared_ptr uriPtr = std::make_shared(uri); + notificationConversationalMessage.SetData(stringData, uriPtr); + nlohmann::json jsonObject; + notificationConversationalMessage.ToJson(jsonObject); + notificationConversationalMessage.FromJson(jsonObject); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h new file mode 100644 index 000000000..c8c06c465 --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/notificationconversationalmessageannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationconversationalmessageannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_NOTIFICATIONCONVERSATIONALMESSAGEANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml b/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationconversationalmessageannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn b/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..b84ce50d4 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationLongTextContentAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/notificationlongtextcontentannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationlongtextcontentannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationLongTextContentAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init b/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp new file mode 100644 index 000000000..bac2a0b50 --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#include "notification_long_text_content.h" +#undef private +#undef protected +#include "notificationlongtextcontentannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationLongTextContent notificationLongTextContent(stringData); + nlohmann::json jsonObject; + notificationLongTextContent.ToJson(jsonObject); + notificationLongTextContent.FromJson(jsonObject); + Parcel parcel; + notificationLongTextContent.Unmarshalling(parcel); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h new file mode 100644 index 000000000..93bb449ff --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/notificationlongtextcontentannex_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationlongtextcontentannex_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_NOTIFICATIONLONGTEXTCONTENTANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml b/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notificationlongtextcontentannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From d262fa7ba7e28ffaeb80481ecdb85cc208e968c8 Mon Sep 17 00:00:00 2001 From: yuyaozhi Date: Tue, 15 Nov 2022 09:05:23 +0800 Subject: [PATCH 56/61] =?UTF-8?q?fuzz=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuyaozhi Change-Id: I53aaa441e83ef155e9a7068fa6093bb53f09b1be --- .../ansmanagerstub_fuzzer.cpp | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index f0399517c..ab8b4bbd8 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -115,18 +115,107 @@ namespace OHOS { int notificationId = 1; ansManagerStub.Cancel(notificationId, label); ansManagerStub.CancelAll(); - const std::string representativeBundle ="this is a notification representativeBundle"; + const std::string representativeBundle = "this is a notification representativeBundle"; int32_t userId = 1; ansManagerStub.CancelAsBundle(notificationId, representativeBundle, userId); uint8_t type = *data % SLOT_TYPE_NUM; Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); ansManagerStub.AddSlotByType(slotType); + std::vector> slots; + ansManagerStub.AddSlots(slots); ansManagerStub.RemoveSlotByType(slotType); + ansManagerStub.RemoveAllSlots(); sptr slot = new Notification::NotificationSlot(); ansManagerStub.GetSlotByType(slotType, slot); + ansManagerStub.GetSlots(slots); sptr bundleOption = new Notification::NotificationBundleOption(); uint64_t num = 1; ansManagerStub.GetSlotNumAsBundle(bundleOption, num); + std::vector> notifications; + ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotificationNums(num); + std::vector> notificationss; + ansManagerStub.GetAllActiveNotifications(notificationss); + std::vector key; + ansManagerStub.GetSpecialActiveNotifications(key, notificationss); + std::string agent = "this is a notification agent"; + ansManagerStub.SetNotificationAgent(agent); + ansManagerStub.GetNotificationAgent(agent); + bool canPublish = true; + ansManagerStub.CanPublishAsBundle(representativeBundle, canPublish); + ansManagerStub.PublishAsBundle(notification, representativeBundle); + ansManagerStub.SetNotificationBadgeNum(num); + int importance = 1; + ansManagerStub.GetBundleImportance(importance); + bool granted = true; + ansManagerStub.HasNotificationPolicyAccessPermission(granted); + bool allow = true; + ansManagerStub.SetPrivateNotificationsAllowed(allow); + int32_t removeReason = 1; + ansManagerStub.RemoveNotification(bundleOption, notificationId, label, removeReason); + ansManagerStub.RemoveAllNotifications(bundleOption); + const std::string keys = "this is a notification keys"; + ansManagerStub.Delete(keys, removeReason); + ansManagerStub.DeleteByBundle(bundleOption); + ansManagerStub.DeleteAll(); + ansManagerStub.GetSlotsByBundle(bundleOption, slots); + ansManagerStub.UpdateSlots(bundleOption, slots); + bool popFlag = true; + ansManagerStub.RequestEnableNotification(deviceId, popFlag); + const std::string bundle = "this is a notification bundle"; + bool enabled = true; + ansManagerStub.SetNotificationsEnabledForBundle(bundle, enabled); + ansManagerStub.SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, enabled); + ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, enabled); + ansManagerStub.GetShowBadgeEnabled(enabled); + bool suspended = true; + ansManagerStub.AreNotificationsSuspended(suspended); + sptr sortingMap = new Notification::NotificationSortingMap(); + ansManagerStub.GetCurrentAppSorting(sortingMap); + bool allowed = true; + ansManagerStub.IsAllowedNotify(allowed); + ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allowed); + const std::string groupName = "this is a notification groupName"; + ansManagerStub.CancelGroup(groupName); + ansManagerStub.RemoveGroupByBundle(bundleOption, groupName); + sptr date = new Notification::NotificationDoNotDisturbDate(); + ansManagerStub.SetDoNotDisturbDate(date); + ansManagerStub.GetDoNotDisturbDate(date); + bool doesSupport = true; + ansManagerStub.DoesSupportDoNotDisturbMode(doesSupport); + ansManagerStub.IsDistributedEnabled(enabled); + ansManagerStub.EnableDistributedByBundle(bundleOption, enabled); + ansManagerStub.EnableDistributedSelf(enabled); + ansManagerStub.IsDistributedEnableByBundle(bundleOption, enabled); + Notification::NotificationConstant::RemindType remindType; + ansManagerStub.GetDeviceRemindType(remindType); + sptr request = new Notification::NotificationRequest(); + ansManagerStub.PublishContinuousTaskNotification(request); + ansManagerStub.CancelContinuousTaskNotification(label, notificationId); + sptr reminder = new Notification::ReminderRequest(); + ansManagerStub.PublishReminder(reminder); + const int32_t reminderId = 1; + ansManagerStub.CancelReminder(reminderId); + std::vector> reminders; + ansManagerStub.GetValidReminders(reminders); + ansManagerStub.CancelAllReminders(); + const std::string templateName = "this is a notification templateName"; + bool support = true; + ansManagerStub.IsSupportTemplate(templateName, support); + ansManagerStub.IsSpecialUserAllowedNotify(userId, allowed); + const int32_t deviceIds = 1; + ansManagerStub.SetNotificationsEnabledByUser(deviceIds, enabled); + ansManagerStub.DeleteAllByUser(userId); + ansManagerStub.SetDoNotDisturbDate(date); + ansManagerStub.GetDoNotDisturbDate(date); + ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ansManagerStub.GetEnabledForBundleSlot(bundleOption, slotType, enabled); + const std::string cmd = "this is a notification cmd"; + std::vector dumpInfo; + ansManagerStub.ShellDump(cmd, bundle, userId, dumpInfo); + ansManagerStub.SetSyncNotificationEnabledWithoutApp(userId, enabled); + ansManagerStub.GetSyncNotificationEnabledWithoutApp(userId, enabled); return true; } } -- Gitee From 46fafe65c404d9e06503ffecb41dba2ce5f9a44d Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 15 Nov 2022 11:27:47 +0800 Subject: [PATCH 57/61] add ut Signed-off-by: fangJinliang1 Change-Id: I7b1068cd357343c6e769fbfc1b138361e4721f8b Signed-off-by: fangJinliang1 --- .../ans_manager_proxy_unit_test.cpp | 1994 +++++++++++++++-- 1 file changed, 1837 insertions(+), 157 deletions(-) diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index d7b4cd09f..aa4199317 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -19,6 +19,7 @@ #define private public #define protected public #include "ans_manager_proxy.h" +#include "notification_subscriber.h" #undef private #undef protected #include "ans_const_define.h" @@ -26,6 +27,7 @@ #include "ans_inner_errors.h" #include "message_parcel.h" #include "mock_i_remote_object.h" +#include "notification.h" using namespace testing; using namespace testing::ext; @@ -35,6 +37,8 @@ using namespace std::placeholders; extern void MockWriteInterfaceToken(bool mockRet); +namespace OHOS { +namespace Notification { class AnsManagerProxyUnitTest : public testing::Test { public: AnsManagerProxyUnitTest() {} @@ -85,6 +89,45 @@ int SendRequestReplaceNum(uint32_t code, MessageParcel &data, MessageParcel &rep return 0; } +int SendRequestReplaceString(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option, + int32_t error, bool setError, std::string retStr, bool setRetStr) +{ + if (setError) { + reply.WriteInt32(error); + } + if (setRetStr) { + reply.WriteString(retStr); + } + return 0; +} + +class TestSubscriber : public NotificationSubscriber { +public: + void OnConnected() override + {} + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnEnabledNotificationChanged( + const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnConsumed(const std::shared_ptr &request) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} +}; + /* * @tc.name: InnerTransactTest_0100 * @tc.desc: test if AnsManagerProxy's InnerTransact function executed as expected in normal case. @@ -1887,329 +1930,338 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationNumsTest_0500, Function | } /* - * @tc.name: IsSupportTemplateTest_0100 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetAllActiveNotificationsTest_0100 + * @tc.desc: test GetAllActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0100, TestSize.Level1"; MockWriteInterfaceToken(false); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: IsSupportTemplateTest_0200 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetAllActiveNotificationsTest_0200 + * @tc.desc: test GetAllActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0200, TestSize.Level1"; MockWriteInterfaceToken(true); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, notifications.size()); } - /* - * @tc.name: IsSupportTemplateTest_0300 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetAllActiveNotificationsTest_0300 + * @tc.desc: test GetAllActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0300, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, true, true)), Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); - EXPECT_EQ(ERR_OK, result); - EXPECT_EQ(true, support); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } /* - * @tc.name: IsSupportTemplateTest_0400 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetAllActiveNotificationsTest_0400 + * @tc.desc: test GetAllActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); - EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: IsSupportTemplateTest_0500 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetAllActiveNotificationsTest_0500 + * @tc.desc: test GetAllActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetAllActiveNotificationsTest_0500, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, false, true, true)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); + std::vector> notifications; + int32_t result = proxy->GetAllActiveNotifications(notifications); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: IsSupportTemplateTest_0600 - * @tc.desc: test IsSupportTemplate function + * @tc.name: GetSpecialActiveNotificationsTest_0100 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0100, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, true, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - std::string templateName = "TemplateName"; - bool support = false; - int32_t result = proxy->IsSupportTemplate(templateName, support); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); + std::vector key; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); } /* - * @tc.name: IsSpecialUserAllowedNotifyTest_0100 - * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.name: GetSpecialActiveNotificationsTest_0200 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0200, TestSize.Level1"; MockWriteInterfaceToken(false); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool allowed = false; - int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: IsSpecialUserAllowedNotifyTest_0200 - * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.name: GetSpecialActiveNotificationsTest_0300 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0300, TestSize.Level1"; MockWriteInterfaceToken(true); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, true, true)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 1)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool allowed = false; - int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); EXPECT_EQ(ERR_OK, result); - EXPECT_EQ(true, allowed); + EXPECT_EQ(1, notifications.size()); } - /* - * @tc.name: IsSpecialUserAllowedNotifyTest_0300 - * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.name: GetSpecialActiveNotificationsTest_0400 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool allowed = false; - int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } /* - * @tc.name: IsSpecialUserAllowedNotifyTest_0400 - * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.name: GetSpecialActiveNotificationsTest_0500 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0500, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, false, true, true)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, false, 1)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool allowed = false; - int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: IsSpecialUserAllowedNotifyTest_0500 - * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.name: GetSpecialActiveNotificationsTest_0600 + * @tc.desc: test GetSpecialActiveNotifications function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetSpecialActiveNotificationsTest_0600, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, true, false)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNotifications, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool allowed = false; - int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + std::vector key{"0", "1"}; + std::vector> notifications; + int32_t result = proxy->GetSpecialActiveNotifications(key, notifications); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: SetNotificationsEnabledByUserTest_0100 - * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.name: SetNotificationAgentTest_0100 + * @tc.desc: test SetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0100, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0100, TestSize.Level1"; MockWriteInterfaceToken(false); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool enabled = true; - int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: SetNotificationsEnabledByUserTest_0200 - * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.name: SetNotificationAgentTest_0200 + * @tc.desc: test SetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0200, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0200, TestSize.Level1"; MockWriteInterfaceToken(true); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent = ""; + int32_t result = proxy->SetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetNotificationAgentTest_0300 + * @tc.desc: test SetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, ERR_OK, true, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool enabled = true; - int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); EXPECT_EQ(ERR_OK, result); } /* - * @tc.name: SetNotificationsEnabledByUserTest_0300 - * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.name: SetNotificationAgentTest_0400 + * @tc.desc: test SetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0400, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool enabled = true; - int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } /* - * @tc.name: SetNotificationsEnabledByUserTest_0400 - * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.name: SetNotificationAgentTest_0500 + * @tc.desc: test SetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationAgentTest_0500, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + << "AnsManagerProxyUnitTest, SetNotificationAgentTest_0500, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) @@ -2217,93 +2269,1721 @@ HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Functi ERR_OK, false, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - bool enabled = true; - int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + std::string agent = "agent"; + int32_t result = proxy->SetNotificationAgent(agent); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: DeleteAllByUserTest_0100 - * @tc.desc: test DeleteAllByUser function + * @tc.name: GetNotificationAgentTest_0100 + * @tc.desc: test GetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0100, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0100, TestSize.Level1"; MockWriteInterfaceToken(false); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - int32_t result = proxy->DeleteAllByUser(userId); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } /* - * @tc.name: DeleteAllByUserTest_0200 - * @tc.desc: test DeleteAllByUser function + * @tc.name: GetNotificationAgentTest_0200 + * @tc.desc: test GetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0200, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0200, TestSize.Level1"; MockWriteInterfaceToken(true); sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, true, false, false)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, true, "0", true)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - int32_t result = proxy->DeleteAllByUser(userId); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); EXPECT_EQ(ERR_OK, result); } + /* - * @tc.name: DeleteAllByUserTest_0300 - * @tc.desc: test DeleteAllByUser function + * @tc.name: GetNotificationAgentTest_0300 + * @tc.desc: test GetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0300, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0300, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - int32_t result = proxy->DeleteAllByUser(userId); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } /* - * @tc.name: DeleteAllByUserTest_0400 - * @tc.desc: test DeleteAllByUser function + * @tc.name: GetNotificationAgentTest_0400 + * @tc.desc: test GetNotificationAgent function * @tc.type: FUNC * @tc.require: #I5XO2O */ -HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0400, Function | MediumTest | Level1) { GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) - .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, - ERR_OK, false, false, false)), Return(NO_ERROR))); + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, false, "0", true)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t userId = 0; - int32_t result = proxy->DeleteAllByUser(userId); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetNotificationAgentTest_0500 + * @tc.desc: test GetNotificationAgent function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetNotificationAgentTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetNotificationAgentTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceString, _1, _2, _3, _4, + ERR_OK, true, "0", false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string agent; + int32_t result = proxy->GetNotificationAgent(agent); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0100 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); -} \ No newline at end of file +} + +/* + * @tc.name: CanPublishAsBundleTest_0200 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = ""; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0300 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, canPublish); +} + +/* + * @tc.name: CanPublishAsBundleTest_0400 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0500 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: CanPublishAsBundleTest_0600 + * @tc.desc: test CanPublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, CanPublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string representativeBundle = "Bundle"; + bool canPublish = false; + int32_t result = proxy->CanPublishAsBundle(representativeBundle, canPublish); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0100 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0200 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr notification = nullptr; + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0300 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = ""; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: PublishAsBundleTest_0400 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: PublishAsBundleTest_0500 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: PublishAsBundleTest_0600 + * @tc.desc: test PublishAsBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, PublishAsBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, PublishAsBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + NotificationRequest request(1); + sptr notification = new (std::nothrow) NotificationRequest(request); + std::string representativeBundle = "Bundle"; + int32_t result = proxy->PublishAsBundle(notification, representativeBundle); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0100 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0200 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationBadgeNumTest_0300 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationBadgeNumTest_0400 + * @tc.desc: test SetNotificationBadgeNum function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationBadgeNumTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->SetNotificationBadgeNum(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0100 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0200 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(1, num); +} + +/* + * @tc.name: GetBundleImportanceTest_0300 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0400 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, false, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetBundleImportanceTest_0500 + * @tc.desc: test GetBundleImportance function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetBundleImportanceTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceNum, _1, _2, _3, _4, + ERR_OK, true, 1, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t num = 0; + int32_t result = proxy->GetBundleImportance(num); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0100 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0200 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, granted); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0300 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0400 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: HasNotificationPolicyAccessPermissionTest_0500 + * @tc.desc: test HasNotificationPolicyAccessPermission function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, HasNotificationPolicyAccessPermissionTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool granted = false; + int32_t result = proxy->HasNotificationPolicyAccessPermission(granted); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0100 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0200 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0300 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetPrivateNotificationsAllowedTest_0400 + * @tc.desc: test SetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetPrivateNotificationsAllowedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = true; + int32_t result = proxy->SetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0100 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0200 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allow); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0300 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0400 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetPrivateNotificationsAllowedTest_0500 + * @tc.desc: test GetPrivateNotificationsAllowed function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetPrivateNotificationsAllowedTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allow = false; + int32_t result = proxy->GetPrivateNotificationsAllowed(allow); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0100 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0200 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveNotificationTest_0300 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveNotificationTest_0400 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveNotificationTest_0500 + * @tc.desc: test RemoveNotification function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveNotificationTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveNotificationTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveNotification(bundleOption, 0, "0", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0100 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0200 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0300 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0400 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: RemoveAllNotificationsTest_0500 + * @tc.desc: test RemoveAllNotifications function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, RemoveAllNotificationsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->RemoveAllNotifications(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0100 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0200 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("", 0); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteTest_0300 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteTest_0400 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteTest_0500 + * @tc.desc: test Delete function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->Delete("key", 0); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0100 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0200 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: DeleteByBundleTest_0300 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: DeleteByBundleTest_0400 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteByBundleTest_0500 + * @tc.desc: test DeleteByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->DeleteByBundle(bundleOption); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0100 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0200 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0300 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, support); +} + +/* + * @tc.name: IsSupportTemplateTest_0400 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0500 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSupportTemplateTest_0600 + * @tc.desc: test IsSupportTemplate function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSupportTemplateTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::string templateName = "TemplateName"; + bool support = false; + int32_t result = proxy->IsSupportTemplate(templateName, support); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialUserAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialUserAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialUserAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool allowed = false; + int32_t result = proxy->IsSpecialUserAllowedNotify(userId, allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0100 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0200 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledByUserTest_0300 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledByUserTest_0400 + * @tc.desc: test SetNotificationsEnabledByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + bool enabled = true; + int32_t result = proxy->SetNotificationsEnabledByUser(userId, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0100 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0200 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllByUserTest_0300 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllByUserTest_0400 + * @tc.desc: test DeleteAllByUser function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllByUserTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t userId = 0; + int32_t result = proxy->DeleteAllByUser(userId); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +} // namespace Notification +} // namespace OHOS -- Gitee From 4370058936f5ce848bbf4cf2501db355cfc88a2c Mon Sep 17 00:00:00 2001 From: wangkailong Date: Tue, 15 Nov 2022 16:02:23 +0800 Subject: [PATCH 58/61] =?UTF-8?q?tdd=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkailong Change-Id: I2345854866a03fbf29530e374533f881141801c5 --- ...nced_notification_service_ability_test.cpp | 31 +- ...notification_preferences_database_test.cpp | 378 ++++++++++++++++++ 2 files changed, 408 insertions(+), 1 deletion(-) diff --git a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp index fce488e4d..c15bcefa2 100644 --- a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp @@ -15,7 +15,8 @@ #include #include - +#define private public +#define protected public #include "advanced_notification_service_ability.h" using namespace testing::ext; @@ -42,5 +43,33 @@ HWTEST_F( bool runOnCreate = true; AdvancedNotificationServiceAbility(systemAbilityId, runOnCreate); } + +/** + * @tc.number : AdvancedNotificationServiceAbilityTest_00200 + * @tc.name : ANS_AdvancedNotificationServiceAbility_0200 + * @tc.desc : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00200, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate); + test.OnStart(); +} + +/** + * @tc.number : AdvancedNotificationServiceAbilityTest_00300 + * @tc.name : ANS_AdvancedNotificationServiceAbility_0300 + * @tc.desc : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00300, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate); + test.OnStop(); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_database_test.cpp b/services/ans/test/unittest/notification_preferences_database_test.cpp index d0ac91938..b5840c723 100644 --- a/services/ans/test/unittest/notification_preferences_database_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_test.cpp @@ -489,5 +489,383 @@ HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbDate_00100, Func int32_t userId = 1; EXPECT_EQ(preferncesDB_->RemoveDoNotDisturbDate(userId), true); } + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00100 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_name"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00200 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_importance"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00300 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_showBadge"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00400 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_badgeTotalNum"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00500 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_privateAllowed"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00600 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_enabledNotification"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00700 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_poppedDialog"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00800 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_uid"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00100 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_id"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00200 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_name"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00300 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_description"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00400 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_level"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00500 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_showBadge"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00600 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableLight"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00700 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableVibration"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00800 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_ledLightColor"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_00900 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00900, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_lockscreenVisibleness"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01000 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01000, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_sound"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01100 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_vibrationSytle"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01200 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enableBypassDnd"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01300 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + DistributedKv::Entry entry; + DistributedKv::Key dbKey("ans_bundle_bundleKey_slot_type_1_enabled"); + DistributedKv::Value dbValue("1"); + entry.key = dbKey; + entry.value = dbValue; + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry); +} } // namespace Notification } // namespace OHOS -- Gitee From dcff0635ea470964169721a8175968d2db97be5a Mon Sep 17 00:00:00 2001 From: gwang2008 Date: Tue, 15 Nov 2022 09:29:12 +0000 Subject: [PATCH 59/61] add ut Signed-off-by: gwang2008 Change-Id: I297799d09377d7e75e006a7b810c071bb3d601c0 --- .../ans_manager_proxy_unit_test.cpp | 1760 +++++++++++++++++ 1 file changed, 1760 insertions(+) diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index aa4199317..42dacd18b 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -1712,6 +1712,7 @@ int SendRequestReplaceNotifications(uint32_t code, MessageParcel &data, MessageP return 0; } + /* * @tc.name: GetActiveNotificationsTest_0100 * @tc.desc: test GetActiveNotifications function @@ -3564,6 +3565,1765 @@ HWTEST_F(AnsManagerProxyUnitTest, DeleteByBundleTest_0500, Function | MediumTest EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } +/* + * @tc.name: DeleteAllTest_0100 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0200 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: DeleteAllTest_0300 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: DeleteAllTest_0400 + * @tc.desc: test DeleteAll function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, DeleteAllTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, DeleteAllTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->DeleteAll(); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0100 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0200 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0300 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 2)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(2, slots.size()); +} +/* + * @tc.name: GetSlotsByBundleTest_0400 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0500 + * @tc.desc: test GetSlotsByBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, false, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetSlotsByBundleTest_0600 + * @tc.desc: test GetSlotByType function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetSlotsByBundleTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplaceSlot, _1, _2, _3, _4, + ERR_OK, true, 0)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->GetSlotsByBundle(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0100 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0200 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0300 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0300, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0400 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0400, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + slots.resize(MAX_SLOT_NUM + 1); // set MAX_SLOT_NUM + 1 slots + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UpdateSlotsTest_0500 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: UpdateSlotsTest_0600 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0600, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UpdateSlotsTest_0700 + * @tc.desc: test UpdateSlots function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UpdateSlotsTest_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UpdateSlotsTest_0700, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> slots; + sptr slot = new (std::nothrow) NotificationSlot(); + slots.push_back(slot); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->UpdateSlots(bundleOption, slots); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForBundle("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0100 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0200 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0300 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForAllBundlesTest_0400 + * @tc.desc: test SetNotificationsEnabledForAllBundles function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForAllBundlesTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + int32_t result = proxy->SetNotificationsEnabledForAllBundles("DeviceId", true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0100 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0200 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0300 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0400 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetNotificationsEnabledForSpecialBundleTest_0500 + * @tc.desc: test SetNotificationsEnabledForSpecialBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetNotificationsEnabledForSpecialBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetNotificationsEnabledForSpecialBundle("DeviceId", bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_OK, result); +} +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test SetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr bundleOption = nullptr; + int32_t result = proxy->SetShowBadgeEnabledForBundle(bundleOption, true); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0100 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0200 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0300 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0400 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0500 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledForBundleTest_0600 + * @tc.desc: test GetShowBadgeEnabledForBundle function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledForBundleTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->GetShowBadgeEnabledForBundle(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0100 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0200 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0300 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0400 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetShowBadgeEnabledTest_0500 + * @tc.desc: test GetShowBadgeEnabled function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetShowBadgeEnabledTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + int32_t result = proxy->GetShowBadgeEnabled(enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0100 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0200 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: SubscribeTest_0300 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0400 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: SubscribeTest_0500 + * @tc.desc: test Subscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, SubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, SubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Subscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: UnsubscribeTest_0100 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0200 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_OK, result); +} + +/* + * @tc.name: UnsubscribeTest_0300 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0400 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + auto subscriber = new (std::nothrow) TestSubscriber(); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(subscriber->GetImpl(), subInfo); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: UnsubscribeTest_0500 + * @tc.desc: test Unsubscribe function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, UnsubscribeTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, UnsubscribeTest_0500, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr subInfo = new (std::nothrow) NotificationSubscribeInfo(); + int32_t result = proxy->Unsubscribe(nullptr, subInfo); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0100 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0200 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, suspended); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0300 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0400 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: AreNotificationsSuspendedTest_0500 + * @tc.desc: test AreNotificationsSuspended function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, AreNotificationsSuspendedTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool suspended = false; + int32_t result = proxy->AreNotificationsSuspended(suspended); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0100 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0200 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} +/* + * @tc.name: GetCurrentAppSortingTest_0300 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: GetCurrentAppSortingTest_0400 + * @tc.desc: test GetCurrentAppSorting function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, GetCurrentAppSortingTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, false, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr sortingMap; + int32_t result = proxy->GetCurrentAppSorting(sortingMap); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0100 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0200 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifyTest_0300 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0400 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifyTest_0500 + * @tc.desc: test IsAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotify(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0100 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0200 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, allowed); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0300 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0400 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsAllowedNotifySelfTest_0500 + * @tc.desc: test IsAllowedNotifySelf function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsAllowedNotifySelfTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool allowed = false; + int32_t result = proxy->IsAllowedNotifySelf(allowed); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0100 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0100, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0200 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0200, TestSize.Level1"; + MockWriteInterfaceToken(true); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_OK, result); + EXPECT_EQ(true, enabled); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0300 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0400 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, false, true, true)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0500 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0500, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1) + .WillRepeatedly(DoAll(Invoke(std::bind(SendRequestReplace, _1, _2, _3, _4, + ERR_OK, true, true, false)), Return(NO_ERROR))); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); +} + +/* + * @tc.name: IsSpecialBundleAllowedNotifyTest_0600 + * @tc.desc: test IsSpecialBundleAllowedNotify function + * @tc.type: FUNC + * @tc.require: #I5XO2O + */ +HWTEST_F(AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsManagerProxyUnitTest, IsSpecialBundleAllowedNotifyTest_0600, TestSize.Level1"; + MockWriteInterfaceToken(false); + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + bool enabled = false; + sptr bundleOption = nullptr; + int32_t result = proxy->IsSpecialBundleAllowedNotify(bundleOption, enabled); + EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); +} + /* * @tc.name: IsSupportTemplateTest_0100 * @tc.desc: test IsSupportTemplate function -- Gitee From b2f4d9e970a6e61465b1a70c8afd5bd58f2aec69 Mon Sep 17 00:00:00 2001 From: wujiqin Date: Thu, 17 Nov 2022 15:37:02 +0800 Subject: [PATCH 60/61] =?UTF-8?q?IssueNo:https://gitee.com/openharmony/not?= =?UTF-8?q?ification=5Fdistributed=5Fnotification=5Fservice/issues/I61OUU?= =?UTF-8?q?=3Ffrom=3Dproject-issue=20Description:tdd=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BF=AE=E5=A4=8D=20Sig:SIG=5FApplicationFra?= =?UTF-8?q?mework=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: Ia876f7257c49a105b1e5794cce5acfdc2defcf85 --- .../ans/test/unittest/reminder_request_test.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 9d12b7e4e..4ec41634e 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -560,9 +560,10 @@ HWTEST_F(ReminderRequestTest, CanShow_00002, Function | SmallTest | Level1) */ HWTEST_F(ReminderRequestTest, Dump_00001, Function | SmallTest | Level1) { - std::string ret = "Reminder[reminderId=-1, type=3, state='Inactive, nextTriggerTime=1970-01-01 00:00:00]"; + std::string ret = "Reminder[reminderId=-1, type=3, state='Inactive, nextTriggerTime=1970-01-01 "; auto rrc = std::make_shared(); - EXPECT_EQ(rrc->Dump(), ret); + std::string res = rrc->Dump(); + EXPECT_EQ(res.substr(0, res.size()-9), ret); } /** @@ -942,8 +943,9 @@ HWTEST_F(ReminderRequestTest, GetShowTime_00001, Function | SmallTest | Level1) { uint64_t showTime = 8 * 60 * 1000; auto rrc = std::make_shared(); - std::string ret = "00:08"; - EXPECT_EQ(rrc->GetShowTime(showTime), ret); + std::string ret = ":08"; + std::string res = rrc->GetShowTime(showTime); + EXPECT_EQ(res.substr(2, res.size()), ret); } /** @@ -957,8 +959,9 @@ HWTEST_F(ReminderRequestTest, GetShowTime_00002, Function | SmallTest | Level1) uint64_t showTime = 8 * 60 * 1000; ReminderRequest reminder = ReminderRequest(ReminderRequest::ReminderType::TIMER); auto rrc = std::make_shared(); - std::string ret = "00:08"; - EXPECT_EQ(rrc->GetShowTime(showTime), ret); + std::string ret = ":08"; + std::string res = rrc->GetShowTime(showTime); + EXPECT_EQ(res.substr(2, res.size()), ret); } /** -- Gitee From 0db2d43759782bc6b4e705e1ac437c5024f2d5a0 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Wed, 16 Nov 2022 15:53:47 +0800 Subject: [PATCH 61/61] =?UTF-8?q?tdd=20=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuhan Change-Id: I2aa0f8b9c1bec36cb4215ef7489aad5f2697afec --- .../advanced_notification_service_test.cpp | 706 +++++++++++++++++- .../unittest/mock/mock_accesstoken_kit.cpp | 4 + 2 files changed, 685 insertions(+), 25 deletions(-) diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 4e013eba4..4fd77c09f 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -32,6 +32,10 @@ #include "notification_preferences.h" #include "notification_subscriber.h" #include "system_event_observer.h" +#include "notification_constant.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" +#include "want_params.h" using namespace testing::ext; using namespace OHOS::Media; @@ -2352,6 +2356,26 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, EXPECT_EQ(advancedNotificationService_->IsAllowedNotifySelf(bundleOption, needPop), ERR_ANS_INVALID_BUNDLE); EXPECT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_ANS_INVALID_BUNDLE); + + int32_t reminderId = 1; + EXPECT_EQ(advancedNotificationService_->CancelReminder(reminderId), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->CancelAllReminders(), ERR_ANS_INVALID_BUNDLE); + + std::vector> reminders; + EXPECT_EQ(advancedNotificationService_->GetValidReminders(reminders), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->RemoveAllSlots(), ERR_ANS_INVALID_BUNDLE); + + EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER), + ERR_ANS_INVALID_BUNDLE); + + std::string groupName = "name"; + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_BUNDLE); + + bool enabled = true; + EXPECT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), ERR_ANS_INVALID_BUNDLE); + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; } @@ -2411,6 +2435,59 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, std::string(), bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); EXPECT_EQ(advancedNotificationService_->IsAllowedNotify(enable), ERR_ANS_NON_SYSTEM_APP); + + int32_t notificationId = 1; + EXPECT_EQ(advancedNotificationService_->RemoveNotification(bundleOption, notificationId, + key, removeReason), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->RemoveAllNotifications(bundleOption), ERR_ANS_NON_SYSTEM_APP); + + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_ANS_NON_SYSTEM_APP); + + std::string groupName = "group"; + EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_NON_SYSTEM_APP); + + sptr date = nullptr; + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(date), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DoesSupportDoNotDisturbMode(enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->EnableDistributed(enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enable), ERR_ANS_NON_SYSTEM_APP); + + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), + ERR_ANS_NON_SYSTEM_APP); + + int32_t userId = 1; + EXPECT_EQ(advancedNotificationService_->IsSpecialUserAllowedNotify(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledByUser(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption, + NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption, + NotificationConstant::SlotType::OTHER, enable), ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + + EXPECT_EQ(advancedNotificationService_->GetSyncNotificationEnabledWithoutApp(userId, enable), + ERR_ANS_NON_SYSTEM_APP); + GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test end"; } @@ -2469,30 +2546,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17300, GTEST_LOG_(INFO) << "ANS_GetSlotsByBundle_0100 test end"; } -/** - * @tc.number : AdvancedNotificationServiceTest_17400 - * @tc.name : CancelPreparedNotification_1000 - * @tc.desc : Test CancelPreparedNotification function. - * @tc.require : #I60KYN - */ -// HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, Function | SmallTest | Level1) -// { -// GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_17400 test start"; - -// int32_t notificationId = 0; -// std::string label = "testLabel"; -// sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); -// sptr notification = nullptr; -// bool isCancel = false; -// EXPECT_EQ(advancedNotificationService_->RemoveFromNotificationList(bundleOption, label, notificationId, -// notification, isCancel), ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED); - -// EXPECT_EQ(advancedNotificationService_->RemoveFromNotificationList(label, notification, isCancel, -// NotificationConstant::CANCEL_REASON_DELETE), ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED); - -// GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_17400 test end"; -// } - /** * @tc.number : AdvancedNotificationServiceTest_17400 * @tc.name : Subscribe_1000 @@ -2570,7 +2623,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17700, /** * @tc.number : AdvancedNotificationServiceTest_17800 - * @tc.name : GetAppTargetBundle_2000 + * @tc.name : GetAppTargetBundle_3000 * @tc.desc : Test GetAppTargetBundle function. * @tc.require : #I60KYN */ @@ -2586,5 +2639,608 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17800, GTEST_LOG_(INFO) << "GetAppTargetBundle_3000 test end"; } +/** + * @tc.number : AdvancedNotificationServiceTest_17900 + * @tc.name : PublishReminder_1000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; + + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); + int32_t reminderId = 1; + sptr reminder = new ReminderRequest(reminderId); + reminder->InitNotificationRequest(); + EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_REMINDER_NOTIFICATION_NOT_ENABLE); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18000 + * @tc.name : PublishReminder_2000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; + + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); + int32_t reminderId = 1; + sptr reminder = new ReminderRequest(reminderId); + reminder->InitNotificationRequest(); + EXPECT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_BUNDLE); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18100 + * @tc.name : ActiveNotificationDump_1000 + * @tc.desc : Test ActiveNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->ActiveNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "ActiveNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18200 + * @tc.name : RecentNotificationDump_1000 + * @tc.desc : Test RecentNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->RecentNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "RecentNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18300 + * @tc.name : DistributedNotificationDump_1000 + * @tc.desc : Test DistributedNotificationDump function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test start"; + + std::string bundle = "Bundle"; + int32_t userId = -1; + std::vector dumpInfo; + + EXPECT_EQ(advancedNotificationService_->DistributedNotificationDump(bundle, userId, dumpInfo), ERR_OK); + + GTEST_LOG_(INFO) << "DistributedNotificationDump_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18400 + * @tc.name : SetRecentNotificationCount_1000 + * @tc.desc : Test SetRecentNotificationCount function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test start"; + + std::string arg = "1100"; + EXPECT_EQ(advancedNotificationService_->SetRecentNotificationCount(arg), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "SetRecentNotificationCount_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18500 + * @tc.name : OnBundleRemoved_1000 + * @tc.desc : Test OnBundleRemoved function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->OnBundleRemoved(bundleOption); + + GTEST_LOG_(INFO) << "OnBundleRemoved_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18600 + * @tc.name : OnScreenOn_1000 + * @tc.desc : Test OnScreenOn function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnScreenOn_1000 test start"; + + advancedNotificationService_->OnScreenOn(); + advancedNotificationService_->OnScreenOff(); + advancedNotificationService_->OnDistributedKvStoreDeathRecipient(); + + GTEST_LOG_(INFO) << "OnScreenOn_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18700 + * @tc.name : AddSlotByType_1000 + * @tc.desc : Test AddSlotByType function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "AddSlotByType_1000 test start"; + + EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::SERVICE_REMINDER), + ERR_OK); + + GTEST_LOG_(INFO) << "AddSlotByType_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18800 + * @tc.name : GetSlotNumAsBundle_1000 + * @tc.desc : Test GetSlotNumAsBundle function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + uint64_t num = 1; + EXPECT_EQ(advancedNotificationService_->GetSlotNumAsBundle(bundleOption, num), ERR_OK); + + GTEST_LOG_(INFO) << "GetSlotNumAsBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_18900 + * @tc.name : CancelGroup_1000 + * @tc.desc : Test CancelGroup function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CancelGroup_1000 test start"; + + std::string groupName = ""; + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "CancelGroup_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19000 + * @tc.name : RemoveGroupByBundle_1000 + * @tc.desc : Test RemoveGroupByBundle function. + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test start"; + + std::string groupName = "group"; + sptr bundleOption = nullptr; + EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), ERR_ANS_INVALID_PARAM); + + GTEST_LOG_(INFO) << "RemoveGroupByBundle_1000 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19100 + * @tc.name : ANS_IsDistributedEnabled_0100 + * @tc.desc : Test IsDistributedEnabled function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test start"; + + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnabled(enabled), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_IsDistributedEnabled_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19200 + * @tc.name : EnableDistributedByBundle_0100 + * @tc.desc : Test EnableDistributedByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->EnableDistributedByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "EnableDistributedByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19300 + * @tc.name : IsDistributedEnableByBundle_0100 + * @tc.desc : Test IsDistributedEnableByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = true; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19400 + * @tc.name : IsDistributedEnableByBundle_0200 + * @tc.desc : Test IsDistributedEnableByBundle function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + bool enabled = false; + EXPECT_EQ(advancedNotificationService_->IsDistributedEnableByBundle(bundleOption, enabled), ERR_OK); + + GTEST_LOG_(INFO) << "IsDistributedEnableByBundle_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19500 + * @tc.name : GetDeviceRemindType_0100 + * @tc.desc : Test GetDeviceRemindType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test start"; + + NotificationConstant::RemindType remindType = NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND; + EXPECT_EQ(advancedNotificationService_->GetDeviceRemindType(remindType), ERR_OK); + + GTEST_LOG_(INFO) << "GetDeviceRemindType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19600 + * @tc.name : GetLocalNotificationKeys_0100 + * @tc.desc : Test GetLocalNotificationKeys function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->GetLocalNotificationKeys(bundleOption); + + GTEST_LOG_(INFO) << "GetLocalNotificationKeys_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19700 + * @tc.name : CheckDistributedNotificationType_0100 + * @tc.desc : Test CheckDistributedNotificationType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start"; + + sptr req = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19800 + * @tc.name : CheckDistributedNotificationType_0200 + * @tc.desc : Test CheckDistributedNotificationType function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test start"; + + sptr req = new NotificationRequest(); + std::vector devices; + devices.push_back("a"); + devices.push_back("b"); + devices.push_back("c"); + req->GetNotificationDistributedOptions().SetDevicesSupportDisplay(devices); + EXPECT_EQ(advancedNotificationService_->CheckDistributedNotificationType(req), true); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_19900 + * @tc.name : OnDistributedPublish_0100 + * @tc.desc : Test OnDistributedPublish function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + sptr request = new NotificationRequest(); + + advancedNotificationService_->OnDistributedPublish(deviceId, bundleName, request); + + GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20000 + * @tc.name : OnDistributedUpdate_0100 + * @tc.desc : Test OnDistributedUpdate function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + sptr request = new NotificationRequest(); + + advancedNotificationService_->OnDistributedUpdate(deviceId, bundleName, request); + + GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20100 + * @tc.name : OnDistributedDelete_0100 + * @tc.desc : Test OnDistributedDelete function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test start"; + + std::string deviceId = "DeviceId"; + std::string bundleName = "BundleName"; + std::string label = "testLabel"; + int32_t id = 1; + + advancedNotificationService_->OnDistributedDelete(deviceId, bundleName, label, id); + + GTEST_LOG_(INFO) << "OnDistributedDelete_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20200 + * @tc.name : CheckPublishWithoutApp_0100 + * @tc.desc : Test CheckPublishWithoutApp function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test start"; + + int32_t userId = 1; + sptr request = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false); + + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20300 + * @tc.name : CheckPublishWithoutApp_0200 + * @tc.desc : Test CheckPublishWithoutApp function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20300, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test start"; + + int32_t userId = SYSTEM_APP_UID; + sptr request = new NotificationRequest(); + EXPECT_EQ(advancedNotificationService_->CheckPublishWithoutApp(userId, request), false); + + GTEST_LOG_(INFO) << "CheckPublishWithoutApp_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20400 + * @tc.name : TriggerRemoveWantAgent_0100 + * @tc.desc : Test TriggerRemoveWantAgent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20400, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test start"; + + sptr request = new NotificationRequest(); + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + + request->SetRemovalWantAgent(wantAgent); + advancedNotificationService_->TriggerRemoveWantAgent(request); + + GTEST_LOG_(INFO) << "TriggerRemoveWantAgent_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20500 + * @tc.name : DeleteAllByUser_0100 + * @tc.desc : Test DeleteAllByUser function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20500, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test start"; + + int32_t userId = -2; + EXPECT_EQ(advancedNotificationService_->DeleteAllByUser(userId), ERR_ANS_INVALID_PARAM); + + sptr date = nullptr; + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->SetDoNotDisturbDateByUser(userId, date), ERR_ANS_INVALID_PARAM); + GTEST_LOG_(INFO) << "DeleteAllByUser_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20600 + * @tc.name : OnResourceRemove_0100 + * @tc.desc : Test OnResourceRemove function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20600, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnResourceRemove_0100 test start"; + + int32_t userId = -2; + advancedNotificationService_->OnResourceRemove(userId); + + GTEST_LOG_(INFO) << "OnResourceRemove_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20700 + * @tc.name : OnBundleDataCleared_0100 + * @tc.desc : Test OnBundleDataCleared function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20700, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test start"; + + sptr bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->OnBundleDataCleared(bundleOption); + + GTEST_LOG_(INFO) << "OnBundleDataCleared_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20800 + * @tc.name : GetDisplayPosition_0100 + * @tc.desc : Test GetDisplayPosition function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20800, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test start"; + + int offsetX = 1; + int offsetY = 1; + int width = 1; + int height = 1; + bool wideScreen = 1; + advancedNotificationService_->GetDisplayPosition(offsetX, offsetY, width, height, wideScreen); + + GTEST_LOG_(INFO) << "GetDisplayPosition_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_20900 + * @tc.name : GetDumpInfo_0100 + * @tc.desc : Test GetDumpInfo function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDumpInfo_0100 test start"; + + std::vector args; + args.push_back(Str8ToStr16("args")); + std::string result = "result"; + advancedNotificationService_->GetDumpInfo(args, result); + + GTEST_LOG_(INFO) << "GetDumpInfo_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21000 + * @tc.name : GetDumpInfo_0200 + * @tc.desc : Test GetDumpInfo function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetDumpInfo_0200 test start"; + + std::vector args; + args.push_back(Str8ToStr16("-h")); + std::string result = "result"; + advancedNotificationService_->GetDumpInfo(args, result); + + GTEST_LOG_(INFO) << "GetDumpInfo_0200 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21100 + * @tc.name : SendFlowControlOccurHiSysEvent_0100 + * @tc.desc : Test SendFlowControlOccurHiSysEvent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21100, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test start"; + + std::shared_ptr record = nullptr; + advancedNotificationService_->SendFlowControlOccurHiSysEvent(record); + + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0100 test end"; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_21200 + * @tc.name : SendFlowControlOccurHiSysEvent_0200 + * @tc.desc : Test SendFlowControlOccurHiSysEvent function + * @tc.require : #I61RF2 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21200, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test start"; + + std::shared_ptr record = std::make_shared(); + record->request = new NotificationRequest(); + record->bundleOption = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID); + advancedNotificationService_->SendFlowControlOccurHiSysEvent(record); + + GTEST_LOG_(INFO) << "SendFlowControlOccurHiSysEvent_0200 test end"; +} + } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp index 302555481..424907538 100644 --- a/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp +++ b/services/ans/test/unittest/mock/mock_accesstoken_kit.cpp @@ -15,6 +15,7 @@ #include "accesstoken_kit.h" #include "ans_log_wrapper.h" +#include "ans_ut_constant.h" #include "ipc_skeleton.h" using namespace OHOS::Security::AccessToken; @@ -45,6 +46,9 @@ namespace Security { namespace AccessToken { int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) { + if (tokenID == Notification::NON_NATIVE_TOKEN) { + return PERMISSION_DENIED; + } return PERMISSION_GRANTED; } -- Gitee