Add entry, text, effect item class 37/200337/10
authorSukHyung, Kang <shine.kang@samsung.com>
Fri, 22 Feb 2019 00:35:28 +0000 (09:35 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Tue, 26 Feb 2019 01:21:14 +0000 (10:21 +0900)
Change-Id: If23d8c14ddf5916ebcb5ff5f21c0679ea7c54f74
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
13 files changed:
notification-ex/abstract_item.cc
notification-ex/abstract_item.h
notification-ex/abstract_item_implementation.h
notification-ex/entry_item.cc [new file with mode: 0644]
notification-ex/entry_item.h [new file with mode: 0644]
notification-ex/entry_item_implementation.h [moved from unittest/src/test_item.cc with 56% similarity]
notification-ex/item.h
notification-ex/item_factory.cc
notification-ex/text_item.cc [new file with mode: 0644]
notification-ex/text_item.h [new file with mode: 0644]
notification-ex/text_item_implementation.h [new file with mode: 0644]
unittest/src/test_entry_item.cc [new file with mode: 0644]
unittest/src/test_text_item.cc [new file with mode: 0644]

index e6195e4..c6397a2 100644 (file)
@@ -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
index f9fb084..dc5b32b 100644 (file)
@@ -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<LEDInfo> led);
   std::shared_ptr<LEDInfo> GetLEDInfo() const;
+  void SetSoundPath(std::string path);
+  void SetVibrationPath(std::string path);
+  std::string GetSoundPath() const;
+  std::string GetVibrationPath() const;
 
  private:
   class Impl;
index 64f25eb..8a030f0 100644 (file)
@@ -55,6 +55,8 @@ class AbstractItem::Impl {
   std::string can_receive_;
   std::shared_ptr<AbstractAction> 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 (file)
index 0000000..b3a1674
--- /dev/null
@@ -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 <dlog.h>
+
+#include <memory>
+
+#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<AbstractAction> action)
+  : AbstractItem(id, AbstractItem::Type::Entry), impl_(new Impl()) {
+}
+
+EntryItem::EntryItem(std::shared_ptr<AbstractAction> 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 (file)
index 0000000..f60287f
--- /dev/null
@@ -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 <memory>
+#include <string>
+
+#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<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  EntryItem(std::string id,
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  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> impl_;
+};  // class EntryItem
+
+}  // namespace item
+}  // nampace notification
+#endif  // NOTIFICATION_EX_ENTRY_ITEM_H_
\ No newline at end of file
similarity index 56%
rename from unittest/src/test_item.cc
rename to notification-ex/entry_item_implementation.h
index adb1c11..ecfe724 100644 (file)
  * limitations under the License.
  */
 
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#ifndef NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_
 
-#include "notification-ex/item.h"
+#include <string>
+#include <memory>
 
-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_
index a48054e..8582f41 100644 (file)
 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();
index 6d882f8..672bc98 100644 (file)
@@ -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<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
   case AbstractItem::NullObject :
     THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
   case AbstractItem::Text :
-    return make_shared<ButtonItem>("");
+    return make_shared<TextItem>("");
   case AbstractItem::Icon :
     return make_shared<ButtonItem>("");
   case AbstractItem::Image :
@@ -58,8 +60,8 @@ shared_ptr<AbstractItem> ItemFactory::CreateItem(AbstractItem::Type type) {
     return make_shared<InputSelectorItem>();
   case AbstractItem::Group :
     return make_shared<GroupItem>();
-  case AbstractItem::Effect :
-    return make_shared<ButtonItem>("");
+  case AbstractItem::Entry :
+    return make_shared<EntryItem>("");
   case AbstractItem::Progress :
     return make_shared<ProgressItem>(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 (file)
index 0000000..64b0773
--- /dev/null
@@ -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 <dlog.h>
+
+#include <memory>
+
+#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<AbstractAction> action)
+  : AbstractItem(AbstractItem::Type::Text), impl_(new Impl(text)) {
+}
+
+TextItem::TextItem(std::string id, std::string text,
+      std::shared_ptr<AbstractAction> 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 (file)
index 0000000..ccbf2fd
--- /dev/null
@@ -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 <memory>
+#include <string>
+
+#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<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  TextItem(std::string id, std::string text,
+      std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+  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> 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 (file)
index 0000000..3af64c2
--- /dev/null
@@ -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 <string>
+#include <memory>
+
+#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 (file)
index 0000000..b81d8f9
--- /dev/null
@@ -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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#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<EntryItem&>(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<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+  ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+  EntryItem* gen_effect = static_cast<EntryItem*>(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 (file)
index 0000000..9bef5f2
--- /dev/null
@@ -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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#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<TextItem&>(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<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+  ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+  TextItem* gen_text = static_cast<TextItem*>(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