#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 {
: 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");
}
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;
}
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) {
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
virtual ~ProgressItem();
public:
+ enum Type {
+ Default,
+ Time,
+ Percent,
+ Pending,
+ };
+
/**
* @brief Serialize the data of ProgressItem.
* @since_tizen 5.5
*/
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_;
float current_;
float max_;
ProgressItem* parent_;
+ Type type_;
+ std::string unit_;
};
} // namespace item
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