Merge lp:~3v1n0/unity/alt+tab-background-load.tests into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2092
Proposed branch: lp:~3v1n0/unity/alt+tab-background-load.tests
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/alt+tab-background-load
Diff against target: 262 lines (+141/-28)
5 files modified
plugins/unityshell/src/SwitcherController.h (+4/-4)
plugins/unityshell/src/UnityWindowStyle.cpp (+1/-0)
tests/CMakeLists.txt (+17/-6)
tests/test_switcher_controller.cpp (+106/-0)
tests/test_switcher_model.cpp (+13/-18)
To merge this branch: bzr merge lp:~3v1n0/unity/alt+tab-background-load.tests
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Andrea Azzarone (community) Approve
Review via email: mp+95033@code.launchpad.net

Description of the change

Added tests for SwitcherController changes done in lp:~3v1n0/unity/alt+tab-background-load, enabled the SwitcherModel tests as well.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

I'm not a fan of having long sleeps in unit tests.

Can I suggest that you use perhaps a class level static value for the start time delay.

You can then change that to something small in the test. I'd say as small as possible to show what is going on.

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Looks good to me even if I'd prefer to have an abstract class for the controller too. But it's ok.

review: Approve
Revision history for this message
Tim Penhey (thumper) :
review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Thanks for approving, I set as approved also the depending branch.

Revision history for this message
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~3v1n0/unity/alt+tab-background-load into lp:unity.

Revision history for this message
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~3v1n0/unity/alt+tab-background-load into lp:unity.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/SwitcherController.h'
2--- plugins/unityshell/src/SwitcherController.h 2012-03-06 21:32:25 +0000
3+++ plugins/unityshell/src/SwitcherController.h 2012-03-06 21:32:26 +0000
4@@ -98,6 +98,10 @@
5 std::string GetName() const;
6 void AddProperties(GVariantBuilder* builder);
7
8+ virtual void ConstructWindow();
9+ virtual void ConstructView();
10+ virtual void ShowView();
11+
12 unsigned int construct_timeout_;
13
14 private:
15@@ -108,10 +112,6 @@
16 TAB_NEXT_TILE,
17 };
18
19- void ConstructWindow();
20- void ConstructView();
21- void ShowView();
22-
23 void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr icon);
24 void OnBackgroundUpdate(GVariant* data);
25
26
27=== modified file 'plugins/unityshell/src/UnityWindowStyle.cpp'
28--- plugins/unityshell/src/UnityWindowStyle.cpp 2012-02-08 19:54:15 +0000
29+++ plugins/unityshell/src/UnityWindowStyle.cpp 2012-03-06 21:32:26 +0000
30@@ -18,6 +18,7 @@
31 */
32
33 #include "UnityWindowStyle.h"
34+#include "config.h"
35
36 namespace unity {
37 namespace ui {
38
39=== modified file 'tests/CMakeLists.txt'
40--- tests/CMakeLists.txt 2012-02-21 15:17:18 +0000
41+++ tests/CMakeLists.txt 2012-03-06 21:32:26 +0000
42@@ -149,8 +149,6 @@
43 ${UNITY_SRC}/ShortcutModel.h
44 ${UNITY_SRC}/ShortcutHintPrivate.cpp
45 ${UNITY_SRC}/ShortcutHintPrivate.h
46- ${UNITY_SRC}/SwitcherModel.cpp
47- ${UNITY_SRC}/SwitcherModel.h
48 ${UNITY_SRC}/Introspectable.cpp
49 ${UNITY_SRC}/Introspectable.h
50 ${UNITY_SRC}/TextureCache.cpp
51@@ -196,14 +194,27 @@
52 test_texture_cache.cpp
53 test_main.cpp
54 test_icon_loader.cpp
55+ test_switcher_controller.cpp
56+ test_switcher_model.cpp
57+ ${UNITY_SRC}/AbstractLauncherIcon.cpp
58+ ${UNITY_SRC}/BackgroundEffectHelper.cpp
59 ${UNITY_SRC}/DashViewPrivate.cpp
60- ${UNITY_SRC}/DashViewPrivate.h
61 ${UNITY_SRC}/TextureCache.cpp
62- ${UNITY_SRC}/TextureCache.h
63 ${UNITY_SRC}/IconLoader.cpp
64- ${UNITY_SRC}/IconLoader.h
65+ ${UNITY_SRC}/IconRenderer.cpp
66+ ${UNITY_SRC}/IconTextureSource.cpp
67+ ${UNITY_SRC}/Introspectable.cpp
68+ ${UNITY_SRC}/LayoutSystem.cpp
69+ ${UNITY_SRC}/StaticCairoText.cpp
70+ ${UNITY_SRC}/SwitcherController.cpp
71+ ${UNITY_SRC}/SwitcherModel.cpp
72+ ${UNITY_SRC}/SwitcherView.cpp
73 ${UNITY_SRC}/Timer.cpp
74- ${UNITY_SRC}/Timer.h
75+ ${UNITY_SRC}/UBusWrapper.cpp
76+ ${UNITY_SRC}/UnityWindowStyle.cpp
77+ ${UNITY_SRC}/UnityWindowView.cpp
78+ ${UNITY_SRC}/ubus-server.cpp
79+ ${UNITY_SRC}/WindowManager.cpp
80 )
81 target_link_libraries(test-gtest ${GTEST_BOTH_LIBRARIES})
82 add_test(UnityGTest test-gtest)
83
84=== added file 'tests/test_switcher_controller.cpp'
85--- tests/test_switcher_controller.cpp 1970-01-01 00:00:00 +0000
86+++ tests/test_switcher_controller.cpp 2012-03-06 21:32:26 +0000
87@@ -0,0 +1,106 @@
88+/*
89+ * Copyright 2012 Canonical Ltd.
90+ *
91+ * This program is free software: you can redistribute it and/or modify it
92+ * under the terms of the GNU General Public License version 3, as published
93+ * by the Free Software Foundation.
94+ *
95+ * This program is distributed in the hope that it will be useful, but
96+ * WITHOUT ANY WARRANTY; without even the implied warranties of
97+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
98+ * PURPOSE. See the GNU General Public License for more details.
99+ *
100+ * You should have received a copy of the GNU General Public License
101+ * version 3 along with this program. If not, see
102+ * <http://www.gnu.org/licenses/>
103+ *
104+ * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
105+ *
106+ */
107+
108+#include <gtest/gtest.h>
109+
110+#include "SwitcherController.h"
111+#include "test_utils.h"
112+
113+
114+using namespace unity::switcher;
115+
116+namespace
117+{
118+
119+unsigned int DEFAULT_LAZY_CONSTRUCT_TIMEOUT = 20;
120+
121+class MockSwitcherController : public Controller
122+{
123+public:
124+ MockSwitcherController()
125+ : Controller()
126+ , window_constructed_(false)
127+ , view_constructed_(false)
128+ , view_shown_(false)
129+ {};
130+
131+ MockSwitcherController(unsigned int load_timeout)
132+ : Controller(load_timeout)
133+ , window_constructed_(false)
134+ , view_constructed_(false)
135+ , view_shown_(false)
136+ {};
137+
138+ virtual void ConstructWindow()
139+ {
140+ window_constructed_ = true;
141+ }
142+
143+ virtual void ConstructView()
144+ {
145+ view_constructed_ = true;
146+ }
147+
148+ virtual void ShowView()
149+ {
150+ view_shown_ = true;
151+ }
152+
153+ unsigned int GetConstructTimeout() const
154+ {
155+ return construct_timeout_;
156+ }
157+
158+ bool window_constructed_;
159+ bool view_constructed_;
160+ bool view_shown_;
161+};
162+
163+TEST(TestSwitcherController, Construction)
164+{
165+ Controller controller;
166+ EXPECT_FALSE(controller.Visible());
167+}
168+
169+TEST(TestSwitcherController, LazyConstructionTimeoutLength)
170+{
171+ MockSwitcherController controller;
172+ EXPECT_EQ(controller.GetConstructTimeout(), DEFAULT_LAZY_CONSTRUCT_TIMEOUT);
173+}
174+
175+TEST(TestSwitcherController, LazyWindowConstruction)
176+{
177+ // Setting the timeout to a lower value to speed-up the test
178+ MockSwitcherController controller(2);
179+
180+ EXPECT_EQ(controller.GetConstructTimeout(), 2);
181+
182+ g_timeout_add_seconds(controller.GetConstructTimeout()/2, [] (gpointer data) -> gboolean {
183+ auto controller = static_cast<MockSwitcherController*>(data);
184+ EXPECT_FALSE(controller->window_constructed_);
185+
186+ return FALSE;
187+ }, &controller);
188+
189+ Utils::WaitUntil(controller.window_constructed_, controller.GetConstructTimeout() + 1);
190+ EXPECT_TRUE(controller.window_constructed_);
191+}
192+
193+}
194
195=== renamed file 'tests/unit/TestSwitcherModel.cpp' => 'tests/test_switcher_model.cpp'
196--- tests/unit/TestSwitcherModel.cpp 2011-07-21 14:59:25 +0000
197+++ tests/test_switcher_model.cpp 2012-03-06 21:32:26 +0000
198@@ -22,20 +22,23 @@
199
200 #include "SwitcherModel.h"
201 #include "MockLauncherIcon.h"
202+#include "AbstractLauncherIcon.h"
203
204 #include <vector>
205
206
207 using namespace unity::switcher;
208+using unity::launcher::AbstractLauncherIcon;
209+using unity::launcher::MockLauncherIcon;
210
211 namespace
212 {
213
214-TEST(TestSwitcher, TestConstructor)
215+TEST(TestSwitcherModel, TestConstructor)
216 {
217- AbstractLauncherIcon* first = new MockLauncherIcon();
218- AbstractLauncherIcon* second = new MockLauncherIcon();
219- std::vector<AbstractLauncherIcon*> icons;
220+ AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
221+ AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
222+ std::vector<AbstractLauncherIcon::Ptr> icons;
223 icons.push_back(first);
224 icons.push_back(second);
225
226@@ -46,18 +49,15 @@
227 EXPECT_EQ(model->LastSelection(), first);
228 EXPECT_EQ(model->SelectionIndex(), 0);
229 EXPECT_EQ(model->LastSelectionIndex(), 0);
230-
231- delete first;
232- delete second;
233 }
234
235-TEST(TestSwitcher, TestSelection)
236+TEST(TestSwitcherModel, TestSelection)
237 {
238- std::vector<AbstractLauncherIcon*> icons;
239- AbstractLauncherIcon* first = new MockLauncherIcon();
240- AbstractLauncherIcon* second = new MockLauncherIcon();
241- AbstractLauncherIcon* third = new MockLauncherIcon();
242- AbstractLauncherIcon* fourth = new MockLauncherIcon();
243+ std::vector<AbstractLauncherIcon::Ptr> icons;
244+ AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
245+ AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
246+ AbstractLauncherIcon::Ptr third(new MockLauncherIcon());
247+ AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());
248
249 icons.push_back(first);
250 icons.push_back(second);
251@@ -98,11 +98,6 @@
252 model->Select(first);
253 EXPECT_EQ(model->Selection(), first);
254 EXPECT_EQ(model->LastSelection(), third);
255-
256- delete first;
257- delete second;
258- delete third;
259- delete fourth;
260 }
261
262 }