--- /dev/null
+/*
+ * 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 <vector>
+#include <algorithm>
+
+#include "notification-ex/input_selector_item.h"
+#include "notification-ex/input_selector_item_implementation.h"
+#include "notification-ex/item_factory.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define INPUT_SELECTOR_CONTENTS_KEY "__INPUT_SELECTOR_CONTENTS_KEY__"
+
+using namespace std;
+namespace notification {
+namespace item {
+
+InputSelectorItem::InputSelectorItem(std::shared_ptr<AbstractAction> action)
+ : AbstractItem(AbstractItem::InputSelector, action), impl_(new Impl(this)) {
+}
+
+InputSelectorItem::InputSelectorItem(string id, std::shared_ptr<AbstractAction> action)
+ : AbstractItem(id, AbstractItem::InputSelector, action), impl_(new Impl(this)) {
+}
+
+InputSelectorItem::~InputSelectorItem() = default;
+InputSelectorItem::Impl::~Impl() = default;
+
+InputSelectorItem::Impl::Impl(InputSelectorItem* parent)
+ : parent_(parent) {
+ LOGI("InputSelectorItem impl created");
+}
+
+Bundle InputSelectorItem::Serialize() {
+ Bundle b;
+ b = AbstractItem::Serialize();
+ vector<string> contents_vector {
+ begin(impl_->contents_),
+ end(impl_->contents_)
+ };
+ b.Add(INPUT_SELECTOR_CONTENTS_KEY, contents_vector);
+ return b;
+}
+
+void InputSelectorItem::Deserialize(Bundle b) {
+ AbstractItem::Deserialize(b);
+ vector<string> contents = b.GetStringArray(INPUT_SELECTOR_CONTENTS_KEY);
+ impl_->contents_ = list<string>(contents.begin(), contents.end());
+}
+
+AbstractItem& InputSelectorItem::FindByID(std::string id) {
+ if (GetId() == id)
+ return *this;
+ return ItemFactory::GetNullItem();
+}
+
+list<string> InputSelectorItem::GetContents() const {
+ return impl_->contents_;
+}
+
+void InputSelectorItem::SetContents(list<string> contents) {
+ impl_->contents_ = move(contents);
+}
+
+} // namespace item
+} // namespace notification
--- /dev/null
+/*
+ * 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_INPUT_SELECTOR_ITEM_H_
+#define NOTIFICATION_EX_INPUT_SELECTOR_ITEM_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/abstract_item.h"
+
+namespace notification {
+namespace item {
+
+class EXPORT_API InputSelectorItem : public AbstractItem {
+ public:
+ InputSelectorItem(std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ InputSelectorItem(std::string id,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ virtual ~InputSelectorItem();
+
+ public:
+ virtual Bundle Serialize() override;
+ virtual void Deserialize(Bundle b) override;
+ virtual AbstractItem& FindByID(std::string id) override;
+
+ std::list<std::string> GetContents() const;
+ void SetContents(std::list<std::string> contents);
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_INPUT_SELECTOR_ITEM_H_
--- /dev/null
+/*
+ * 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_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/input_selector_item.h"
+
+namespace notification {
+namespace item {
+
+class InputSelectorItem::Impl {
+ public:
+ virtual ~Impl();
+
+ private:
+ Impl(InputSelectorItem* parent);
+
+ private:
+ friend class InputSelectorItem;
+
+ std::list<std::string> contents_;
+ InputSelectorItem* parent_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_INPUT_SELECTOR_ITEM_IMPLEMENTATION_H_
Type GetType() const;
}; // class ChatMessageItem
-class EXPORT_API InputSelectorItem : public AbstractItem {
- public:
- InputSelectorItem();
- virtual ~InputSelectorItem();
-
- Bundle Serialize() override;
- void Deserialize(Bundle b) override;
- AbstractItem& FindByID(std::string id) override;
- std::list<std::string> GetContents() const;
- void SetContents(std::list<std::string> contents);
-
- private:
- std::list<std::string> contents_;
-}; // class InputSelectorItem
-
class EXPORT_API EntryItem : public AbstractItem {
public:
EntryItem();
#include "notification-ex/group_item.h"
#include "notification-ex/null_item.h"
#include "notification-ex/exception.h"
+#include "notification-ex/input_selector_item.h"
#ifdef LOG_TAG
#undef LOG_TAG
case AbstractItem::IconText :
return make_shared<ButtonItem>("");
case AbstractItem::InputSelector :
- return make_shared<ButtonItem>("");
+ return make_shared<InputSelectorItem>();
case AbstractItem::Group :
return make_shared<GroupItem>();
case AbstractItem::Effect :
return nullptr;
}
+
AbstractItem& ItemFactory::GetNullItem() {
static NullItem item;
return item;
#ifdef __cplusplus
#define FFF_EXTERN_C extern "C"{
- #define FFF_END_EXTERN_C }
+ #define FFF_END_EXTERN_C }
#else /* ansi c */
- #define FFF_EXTERN_C
- #define FFF_END_EXTERN_C
+ #define FFF_EXTERN_C
+ #define FFF_END_EXTERN_C
#endif /* cpp/ansi c */
#define DEFINE_RESET_FUNCTION(FUNCNAME) \
/* -- END INTERNAL HELPER MACROS -- */
typedef void (*fff_function_t)(void);
-typedef struct {
+typedef struct {
fff_function_t call_history[FFF_CALL_HISTORY_LEN];
unsigned int call_history_idx;
} fff_globals_t;
--- /dev/null
+// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <gmock/gmock.h>
+
+#include "notification-ex/input_selector_item.h"
+#include "notification-ex/item_inflator.h"
+
+using namespace notification::item;
+using namespace std;
+
+namespace {
+
+class InputSelectorItemTest : public ::testing::Test {
+ protected:
+ void SetUp() override {}
+ void TearDown() override {}
+};
+
+TEST_F(InputSelectorItemTest, SerializeDeserialize) {
+ InputSelectorItem item;
+ list<string> contents;
+ contents.push_back("AA");
+ contents.push_back("BB");
+ contents.push_back("CC");
+ item.SetContents(contents);
+
+ Bundle b = item.Serialize();
+ ItemFactory factory;
+ shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+ InputSelectorItem* gen_input = static_cast<InputSelectorItem*>(gen_item.get());
+
+ list<string> l1 = item.GetContents();
+ list<string> l2 = gen_input->GetContents();
+ list<string>::iterator it1 = l1.begin();
+ list<string>::iterator it2 = l2.begin();
+ while(it1 != l1.end() && it2 != l2.end()) {
+ ASSERT_EQ((*it1), (*it2));
+ it1++;
+ it2++;
+ }
+}
+
+} // namespace