Add input selector item implementation 64/200264/4
authorhyunho <hhstark.kang@samsung.com>
Thu, 21 Feb 2019 02:56:58 +0000 (11:56 +0900)
committerhyunho <hhstark.kang@samsung.com>
Thu, 21 Feb 2019 10:04:19 +0000 (19:04 +0900)
Change-Id: I71e7c316574192b3415a021ffe3259853f2f86d7
Signed-off-by: hyunho <hhstark.kang@samsung.com>
notification-ex/input_selector_item.cc [new file with mode: 0644]
notification-ex/input_selector_item.h [new file with mode: 0644]
notification-ex/input_selector_item_implementation.h [new file with mode: 0644]
notification-ex/item.h
notification-ex/item_factory.cc
unittest/mock/fff.h
unittest/src/test_input_selector_item.cc [new file with mode: 0644]

diff --git a/notification-ex/input_selector_item.cc b/notification-ex/input_selector_item.cc
new file mode 100644 (file)
index 0000000..73f4f7b
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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 <dlog.h>
+
+#include <memory>
+#include <vector>
+#include <algorithm>
+
+#include "notification-ex/input_selector_item.h"
+#include "notification-ex/input_selector_item_implementation.h"
+#include "notification-ex/item_factory.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define INPUT_SELECTOR_CONTENTS_KEY "__INPUT_SELECTOR_CONTENTS_KEY__"
+
+using namespace std;
+namespace notification {
+namespace item {
+
+InputSelectorItem::InputSelectorItem(std::shared_ptr<AbstractAction> action)
+  : AbstractItem(AbstractItem::InputSelector, action), impl_(new Impl(this)) {
+}
+
+InputSelectorItem::InputSelectorItem(string id, std::shared_ptr<AbstractAction> action)
+  : AbstractItem(id, AbstractItem::InputSelector, action), impl_(new Impl(this)) {
+}
+
+InputSelectorItem::~InputSelectorItem() = default;
+InputSelectorItem::Impl::~Impl() = default;
+
+InputSelectorItem::Impl::Impl(InputSelectorItem* parent)
+  : parent_(parent) {
+  LOGI("InputSelectorItem impl created");
+}
+
+Bundle InputSelectorItem::Serialize() {
+  Bundle b;
+  b = AbstractItem::Serialize();
+  vector<string> contents_vector {
+    begin(impl_->contents_),
+    end(impl_->contents_)
+  };
+  b.Add(INPUT_SELECTOR_CONTENTS_KEY, contents_vector);
+  return b;
+}
+
+void InputSelectorItem::Deserialize(Bundle b) {
+  AbstractItem::Deserialize(b);
+  vector<string> contents = b.GetStringArray(INPUT_SELECTOR_CONTENTS_KEY);
+  impl_->contents_ = list<string>(contents.begin(), contents.end());
+}
+
+AbstractItem& InputSelectorItem::FindByID(std::string id) {
+  if (GetId() == id)
+    return *this;
+  return ItemFactory::GetNullItem();
+}
+
+list<string> InputSelectorItem::GetContents() const {
+  return impl_->contents_;
+}
+
+void InputSelectorItem::SetContents(list<string> contents) {
+  impl_->contents_ = move(contents);
+}
+
+}  // namespace item
+}  // namespace notification
diff --git a/notification-ex/input_selector_item.h b/notification-ex/input_selector_item.h
new file mode 100644 (file)
index 0000000..339798d
--- /dev/null
@@ -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_INPUT_SELECTOR_ITEM_H_
+#define NOTIFICATION_EX_INPUT_SELECTOR_ITEM_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/abstract_item.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API InputSelectorItem : public AbstractItem {
+ public:
+  InputSelectorItem(std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  InputSelectorItem(std::string id,
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  virtual ~InputSelectorItem();
+
+ public:
+  virtual Bundle Serialize() override;
+  virtual void Deserialize(Bundle b) override;
+  virtual AbstractItem& FindByID(std::string id) override;
+
+  std::list<std::string> GetContents() const;
+  void SetContents(std::list<std::string> contents);
+
+ private:
+  class Impl;
+  std::unique_ptr<Impl> impl_;
+};
+
+}  // namespace item
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_INPUT_SELECTOR_ITEM_H_
diff --git a/notification-ex/input_selector_item_implementation.h b/notification-ex/input_selector_item_implementation.h
new file mode 100644 (file)
index 0000000..21a12b2
--- /dev/null
@@ -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_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/input_selector_item.h"
+
+namespace notification {
+namespace item {
+
+class InputSelectorItem::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  Impl(InputSelectorItem* parent);
+
+ private:
+  friend class InputSelectorItem;
+
+  std::list<std::string> contents_;
+  InputSelectorItem* parent_;
+};
+
+}  // namespace item
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
index 1c8bc49..72b4ff6 100644 (file)
@@ -145,21 +145,6 @@ class EXPORT_API ChatMessageItem : public AbstractItem {
   Type GetType() const;
 };  // class ChatMessageItem
 
-class EXPORT_API InputSelectorItem : public AbstractItem {
- public:
-  InputSelectorItem();
-  virtual ~InputSelectorItem();
-
-  Bundle Serialize() override;
-  void Deserialize(Bundle b) override;
-  AbstractItem& FindByID(std::string id) override;
-  std::list<std::string> GetContents() const;
-  void SetContents(std::list<std::string> contents);
-
- private:
-  std::list<std::string> contents_;
-};  // class InputSelectorItem
-
 class EXPORT_API EntryItem : public AbstractItem {
  public:
   EntryItem();
index b8aab47..a90dddd 100644 (file)
@@ -23,6 +23,7 @@
 #include "notification-ex/group_item.h"
 #include "notification-ex/null_item.h"
 #include "notification-ex/exception.h"
+#include "notification-ex/input_selector_item.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -53,7 +54,7 @@ shared_ptr<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
   case AbstractItem::IconText :
     return make_shared<ButtonItem>("");
   case AbstractItem::InputSelector :
-    return make_shared<ButtonItem>("");
+    return make_shared<InputSelectorItem>();
   case AbstractItem::Group :
     return make_shared<GroupItem>();
   case AbstractItem::Effect :
@@ -66,6 +67,7 @@ shared_ptr<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
 
   return nullptr;
 }
+
 AbstractItem& ItemFactory::GetNullItem() {
   static NullItem item;
   return item;
index 6289a58..f8d6d5f 100644 (file)
@@ -105,10 +105,10 @@ SOFTWARE.
 
 #ifdef __cplusplus
     #define FFF_EXTERN_C extern "C"{
-    #define FFF_END_EXTERN_C } 
+    #define FFF_END_EXTERN_C }
 #else  /* ansi c */
-    #define FFF_EXTERN_C 
-    #define FFF_END_EXTERN_C 
+    #define FFF_EXTERN_C
+    #define FFF_END_EXTERN_C
 #endif  /* cpp/ansi c */
 
 #define DEFINE_RESET_FUNCTION(FUNCNAME) \
@@ -119,7 +119,7 @@ SOFTWARE.
 /* -- END INTERNAL HELPER MACROS -- */
 
 typedef void (*fff_function_t)(void);
-typedef struct { 
+typedef struct {
     fff_function_t call_history[FFF_CALL_HISTORY_LEN];
     unsigned int call_history_idx;
 } fff_globals_t;
diff --git a/unittest/src/test_input_selector_item.cc b/unittest/src/test_input_selector_item.cc
new file mode 100644 (file)
index 0000000..9c56bc6
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <gmock/gmock.h>
+
+#include "notification-ex/input_selector_item.h"
+#include "notification-ex/item_inflator.h"
+
+using namespace notification::item;
+using namespace std;
+
+namespace {
+
+class InputSelectorItemTest : public ::testing::Test {
+ protected:
+  void SetUp() override {}
+  void TearDown() override {}
+};
+
+TEST_F(InputSelectorItemTest, SerializeDeserialize) {
+  InputSelectorItem item;
+  list<string> contents;
+  contents.push_back("AA");
+  contents.push_back("BB");
+  contents.push_back("CC");
+  item.SetContents(contents);
+
+  Bundle b = item.Serialize();
+  ItemFactory factory;
+  shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+  ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+  InputSelectorItem* gen_input = static_cast<InputSelectorItem*>(gen_item.get());
+
+  list<string> l1 = item.GetContents();
+  list<string> l2 = gen_input->GetContents();
+  list<string>::iterator it1 = l1.begin();
+  list<string>::iterator it2 = l2.begin();
+  while(it1 != l1.end() && it2 != l2.end()) {
+    ASSERT_EQ((*it1), (*it2));
+    it1++;
+    it2++;
+  }
+}
+
+}  // namespace