Add is_type_exist function to an abstract item 25/209125/4
authorhyunho <hhstark.kang@samsung.com>
Tue, 2 Jul 2019 10:27:20 +0000 (19:27 +0900)
committerhyunho <hhstark.kang@samsung.com>
Wed, 3 Jul 2019 04:26:06 +0000 (13:26 +0900)
Change-Id: I492fad061a0d804906cd4fb008e5a81c62fd3bb1
Signed-off-by: hyunho <hhstark.kang@samsung.com>
27 files changed:
notification-ex/abstract_item.h
notification-ex/button_item.cc
notification-ex/button_item.h
notification-ex/chat_message_item.cc
notification-ex/chat_message_item.h
notification-ex/checkbox_item.cc
notification-ex/checkbox_item.h
notification-ex/entry_item.cc
notification-ex/entry_item.h
notification-ex/group_item.cc
notification-ex/group_item.h
notification-ex/icon_text_item.cc
notification-ex/icon_text_item.h
notification-ex/image_item.cc
notification-ex/image_item.h
notification-ex/input_selector_item.cc
notification-ex/input_selector_item.h
notification-ex/null_item.cc
notification-ex/null_item.h
notification-ex/progress_item.cc
notification-ex/progress_item.h
notification-ex/text_item.cc
notification-ex/text_item.h
notification-ex/time_item.cc
notification-ex/time_item.h
unittest/src/test_abstract_item.cc
unittest/src/test_group_item.cc

index ccb9d62..4a9f3b7 100644 (file)
@@ -776,6 +776,14 @@ class EXPORT_API AbstractItem {
   virtual AbstractItem& FindByID(std::string id) = 0;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  virtual bool IsItemTypeExist(int type) = 0;
+
+  /**
    * @brief Gets the type of notification item.
    * @since_tizen 5.5
    * @return The type of notification item
index 0c862ab..1535914 100644 (file)
@@ -72,6 +72,12 @@ AbstractItem& ButtonItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool ButtonItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 std::string ButtonItem::GetTitle() const {
   return impl_->title_;
 }
index 4e11722..d489208 100644 (file)
@@ -83,6 +83,14 @@ class EXPORT_API ButtonItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of ButtonItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::Button
index ae02fd7..bad7938 100644 (file)
@@ -131,6 +131,12 @@ AbstractItem&  ChatMessageItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool ChatMessageItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 TextItem& ChatMessageItem::GetNameItem() const {
   return *(impl_->name_);
 }
index bae99b7..95f4c9c 100644 (file)
@@ -96,6 +96,14 @@ class EXPORT_API ChatMessageItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the path of shared file location.
    * @since_tizen 5.5
    * @return The list of shared path.
index ed5e99a..a67dce0 100644 (file)
@@ -70,6 +70,12 @@ AbstractItem& CheckBoxItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool CheckBoxItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 std::string CheckBoxItem::GetTitle(void) const {
   return impl_->title_;
 }
index fa1d20a..b59fa04 100644 (file)
@@ -73,6 +73,14 @@ class EXPORT_API CheckBoxItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of CheckBoxItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::CheckBox
index 9b0bdc6..de242cb 100644 (file)
@@ -77,6 +77,12 @@ AbstractItem& EntryItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool EntryItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 std::string EntryItem::GetText() const {
   return impl_->text_;
 }
index 6bc04a3..23bb400 100644 (file)
@@ -81,6 +81,14 @@ class EXPORT_API EntryItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of EntryItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::Entry
index 4ead0d9..dbe1b2f 100644 (file)
@@ -118,6 +118,17 @@ AbstractItem& GroupItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool GroupItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+
+  for (auto& i : impl_->children_list_) {
+    if (i.get()->IsItemTypeExist(type))
+      return true;
+  }
+  return false;
+}
+
 list<string> GroupItem::GetSharedPath() const {
   list<string> ret;
 
index fe93cd0..5b34979 100644 (file)
@@ -79,6 +79,14 @@ class EXPORT_API GroupItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of GroupItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::Group
index 9718d4e..9173c40 100644 (file)
@@ -79,6 +79,12 @@ AbstractItem& IconTextItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool IconTextItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 IconItem& IconTextItem::GetIconItem() const {
   return *(impl_->icon_);
 }
index 9225ad9..afe6197 100644 (file)
@@ -76,6 +76,14 @@ class EXPORT_API IconTextItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of IconTextItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::IconText
index 07fd987..21689f3 100644 (file)
@@ -70,6 +70,12 @@ AbstractItem& ImageItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool ImageItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 std::string ImageItem::GetImagePath() const {
   return impl_->image_path_;
 }
index 0ac43e3..3e7a9e8 100644 (file)
@@ -88,6 +88,14 @@ class EXPORT_API ImageItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the path of image.
    * @since_tizen 5.5
    * @return The path of image
index f8ea926..2aaa1f5 100644 (file)
@@ -78,6 +78,12 @@ AbstractItem& InputSelectorItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool InputSelectorItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 list<string> InputSelectorItem::GetContents() const {
   return impl_->contents_;
 }
index f769be9..90c673c 100644 (file)
@@ -79,6 +79,14 @@ class EXPORT_API InputSelectorItem : public AbstractItem {
   virtual AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of InputSelectorItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::InputSelector
index 3c0f7f8..0c3e867 100644 (file)
@@ -58,5 +58,11 @@ AbstractItem& NullItem::FindByID(std::string id) {
   return *this;
 }
 
+bool NullItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 }  // namespace item
 }  // namespace notification
index fe5927b..75b0421 100644 (file)
@@ -77,6 +77,14 @@ class EXPORT_API NullItem : public AbstractItem {
   void Deserialize(Bundle b) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Finds the AbstractItem using by notification item id.
    * @since_tizen 5.5
    * @param[in] id notification item id
index 3a0c6b2..c06d0ed 100644 (file)
@@ -93,6 +93,12 @@ AbstractItem& ProgressItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool ProgressItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 float ProgressItem::GetCurrent() const {
   return impl_->current_;
 }
index 8aefcc6..a83e6d0 100644 (file)
@@ -93,6 +93,14 @@ class EXPORT_API ProgressItem : public AbstractItem {
   virtual AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the type of ProgressItem.
    * @since_tizen 5.5
    * @return AbstractItem::Type::Progress
index 075df87..01fe1d2 100644 (file)
@@ -74,6 +74,12 @@ AbstractItem& TextItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool TextItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 void TextItem::SetContents(std::string contents) {
   impl_->text_ = contents;
 }
index 4ac8731..8f1681e 100644 (file)
@@ -85,6 +85,14 @@ class EXPORT_API TextItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Sets the contents of TextItem.
    * @since_tizen 5.5
    * @return The text contents
index 719eb50..e22d543 100644 (file)
@@ -93,6 +93,12 @@ AbstractItem& TimeItem::FindByID(std::string id) {
   return FactoryManager::GetInst().GetNullItem();
 }
 
+bool TimeItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+  return false;
+}
+
 time_t TimeItem::GetTime() const {
   return impl_->time_;
 }
index 4291344..afbcc78 100644 (file)
@@ -98,6 +98,14 @@ class EXPORT_API TimeItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override;
 
   /**
+   * @brief Checks the item type exist in this notification.
+   * @since_tizen 5.5
+   * @param[in] type notification item type
+   * @return true if the item type exists
+   */
+  bool IsItemTypeExist(int type) override;
+
+  /**
    * @brief Gets the time state of TimeItem.
    * @since_tizen 5.5
    * @return The time state of TimeItem.
index 784b8df..3a205c3 100644 (file)
@@ -52,6 +52,11 @@ class TestItem : public AbstractItem {
   AbstractItem& FindByID(std::string id) override {
     return *this;
   }
+  bool IsItemTypeExist(int type) {
+  if (GetType() == type)
+      return true;
+    return false;
+  }
   int GetType() const override {
     return MY_ITEM_TYPE;
   }
index 1e6817c..ee54af9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "notification-ex/group_item.h"
 #include "notification-ex/button_item.h"
+#include "notification-ex/text_item.h"
 #include "notification-ex/item_inflator.h"
 #include "unittest/mock/app_common.h"
 
@@ -99,6 +100,27 @@ TEST_F(GroupItemTest, FindByIDGroupItem) {
   ASSERT_EQ(ret_gr.GetChildren().size(), 1);
 }
 
+
+TEST_F(GroupItemTest, IsItemTypeExist) {
+  GroupItem item("GROUP1");
+  shared_ptr<GroupItem> gr2 = shared_ptr<GroupItem>(new GroupItem("GROUP2"));
+  shared_ptr<GroupItem> gr3 = shared_ptr<GroupItem>(new GroupItem("GROUP3"));
+  gr2->AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
+  gr2->AddChild(std::make_shared<ButtonItem>("btn3", "test3"));
+  gr2->AddChild(std::make_shared<ButtonItem>("btn4", "test4"));
+  gr3->AddChild(std::make_shared<ButtonItem>("btn6", "test6"));
+  gr3->AddChild(std::make_shared<TextItem>("text1", "text1"));
+  gr2->AddChild(gr3);
+
+  item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
+  item.AddChild(gr2);
+  item.AddChild(std::make_shared<ButtonItem>("btn5", "test5"));
+  ASSERT_EQ(item.GetChildren().size(), 3);
+
+  ASSERT_EQ(item.IsItemTypeExist(AbstractItem::Text), true);
+  ASSERT_EQ(item.IsItemTypeExist(AbstractItem::Image), false);
+}
+
 TEST_F(GroupItemTest, FindByIDNullItemReturn) {
   GroupItem item("GROUP1");
   item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));