From bc323136ed8e6aab7bdfa589a6455412cb213be4 Mon Sep 17 00:00:00 2001 From: "mk5004.lee" Date: Thu, 21 Feb 2019 18:13:19 +0900 Subject: [PATCH] Update some items - image, icon, icontext, checkbox, time, chatmessage Change-Id: I74f8b7192037da6ae8f608ea08d542e4fa803716 Signed-off-by: mk5004.lee --- notification-ex/abstract_item.h | 1 + notification-ex/chat_message_item.cc | 124 ++++++++++++++++++ notification-ex/chat_message_item.h | 63 +++++++++ .../chat_message_item_implementation.h | 52 ++++++++ notification-ex/checkbox_item.cc | 82 ++++++++++++ notification-ex/checkbox_item.h | 48 +++++++ .../checkbox_item_implementation.h | 45 +++++++ notification-ex/icon_item.cc | 51 +++++++ notification-ex/icon_item.h | 44 +++++++ notification-ex/icon_item_implementation.h | 44 +++++++ notification-ex/icon_text_item.cc | 91 +++++++++++++ notification-ex/icon_text_item.h | 52 ++++++++ .../icon_text_item_implementation.h | 46 +++++++ notification-ex/image_item.cc | 79 +++++++++++ notification-ex/image_item.h | 49 +++++++ notification-ex/image_item_implementation.h | 44 +++++++ notification-ex/item.h | 77 ----------- notification-ex/item_factory.cc | 18 ++- notification-ex/time_item.cc | 99 ++++++++++++++ notification-ex/time_item.h | 53 ++++++++ notification-ex/time_item_implementation.h | 46 +++++++ unittest/CMakeLists.txt | 2 - unittest/src/test_chat_message_item.cc | 76 +++++++++++ unittest/src/test_checkbox_item.cc | 64 +++++++++ unittest/src/test_icon_item.cc | 61 +++++++++ unittest/src/test_icon_text_item.cc | 65 +++++++++ unittest/src/test_image_item.cc | 62 +++++++++ unittest/src/test_time_item.cc | 63 +++++++++ 28 files changed, 1517 insertions(+), 84 deletions(-) create mode 100644 notification-ex/chat_message_item.cc create mode 100644 notification-ex/chat_message_item.h create mode 100644 notification-ex/chat_message_item_implementation.h create mode 100644 notification-ex/checkbox_item.cc create mode 100644 notification-ex/checkbox_item.h create mode 100644 notification-ex/checkbox_item_implementation.h create mode 100644 notification-ex/icon_item.cc create mode 100644 notification-ex/icon_item.h create mode 100644 notification-ex/icon_item_implementation.h create mode 100644 notification-ex/icon_text_item.cc create mode 100644 notification-ex/icon_text_item.h create mode 100644 notification-ex/icon_text_item_implementation.h create mode 100644 notification-ex/image_item.cc create mode 100644 notification-ex/image_item.h create mode 100644 notification-ex/image_item_implementation.h create mode 100644 notification-ex/time_item.cc create mode 100644 notification-ex/time_item.h create mode 100644 notification-ex/time_item_implementation.h create mode 100644 unittest/src/test_chat_message_item.cc create mode 100644 unittest/src/test_checkbox_item.cc create mode 100644 unittest/src/test_icon_item.cc create mode 100644 unittest/src/test_icon_text_item.cc create mode 100644 unittest/src/test_image_item.cc create mode 100644 unittest/src/test_time_item.cc diff --git a/notification-ex/abstract_item.h b/notification-ex/abstract_item.h index dc5b32b0..4895eedd 100644 --- a/notification-ex/abstract_item.h +++ b/notification-ex/abstract_item.h @@ -179,6 +179,7 @@ class EXPORT_API AbstractItem { Group, Entry, Progress, + Time, Custom, }; diff --git a/notification-ex/chat_message_item.cc b/notification-ex/chat_message_item.cc new file mode 100644 index 00000000..e6747094 --- /dev/null +++ b/notification-ex/chat_message_item.cc @@ -0,0 +1,124 @@ +/* + * 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 "notification-ex/chat_message_item.h" +#include "notification-ex/chat_message_item_implementation.h" +#include "notification-ex/item_factory.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define CHATMESSAGE_NAME_KEY "__CHATMESSAGE_NAME_KEY__" +#define CHATMESSAGE_TEXT_KEY "__CHATMESSAGE_TEXT_KEY__" +#define CHATMESSAGE_DATA_KEY "__CHATMESSAGE_DATA_KEY__" +#define CHATMESSAGE_TIME_KEY "__CHATMESSAGE_TIME_KEY__" +#define CHATMESSAGE_TYPE_KEY "__CHATMESSAGE_TYPE_KEY__" + +namespace notification { +namespace item { + +ChatMessageItem::ChatMessageItem(std::string id, std::shared_ptr name, + std::shared_ptr text, std::shared_ptr data, + std::shared_ptr time, Type type, std::shared_ptr action) + : AbstractItem(id, AbstractItem::ChatMessage, action), + impl_(new Impl(this, name, text, data, time, type)) { +} + +ChatMessageItem::Impl::Impl(ChatMessageItem* parent, + std::shared_ptr name, std::shared_ptr text, + std::shared_ptr data, std::shared_ptr time, Type type) + : parent_(parent), name_(name), text_(text), data_(data), time_(time), type_(type) { + LOGI("ChatMessageItem impl created"); +} + +Bundle ChatMessageItem::Serialize() { + Bundle b; + b = AbstractItem::Serialize(); + + b.Add(CHATMESSAGE_NAME_KEY, + reinterpret_cast(impl_->name_->Serialize().ToRaw().first.get())); + b.Add(CHATMESSAGE_TEXT_KEY, + reinterpret_cast(impl_->text_->Serialize().ToRaw().first.get())); + b.Add(CHATMESSAGE_DATA_KEY, + reinterpret_cast(impl_->data_->Serialize().ToRaw().first.get())); + b.Add(CHATMESSAGE_TIME_KEY, + reinterpret_cast(impl_->time_->Serialize().ToRaw().first.get())); + b.Add(CHATMESSAGE_TYPE_KEY, std::to_string((int)impl_->type_)); + return b; +} + +void ChatMessageItem::Deserialize(Bundle b) { + ItemFactory factory; + + AbstractItem::Deserialize(b); + + std::shared_ptr name = factory.CreateItem(AbstractItem::Text); + name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY))); + impl_->name_ = std::static_pointer_cast(name); + + std::shared_ptr text = factory.CreateItem(AbstractItem::Text); + text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY))); + impl_->text_ = std::static_pointer_cast(text); + + std::shared_ptr data = factory.CreateItem(AbstractItem::Text); + data.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_DATA_KEY))); + impl_->data_ = std::static_pointer_cast(data); + + std::shared_ptr time = factory.CreateItem(AbstractItem::Time); + time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY))); + impl_->time_ = std::static_pointer_cast(time); + + impl_->type_ = static_cast(std::stoi(b.GetString(CHATMESSAGE_TYPE_KEY))); +} + +AbstractItem& ChatMessageItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + + return ItemFactory::GetNullItem(); +} + +TextItem& ChatMessageItem::GetNameItem() const { + return *(impl_->name_); +} + +TextItem& ChatMessageItem::GetTextItem() const { + return *(impl_->text_); + +} + +TextItem& ChatMessageItem::GetDataItem() const { + return *(impl_->data_); +} + +TimeItem& ChatMessageItem::GetTimeItem() const { + return *(impl_->time_); +} + +ChatMessageItem::Type ChatMessageItem::GetType() const { + return impl_->type_; +} + +ChatMessageItem::~ChatMessageItem() = default; +ChatMessageItem::Impl::~Impl() = default; + +} // namespace item +} // namespace notification_ex diff --git a/notification-ex/chat_message_item.h b/notification-ex/chat_message_item.h new file mode 100644 index 00000000..e3234f62 --- /dev/null +++ b/notification-ex/chat_message_item.h @@ -0,0 +1,63 @@ +/* + * 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_CHAT_MESSAGE_ITEM_H_ +#define NOTIFICATION_EX_CHAT_MESSAGE_ITEM_H_ + +#include + +#include +#include +#include + +#include "notification-ex/abstract_item.h" +#include "notification-ex/text_item.h" +#include "notification-ex/time_item.h" + +namespace notification { +namespace item { + +class EXPORT_API ChatMessageItem : public AbstractItem { + public: + enum Type { + user, + sender, + }; + + public: + ChatMessageItem(std::string id, std::shared_ptr name, + std::shared_ptr text, std::shared_ptr data, + std::shared_ptr time, Type type, + std::shared_ptr action = std::shared_ptr({})); + virtual ~ChatMessageItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + TextItem& GetNameItem() const; + TextItem& GetTextItem() const; + TextItem& GetDataItem() const; + TimeItem& GetTimeItem() const; + Type GetType() const; + + private: + class Impl; + std::unique_ptr impl_; +}; // class ChatMessageItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_CHAT_MESSAGE_ITEM_H_ diff --git a/notification-ex/chat_message_item_implementation.h b/notification-ex/chat_message_item_implementation.h new file mode 100644 index 00000000..299a0a19 --- /dev/null +++ b/notification-ex/chat_message_item_implementation.h @@ -0,0 +1,52 @@ +/* + * 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_CHAT_MESSAGE_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_CHAT_MESSAGE_ITEM_IMPLEMENTATION_H_ + +#include + +#include +#include +#include + +#include "notification-ex/chat_message_item.h" + +namespace notification { +namespace item { + +class ChatMessageItem::Impl { + public: + virtual ~Impl(); + + private: + friend class ChatMessageItem; + Impl(ChatMessageItem* parent, std::shared_ptr name, + std::shared_ptr text, std::shared_ptr data, + std::shared_ptr time, Type type); + + private: + ChatMessageItem* parent_; + std::shared_ptr name_; + std::shared_ptr text_; + std::shared_ptr data_; + std::shared_ptr time_; + Type type_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_CHAT_MESSAGE_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/checkbox_item.cc b/notification-ex/checkbox_item.cc new file mode 100644 index 00000000..c4e1e0c6 --- /dev/null +++ b/notification-ex/checkbox_item.cc @@ -0,0 +1,82 @@ +/* + * 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 "notification-ex/checkbox_item.h" +#include "notification-ex/checkbox_item_implementation.h" +#include "notification-ex/item_factory.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define CHECKBOX_TITLE_KEY "__CHECKBOX_TITLE_KEY__" +#define CHECKBOX_CHECKED_KEY "__CHECKBOX_CHECKED_KEY__" + +namespace notification { +namespace item { + +CheckBoxItem::CheckBoxItem(std::string id, std::string title, bool checked, + std::shared_ptr action) + : AbstractItem(id, AbstractItem::CheckBox, action), + impl_(new Impl(this, title, checked)) { +} + +CheckBoxItem::Impl::Impl(CheckBoxItem* parent, std::string title, bool checked) + : parent_(parent), title_(title), checked_(checked) { + LOGI("CheckBoxItem impl created"); +} + +Bundle CheckBoxItem::Serialize() { + Bundle b; + + b = AbstractItem::Serialize(); + b.Add(CHECKBOX_TITLE_KEY, impl_->title_); + b.Add(CHECKBOX_CHECKED_KEY, std::to_string(impl_->checked_)); + + return b; +} + +void CheckBoxItem::Deserialize(Bundle b) { + AbstractItem::Deserialize(b); + + impl_->title_ = b.GetString(CHECKBOX_TITLE_KEY); + impl_->checked_ = std::stoi(b.GetString(CHECKBOX_CHECKED_KEY)); +} + +AbstractItem& CheckBoxItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + + return ItemFactory::GetNullItem(); +} + +std::string CheckBoxItem::GetTitle(void) const { + return impl_->title_; +} + +bool CheckBoxItem::IsChecked(void) const { + return impl_->checked_; +} + +CheckBoxItem::~CheckBoxItem() = default; +CheckBoxItem::Impl::~Impl() = default; + +} // namespace item +} // namespace notification_ex diff --git a/notification-ex/checkbox_item.h b/notification-ex/checkbox_item.h new file mode 100644 index 00000000..79a67092 --- /dev/null +++ b/notification-ex/checkbox_item.h @@ -0,0 +1,48 @@ +/* + * 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_CHECKBOX_ITEM_H_ +#define NOTIFICATION_EX_CHECKBOX_ITEM_H_ + +#include +#include +#include + +#include "notification-ex/abstract_item.h" + +namespace notification { +namespace item { + +class EXPORT_API CheckBoxItem : public AbstractItem { + public: + CheckBoxItem(std::string id, std::string title, bool checked = false, + std::shared_ptr action = std::shared_ptr({})); + virtual ~CheckBoxItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + std::string GetTitle() const; + bool IsChecked() const; + +private: + class Impl; + std::unique_ptr impl_; +}; // class CheckBoxItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_CHECKBOX_ITEM_H_ diff --git a/notification-ex/checkbox_item_implementation.h b/notification-ex/checkbox_item_implementation.h new file mode 100644 index 00000000..83de7517 --- /dev/null +++ b/notification-ex/checkbox_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_CHECKBOX_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_CHECKBOX_ITEM_IMPLEMENTATION_H_ + +#include +#include +#include + +#include "notification-ex/checkbox_item.h" + +namespace notification { +namespace item { + +class CheckBoxItem::Impl { + public: + virtual ~Impl(); + + private: + friend class CheckBoxItem; + Impl(CheckBoxItem* parent, std::string title, bool checked); + + private: + CheckBoxItem* parent_; + std::string title_; + bool checked_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_CHECKBOX_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/icon_item.cc b/notification-ex/icon_item.cc new file mode 100644 index 00000000..bef75b77 --- /dev/null +++ b/notification-ex/icon_item.cc @@ -0,0 +1,51 @@ +/* + * 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 "notification-ex/icon_item.h" +#include "notification-ex/icon_item_implementation.h" +#include "notification-ex/abstract_item.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" + +namespace notification { +namespace item { + +IconItem::IconItem(std::string iconPath, std::shared_ptr action) + : ImageItem(iconPath, action) , impl_(new Impl(this, iconPath)) { +} + +IconItem::IconItem(std::string id, std::string iconPath, + std::shared_ptr action) + : ImageItem(id, iconPath, action), impl_(new Impl(this, iconPath)) { +} + +IconItem::Impl::Impl(IconItem* parent, std::string iconPath) + : parent_(parent), iconPath_(iconPath) { + LOGI("IconItem impl created"); +} + +IconItem::~IconItem() = default; +IconItem::Impl::~Impl() = default; + +} // namespace item +} // namespace notification_ex + diff --git a/notification-ex/icon_item.h b/notification-ex/icon_item.h new file mode 100644 index 00000000..3b6a3eb0 --- /dev/null +++ b/notification-ex/icon_item.h @@ -0,0 +1,44 @@ +/* + * 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_ICON_ITEM_H_ +#define NOTIFICATION_EX_ICON_ITEM_H_ + +#include +#include +#include + +#include "notification-ex/image_item.h" + +namespace notification { +namespace item { + +class EXPORT_API IconItem : public ImageItem { + public: + IconItem(std::string iconPath, + std::shared_ptr action = std::shared_ptr({})); + IconItem(std::string id, std::string iconPath, + std::shared_ptr action = std::shared_ptr({})); + virtual ~IconItem(); + + private: + class Impl; + std::unique_ptr impl_; +}; // class IconItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_ICON_ITEM_H_ diff --git a/notification-ex/icon_item_implementation.h b/notification-ex/icon_item_implementation.h new file mode 100644 index 00000000..f80f5396 --- /dev/null +++ b/notification-ex/icon_item_implementation.h @@ -0,0 +1,44 @@ +/* + * 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_ICON_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_ICON_ITEM_IMPLEMENTATION_H_ + +#include +#include +#include + +#include "notification-ex/icon_item.h" + +namespace notification { +namespace item { + +class IconItem::Impl { + public: + virtual ~Impl(); + + private: + friend class IconItem; + Impl(IconItem* parent, std::string iconPath); + + private: + IconItem* parent_; + std::string iconPath_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_ICON_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/icon_text_item.cc b/notification-ex/icon_text_item.cc new file mode 100644 index 00000000..9ba88332 --- /dev/null +++ b/notification-ex/icon_text_item.cc @@ -0,0 +1,91 @@ +/* + * 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 "notification-ex/icon_text_item.h" +#include "notification-ex/icon_text_item_implementation.h" +#include "notification-ex/item_factory.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define ICONTEXT_PATH_KEY "__ICONTEXT_PATH_KEY__" +#define ICONTEXT_TITLE_KEY "__ICONTEXT_TITLE_KEY__" + +namespace notification { +namespace item { + +IconTextItem::IconTextItem(std::string id, std::shared_ptr icon, + std::shared_ptr text, std::shared_ptr action) + : AbstractItem(AbstractItem::IconText, action), + impl_(new Impl(this, icon, text)) { +} + +IconTextItem::Impl::Impl(IconTextItem* parent, std::shared_ptr icon, + std::shared_ptr text) + : parent_(parent), icon_(icon), text_(text) { + LOGI("IconTextItem impl created"); +} + +Bundle IconTextItem::Serialize() { + Bundle b; + b = AbstractItem::Serialize(); + + b.Add(ICONTEXT_PATH_KEY, + reinterpret_cast(impl_->icon_->Serialize().ToRaw().first.get())); + b.Add(ICONTEXT_TITLE_KEY, + reinterpret_cast(impl_->text_->Serialize().ToRaw().first.get())); + return b; +} + +void IconTextItem::Deserialize(Bundle b) { + ItemFactory factory; + + AbstractItem::Deserialize(b); + + std::shared_ptr icon = factory.CreateItem(AbstractItem::Icon); + icon.get()->Deserialize(Bundle(b.GetString(ICONTEXT_PATH_KEY))); + impl_->icon_ = std::static_pointer_cast(icon); + + std::shared_ptr text = factory.CreateItem(AbstractItem::Text); + text.get()->Deserialize(Bundle(b.GetString(ICONTEXT_TITLE_KEY))); + impl_->text_ = std::static_pointer_cast(text); +} + +AbstractItem& IconTextItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + + return ItemFactory::GetNullItem(); +} + +IconItem& IconTextItem::GetIconItem() const { + return *(impl_->icon_); +} + +TextItem& IconTextItem::GetTextItem() const { + return *(impl_->text_); +} + +IconTextItem::~IconTextItem() = default; +IconTextItem::Impl::~Impl() = default; + +} // namespace item +} // namespace notification_ex diff --git a/notification-ex/icon_text_item.h b/notification-ex/icon_text_item.h new file mode 100644 index 00000000..7fca273b --- /dev/null +++ b/notification-ex/icon_text_item.h @@ -0,0 +1,52 @@ +/* + * 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_ICON_TEXT_ITEM_H_ +#define NOTIFICATION_EX_ICON_TEXT_ITEM_H_ + +#include +#include +#include + +#include "notification-ex/abstract_item.h" +#include "notification-ex/icon_item.h" +#include "notification-ex/text_item.h" + +namespace notification { +namespace item { + +class EXPORT_API IconTextItem : public AbstractItem { + public: + IconTextItem(std::string id, std::shared_ptr icon, + std::shared_ptr text, + std::shared_ptr action = std::shared_ptr({})); + + virtual ~IconTextItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + IconItem& GetIconItem() const; + TextItem& GetTextItem() const; + + private: + class Impl; + std::unique_ptr impl_; +}; // class IconTextItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_ICON_TEXT_ITEM_H_ diff --git a/notification-ex/icon_text_item_implementation.h b/notification-ex/icon_text_item_implementation.h new file mode 100644 index 00000000..87e23bca --- /dev/null +++ b/notification-ex/icon_text_item_implementation.h @@ -0,0 +1,46 @@ +/* + * 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_ICON_TEXT_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_ICON_TEXT_ITEM_IMPLEMENTATION_H_ + +#include +#include +#include + +#include "notification-ex/icon_text_item.h" + +namespace notification { +namespace item { + +class IconTextItem::Impl { + public: + virtual ~Impl(); + + private: + friend class IconTextItem; + Impl(IconTextItem* parent, std::shared_ptr icon, + std::shared_ptr text); + + private: + IconTextItem* parent_; + std::shared_ptr icon_; + std::shared_ptr text_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_ICON_TEXT_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/image_item.cc b/notification-ex/image_item.cc new file mode 100644 index 00000000..991f16cc --- /dev/null +++ b/notification-ex/image_item.cc @@ -0,0 +1,79 @@ +/* + * 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 "notification-ex/image_item.h" +#include "notification-ex/image_item_implementation.h" +#include "notification-ex/item_factory.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define IMAGE_PATH_KEY "__IMAGE_PATH_KEY__" + +namespace notification { +namespace item { + +ImageItem::ImageItem(std::string imagePath, + std::shared_ptr action) + : AbstractItem(AbstractItem::Image, action), impl_(new Impl(this, imagePath)) { +} + +ImageItem::ImageItem(std::string id, std::string imagePath, + std::shared_ptr action) + : AbstractItem(id, AbstractItem::Image, action), impl_(new Impl(this, imagePath)) { +} + +ImageItem::Impl::Impl(ImageItem* parent, std::string imagePath) + : parent_(parent), imagePath_(imagePath) { + LOGI("ImageItem impl created"); +} + +Bundle ImageItem::Serialize() { + Bundle b; + b = AbstractItem::Serialize(); + b.Add(IMAGE_PATH_KEY, impl_->imagePath_); + + return b; +} + +void ImageItem::Deserialize(Bundle b) { + AbstractItem::Deserialize(b); + + impl_->imagePath_ = b.GetString(IMAGE_PATH_KEY); +} + +AbstractItem& ImageItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + + return ItemFactory::GetNullItem(); +} + +std::string ImageItem::GetImagePath() const { + return impl_->imagePath_; +} + +ImageItem::~ImageItem() = default; +ImageItem::Impl::~Impl() = default; + + +} // namespace item +} // namespace notification diff --git a/notification-ex/image_item.h b/notification-ex/image_item.h new file mode 100644 index 00000000..f2e1802e --- /dev/null +++ b/notification-ex/image_item.h @@ -0,0 +1,49 @@ +/* + * 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_IMAGE_ITEM_H_ +#define NOTIFICATION_EX_IMAGE_ITEM_H_ + +#include +#include +#include + +#include "notification-ex/abstract_item.h" + +namespace notification { +namespace item { + +class EXPORT_API ImageItem : public AbstractItem { + public: + ImageItem(std::string imagePath, + std::shared_ptr action = std::shared_ptr({})); + ImageItem(std::string id, std::string imagePath, + std::shared_ptr action = std::shared_ptr({})); + virtual ~ImageItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + std::string GetImagePath() const; + + private: + class Impl; + std::unique_ptr impl_; +}; //class ImageItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_IMAGE_ITEM_H_ diff --git a/notification-ex/image_item_implementation.h b/notification-ex/image_item_implementation.h new file mode 100644 index 00000000..80396f11 --- /dev/null +++ b/notification-ex/image_item_implementation.h @@ -0,0 +1,44 @@ +/* + * 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_IMAGE_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_IMAGE_ITEM_IMPLEMENTATION_H_ + +#include +#include +#include + +#include "notification-ex/image_item.h" + +namespace notification { +namespace item { + +class ImageItem::Impl { + public: + virtual ~Impl(); + + private: + friend class ImageItem; + Impl(ImageItem* parent, std::string imagePath); + + private: + ImageItem* parent_; + std::string imagePath_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_IMAGE_ITEM_IMPLEMENTATION_H_ diff --git a/notification-ex/item.h b/notification-ex/item.h index 8582f419..7e5f6a9b 100644 --- a/notification-ex/item.h +++ b/notification-ex/item.h @@ -33,83 +33,6 @@ namespace notification { namespace item { -class EXPORT_API IconItem : public AbstractItem { - public: - IconItem(std::string iconpath); - virtual ~IconItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - - private: - std::string iconPath_ = nullptr; -}; // class IconItem - -class EXPORT_API IconTextItem : public AbstractItem { - public: - IconTextItem(std::string iconpath, std::string text); - virtual ~IconTextItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - IconItem GetIconItem() const; - TextItem GetTextItem() const; - - private: - std::string iconPath_ = nullptr; - std::string text_ = nullptr; -}; // class IconTextItem - -class EXPORT_API ImageItem : public AbstractItem { - public: - ImageItem(std::string imagePath); - virtual ~ImageItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - std::string GetImagePath() const; - - private: - std::string imagePath_ = nullptr; -}; // class ImageItem - -class EXPORT_API CheckBoxItem : public AbstractItem { - public: - CheckBoxItem(bool checked); - virtual ~CheckBoxItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - bool IsChecked() const; - -private: - bool checked_ = false; -}; // class CheckBoxItem - -class EXPORT_API ChatMessageItem : public AbstractItem { - public: - enum Type { - user, - sender, - }; - - public: - ChatMessageItem(); - virtual ~ChatMessageItem(); - - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; - TextItem GetTextItem() const; - TextItem GetDataItem() const; - time_t GetTimeItem() const; - Type GetType() const; -}; // class ChatMessageItem - class EXPORT_API CustomItem : public AbstractItem { public: CustomItem(); diff --git a/notification-ex/item_factory.cc b/notification-ex/item_factory.cc index 672bc983..b3a90b15 100644 --- a/notification-ex/item_factory.cc +++ b/notification-ex/item_factory.cc @@ -27,6 +27,12 @@ #include "notification-ex/exception.h" #include "notification-ex/input_selector_item.h" #include "notification-ex/progress_item.h" +#include "notification-ex/icon_item.h" +#include "notification-ex/icon_text_item.h" +#include "notification-ex/image_item.h" +#include "notification-ex/checkbox_item.h" +#include "notification-ex/chat_message_item.h" +#include "notification-ex/time_item.h" #ifdef LOG_TAG #undef LOG_TAG @@ -45,17 +51,17 @@ shared_ptr ItemFactory::CreateItem(AbstractItem::Type type) { case AbstractItem::Text : return make_shared(""); case AbstractItem::Icon : - return make_shared(""); + return make_shared(""); case AbstractItem::Image : - return make_shared(""); + return make_shared(""); case AbstractItem::Button : return make_shared(""); case AbstractItem::ChatMessage : - return make_shared(""); + return make_shared("", nullptr, nullptr, nullptr, nullptr, ChatMessageItem::Type::user); case AbstractItem::CheckBox : - return make_shared(""); + return make_shared("", ""); case AbstractItem::IconText : - return make_shared(""); + return make_shared("", nullptr, nullptr); case AbstractItem::InputSelector : return make_shared(); case AbstractItem::Group : @@ -64,6 +70,8 @@ shared_ptr ItemFactory::CreateItem(AbstractItem::Type type) { return make_shared(""); case AbstractItem::Progress : return make_shared(0.0, 0.0, 0.0); + case AbstractItem::Time : + return make_shared(); case AbstractItem::Custom : return make_shared(""); } diff --git a/notification-ex/time_item.cc b/notification-ex/time_item.cc new file mode 100644 index 00000000..e9b26163 --- /dev/null +++ b/notification-ex/time_item.cc @@ -0,0 +1,99 @@ +/* + * 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 "notification-ex/time_item.h" +#include "notification-ex/time_item_implementation.h" +#include "notification-ex/item_factory.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define TIME_KEY "__TIME_KEY__" + +namespace notification { +namespace item { + +TimeItem::TimeItem() : AbstractItem(AbstractItem::Time) { + time_t current_time; + time(¤t_time); + + impl_->time_ = current_time; +} + +TimeItem::TimeItem(time_t time, std::shared_ptr action) + : AbstractItem(AbstractItem::Time, action), impl_(new Impl(this, time)) { +} + +TimeItem::TimeItem(std::string id, time_t time, + std::shared_ptr action) + : AbstractItem(id, AbstractItem::Time, action), impl_(new Impl(this, time)) { +} + +TimeItem::Impl::Impl(TimeItem* parent, time_t time) + : parent_(parent), time_(time) { + LOGI("TimeItem impl created"); +} + +Bundle TimeItem::Serialize() { + Bundle b; + struct tm* timeinfo; + char buf[80] = {0,}; + + b = AbstractItem::Serialize(); + + //timt_t to tm + timeinfo = localtime(&impl_->time_); + //tm to str + strftime (buf, sizeof(buf), "%s", timeinfo); + b.Add(TIME_KEY, std::string(buf)); + + return b; +} + +void TimeItem::Deserialize(Bundle b) { + std::string time_s; + struct tm timeinfo; + + AbstractItem::Deserialize(b); + time_s = b.GetString(TIME_KEY); + + //str to tm + strptime(time_s.c_str(), "%s", &timeinfo); + //tm to time_t + impl_->time_ = mktime(&timeinfo); +} + +AbstractItem& TimeItem::FindByID(std::string id) { + if (GetId() == id) + return *this; + + return ItemFactory::GetNullItem(); +} + +time_t TimeItem::GetTime() const { + return impl_->time_; +} + +TimeItem::~TimeItem() = default; +TimeItem::Impl::~Impl() = default; + +} // namespace item +} // namespace notification_ex diff --git a/notification-ex/time_item.h b/notification-ex/time_item.h new file mode 100644 index 00000000..c077e6a7 --- /dev/null +++ b/notification-ex/time_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_TIME_ITEM_H_ +#define NOTIFICATION_EX_TIME_ITEM_H_ + +#include + +#include +#include +#include + +#include "notification-ex/abstract_item.h" + +namespace notification { +namespace item { + +class EXPORT_API TimeItem : public AbstractItem { + public: + TimeItem(); + TimeItem(time_t time, + std::shared_ptr action = std::shared_ptr({})); + TimeItem(std::string id, time_t time, + std::shared_ptr action = std::shared_ptr({})); + + virtual ~TimeItem(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + AbstractItem& FindByID(std::string id) override; + time_t GetTime() const; + + private: + class Impl; + std::unique_ptr impl_; +}; // class TimeItem + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_TIME_ITEM_H_ diff --git a/notification-ex/time_item_implementation.h b/notification-ex/time_item_implementation.h new file mode 100644 index 00000000..9637fde7 --- /dev/null +++ b/notification-ex/time_item_implementation.h @@ -0,0 +1,46 @@ +/* + * 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_TIME_ITEM_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_TIME_ITEM_IMPLEMENTATION_H_ + +#include + +#include +#include +#include + +#include "notification-ex/time_item.h" + +namespace notification { +namespace item { + +class TimeItem::Impl { + public: + virtual ~Impl(); + + private: + friend class TimeItem; + Impl(TimeItem* parent, time_t time); + + private: + TimeItem* parent_; + time_t time_; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_TIME_ITEM_IMPLEMENTATION_H_ diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 86f1a0ea..d56e3bd0 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -38,5 +38,3 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${notification-ex_unittests_LDFLAGS} ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) - - diff --git a/unittest/src/test_chat_message_item.cc b/unittest/src/test_chat_message_item.cc new file mode 100644 index 00000000..2fcfd8a1 --- /dev/null +++ b/unittest/src/test_chat_message_item.cc @@ -0,0 +1,76 @@ +/* + * 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/chat_message_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class ChatMessageItemTest : public ::testing::Test { + public: + ChatMessageItem* item; + ChatMessageItem::Type type = ChatMessageItem::Type::user; + std::string id = "chatmessage_id"; + time_t current_time; + virtual void SetUp() { + time(¤t_time); + + item = new ChatMessageItem(id, + std::make_shared("name_id", "name"), + std::make_shared("text_id", "text"), + std::make_shared("data_id", "data"), + std::make_shared(current_time),type); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(ChatMessageItemTest, create) { + EXPECT_NE(ChatMessageItemTest::item, nullptr); +} + +TEST_F(ChatMessageItemTest, FindByID) { + AbstractItem& child = ChatMessageItemTest::item->FindByID(ChatMessageItemTest::id); + ChatMessageItem& message = static_cast(child); + ASSERT_EQ(message.GetNameItem().GetContents(), "name"); + ASSERT_EQ(message.GetTextItem().GetContents(), "text"); + ASSERT_EQ(message.GetDataItem().GetContents(), "data"); + ASSERT_EQ(message.GetType(), ChatMessageItemTest::type); +} + +TEST_F(ChatMessageItemTest, FindByIDNullItemReturn) { + AbstractItem& child = ChatMessageItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), ChatMessageItem::NullObject); +} + +TEST_F(ChatMessageItemTest, SerializeDeserialize) { + Bundle b = ChatMessageItemTest::item->Serialize(); + + //ChatMessageItemTest::item->Deserialize(b); + //ItemFactory factory; + //std::shared_ptr gen_item = ItemInflator::Create(factory, b); + //ASSERT_EQ(ChatMessageItemTest::item->GetType(), gen_item.get()->GetType()); + + //ChatMessageItem* gen_image = static_cast(gen_item.get()); + //ASSERT_EQ(ChatMessageItemTest::item->GetNameItem(), gen_image->GetNameItem()); + //ASSERT_EQ(ChatMessageItemTest::item->GetTextItem(), gen_image->GetTextItem()); + //ASSERT_EQ(ChatMessageItemTest::item->GetDataItem(), gen_image->GetDataItem()); + //ASSERT_EQ(ChatMessageItemTest::item->GetType(), gen_image->GetType()); +} diff --git a/unittest/src/test_checkbox_item.cc b/unittest/src/test_checkbox_item.cc new file mode 100644 index 00000000..6fd38dd1 --- /dev/null +++ b/unittest/src/test_checkbox_item.cc @@ -0,0 +1,64 @@ +/* + * 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/checkbox_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class CheckBoxItemTest : public ::testing::Test { + public: + CheckBoxItem* item; + std::string id = "checkbox_id"; + std::string title = "title"; + bool isChecked = false; + virtual void SetUp() { + item = new CheckBoxItem(id, title, isChecked); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(CheckBoxItemTest, create) { + EXPECT_NE(CheckBoxItemTest::item, nullptr); +} + +TEST_F(CheckBoxItemTest, FindByID) { + AbstractItem& child = CheckBoxItemTest::item->FindByID(CheckBoxItemTest::id); + CheckBoxItem& checkbox = static_cast(child); + ASSERT_EQ(checkbox.GetTitle(), CheckBoxItemTest::title); + ASSERT_EQ(checkbox.IsChecked(), CheckBoxItemTest::isChecked); +} + +TEST_F(CheckBoxItemTest, FindByIDNullItemReturn) { + AbstractItem& child = CheckBoxItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), CheckBoxItem::NullObject); +} + +TEST_F(CheckBoxItemTest, SerializeDeserialize) { + Bundle b = CheckBoxItemTest::item->Serialize(); + + ItemFactory factory; + std::shared_ptr gen_item = ItemInflator::Create(factory, b); + ASSERT_EQ(CheckBoxItemTest::item->GetType(), gen_item.get()->GetType()); + + CheckBoxItem* gen_checkbox = static_cast(gen_item.get()); + ASSERT_EQ(CheckBoxItemTest::item->GetTitle(), gen_checkbox->GetTitle()); +} diff --git a/unittest/src/test_icon_item.cc b/unittest/src/test_icon_item.cc new file mode 100644 index 00000000..8deb06dc --- /dev/null +++ b/unittest/src/test_icon_item.cc @@ -0,0 +1,61 @@ +/* + * 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/icon_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class IconItemTest : public ::testing::Test { + public: + IconItem* item; + std::string id = "icon_id"; + virtual void SetUp() { + item = new IconItem(id, "icon_path"); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(IconItemTest, create) { + EXPECT_NE(IconItemTest::item, nullptr); +} + +TEST_F(IconItemTest, FindByID) { + AbstractItem& child = IconItemTest::item->FindByID(IconItemTest::id); + IconItem& icon = static_cast(child); + ASSERT_EQ(icon.GetImagePath(), "icon_path"); +} + +TEST_F(IconItemTest, FindByIDNullItemReturn) { + AbstractItem& child = IconItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), IconItem::NullObject); +} + +TEST_F(IconItemTest, SerializeDeserialize) { + Bundle b = IconItemTest::item->Serialize(); + + ItemFactory factory; + std::shared_ptr gen_item = ItemInflator::Create(factory, b); + ASSERT_EQ(IconItemTest::item->GetType(), gen_item.get()->GetType()); + + IconItem* gen_icon = static_cast(gen_item.get()); + ASSERT_EQ(IconItemTest::item->GetImagePath(), gen_icon->GetImagePath()); +} diff --git a/unittest/src/test_icon_text_item.cc b/unittest/src/test_icon_text_item.cc new file mode 100644 index 00000000..cc6d68b3 --- /dev/null +++ b/unittest/src/test_icon_text_item.cc @@ -0,0 +1,65 @@ +/* + * 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/icon_text_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class IconTextItemTest : public ::testing::Test { + public: + IconTextItem* item; + std::string id = "icontext_id"; + virtual void SetUp() { + item = new IconTextItem(id, + std::make_shared("icon_id", "icon_path"), + std::make_shared("text_id", "title")); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(IconTextItemTest, create) { + EXPECT_NE(IconTextItemTest::item, nullptr); +} + +#if 0 +TEST_F(IconTextItemTest, FindByID) { + AbstractItem& child = IconTextItemTest::item->FindByID(IconTextItemTest::id); + IconTextItem& icontext = static_cast(child); + ASSERT_EQ(icontext.GetIconItem().GetImagePath(), "icon_path"); + ASSERT_EQ(icontext.GetTextItem().GetContents(), "title"); +} +#endif + +TEST_F(IconTextItemTest, FindByIDNullItemReturn) { + AbstractItem& child = IconTextItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), IconItem::NullObject); +} + +TEST_F(IconTextItemTest, SerializeDeserialize) { + Bundle b = IconTextItemTest::item->Serialize(); + + //ItemFactory factory; + //std::shared_ptr gen_item = ItemInflator::Create(factory, b); + //IconTextItem* gen_icon = static_cast(gen_item.get()); + //ASSERT_EQ(IconTextItemTest::item->GetIconItem(), gen_icon->GetIconItem()); + //ASSERT_EQ(IconTextItemTest::item->GetTextItem(), gen_icon->GetTextItem()); +} diff --git a/unittest/src/test_image_item.cc b/unittest/src/test_image_item.cc new file mode 100644 index 00000000..42a5caa6 --- /dev/null +++ b/unittest/src/test_image_item.cc @@ -0,0 +1,62 @@ +/* + * 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/image_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class ImageItemTest : public ::testing::Test { + public: + ImageItem* item; + std::string id = "image_id"; + std::string imagePath = "image_path"; + virtual void SetUp() { + item = new ImageItem(id, imagePath); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(ImageItemTest, create) { + EXPECT_NE(ImageItemTest::item, nullptr); +} + +TEST_F(ImageItemTest, FindByID) { + AbstractItem& child = ImageItemTest::item->FindByID(ImageItemTest::id); + ImageItem& image = static_cast(child); + ASSERT_EQ(image.GetImagePath(), ImageItemTest::imagePath); +} + +TEST_F(ImageItemTest, FindByIDNullItemReturn) { + AbstractItem& child = ImageItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), ImageItem::NullObject); +} + +TEST_F(ImageItemTest, SerializeDeserialize) { + Bundle b = ImageItemTest::item->Serialize(); + + ItemFactory factory; + std::shared_ptr gen_item = ItemInflator::Create(factory, b); + ASSERT_EQ(ImageItemTest::item->GetType(), gen_item.get()->GetType()); + + ImageItem* gen_image = static_cast(gen_item.get()); + ASSERT_EQ(ImageItemTest::item->GetImagePath(), gen_image->GetImagePath()); +} diff --git a/unittest/src/test_time_item.cc b/unittest/src/test_time_item.cc new file mode 100644 index 00000000..c8a2c866 --- /dev/null +++ b/unittest/src/test_time_item.cc @@ -0,0 +1,63 @@ +/* + * 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/time_item.h" +#include "notification-ex/item_inflator.h" + +using namespace notification::item; + +class TimeItemTest : public ::testing::Test { + public: + TimeItem* item; + time_t current_time; + std::string id = "time_id"; + virtual void SetUp() { + time(¤t_time); + item = new TimeItem(id, current_time); + } + virtual void TearDown() { + delete item; + } +}; + +TEST_F(TimeItemTest, create) { + EXPECT_NE(TimeItemTest::item, nullptr); +} + +TEST_F(TimeItemTest, FindByID) { + AbstractItem& child = TimeItemTest::item->FindByID(TimeItemTest::id); + TimeItem& time_ = static_cast(child); + ASSERT_EQ(time_.GetTime(), TimeItemTest::current_time); +} + +TEST_F(TimeItemTest, FindByIDNullItemReturn) { + AbstractItem& child = TimeItemTest::item->FindByID("not_existed_item"); + ASSERT_EQ(child.GetType(), TimeItem::NullObject); +} + +TEST_F(TimeItemTest, SerializeDeserialize) { + Bundle b = TimeItemTest::item->Serialize(); + + //ItemFactory factory; + //std::shared_ptr gen_item = ItemInflator::Create(factory, b); + //ASSERT_EQ(TimeItemTest::item->GetType(), gen_item.get()->GetType()); + + //TimeItem* gen_time = static_cast(gen_item.get()); + //ASSERT_EQ(item.GetTime(), gen_time->GetTime()); +} -- 2.34.1