return impl_->ongoing_;
}
+bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
+ int item_type = target.GetType();
+
+ switch (type) {
+ case MainTitle:
+ case MainContents:
+ if (item_type != Text)
+ return false;
+ break;
+ case MainIcon:
+ if (item_type != Image)
+ return false;
+ break;
+ case MainButton:
+ if (item_type != Button)
+ return false;
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+}
+
bool AbstractItem::SetMainType(std::string target_id, MainType type) {
AbstractItem& target = FindByID(target_id);
if (target.GetType() == NullObject)
return false;
+ if (!impl_->IsValidMainType(target,type)) {
+ LOGE("Main type and item type are not matched (%d, %d)",
+ type, target.GetType());
+ return false;
+ }
+
AbstractItem& old = FindByMainType(type);
if (target.GetType() != NullObject)
old.impl_->main_type_ = MainNone;
std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
Impl(AbstractItem* parent, std::string id,
std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ bool IsValidMainType(AbstractItem& target, MainType type);
private:
friend class AbstractItem;
EXPECT_EQ(i.GetId(), "test_id");
}
+TEST_F(AbstractItemTest, SetInvalidMainType) {
+ auto root = std::make_shared<GroupItem>("test_group");
+ auto item = std::make_shared<ButtonItem>("test_id", "title");
+ root->AddChild(item);
+
+ bool ret = root->SetMainType("test_id", AbstractItem::MainTitle);
+ EXPECT_FALSE(ret);
+}
+
} // namespace
\ No newline at end of file