From 7ce27d9bda8cd08f1cb24606f8350ab0af4e93fd Mon Sep 17 00:00:00 2001 From: "SukHyung, Kang" Date: Fri, 22 Feb 2019 09:35:28 +0900 Subject: [PATCH] Add entry, text, effect item class Change-Id: If23d8c14ddf5916ebcb5ff5f21c0679ea7c54f74 Signed-off-by: SukHyung, Kang --- notification-ex/abstract_item.cc | 13 ++++ notification-ex/abstract_item.h | 6 +- notification-ex/abstract_item_implementation.h | 2 + notification-ex/entry_item.cc | 88 +++++++++++++++++++++ notification-ex/entry_item.h | 53 +++++++++++++ .../entry_item_implementation.h | 35 ++++++--- notification-ex/item.h | 50 ------------ notification-ex/item_factory.cc | 8 +- notification-ex/text_item.cc | 90 ++++++++++++++++++++++ notification-ex/text_item.h | 54 +++++++++++++ notification-ex/text_item_implementation.h | 45 +++++++++++ unittest/src/test_entry_item.cc | 72 +++++++++++++++++ unittest/src/test_text_item.cc | 74 ++++++++++++++++++ 13 files changed, 527 insertions(+), 63 deletions(-) create mode 100644 notification-ex/entry_item.cc create mode 100644 notification-ex/entry_item.h rename unittest/src/test_item.cc => notification-ex/entry_item_implementation.h (56%) create mode 100644 notification-ex/text_item.cc create mode 100644 notification-ex/text_item.h create mode 100644 notification-ex/text_item_implementation.h create mode 100644 unittest/src/test_entry_item.cc create mode 100644 unittest/src/test_text_item.cc diff --git a/notification-ex/abstract_item.cc b/notification-ex/abstract_item.cc index e6195e4..c6397a2 100644 --- a/notification-ex/abstract_item.cc +++ b/notification-ex/abstract_item.cc @@ -167,5 +167,18 @@ void AbstractItem::SetChannel(string channel) { impl_->channel_ = channel; } +void AbstractItem::SetSoundPath(std::string path) { + impl_->sound_path_ = path; +} +void AbstractItem::SetVibrationPath(std::string path) { + impl_->vibration_path_ = path; +} +std::string AbstractItem::GetSoundPath() const { + return impl_->sound_path_; +} +std::string AbstractItem::GetVibrationPath() const { + return impl_->vibration_path_; +} + } // namespace item } // namespace notification diff --git a/notification-ex/abstract_item.h b/notification-ex/abstract_item.h index f9fb084..dc5b32b 100644 --- a/notification-ex/abstract_item.h +++ b/notification-ex/abstract_item.h @@ -177,7 +177,7 @@ class EXPORT_API AbstractItem { IconText, InputSelector, Group, - Effect, + Entry, Progress, Custom, }; @@ -222,6 +222,10 @@ class EXPORT_API AbstractItem { void SetChannel(std::string channel); void SetLEDInfo(std::shared_ptr led); std::shared_ptr GetLEDInfo() const; + void SetSoundPath(std::string path); + void SetVibrationPath(std::string path); + std::string GetSoundPath() const; + std::string GetVibrationPath() const; private: class Impl; diff --git a/notification-ex/abstract_item_implementation.h b/notification-ex/abstract_item_implementation.h index 64f25eb..8a030f0 100644 --- a/notification-ex/abstract_item_implementation.h +++ b/notification-ex/abstract_item_implementation.h @@ -55,6 +55,8 @@ class AbstractItem::Impl { std::string can_receive_; std::shared_ptr action_; AbstractItem* parent_; + std::string sound_path_; + std::string vibration_path_; }; } // namespace item diff --git a/notification-ex/entry_item.cc b/notification-ex/entry_item.cc new file mode 100644 index 0000000..b3a1674 --- /dev/null +++ b/notification-ex/entry_item.cc @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "notification-ex/entry_item.h" +#include "notification-ex/entry_item_implementation.h" +#include "notification-ex/item_factory.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define ENTRY_TEXT_KEY "__ENTRY_TEXT_KEY__" +#define ENTRY_LIMIT_KEY "__ENTRY_LIMIT_KEY__" + +namespace notification { +namespace item { + +EntryItem::EntryItem(std::string id, std::shared_ptr action) + : AbstractItem(id, AbstractItem::Type::Entry), impl_(new Impl()) { +} + +EntryItem::EntryItem(std::shared_ptr action) + : AbstractItem(AbstractItem::Type::Entry), impl_(new Impl()) { +} + +EntryItem::Impl::Impl() { + LOGI("EntryItem created"); +} + +EntryItem::~EntryItem() = default; +EntryItem::Impl::~Impl() = default; + +Bundle EntryItem::Serialize() { + Bundle b; + b = AbstractItem::Serialize(); + + if (!impl_->text_.empty()) + b.Add(ENTRY_TEXT_KEY, impl_->text_); + + b.Add(ENTRY_LIMIT_KEY, std::to_string(impl_->limit_)); + + return b; +} + +void EntryItem::Deserialize(Bundle b) { + AbstractItem::Deserialize(b); + impl_->text_ = b.GetString(ENTRY_TEXT_KEY); + impl_->limit_ = std::stoi(b.GetString(ENTRY_LIMIT_KEY)); +} + +AbstractItem& EntryItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + return ItemFactory::GetNullItem(); +} + +std::string EntryItem::GetText() const { + return impl_->text_; +} + +void EntryItem::SetText(std::string text) { + impl_->text_ = text; +} + +int EntryItem::GetTextLimit() const { + return impl_->limit_; +} + +} // namespace item +} // namespace notification diff --git a/notification-ex/entry_item.h b/notification-ex/entry_item.h new file mode 100644 index 0000000..f60287f --- /dev/null +++ b/notification-ex/entry_item.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 NOTIFICATION_EX_ENTRY_ITEM_H_ +#define NOTIFICATION_EX_ENTRY_ITEM_H_ + +#include +#include + +#include "notification-ex/abstract_item.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace notification { +namespace item { + +class EXPORT_API EntryItem : public AbstractItem { + public: + EntryItem(std::shared_ptr action = std::shared_ptr({})); + EntryItem(std::string id, + std::shared_ptr action = std::shared_ptr({})); + virtual ~EntryItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + std::string GetText() const; + void SetText(std::string text); + int GetTextLimit() const; + + private: + class Impl; + std::unique_ptr impl_; +}; // class EntryItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_ENTRY_ITEM_H_ \ No newline at end of file diff --git a/unittest/src/test_item.cc b/notification-ex/entry_item_implementation.h similarity index 56% rename from unittest/src/test_item.cc rename to notification-ex/entry_item_implementation.h index adb1c11..ecfe724 100644 --- a/unittest/src/test_item.cc +++ b/notification-ex/entry_item_implementation.h @@ -14,15 +14,32 @@ * limitations under the License. */ -#include -#include +#ifndef NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_ -#include "notification-ex/item.h" +#include +#include -class ENTRY_ITEM : public ::testing::Test { +#include "notification-ex/entry_item.h" + +namespace notification { +namespace item { + +class EntryItem::Impl { public: - virtual void SetUp() { - } - virtual void TearDown() { - } -}; \ No newline at end of file + virtual ~Impl(); + + private: + Impl(); + + private: + friend class EntryItem; + + std::string text_; + int limit_ = 160; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/item.h b/notification-ex/item.h index a48054e..8582f41 100644 --- a/notification-ex/item.h +++ b/notification-ex/item.h @@ -33,22 +33,6 @@ namespace notification { namespace item { -class EXPORT_API TextItem : public AbstractItem { - public: - TextItem(std::string text); - virtual ~TextItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - void SetContents(std::string contents); - std::string GetContents() const; - std::string GetHyperLink() const; - - private: - std::string text_ = nullptr; -}; // class TextItem - class EXPORT_API IconItem : public AbstractItem { public: IconItem(std::string iconpath); @@ -126,40 +110,6 @@ class EXPORT_API ChatMessageItem : public AbstractItem { Type GetType() const; }; // class ChatMessageItem -class EXPORT_API EntryItem : public AbstractItem { - public: - EntryItem(); - virtual ~EntryItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - std::string GetText() const; - void SetText(std::string text); - void SetTextLimit(int size); - int GetTextLimit() const; - - private: - std::string text_ = nullptr; - int limit_ = 160; -}; // class EntryItem - -class EXPORT_API EffectItem : public AbstractItem { - public: - EffectItem(); - virtual ~EffectItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - std::string GetSoundPath() const; - std::string GetVibrationPath() const; - - private: - std::string soundPath_ = nullptr; - std::string vibrationPath_ = nullptr; -}; // class EffectItem - class EXPORT_API CustomItem : public AbstractItem { public: CustomItem(); diff --git a/notification-ex/item_factory.cc b/notification-ex/item_factory.cc index 6d882f8..672bc98 100644 --- a/notification-ex/item_factory.cc +++ b/notification-ex/item_factory.cc @@ -22,6 +22,8 @@ #include "notification-ex/button_item.h" #include "notification-ex/group_item.h" #include "notification-ex/null_item.h" +#include "notification-ex/entry_item.h" +#include "notification-ex/text_item.h" #include "notification-ex/exception.h" #include "notification-ex/input_selector_item.h" #include "notification-ex/progress_item.h" @@ -41,7 +43,7 @@ shared_ptr ItemFactory::CreateItem(AbstractItem::Type type) { case AbstractItem::NullObject : THROW(NOTIFICATION_ERROR_INVALID_PARAMETER); case AbstractItem::Text : - return make_shared(""); + return make_shared(""); case AbstractItem::Icon : return make_shared(""); case AbstractItem::Image : @@ -58,8 +60,8 @@ shared_ptr ItemFactory::CreateItem(AbstractItem::Type type) { return make_shared(); case AbstractItem::Group : return make_shared(); - case AbstractItem::Effect : - return make_shared(""); + case AbstractItem::Entry : + return make_shared(""); case AbstractItem::Progress : return make_shared(0.0, 0.0, 0.0); case AbstractItem::Custom : diff --git a/notification-ex/text_item.cc b/notification-ex/text_item.cc new file mode 100644 index 0000000..64b0773 --- /dev/null +++ b/notification-ex/text_item.cc @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "notification-ex/text_item.h" +#include "notification-ex/text_item_implementation.h" +#include "notification-ex/item_factory.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define TEXT_CONTENTS_KEY "__TEXT_CONTENTS_KEY__" +#define TEXT_HYPERLINK_KEY "__TEXT_HYPERLINK_KEY__" + +namespace notification { +namespace item { +TextItem::TextItem(std::string text, std::shared_ptr action) + : AbstractItem(AbstractItem::Type::Text), impl_(new Impl(text)) { +} + +TextItem::TextItem(std::string id, std::string text, + std::shared_ptr action) + : AbstractItem(id, AbstractItem::Type::Text), impl_(new Impl(text)) { +} + +TextItem::Impl::Impl(std::string text) + : text_(text) { + LOGI("TextItem created"); +} + +TextItem::~TextItem() = default; +TextItem::Impl::~Impl() = default; + +Bundle TextItem::Serialize() { + Bundle b; + b = AbstractItem::Serialize(); + + if (!impl_->text_.empty()) + b.Add(TEXT_CONTENTS_KEY, impl_->text_); + + if (!impl_->hyperlink_.empty()) + b.Add(TEXT_HYPERLINK_KEY, impl_->hyperlink_); + + return b; +} + +void TextItem::Deserialize(Bundle b) { + AbstractItem::Deserialize(b); + impl_->text_ = b.GetString(TEXT_CONTENTS_KEY); + impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY); +} + +AbstractItem& TextItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + return ItemFactory::GetNullItem(); +} + +void TextItem::SetContents(std::string contents) { + impl_->text_ = contents; +} + +std::string TextItem::GetContents() const { + return impl_->text_; +} + +std::string TextItem::GetHyperLink() const { + return impl_->hyperlink_; +} + +} // namespace item +} // namespace notification \ No newline at end of file diff --git a/notification-ex/text_item.h b/notification-ex/text_item.h new file mode 100644 index 0000000..ccbf2fd --- /dev/null +++ b/notification-ex/text_item.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 NOTIFICATION_EX_TEXT_ITEM_H_ +#define NOTIFICATION_EX_TEXT_ITEM_H_ + +#include +#include + +#include "notification-ex/abstract_item.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace notification { +namespace item { + +class EXPORT_API TextItem : public AbstractItem { + public: + TextItem(std::string text, + std::shared_ptr action = std::shared_ptr({})); + TextItem(std::string id, std::string text, + std::shared_ptr action = std::shared_ptr({})); + virtual ~TextItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + void SetContents(std::string contents); + std::string GetContents() const; + std::string GetHyperLink() const; + + private: + class Impl; + std::unique_ptr impl_; +}; // class TextItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_TEXT_ITEM_H_ \ No newline at end of file diff --git a/notification-ex/text_item_implementation.h b/notification-ex/text_item_implementation.h new file mode 100644 index 0000000..3af64c2 --- /dev/null +++ b/notification-ex/text_item_implementation.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_ + +#include +#include + +#include "notification-ex/text_item.h" + +namespace notification { +namespace item { + +class TextItem::Impl { + public: + virtual ~Impl(); + + private: + Impl(std::string text); + + private: + friend class TextItem; + + std::string text_; + std::string hyperlink_; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_ \ No newline at end of file diff --git a/unittest/src/test_entry_item.cc b/unittest/src/test_entry_item.cc new file mode 100644 index 0000000..b81d8f9 --- /dev/null +++ b/unittest/src/test_entry_item.cc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "notification-ex/entry_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +namespace { + +class EntryItemTest : public ::testing::Test { + public: + virtual void SetUp() {} + virtual void TearDown() {} +}; + +TEST_F(EntryItemTest, FindByID) { + EntryItem item("entry_id"); + + AbstractItem& child = item.FindByID("entry_id"); + EntryItem& btn = static_cast(child); + ASSERT_EQ(btn.GetId(), "entry_id"); +} + +TEST_F(EntryItemTest, FindByIDNullItemReturn) { + EntryItem item("entry_id"); + + AbstractItem& child = item.FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), EntryItem::NullObject); +} + +TEST_F(EntryItemTest, SerializeDeserialize) { + EntryItem item("entry_id"); + Bundle b = item.Serialize(); + ItemFactory factory; + std::shared_ptr gen_item = ItemInflator::Create(factory, b); + ASSERT_EQ(gen_item.get()->GetType(), item.GetType()); + + EntryItem* gen_effect = static_cast(gen_item.get()); + ASSERT_EQ(item.GetId(), gen_effect->GetId()); +} + +TEST_F(EntryItemTest, SetTextGetText) { + EntryItem item("entry_id"); + item.SetText("test"); + + ASSERT_EQ(item.GetText(), "test"); +} + +TEST_F(EntryItemTest, GetTextLimit) { + EntryItem item("entry_id"); + + ASSERT_EQ(item.GetTextLimit(), 160); +} + +} // namespace \ No newline at end of file diff --git a/unittest/src/test_text_item.cc b/unittest/src/test_text_item.cc new file mode 100644 index 0000000..9bef5f2 --- /dev/null +++ b/unittest/src/test_text_item.cc @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 "notification-ex/text_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +namespace { + +class TexttItemTest : public ::testing::Test { + public: + virtual void SetUp() { + } + virtual void TearDown() { + } +}; + +TEST_F(TexttItemTest, FindByID) { + TextItem item("text_id", "default"); + + AbstractItem& child = item.FindByID("text_id"); + TextItem& btn = static_cast(child); + ASSERT_EQ(btn.GetContents(), "default"); +} + +TEST_F(TexttItemTest, FindByIDNullItemReturn) { + TextItem item("text_id", "default"); + + AbstractItem& child = item.FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), TextItem::NullObject); +} + +TEST_F(TexttItemTest, SerializeDeserializeGetContents) { + TextItem item("text_id", "default"); + Bundle b = item.Serialize(); + ItemFactory factory; + std::shared_ptr gen_item = ItemInflator::Create(factory, b); + ASSERT_EQ(gen_item.get()->GetType(), item.GetType()); + + TextItem* gen_text = static_cast(gen_item.get()); + ASSERT_EQ(item.GetContents(), gen_text->GetContents()); +} + +TEST_F(TexttItemTest, SetContentsGetContents) { + TextItem item("text_id", "default"); + item.SetContents("test"); + + ASSERT_EQ(item.GetContents(), "test"); +} + +TEST_F(TexttItemTest, GetHyperLink) { + TextItem item("text_id", "default"); + + ASSERT_EQ(item.GetHyperLink(), ""); +} + +} // namespace \ No newline at end of file -- 2.7.4