Removed dead code from SimpleUI
[profile/tv/apps/web/browser.git] / unit_tests / ut_Action.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <string>
18
19 #include <boost/signals2.hpp>
20 #include <boost/test/unit_test.hpp>
21 #include <boost/concept_check.hpp>
22
23 #include "Action.h"
24
25 BOOST_AUTO_TEST_SUITE(action)
26
27 BOOST_AUTO_TEST_CASE(action_constructors)
28 {
29     tizen_browser::base_ui::Action action_01;
30     BOOST_CHECK_EQUAL(action_01.isEnabled(), true);
31     BOOST_CHECK_EQUAL(action_01.isCheckable(), false);
32     BOOST_CHECK_EQUAL(action_01.isChecked(), false);
33     BOOST_CHECK_EQUAL(action_01.isIconVisibleInMenu(), true);
34
35     std::string a02_text("test02");
36     tizen_browser::base_ui::Action  action_02(a02_text);
37     BOOST_CHECK_EQUAL(action_02.isEnabled(), true);
38     BOOST_CHECK_EQUAL(action_02.isCheckable(), false);
39     BOOST_CHECK_EQUAL(action_02.isChecked(), false);
40     BOOST_CHECK_EQUAL(action_02.isIconVisibleInMenu(), true);
41     BOOST_CHECK_EQUAL(action_02.getText(), a02_text);
42
43     std::string a03_text("test02");
44     tizen_browser::base_ui::Action  action_03(a03_text);
45     BOOST_CHECK_EQUAL(action_03.isEnabled(), true);
46     BOOST_CHECK_EQUAL(action_03.isCheckable(), false);
47     BOOST_CHECK_EQUAL(action_03.isChecked(), false);
48     BOOST_CHECK_EQUAL(action_03.isIconVisibleInMenu(), true);
49     BOOST_CHECK_EQUAL(action_03.getText(), a03_text);
50
51     std::string a04_text("test04");
52     std::string a04_icon("test04Icon");
53     tizen_browser::base_ui::Action  action_04(a04_icon, a04_text);
54     BOOST_CHECK_EQUAL(action_04.isEnabled(), true);
55     BOOST_CHECK_EQUAL(action_04.isCheckable(), false);
56     BOOST_CHECK_EQUAL(action_04.isChecked(), false);
57     BOOST_CHECK_EQUAL(action_04.isIconVisibleInMenu(), true);
58     BOOST_CHECK_EQUAL(action_04.getText(), a04_text);
59     BOOST_CHECK_EQUAL(action_04.getIcon(), a04_icon);
60
61 }
62 BOOST_AUTO_TEST_CASE(action_get_and_set){
63
64
65     std::string iconText("iconText");
66     std::string text("text");
67     std::string statusTip("statusTip");
68     std::string toolTip("toolTip");
69     std::string icon("icon");
70     std::string selIcon("selIcon");
71     std::string disIcon("disabledIcon");
72
73     tizen_browser::base_ui::Action action;
74
75     action.setIconText(iconText);
76     action.setText(text);
77     action.setStatusTip(statusTip);
78     action.setToolTip(toolTip);
79     action.setIcon(icon);
80     action.setSelIcon(selIcon);
81     action.setDisIcon(disIcon);
82
83     BOOST_CHECK_EQUAL(action.getIconText(), iconText);
84     BOOST_CHECK_EQUAL(action.getText(), text);
85     BOOST_CHECK_EQUAL(action.getStatusTip(), statusTip);
86     BOOST_CHECK_EQUAL(action.getToolTip(), toolTip);
87     BOOST_CHECK_EQUAL(action.getIcon(), icon);
88     BOOST_CHECK_EQUAL(action.getSelIcon(), selIcon);
89     BOOST_CHECK_EQUAL(action.getDisIcon(), disIcon);
90 }
91
92 BOOST_AUTO_TEST_CASE(action_bool_behaviour){
93
94     tizen_browser::base_ui::Action action_01;
95     //action is not checkable by defalut,
96     //this call should be ignored.
97     action_01.setChecked(true);
98     BOOST_CHECK_EQUAL(action_01.isCheckable(), false);
99     BOOST_CHECK_EQUAL(action_01.isChecked(), false);
100
101     tizen_browser::base_ui::Action action_02;
102     action_02.setCheckable(true);
103     action_02.setChecked(true);
104     BOOST_CHECK_EQUAL(action_02.isCheckable(), true);
105     BOOST_CHECK_EQUAL(action_02.isChecked(), true);
106
107     //toggle test
108     action_02.toggle();
109     BOOST_CHECK_EQUAL(action_02.isChecked(), false);
110
111 }
112
113 BOOST_AUTO_TEST_CASE(action_trigger_test){
114     struct TriggerHandler{
115         TriggerHandler()
116             :beenCalled(false){};
117         ~TriggerHandler(){
118             BOOST_CHECK_EQUAL(beenCalled, true);
119         };
120         void operator()(){
121             beenCalled = true;
122         };
123 //     private:
124         bool beenCalled;
125     };
126
127
128     TriggerHandler triggered;
129     tizen_browser::base_ui::Action action_01;
130     action_01.triggered.connect(boost::ref(triggered));
131     action_01.trigger();
132     BOOST_CHECK_EQUAL(triggered.beenCalled, true);
133 }
134
135 BOOST_AUTO_TEST_CASE(action_togle_test){
136     struct ToggleHandler{
137         ToggleHandler()
138             :isChecked(false),beenCalled(false){};
139         ~ToggleHandler(){
140         };
141         void operator()(bool checked){
142             isChecked = checked;
143             beenCalled = true;
144         };
145         bool isChecked;
146         bool beenCalled;
147     };
148
149     ToggleHandler toggelHandler;
150     tizen_browser::base_ui::Action action;
151
152     action.setCheckable(true);
153     action.toggled.connect(boost::ref(toggelHandler));
154
155     action.toggle();
156     BOOST_CHECK_EQUAL(toggelHandler.beenCalled, true);
157     BOOST_CHECK_EQUAL(action.isChecked(), toggelHandler.isChecked);
158 }
159
160 BOOST_AUTO_TEST_SUITE_END()