From 1ec2c765ad03e04f7dca3e35814f21b026162e1a Mon Sep 17 00:00:00 2001 From: hyunho Date: Tue, 19 Feb 2019 16:19:45 +0900 Subject: [PATCH] Add implementation of some classes - ItemFactory - ItemInflator - AbstractItem - GroupItem - ButtonItem Change-Id: I3e27193e8d9dd2e280fc1f894a1a4f12be03f3d3 Signed-off-by: hyunho --- CMakeLists.txt | 8 +- notification-ex/CMakeLists.txt | 1 + notification-ex/abstract_action.h | 4 - notification-ex/abstract_item.cc | 180 + notification-ex/abstract_item.h | 32 +- notification-ex/abstract_item_implementation.h | 63 + notification-ex/action.h | 71 +- notification-ex/bundle.cc | 112 - notification-ex/button_item.cc | 67 + notification-ex/button_item.h | 50 + notification-ex/ex_bundle.h | 192 +- notification-ex/group_item.cc | 151 + notification-ex/group_item.h | 56 + notification-ex/group_item_implementation.h | 49 + notification-ex/item.h | 40 - notification-ex/item_factory.cc | 67 + notification-ex/item_factory.h | 37 + notification-ex/item_inflator.cc | 41 + notification-ex/item_inflator.h | 38 + packaging/notification.spec | 5 + unittest/CMakeLists.txt | 9 +- unittest/mock/app_common.h | 42 + unittest/mock/fff.h | 6493 ++++++++++++++++++++++++ unittest/mock/mock.cc | 10 + unittest/mock/mock.h | 22 + unittest/src/test_button_item.cc | 32 + unittest/src/test_group_item.cc | 99 + 27 files changed, 7774 insertions(+), 197 deletions(-) create mode 100644 notification-ex/abstract_item.cc create mode 100644 notification-ex/abstract_item_implementation.h delete mode 100644 notification-ex/bundle.cc create mode 100644 notification-ex/button_item.cc create mode 100644 notification-ex/button_item.h create mode 100644 notification-ex/group_item.cc create mode 100644 notification-ex/group_item.h create mode 100644 notification-ex/group_item_implementation.h create mode 100644 notification-ex/item_factory.cc create mode 100644 notification-ex/item_factory.h create mode 100644 notification-ex/item_inflator.cc create mode 100644 notification-ex/item_inflator.h create mode 100644 unittest/mock/app_common.h create mode 100644 unittest/mock/fff.h create mode 100644 unittest/mock/mock.cc create mode 100644 unittest/mock/mock.h create mode 100644 unittest/src/test_button_item.cc create mode 100644 unittest/src/test_group_item.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index e85ca6c..90ed25c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +ENABLE_TESTING() +SET(NOTIFICATION_UNIT_TESTS notification-ex_unittests) +ADD_TEST(NAME ${NOTIFICATION_UNIT_TESTS} COMMAND ${NOTIFICATION_UNIT_TESTS}) ADD_SUBDIRECTORY(notification) ADD_SUBDIRECTORY(notification-ex) ADD_SUBDIRECTORY(unittest) + +ADD_DEPENDENCIES(notification-ex_unittests notification-ex) diff --git a/notification-ex/CMakeLists.txt b/notification-ex/CMakeLists.txt index ccfaaa8..cebea32 100644 --- a/notification-ex/CMakeLists.txt +++ b/notification-ex/CMakeLists.txt @@ -15,6 +15,7 @@ pkg_check_modules(notification-ex REQUIRED bundle dlog capi-appfw-app-control + capi-appfw-app-common ) FOREACH(flag ${notification-ex_CFLAGS}) diff --git a/notification-ex/abstract_action.h b/notification-ex/abstract_action.h index 347c659..b9ea312 100644 --- a/notification-ex/abstract_action.h +++ b/notification-ex/abstract_action.h @@ -32,12 +32,8 @@ namespace notification { namespace item { class AbstractItem; - class EXPORT_API AbstractAction { public: - AbstractAction(); - virtual ~AbstractAction(); - virtual bool IsLocal() const = 0; virtual void Execute(std::shared_ptr item) = 0; virtual Bundle Serialize() = 0; diff --git a/notification-ex/abstract_item.cc b/notification-ex/abstract_item.cc new file mode 100644 index 0000000..2503d88 --- /dev/null +++ b/notification-ex/abstract_item.cc @@ -0,0 +1,180 @@ +/* + * 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 + +#include "notification-ex/exception.h" +#include "notification-ex/abstract_item.h" +#include "notification-ex/abstract_item_implementation.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" + +#define ABSTRACT_ITEM_TYPE_KEY "__ABSTRACT_ITEM_TYPE_KEY__" +#define ABSTRACT_ITEM_ID_KEY "__ABSTRACT_ITEM_ID_KEY__" + +using namespace std; +namespace notification { +namespace item { + +AbstractItem::AbstractItem() + : impl_(new Impl(this)) { +} + +AbstractItem::AbstractItem(AbstractItem::Type type, + std::shared_ptr action) + : impl_(new Impl(this, type, action)) { +} + +AbstractItem::AbstractItem(std::string id, AbstractItem::Type type, + std::shared_ptr action) + : impl_(new Impl(this, id, type, action)) { +} + +AbstractItem::Impl::Impl(AbstractItem* parent, string id, + AbstractItem::Type type, std::shared_ptr action) + : id_(id), type_(type), action_(action), parent_(parent) { + LOGI("GroupItem created"); +} + +AbstractItem::Impl::Impl(AbstractItem* parent, + AbstractItem::Type type, std::shared_ptr action) + : type_(type), action_(action), parent_(parent) { + LOGI("GroupItem created"); +} + +AbstractItem::Impl::Impl(AbstractItem* parent) + : parent_(parent) { + LOGI("GroupItem created"); +} + +AbstractItem::~AbstractItem() = default; + +Bundle AbstractItem::Serialize() { + Bundle b; + b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string((int)impl_->type_)); + b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_); + return b; +} + +void AbstractItem::Deserialize(Bundle b) { + string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY); + if (type_str.empty()) + THROW(NOTIFICATION_ERROR_IO_ERROR); + + string id_str = b.GetString(ABSTRACT_ITEM_ID_KEY); + impl_->id_ = id_str; + impl_->type_ = static_cast(strtol(type_str.c_str(), NULL, 10)); +} + +string AbstractItem::GetId() const { + return impl_->id_; +} + +shared_ptr AbstractItem::GetAction() const { + return impl_->action_; +} + +shared_ptr