Add Progress type 15/207715/6
authorSukHyung, Kang <shine.kang@samsung.com>
Tue, 11 Jun 2019 09:21:27 +0000 (18:21 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Fri, 28 Jun 2019 00:37:35 +0000 (09:37 +0900)
Change-Id: I43eedafb929ab40174d370748632767c83211775
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
notification-ex/progress_item.cc
notification-ex/progress_item.h
notification-ex/progress_item_implementation.h
unittest/src/test_progress_item.cc

index a697d57..3a0c6b2 100644 (file)
@@ -31,6 +31,8 @@
 #define PROGRESS_MIN_KEY "__PROGRESS_MIN_KEY__"
 #define PROGRESS_CURRENT_KEY "__PROGRESS_CURRENT_KEY__"
 #define PROGRESS_MAX_KEY "__PROGRESS_MAX_KEY__"
+#define PROGRESS_TYPE_KEY "__PROGRESS_TYPE_KEY__"
+#define PROGRESS_UNIT_KEY "__PROGRESS_UNIT_KEY__"
 
 using namespace std;
 namespace notification {
@@ -56,6 +58,8 @@ ProgressItem::Impl::Impl(float min_val, float current, float max_val,
     : min_(min_val), current_(current), max_(max_val), parent_(parent) {
   if (min_val > current || max_val < current)
     THROW(ERROR_INVALID_PARAMETER);
+
+  type_ = ProgressItem::Type::Default;
   LOGI("ProgressItem impl created");
 }
 
@@ -69,6 +73,8 @@ Bundle ProgressItem::Serialize() const {
   b.Add(PROGRESS_MIN_KEY, to_string(impl_->min_));
   b.Add(PROGRESS_CURRENT_KEY, to_string(impl_->current_));
   b.Add(PROGRESS_MAX_KEY, to_string(impl_->max_));
+  b.Add(PROGRESS_TYPE_KEY, to_string(static_cast<int>(impl_->type_)));
+  b.Add(PROGRESS_UNIT_KEY, impl_->unit_);
   return b;
 }
 
@@ -77,6 +83,8 @@ void ProgressItem::Deserialize(Bundle b) {
   impl_->min_ = strtof(b.GetString(PROGRESS_MIN_KEY).c_str(), 0);
   impl_->current_ = strtof(b.GetString(PROGRESS_CURRENT_KEY).c_str(), 0);
   impl_->max_ = strtof(b.GetString(PROGRESS_MAX_KEY).c_str(), 0);
+  impl_->type_ = static_cast<Type>(std::stoi(b.GetString(PROGRESS_TYPE_KEY)));
+  impl_->unit_ = b.GetString(PROGRESS_UNIT_KEY);
 }
 
 AbstractItem& ProgressItem::FindByID(std::string id) {
@@ -101,5 +109,22 @@ float ProgressItem::GetMax() const {
   return impl_->max_;
 }
 
+void ProgressItem::SetProgressType(ProgressItem::Type type) {
+  impl_->type_ = type;
+}
+
+ProgressItem::Type ProgressItem::GetProgressType() const {
+  return impl_->type_;
+}
+
+void ProgressItem::SetDefaultUnit(std::string unit)
+{
+  impl_->unit_ = unit;
+}
+
+std::string ProgressItem::GetDefaultUnit() const {
+  return impl_->unit_;
+}
+
 }  // namespace item
 }  // namespace notification
index 533b322..8aefcc6 100644 (file)
@@ -63,6 +63,13 @@ class EXPORT_API ProgressItem : public AbstractItem {
   virtual ~ProgressItem();
 
  public:
+  enum Type {
+    Default,
+    Time,
+    Percent,
+    Pending,
+  };
+
   /**
    * @brief Serialize the data of ProgressItem.
    * @since_tizen 5.5
@@ -120,6 +127,36 @@ class EXPORT_API ProgressItem : public AbstractItem {
    */
   float GetMax() const;
 
+  /**
+   * @brief Sets the type of progress.
+   * @since_tizen 5.5
+   * @param[in] type The type of progress
+   */
+  void SetProgressType(ProgressItem::Type type);
+
+  /**
+   * @brief Gets the type of progress.
+   * @since_tizen 5.5
+   * @return The type of progress
+   */
+  Type GetProgressType() const;
+
+   /**
+   * @brief Sets the default unit of progress.
+   * @details the unit is valid when the progress type is default.
+   * @since_tizen 5.5
+   * @param[in] unit The unit of progress
+   */
+  void SetDefaultUnit(std::string unit);
+
+  /**
+   * @brief Gets the default unit of progress.
+   * @details the unit is valid when the progress type is default.
+   * @since_tizen 5.5
+   * @return The type of progress
+   */
+  std::string GetDefaultUnit() const;
+
  private:
   class Impl;
   std::unique_ptr<Impl> impl_;
index 865e96f..24040be 100644 (file)
@@ -43,6 +43,8 @@ class ProgressItem::Impl {
   float current_;
   float max_;
   ProgressItem* parent_;
+  Type type_;
+  std::string unit_;
 };
 
 }  // namespace item
index 6f3d5f8..c4b115d 100644 (file)
@@ -21,18 +21,38 @@ class ProgressItemTest : public ::testing::Test {
 
 TEST_F(ProgressItemTest, SerializeDeserializeGetTitle) {
   ProgressItem item(1.0, 10.0, 100.0);
+  item.SetDefaultUnit("byte");
   Bundle b = item.Serialize();
   shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
-  ASSERT_EQ(gen_item->GetType(), item.GetType());
 
   auto gen_progress = std::static_pointer_cast<ProgressItem>(gen_item);
   ASSERT_EQ(item.GetCurrent(), gen_progress->GetCurrent());
   ASSERT_EQ(item.GetMin(), gen_progress->GetMin());
   ASSERT_EQ(item.GetMax(), gen_progress->GetMax());
+  ASSERT_EQ(item.GetType(), gen_progress->GetType());
+  ASSERT_EQ(item.GetDefaultUnit(), gen_progress->GetDefaultUnit());
 
   ASSERT_EQ(gen_progress->GetMin(), 1.0);
   ASSERT_EQ(gen_progress->GetCurrent(), 10.0);
   ASSERT_EQ(gen_progress->GetMax(), 100.0);
+  ASSERT_EQ(gen_progress->GetProgressType(), ProgressItem::Type::Default);
+  ASSERT_EQ(gen_progress->GetDefaultUnit(), "byte");
+}
+
+TEST_F(ProgressItemTest, SetGetProgressType) {
+  ProgressItem item(1.0, 10.0, 100.0);
+
+  ASSERT_EQ(item.GetProgressType(), ProgressItem::Type::Default);
+
+  item.SetProgressType(ProgressItem::Type::Pending);
+  ASSERT_EQ(item.GetProgressType(), ProgressItem::Type::Pending);
+}
+
+TEST_F(ProgressItemTest, SetGetUnit) {
+  ProgressItem item(1.0, 10.0, 100.0);
+  item.SetDefaultUnit("byte");
+
+  ASSERT_EQ(item.GetDefaultUnit(), "byte");
 }
 
 }  // namespace