2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
20 #include "notification-ex/app_control_action.h"
21 #include "notification-ex/action_inflator.h"
23 using namespace notification;
24 using namespace notification::item;
26 class AppControlActionTest : public ::testing::Test {
28 AppControlAction* action;
29 app_control_h app_control;
30 const char* app_id = "test_appid";
31 std::string extra = "appcontrol_extra";
33 virtual void SetUp() {
34 app_control_create(&app_control);
35 app_control_set_app_id(app_control, app_id);
37 action = new AppControlAction(app_control, extra);
39 virtual void TearDown() {
41 app_control_destroy(app_control);
45 TEST_F(AppControlActionTest, create) {
46 EXPECT_NE(AppControlActionTest::action, nullptr);
49 TEST_F(AppControlActionTest, IsLocal) {
50 ASSERT_EQ(AppControlActionTest::action->IsLocal(), 1);
53 TEST_F(AppControlActionTest, GetExtra) {
54 ASSERT_EQ(AppControlActionTest::action->GetExtra(),
55 AppControlActionTest::extra);
58 TEST_F(AppControlActionTest, SerializeDeserialize) {
59 Bundle b = AppControlActionTest::action->Serialize();
61 std::shared_ptr<AbstractAction> gen_action = ActionInflator::Create(b);
62 ASSERT_EQ(gen_action->GetType(), AbstractAction::AppControl);
64 AppControlAction* gen_appcontrol_action =
65 static_cast<AppControlAction*>(gen_action.get());
67 char* app_id = nullptr;
68 app_control_get_app_id(gen_appcontrol_action->GetAppControl(), &app_id);
69 std::unique_ptr<char, decltype(std::free)*> ptr(app_id, std::free);
70 ASSERT_STREQ(app_id, AppControlActionTest::app_id);
73 TEST_F(AppControlActionTest, AppControl) {
74 app_control_h app_control;
75 const char* app_id = "new_appid";
77 app_control_create(&app_control);
78 app_control_set_app_id(app_control, app_id);
79 AppControlActionTest::action->SetAppControl(app_control);
80 app_control_destroy(app_control);
82 Bundle b = AppControlActionTest::action->Serialize();
84 std::shared_ptr<AbstractAction> gen_action = ActionInflator::Create(b);
85 AppControlAction* gen_appcontrol_action =
86 static_cast<AppControlAction*>(gen_action.get());
88 char* app_id_ = nullptr;
89 app_control_get_app_id(gen_appcontrol_action->GetAppControl(), &app_id_);
90 std::unique_ptr<char, decltype(std::free)*> ptr(app_id_, std::free);
91 EXPECT_STREQ(app_id, app_id_);