From: mk5004.lee Date: Mon, 4 Mar 2019 09:37:42 +0000 (+0900) Subject: Update actions X-Git-Tag: submit/tizen/20190326.074206~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a631bd5c03571dbdb68e9ed9d05ade92f3b1989;p=platform%2Fcore%2Fapi%2Fnotification.git Update actions - AbstractAction, AppControlAction, VisibilityAction Change-Id: Iaf5b09526956a0ed8ec512ec428e8fdb7530a0da Signed-off-by: mk5004.lee --- diff --git a/notification-ex/abstract_action.cc b/notification-ex/abstract_action.cc new file mode 100644 index 00000000..f6aa0f89 --- /dev/null +++ b/notification-ex/abstract_action.cc @@ -0,0 +1,79 @@ +/* + * 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 + +#include "notification-ex/abstract_action.h" +#include "notification-ex/abstract_action_implementation.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define ABSTRACT_ACTION_IS_LOCAL_KEY "__ABSTRACT_ACTION_IS_LOCAL_KEY__" +#define ABSTRACT_ACTION_EXTRA_KEY "__ABSTRACT_ACTION_EXTRA_KEY__" + +namespace notification { +namespace item { +AbstractAction::AbstractAction(bool isLocal) + : impl_(new Impl(this, isLocal)) { +} + +AbstractAction::AbstractAction(bool isLocal, std::string extra) + : impl_(new Impl(this, isLocal, extra)) { +} + +AbstractAction::Impl::Impl(AbstractAction* parent, bool isLocal) + : parent_(parent) , isLocal_(isLocal) { + LOGI("Action created"); +} + +AbstractAction::Impl::Impl(AbstractAction* parent, bool isLocal, std::string extra) + : parent_(parent) , isLocal_(isLocal), extra_(extra) { + LOGI("Action created"); +} + +AbstractAction::~AbstractAction() = default; +AbstractAction::Impl::~Impl() = default; + +Bundle AbstractAction::Serialize() { + Bundle b; + + b.Add(ABSTRACT_ACTION_IS_LOCAL_KEY, std::to_string(impl_->isLocal_)); + if (!impl_->extra_.empty()) + b.Add(ABSTRACT_ACTION_EXTRA_KEY ,impl_->extra_); + return b; +} + +void AbstractAction::Deserialize(Bundle b) { + impl_->isLocal_ = std::stoi(b.GetString(ABSTRACT_ACTION_IS_LOCAL_KEY)); + impl_->extra_ = b.GetString(ABSTRACT_ACTION_EXTRA_KEY); +} + +bool AbstractAction::IsLocal() const { + return impl_->isLocal_; +} + +void AbstractAction::Execute(std::shared_ptr item) { +} + +std::string AbstractAction::GetExtra() const { + return impl_->extra_; +} + +} // namespace item +} // namespace notification diff --git a/notification-ex/abstract_action.h b/notification-ex/abstract_action.h index b9ea3120..8a2d9aef 100644 --- a/notification-ex/abstract_action.h +++ b/notification-ex/abstract_action.h @@ -17,8 +17,6 @@ #ifndef NOTIFICATION_EX_ABSTRACT_ACTION_H_ #define NOTIFICATION_EX_ABSTRACT_ACTION_H_ -#include - #include #include @@ -34,11 +32,19 @@ namespace item { class AbstractItem; class EXPORT_API AbstractAction { public: - virtual bool IsLocal() const = 0; - virtual void Execute(std::shared_ptr item) = 0; + AbstractAction(bool isLocal); + AbstractAction(bool isLocal, std::string extra); + virtual ~AbstractAction(); + virtual Bundle Serialize() = 0; virtual void Deserialize(Bundle b) = 0; + virtual bool IsLocal() const = 0; + virtual void Execute(std::shared_ptr item) = 0; virtual std::string GetExtra() const = 0; + + private: + class Impl; + std::unique_ptr impl_; }; } // namespace item diff --git a/notification-ex/abstract_action_implementation.h b/notification-ex/abstract_action_implementation.h new file mode 100644 index 00000000..cb60c459 --- /dev/null +++ b/notification-ex/abstract_action_implementation.h @@ -0,0 +1,47 @@ +/* + * 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_ABSTRACT_ACTION_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_ABSTRACT_ACTION_IMPLEMENTATION_H_ + +#include +#include + +#include "notification-ex/abstract_action.h" + +namespace notification { +namespace item { + +class AbstractAction::Impl { + public: + virtual ~Impl(); + + private: + friend class AbstractAction; + Impl(AbstractAction* parent, bool isLocal); + Impl(AbstractAction* parent, bool isLocal, std::string extra); + + private: + AbstractAction* parent_; + + bool isLocal_ = true; + std::string extra_; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_ABSTRACT_ACTION_IMPLEMENTATION_H_ diff --git a/notification-ex/action.cc b/notification-ex/action.cc deleted file mode 100644 index 4866dd30..00000000 --- a/notification-ex/action.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 -#include - -#include "notification-ex/action.h" -#include "notification-ex/ex_bundle.h" -#include "notification-ex/exception.h" - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "NOTIFICATION_EX" - -namespace notification { -namespace item { - -AppControlAction::AppControlAction(app_control_h control) - : control_(control) { -} - -AppControlAction::~AppControlAction() { -} - -ReplyAction::ReplyAction() { -} - -ReplyAction::~ReplyAction() { -} - -VisibilityAction::VisibilityAction() { -} - -VisibilityAction::~VisibilityAction() { -} - - -} //namespace item -} //namespace notification diff --git a/notification-ex/action.h b/notification-ex/action.h deleted file mode 100644 index 5b9c3870..00000000 --- a/notification-ex/action.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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_ACTION_H_ -#define NOTIFICATION_EX_ACTION_H_ - -#include - -#include -#include - -#include "notification-ex/abstract_action.h" -#include "notification-ex/ex_bundle.h" - -namespace notification { -namespace item { - -class EXPORT_API AppControlAction : public AbstractAction { - public: - explicit AppControlAction(app_control_h control); - virtual ~AppControlAction(); - - bool IsLocal() const override { - return true; - } - - void Execute(std::shared_ptr item) override { - } - - Bundle Serialize() override { - Bundle b; - return b; - } - - void Deserialize(Bundle b) override { - } - - void SetAppControl(app_control_h control) { - } - - app_control_h GetAppControl() const { - return control_; - } - - private: - app_control_h control_ = nullptr; -}; - -class EXPORT_API ReplyAction : public AbstractAction { - public: - ReplyAction(); - virtual ~ReplyAction(); - - bool IsLocal() const override { - return true; - } - - void Execute(std::shared_ptr item) override { - } - - Bundle Serialize() override { - Bundle b; - return b; - } - - void Deserialize(Bundle b) override { - } -}; - -class EXPORT_API VisibilityAction : public AbstractAction { - public: - VisibilityAction(); - virtual ~VisibilityAction(); - - bool IsLocal() const override { - return true; - } - - void Execute(std::shared_ptr item) override { - } - - Bundle Serialize() override { - Bundle b; - return b; - } - - void Deserialize(Bundle b) override { - } - - void SetVisibility(std::string id, bool visible) { - id_ = id; - visible_ = visible; - } - - private: - std::string id_; - bool visible_ = false; -}; - -} // namespace item -} // namespace notification - -#endif // NOTIFICATION_EX_ACTION_H_ diff --git a/notification-ex/app_control_action.cc b/notification-ex/app_control_action.cc new file mode 100644 index 00000000..5930f523 --- /dev/null +++ b/notification-ex/app_control_action.cc @@ -0,0 +1,143 @@ +/* + * 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 +#include + +#include "notification-ex/app_control_action.h" +#include "notification-ex/app_control_action_implementation.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define APPCONTROL_ACTION_KEY "__APPCONTROL_ACTION_KEY__" + +namespace notification { +namespace item { + +AppControlAction::AppControlAction(app_control_h app_control) + : AbstractAction(true), impl_(new Impl(this)) { + app_control_h control_; + app_control_clone(&control_, app_control); + impl_->control_ = control_; +} + +AppControlAction::AppControlAction(app_control_h app_control, std::string extra) + : AbstractAction(true, extra), impl_(new Impl(this)) { + app_control_h control_; + app_control_clone(&control_, app_control); + impl_->control_ = control_; +} + +AppControlAction::Impl::Impl(AppControlAction* parent) + : parent_(parent) { + LOGI("AppControlAction created"); +} + +AppControlAction::~AppControlAction() = default; +AppControlAction::Impl::~Impl() { + if (control_) + app_control_destroy(control_); +} + +Bundle AppControlAction::Serialize() { + Bundle b; + bundle* control_b = NULL; + bundle_raw* control_raw; + int len = 0; + + app_control_export_as_bundle(impl_->control_, &control_b); + if (control_b == NULL) { + LOGE("failed to get bundle from app_control"); + return nullptr; + } + + bundle_encode(control_b, &control_raw, &len); + if (len <= 0) { + LOGE("bundle encode failed"); + return nullptr; + } + + b = AbstractAction::Serialize(); + b.Add(APPCONTROL_ACTION_KEY, + std::string(reinterpret_cast(control_raw))); + + bundle_free(control_b); + free(control_raw); + return b; +} + +void AppControlAction::Deserialize(Bundle b) { + app_control_h app_control = nullptr; + bundle* b_ = nullptr; + std::string control_str; + + AbstractAction::Deserialize(b); + + control_str = b.GetString(APPCONTROL_ACTION_KEY); + + b_ = bundle_decode((bundle_raw*)control_str.c_str(), control_str.length()); + if (b_ == nullptr) { + LOGE("bundle_decode failed"); + return; + } + + app_control_create(&app_control); + if (app_control == nullptr) { + LOGE("failed to create app_control"); + return; + } + + app_control_import_from_bundle(app_control, b_); + if (app_control == nullptr) { + LOGE("failed to make app_control from bundle"); + return; + } + + impl_->control_ = app_control; +} + +bool AppControlAction::IsLocal() const { + return AbstractAction::IsLocal(); +} + +void AppControlAction::Execute(std::shared_ptr item) { + app_control_send_launch_request(impl_->control_, NULL, NULL); +} + +std::string AppControlAction::GetExtra() const { + return AbstractAction::GetExtra(); +} + +void AppControlAction::SetAppControl(app_control_h app_control) { + if (impl_->control_ != nullptr) + app_control_destroy(impl_->control_); + + app_control_h control_; + app_control_clone(&control_, app_control); + + impl_->control_ = control_; +} + +app_control_h AppControlAction::GetAppControl() const { + return impl_->control_; +} + +} //namespace item +} //namespace notification diff --git a/notification-ex/app_control_action.h b/notification-ex/app_control_action.h new file mode 100644 index 00000000..3a614b73 --- /dev/null +++ b/notification-ex/app_control_action.h @@ -0,0 +1,50 @@ +/* + * 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_APP_CONTROL_ACTION_H_ +#define NOTIFICATION_EX_APP_CONTROL_ACTION_H_ + +#include + +#include "notification-ex/abstract_action.h" + +namespace notification { +namespace item { + +class EXPORT_API AppControlAction : public AbstractAction { + public: + AppControlAction(app_control_h app_control); + AppControlAction(app_control_h app_control, std::string extra); + virtual ~AppControlAction(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + bool IsLocal() const override; + void Execute(std::shared_ptr item) override; + std::string GetExtra() const override; + void SetAppControl(app_control_h app_control); + app_control_h GetAppControl() const; + + private: + class Impl; + std::unique_ptr impl_; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_APP_CONTROL_ACTION_H_ + diff --git a/notification-ex/app_control_action_implementation.h b/notification-ex/app_control_action_implementation.h new file mode 100644 index 00000000..36c25b51 --- /dev/null +++ b/notification-ex/app_control_action_implementation.h @@ -0,0 +1,43 @@ +/* + * 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_APP_CONTROL_ACTION_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_APP_CONTROL_ACTION_IMPLEMENTATION_H_ + +#include "notification-ex/app_control_action.h" + +namespace notification { +namespace item { + +class AppControlAction::Impl { + public: + virtual ~Impl(); + + private: + friend class AppControlAction; + Impl(AppControlAction* parent); + + private: + AppControlAction* parent_; + + app_control_h control_ = nullptr; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_APP_CONTROL_ACTION_IMPLEMENTATION_H_ + diff --git a/notification-ex/visibility_action.cc b/notification-ex/visibility_action.cc new file mode 100644 index 00000000..3a8b3dff --- /dev/null +++ b/notification-ex/visibility_action.cc @@ -0,0 +1,131 @@ +/* + * 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 "notification-ex/abstract_item.h" +#include "notification-ex/visibility_action.h" +#include "notification-ex/visibility_action_implementation.h" +#include "notification-ex/exception.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" +#define VISIBILITY_ACTION_ENTITY_KEY "__VISIBILITY_ACTION_VISIBLE_KEY__" +#define VISIBILITY_ACTION_ENTITY_SIZE_KEY "__VISIBILITY_ACTION_ENTITY_SIZE_KEY__" + +namespace notification { +namespace item { + +VisibilityAction::VisibilityAction() + : AbstractAction(true), impl_(new Impl(this)) { +} + +VisibilityAction::VisibilityAction(std::string extra) + : AbstractAction(true, extra), impl_(new Impl(this)) { +} + +VisibilityAction::Impl::Impl(VisibilityAction* parent) + : parent_(parent) { + LOGI("VisibilityAction created"); +} + +VisibilityAction::~VisibilityAction() = default; +VisibilityAction::Impl::~Impl() = default; + +Bundle VisibilityAction::Serialize() { + char buf_key[128]; + char buf_data[128]; + Bundle b; + int i = 0; + + b = AbstractAction::Serialize(); + + std::list>::iterator it; + + for (it = impl_->entities_.begin(); it != impl_->entities_.end(); it++) { + buf_key[0] = '\0'; + buf_data[0] = '\0'; + + snprintf(buf_key, sizeof(buf_key), "%s:%d", + VISIBILITY_ACTION_ENTITY_SIZE_KEY, i); + + snprintf(buf_data, sizeof(buf_data), "%s:%d", + (*it)->id_.c_str(), (*it)->visibility_); + + b.Add(std::string(buf_key), std::string(buf_data)); + i++; + } + + b.Add(VISIBILITY_ACTION_ENTITY_SIZE_KEY, std::to_string(i)); + return b; +} + +void VisibilityAction::Deserialize(Bundle b) { + char buf_key[128]; + int size; + std::size_t pos; + + AbstractAction::Deserialize(b); + + size = std::stoi(b.GetString(VISIBILITY_ACTION_ENTITY_SIZE_KEY)); + + for (int i = 0; i < size; i++) { + buf_key[0] = '\0'; + + snprintf(buf_key, sizeof(buf_key), "%s:%d", + VISIBILITY_ACTION_ENTITY_SIZE_KEY, i); + + std::string str = b.GetString(std::string(buf_key)); + + pos = str.find(":"); + std::string id = str.substr(0, pos); + bool visible = std::stoi(str.substr(pos+1)); + + impl_->entities_.emplace_back(new VisibilityAction::Impl::VisibilityEntity( + id, visible)); + } +} + +bool VisibilityAction::IsLocal() const { + return AbstractAction::IsLocal(); +} + +void VisibilityAction::Execute(std::shared_ptr item) { + std::string id = item->GetId(); + std::list>::iterator it; + + for (it = impl_->entities_.begin(); it != impl_->entities_.end(); it++) { + if (id == (*it)->id_) { + if ((*it)->visibility_) + (*it)->visibility_ = false; + else + (*it)->visibility_ = true; + } + } +} + +std::string VisibilityAction::GetExtra() const { + return AbstractAction::GetExtra(); +} + +void VisibilityAction::SetVisibility(std::string id, bool visible) { + impl_->entities_.emplace_back(new VisibilityAction::Impl::VisibilityEntity(id, + visible)); +} + +} //namespace item +} //namespace notification diff --git a/notification-ex/visibility_action.h b/notification-ex/visibility_action.h new file mode 100644 index 00000000..7c0f6e22 --- /dev/null +++ b/notification-ex/visibility_action.h @@ -0,0 +1,46 @@ +/* + * 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_VISIBILITY_ACTION_H_ +#define NOTIFICATION_EX_VISIBILITY_ACTION_H_ + +#include "notification-ex/abstract_action.h" + +namespace notification { +namespace item { + +class EXPORT_API VisibilityAction : public AbstractAction { + public: + VisibilityAction(); + VisibilityAction(std::string extra); + virtual ~VisibilityAction(); + + Bundle Serialize() override; + void Deserialize(Bundle b) override; + bool IsLocal() const override; + void Execute(std::shared_ptr item) override; + std::string GetExtra() const override; + void SetVisibility(std::string id, bool visible); + + private: + class Impl; + std::unique_ptr impl_; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_VISIBILITY_ACTION_H_ diff --git a/notification-ex/visibility_action_implementation.h b/notification-ex/visibility_action_implementation.h new file mode 100644 index 00000000..d21479f0 --- /dev/null +++ b/notification-ex/visibility_action_implementation.h @@ -0,0 +1,53 @@ +/* + * 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_VISIBILITY_ACTION_IMPLEMENTATION_H_ +#define NOTIFICATION_EX_VISIBILITY_ACTION_IMPLEMENTATION_H_ + +#include + +#include "notification-ex/visibility_action.h" + +namespace notification { +namespace item { + +class VisibilityAction::Impl { + public: + virtual ~Impl(); + + private: + friend class VisibilityAction; + Impl(VisibilityAction* parent); + + class VisibilityEntity { + public: + std::string id_; + bool visibility_; + public: + VisibilityEntity(std::string id, bool visibility) + : id_(id), visibility_(visibility) { + } + }; + + private: + VisibilityAction* parent_; + std::list> entities_; +}; + +} // namespace item +} // namespace notification + +#endif // NOTIFICATION_EX_VISIBILITY_ACTION_IMPLEMENTATION_H_ diff --git a/unittest/src/test_app_control_action.cc b/unittest/src/test_app_control_action.cc new file mode 100644 index 00000000..e0371e40 --- /dev/null +++ b/unittest/src/test_app_control_action.cc @@ -0,0 +1,75 @@ +/* + * 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 +#include + +#include "notification-ex/app_control_action.h" + +using namespace notification; +using namespace notification::item; + +class AppControlActionTest : public ::testing::Test { + public: + AppControlAction* action; + app_control_h app_control; + const char* app_id = "test_appid"; + + virtual void SetUp() { + app_control_create(&app_control); + app_control_set_app_id(app_control, app_id); + + action = new AppControlAction(app_control); + } + virtual void TearDown() { + delete action; + app_control_destroy(app_control); + } +}; + +TEST_F(AppControlActionTest, create) { + EXPECT_NE(AppControlActionTest::action, nullptr); +} + +TEST_F(AppControlActionTest, IsLocal) { + ASSERT_EQ(AppControlActionTest::action->IsLocal(), 1); +} + +TEST_F(AppControlActionTest, SerializeDeserialize) { + char* app_id = NULL; + + Bundle b = AppControlActionTest::action->Serialize(); + AppControlActionTest::action->Deserialize(b); + + app_control_get_app_id(AppControlActionTest::action->GetAppControl(), &app_id); + ASSERT_STREQ(AppControlActionTest::app_id, app_id); +} + +TEST_F(AppControlActionTest, AppControl) { + const char* app_id = "new_appid"; + char* app_id_ = NULL; + app_control_h app_control; + app_control_h app_control_; + + app_control_create(&app_control); + app_control_set_app_id(app_control, app_id); + + AppControlActionTest::action->SetAppControl(app_control); + app_control_ = AppControlActionTest::action->GetAppControl(); + app_control_get_app_id(app_control_, &app_id_); + + EXPECT_STREQ(app_id, app_id_); +} diff --git a/unittest/src/test_visibility_action.cc b/unittest/src/test_visibility_action.cc new file mode 100644 index 00000000..0795a47e --- /dev/null +++ b/unittest/src/test_visibility_action.cc @@ -0,0 +1,57 @@ +/* + * 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 + +#include +#include + +#include "notification-ex/visibility_action.h" + +using namespace notification; +using namespace notification::item; + +class VisibilityActionTest : public ::testing::Test { + public: + VisibilityAction* visibility; + std::string id = "visibility_id"; + bool visible = true; + + virtual void SetUp() { + visibility = new VisibilityAction(); + visibility->SetVisibility("visibility_id", visible); + } + virtual void TearDown() { + delete visibility; + } +}; + +TEST_F(VisibilityActionTest, create) { + EXPECT_NE(VisibilityActionTest::visibility, nullptr); +} + +TEST_F(VisibilityActionTest, IsLocal) { + ASSERT_EQ(VisibilityActionTest::visibility->IsLocal(), 1); +} + +TEST_F(VisibilityActionTest, SerializeDeserialize) { + Bundle b = VisibilityActionTest::visibility->Serialize(); + VisibilityActionTest::visibility->Deserialize(b); +} + +TEST_F(VisibilityActionTest, SetVisibility) { + VisibilityActionTest::visibility->SetVisibility("test_id", true); +}