Merge lp:~unity-team/unity/libunity-7.0-breakage-tests into lp:~unity-team/unity/libunity-7.0-breakage

Proposed by Nick Dedekind
Status: Merged
Approved by: Nick Dedekind
Approved revision: no longer in the source branch.
Merged at revision: 3089
Proposed branch: lp:~unity-team/unity/libunity-7.0-breakage-tests
Merge into: lp:~unity-team/unity/libunity-7.0-breakage
Diff against target: 6520 lines (+4236/-767)
53 files modified
CMakeLists.txt (+16/-0)
tests/CMakeLists.txt (+39/-14)
tests/MockCategories.h (+67/-0)
tests/autopilot/unity/emulators/dash.py (+113/-101)
tests/autopilot/unity/emulators/hud.py (+2/-2)
tests/autopilot/unity/emulators/launcher.py (+3/-2)
tests/autopilot/unity/emulators/panel.py (+4/-4)
tests/autopilot/unity/emulators/quicklist.py (+7/-3)
tests/autopilot/unity/emulators/switcher.py (+2/-2)
tests/autopilot/unity/tests/test_command_lens.py (+23/-23)
tests/autopilot/unity/tests/test_dash.py (+177/-177)
tests/autopilot/unity/tests/test_home_lens.py (+4/-4)
tests/autopilot/unity/tests/test_search.py (+20/-20)
tests/autopilot/unity/tests/test_shopping_lens.py (+31/-31)
tests/data/unity/scopes/testscope1.scope (+13/-0)
tests/data/unity/scopes/testscope2.scope (+13/-0)
tests/data/unity/scopes/testscope3.scope (+13/-0)
tests/data/unity/scopes/testscope4.scope (+13/-0)
tests/test_categories.cpp (+86/-4)
tests/test_dash_view.cpp (+0/-67)
tests/test_dashview.cpp (+116/-0)
tests/test_dashview_impl.cpp (+12/-12)
tests/test_dbus_indicators.cpp (+3/-3)
tests/test_desktop_utilities.cpp (+67/-55)
tests/test_glib_source.cpp (+1/-1)
tests/test_glib_variant.cpp (+23/-9)
tests/test_gsettings_scopes.cpp (+230/-0)
tests/test_hud.cpp (+48/-92)
tests/test_hud_view.cpp (+1/-0)
tests/test_lensview.cpp (+0/-98)
tests/test_main.cpp (+8/-0)
tests/test_main_dbus.cpp (+25/-1)
tests/test_main_xless.cpp (+6/-0)
tests/test_mock_scope.h (+178/-0)
tests/test_model_iterator.cpp (+87/-1)
tests/test_preview_player.cpp (+151/-0)
tests/test_results.cpp (+140/-0)
tests/test_resultviewgrid.cpp (+1/-1)
tests/test_scope.cpp (+236/-0)
tests/test_scope_bar.cpp (+134/-0)
tests/test_scope_data.cpp (+67/-0)
tests/test_scope_filter.cpp (+335/-0)
tests/test_scope_impl.c (+511/-0)
tests/test_scope_impl.h (+66/-0)
tests/test_scope_proxy.cpp (+312/-0)
tests/test_scopeview.cpp (+104/-0)
tests/test_service_main.cpp (+24/-0)
tests/test_service_model.cpp (+195/-20)
tests/test_service_model.h (+11/-0)
tests/test_service_scope.cpp (+270/-0)
tests/test_service_scope.h (+48/-0)
tests/test_tracks.cpp (+131/-0)
tests/test_utils.h (+49/-20)
To merge this branch: bzr merge lp:~unity-team/unity/libunity-7.0-breakage-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Łukasz Zemczak autopilot Approve
Review via email: mp+153607@code.launchpad.net

Commit message

Added/Updated unit tests for new libunity scope API.

Description of the change

Added/Updated unit tests for new libunity scope API.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

+1 regarding the autopilot parts

review: Approve (autopilot)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

- TEST(TestDesktopUtilitiesDataDirectories, TestGetUserDataDirectory)
- TEST(TestDesktopUtilitiesDataDirectories, TestGetSystemDataDirectory)
- TEST(TestDesktopUtilitiesDataDirectories, TestGetDataDirectory)

Removed these tests. Calling the functions these tests are testing before running these tests invalidates the results (:S). glib caches the function results and therefore does not change their values when XDG folders update.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-03-20 13:14:31 +0000
+++ CMakeLists.txt 2013-03-21 14:03:22 +0000
@@ -53,6 +53,8 @@
5353
54if (CMAKE_BUILD_TYPE MATCHES coverage)54if (CMAKE_BUILD_TYPE MATCHES coverage)
55 set (COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")55 set (COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
56 set (COVERAGE_INFO_FILE "${CMAKE_BINARY_DIR}/coverage-html.info")
57 set (COVERAGE_HTML_DIR "${CMAKE_BINARY_DIR}/coverage-html")
5658
57 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )59 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )
58 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )60 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
@@ -67,6 +69,20 @@
67 add_custom_target (coverage-xml 69 add_custom_target (coverage-xml
68 COMMAND "${GCOVR_EXECUTABLE}" --exclude="tests.*" --exclude="obj-.*" -x -r "${CMAKE_SOURCE_DIR}" -o "${COVERAGE_XML_FILE}")70 COMMAND "${GCOVR_EXECUTABLE}" --exclude="tests.*" --exclude="obj-.*" -x -r "${CMAKE_SOURCE_DIR}" -o "${COVERAGE_XML_FILE}")
69 endif()71 endif()
72
73 find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${LCOV_ROOT}/bin")
74 find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT} "${GENHTML_ROOT}/bin")
75 if (NOT LCOV_EXECUTABLE)
76 message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not found.")
77 elseif (NOT GENHTML_EXECUTABLE)
78 message(FATAL_ERROR "Cannot enable coverage targets because genhtml was not found.")
79 else ()
80 message (STATUS "Enabling HTML coverage report")
81 add_custom_target (coverage-html
82 COMMAND "${LCOV_EXECUTABLE}" --directory "${CMAKE_BINARY_DIR}" --capture --output-file "${COVERAGE_INFO_FILE}"
83 COMMAND "${GENHTML_EXECUTABLE}" --output-directory "${COVERAGE_HTML_DIR}" "${COVERAGE_INFO_FILE}")
84 endif()
85
70endif (CMAKE_BUILD_TYPE MATCHES coverage)86endif (CMAKE_BUILD_TYPE MATCHES coverage)
7187
7288
7389
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-03-20 13:14:31 +0000
+++ tests/CMakeLists.txt 2013-03-21 14:03:22 +0000
@@ -16,16 +16,20 @@
16configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/kde4/afile.desktop16configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/applications/kde4/afile.desktop
17 ${CMAKE_BINARY_DIR}/tests/data/applications/kde4/afile.desktop)17 ${CMAKE_BINARY_DIR}/tests/data/applications/kde4/afile.desktop)
1818
19configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/lenses/social/social.lens19configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/scopes/testscope1.scope
20 ${CMAKE_BINARY_DIR}/tests/data/lenses/social/social.lens)20 ${CMAKE_BINARY_DIR}/tests/data/unity/scopes/testscope1.scope)
21configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/lenses/files/files.lens21configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/scopes/testscope2.scope
22 ${CMAKE_BINARY_DIR}/tests/data/lenses/files/files.lens)22 ${CMAKE_BINARY_DIR}/tests/data/unity/scopes/testscope2.scope)
23configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/lenses/applications/applications.lens23configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/scopes/testscope3.scope
24 ${CMAKE_BINARY_DIR}/tests/data/lenses/applications/applications.lens)24 ${CMAKE_BINARY_DIR}/tests/data/unity/scopes/testscope3.scope)
25configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/lenses/invalid-lens-file/invalid-lens-file.lens25configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/scopes/testscope4.scope
26 ${CMAKE_BINARY_DIR}/tests/data/lenses/invalid-lens-file/invalid-lens-file.lens)26 ${CMAKE_BINARY_DIR}/tests/data/unity/scopes/testscope4.scope)
27configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/lenses/invalid-lens-group/invalid-lens-group.lens27configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/sounds/brownnoise.mp3
28 ${CMAKE_BINARY_DIR}/tests/data/lenses/invalid-lens-group/invalid-lens-group.lens)28 ${CMAKE_BINARY_DIR}/tests/data/unity/sounds/brownnoise.mp3 COPYONLY)
29configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/sounds/pinknoise.mp3
30 ${CMAKE_BINARY_DIR}/tests/data/unity/sounds/pinknoise.mp3 COPYONLY)
31configure_file (${CMAKE_CURRENT_SOURCE_DIR}/data/unity/sounds/whitenoise.mp3
32 ${CMAKE_BINARY_DIR}/tests/data/unity/sounds/whitenoise.mp3 COPYONLY)
2933
30#34#
31# Unit tests35# Unit tests
@@ -95,8 +99,18 @@
95 test_service_hud.cpp99 test_service_hud.cpp
96 test_service_main.cpp100 test_service_main.cpp
97 test_service_model.cpp101 test_service_model.cpp
98 test_service_panel.cpp)102 test_service_panel.cpp
99 target_link_libraries(test-gtest-service unity-shared ${LIBS})103 test_service_scope.cpp)
104
105 # Build plain C files separately so they don't try to include the
106 # C++ pch.
107 add_library(test-gtest-service-plainc STATIC
108 test_scope_impl.c)
109
110 target_link_libraries(test-gtest-service
111 test-gtest-service-plainc
112 unity-shared
113 ${LIBS})
100114
101# gtest-slow, start moving things over that are slow running tests115# gtest-slow, start moving things over that are slow running tests
102 set (GTEST_SLOW_SOURCES116 set (GTEST_SLOW_SOURCES
@@ -135,6 +149,7 @@
135 test_glib_source.cpp149 test_glib_source.cpp
136 test_glib_variant.cpp150 test_glib_variant.cpp
137 test_grabhandle.cpp151 test_grabhandle.cpp
152 test_gsettings_scopes.cpp
138 test_desktop_utilities.cpp153 test_desktop_utilities.cpp
139 test_indicator.cpp154 test_indicator.cpp
140 test_indicator_appmenu.cpp155 test_indicator_appmenu.cpp
@@ -149,6 +164,7 @@
149 test_layout_system.cpp164 test_layout_system.cpp
150 test_model_iterator.cpp165 test_model_iterator.cpp
151 test_previews.cpp166 test_previews.cpp
167 test_scope_data.cpp
152 test_time_util.cpp168 test_time_util.cpp
153 test_ubus.cpp169 test_ubus.cpp
154 test_unityshell_private.cpp170 test_unityshell_private.cpp
@@ -204,10 +220,14 @@
204 test_utils.h220 test_utils.h
205 test_ratings_filter.cpp221 test_ratings_filter.cpp
206 test_results.cpp222 test_results.cpp
223 test_scope.cpp
224 test_scope_filter.cpp
225 test_scope_proxy.cpp
226 test_tracks.cpp
207 )227 )
208 target_link_libraries(test-gtest-dbus gtest unity-shared ${LIBS})228 target_link_libraries(test-gtest-dbus gtest unity-shared ${LIBS})
209 add_test(UnityGTestDBus test-gtest-dbus)229 add_test(UnityGTestDBus test-gtest-dbus)
210 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service gtest)230 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} unity-shared test-gtest-service gtest)
211231
212if (ENABLE_X_SUPPORT)232if (ENABLE_X_SUPPORT)
213# Tests that require X233# Tests that require X
@@ -219,6 +239,8 @@
219 test_application_launcher_icon.cpp239 test_application_launcher_icon.cpp
220 test_bamf_application.cpp240 test_bamf_application.cpp
221 test_bfb_launcher_icon.cpp241 test_bfb_launcher_icon.cpp
242 test_dashview.cpp
243 test_dashview_impl.cpp
222 test_dash_controller.cpp244 test_dash_controller.cpp
223 test_desktop_launcher_icon.cpp245 test_desktop_launcher_icon.cpp
224 test_device_launcher_section.cpp246 test_device_launcher_section.cpp
@@ -233,6 +255,7 @@
233 test_hud_view.cpp255 test_hud_view.cpp
234 test_icon_loader.cpp256 test_icon_loader.cpp
235 test_im_text_entry.cpp257 test_im_text_entry.cpp
258 test_keyboard_util.cpp
236 test_im_text_entry_class.cpp259 test_im_text_entry_class.cpp
237 test_launcher.cpp260 test_launcher.cpp
238 test_launcher_controller.cpp261 test_launcher_controller.cpp
@@ -242,13 +265,13 @@
242 test_launcher_icon.cpp265 test_launcher_icon.cpp
243 test_launcher_minimize_speed.cpp266 test_launcher_minimize_speed.cpp
244 test_launcher_tooltip.cpp267 test_launcher_tooltip.cpp
245 test_keyboard_util.cpp
246 test_panel_indicators_view.cpp268 test_panel_indicators_view.cpp
247 test_panel_menu_view.cpp269 test_panel_menu_view.cpp
248 test_panel_style.cpp270 test_panel_style.cpp
249 test_panel_tray.cpp271 test_panel_tray.cpp
250 test_panel_view.cpp272 test_panel_view.cpp
251 test_places_group.cpp273 test_places_group.cpp
274 test_preview_player.cpp
252 test_previews_application.cpp275 test_previews_application.cpp
253 test_previews_generic.cpp276 test_previews_generic.cpp
254 test_previews_movie.cpp277 test_previews_movie.cpp
@@ -260,6 +283,8 @@
260 test_quicklist_view.cpp283 test_quicklist_view.cpp
261 test_result_renderer.cpp284 test_result_renderer.cpp
262 test_resultviewgrid.cpp285 test_resultviewgrid.cpp
286 test_scope_bar.cpp
287 test_scopeview.cpp
263 test_searchbar.cpp288 test_searchbar.cpp
264 test_session_button.cpp289 test_session_button.cpp
265 test_session_controller.cpp290 test_session_controller.cpp
266291
=== added file 'tests/MockCategories.h'
--- tests/MockCategories.h 1970-01-01 00:00:00 +0000
+++ tests/MockCategories.h 2013-03-21 14:03:22 +0000
@@ -0,0 +1,67 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#ifndef _UNITY_MOCK_CATEGORIES_H
21#define _UNITY_MOCK_CATEGORIES_H
22
23#include <dee.h>
24
25namespace unity
26{
27namespace dash
28{
29
30class MockCategories : public Categories
31{
32public:
33MockCategories(unsigned count)
34: Categories(LOCAL)
35, model_(dee_sequence_model_new())
36{
37 dee_model_set_schema(model_, "s", "s", "s", "s", "a{sv}", nullptr);
38 AddResults(count);
39
40 SetModel(model_);
41}
42
43void AddResults(unsigned count)
44{
45 GVariantBuilder b;
46 g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
47 GVariant *hints = g_variant_builder_end(&b);
48
49 for(unsigned i = 0; i < count; ++i)
50 {
51 dee_model_append(model_,
52 ("cat"+std::to_string(i)).c_str(),
53 ("Category "+std::to_string(i)).c_str(),
54 "gtk-apply",
55 "grid",
56 hints);
57 }
58 g_variant_unref(hints);
59}
60
61glib::Object<DeeModel> model_;
62};
63
64}
65}
66
67#endif // _UNITY_MOCK_CATEGORIES_H
0\ No newline at end of file68\ No newline at end of file
169
=== modified file 'tests/autopilot/unity/emulators/dash.py'
--- tests/autopilot/unity/emulators/dash.py 2013-02-21 10:03:21 +0000
+++ tests/autopilot/unity/emulators/dash.py 2013-03-21 14:03:22 +0000
@@ -9,7 +9,8 @@
99
10from __future__ import absolute_import10from __future__ import absolute_import
1111
12from autopilot.emulators.X11 import Keyboard, Mouse12
13from autopilot.emulators.input import get_keyboard, get_mouse
13from autopilot.keybindings import KeybindingsHelper14from autopilot.keybindings import KeybindingsHelper
14from testtools.matchers import GreaterThan15from testtools.matchers import GreaterThan
1516
@@ -23,6 +24,11 @@
23class DashController(UnityIntrospectionObject, KeybindingsHelper):24class DashController(UnityIntrospectionObject, KeybindingsHelper):
24 """The main dash controller object."""25 """The main dash controller object."""
2526
27 def __init__(self, *args, **kwargs):
28 super(DashController, self).__init__(*args, **kwargs)
29 self.keyboard = get_keyboard()
30 self.mouse = get_mouse()
31
26 def get_dash_view(self):32 def get_dash_view(self):
27 """Get the dash view that's attached to this controller."""33 """Get the dash view that's attached to this controller."""
28 return self.get_children_by_type(DashView)[0]34 return self.get_children_by_type(DashView)[0]
@@ -89,41 +95,41 @@
89 Assumes dash is already visible, and search bar has keyboard focus.95 Assumes dash is already visible, and search bar has keyboard focus.
9096
91 """97 """
92 self._keyboard.press_and_release("Ctrl+a")98 self.keyboard.press_and_release("Ctrl+a")
93 self._keyboard.press_and_release("Delete")99 self.keyboard.press_and_release("Delete")
94 self.search_string.wait_for("")100 self.search_string.wait_for("")
95101
96 def reveal_application_lens(self, clear_search=True):102 def reveal_application_scope(self, clear_search=True):
97 """Reveal the application lense."""103 """Reveal the application scope."""
98 logger.debug("Revealing application lens with Super+a.")104 logger.debug("Revealing application scope with Super+a.")
99 self._reveal_lens("lens_reveal/apps", clear_search)105 self._reveal_scope("lens_reveal/apps", clear_search)
100 return self.view.get_lensview_by_name("applications.lens")106 return self.view.get_scopeview_by_name("applications.scope")
101107
102 def reveal_music_lens(self, clear_search=True):108 def reveal_music_scope(self, clear_search=True):
103 """Reveal the music lense."""109 """Reveal the music scope."""
104 logger.debug("Revealing music lens with Super+m.")110 logger.debug("Revealing music scope with Super+m.")
105 self._reveal_lens("lens_reveal/music", clear_search)111 self._reveal_scope("lens_reveal/music", clear_search)
106 return self.view.get_lensview_by_name("music.lens")112 return self.view.get_scopeview_by_name("music.scope")
107113
108 def reveal_file_lens(self, clear_search=True):114 def reveal_file_scope(self, clear_search=True):
109 """Reveal the file lense."""115 """Reveal the file scope."""
110 logger.debug("Revealing file lens with Super+f.")116 logger.debug("Revealing file scope with Super+f.")
111 self._reveal_lens("lens_reveal/files", clear_search)117 self._reveal_scope("lens_reveal/files", clear_search)
112 return self.view.get_lensview_by_name("files.lens")118 return self.view.get_scopeview_by_name("files.scope")
113119
114 def reveal_video_lens(self, clear_search=True):120 def reveal_video_scope(self, clear_search=True):
115 """Reveal the video lens"""121 """Reveal the video scope"""
116 logger.debug("Revealing video lens with Super+v.")122 logger.debug("Revealing video scope with Super+v.")
117 self._reveal_lens("lens_reveal/video", clear_search)123 self._reveal_scope("lens_reveal/video", clear_search)
118 return self.view.get_lensview_by_name("video.lens")124 return self.view.get_scopeview_by_name("video.scope")
119125
120 def reveal_command_lens(self, clear_search=True):126 def reveal_command_scope(self, clear_search=True):
121 """Reveal the 'run command' lens."""127 """Reveal the 'run command' scope."""
122 logger.debug("Revealing command lens with Alt+F2.")128 logger.debug("Revealing command scope with Alt+F2.")
123 self._reveal_lens("lens_reveal/command", clear_search)129 self._reveal_scope("lens_reveal/command", clear_search)
124 return self.view.get_lensview_by_name("commands.lens")130 return self.view.get_scopeview_by_name("commands.scope")
125131
126 def _reveal_lens(self, binding_name, clear_search):132 def _reveal_scope(self, binding_name, clear_search):
127 self.keybinding_hold(binding_name)133 self.keybinding_hold(binding_name)
128 self.keybinding_tap(binding_name)134 self.keybinding_tap(binding_name)
129 self.keybinding_release(binding_name)135 self.keybinding_release(binding_name)
@@ -132,13 +138,13 @@
132 self.clear_search()138 self.clear_search()
133139
134 @property140 @property
135 def active_lens(self):141 def active_scope(self):
136 return self.view.get_lensbar().active_lens142 return self.view.get_scopebar().active_scope
137143
138 def get_current_lens(self):144 def get_current_scope(self):
139 """Get the currently-active LensView object."""145 """Get the currently-active ScopeView object."""
140 active_lens_name = self.view.get_lensbar().active_lens146 active_scope_name = self.view.get_scopebar().active_scope
141 return self.view.get_lensview_by_name(active_lens_name)147 return self.view.get_scopeview_by_name(active_scope_name)
142148
143 @property149 @property
144 def geometry(self):150 def geometry(self):
@@ -152,16 +158,16 @@
152 """Get the search bar attached to this dash view."""158 """Get the search bar attached to this dash view."""
153 return self.get_children_by_type(SearchBar)[0]159 return self.get_children_by_type(SearchBar)[0]
154160
155 def get_lensbar(self):161 def get_scopebar(self):
156 """Get the lensbar attached to this dash view."""162 """Get the scopebar attached to this dash view."""
157 return self.get_children_by_type(LensBar)[0]163 return self.get_children_by_type(ScopeBar)[0]
158164
159 def get_lensview_by_name(self, lens_name):165 def get_scopeview_by_name(self, scope_name):
160 """Get a LensView child object by it's name. For example, "home.lens"."""166 """Get a ScopeView child object by it's name. For example, "home.scope"."""
161 lenses = self.get_children_by_type(LensView)167 scopes = self.get_children_by_type(ScopeView)
162 for lens in lenses:168 for scope in scopes:
163 if lens.name == lens_name:169 if scope.name == scope_name:
164 return lens170 return scope
165171
166 def get_preview_container(self):172 def get_preview_container(self):
167 """Get the preview container attached to this dash view."""173 """Get the preview container attached to this dash view."""
@@ -175,24 +181,24 @@
175 """The search bar for the dash view."""181 """The search bar for the dash view."""
176182
177183
178class LensBar(UnityIntrospectionObject):184class ScopeBar(UnityIntrospectionObject):
179 """The bar of lens icons at the bottom of the dash."""185 """The bar of scope icons at the bottom of the dash."""
180 def get_icon_by_name(self, name):186 def get_icon_by_name(self, name):
181 """Get a LensBarIcon child object by it's name. For example, 'home.lens'."""187 """Get a ScopeBarIcon child object by it's name. For example, 'home.scope'."""
182 icons = self.get_children_by_type(LensBarIcon)188 icons = self.get_children_by_type(ScopeBarIcon)
183 for icon in icons:189 for icon in icons:
184 if icon.name == name:190 if icon.name == name:
185 return icon191 return icon
186192
187class LensBarIcon(UnityIntrospectionObject):193class ScopeBarIcon(UnityIntrospectionObject):
188 """A lens icon at the bottom of the dash."""194 """A scope icon at the bottom of the dash."""
189195
190196
191class LensView(UnityIntrospectionObject):197class ScopeView(UnityIntrospectionObject):
192 """A Lens View."""198 """A Scope View."""
193199
194 def get_groups(self):200 def get_groups(self):
195 """Get a list of all groups within this lensview. May return an empty list."""201 """Get a list of all groups within this scopeview. May return an empty list."""
196 groups = self.get_children_by_type(PlacesGroup)202 groups = self.get_children_by_type(PlacesGroup)
197 return groups203 return groups
198204
@@ -217,11 +223,11 @@
217 return None223 return None
218224
219 def get_num_visible_categories(self):225 def get_num_visible_categories(self):
220 """Get the number of visible categories in this lens."""226 """Get the number of visible categories in this scope."""
221 return len([c for c in self.get_children_by_type(PlacesGroup) if c.is_visible])227 return len([c for c in self.get_children_by_type(PlacesGroup) if c.is_visible])
222228
223 def get_filterbar(self):229 def get_filterbar(self):
224 """Get the filter bar for the current lense, or None if it doesn't have one."""230 """Get the filter bar for the current scope, or None if it doesn't have one."""
225 bars = self.get_children_by_type(FilterBar)231 bars = self.get_children_by_type(FilterBar)
226 if bars:232 if bars:
227 return bars[0]233 return bars[0]
@@ -229,7 +235,7 @@
229235
230236
231class PlacesGroup(UnityIntrospectionObject):237class PlacesGroup(UnityIntrospectionObject):
232 """A category in the lense view."""238 """A category in the scope view."""
233239
234 def get_results(self):240 def get_results(self):
235 """Get a list of all results within this category. May return an empty list."""241 """Get a list of all results within this category. May return an empty list."""
@@ -244,31 +250,36 @@
244class Result(UnityIntrospectionObject):250class Result(UnityIntrospectionObject):
245 """A single result in the dash."""251 """A single result in the dash."""
246252
253 def __init__(self, *args, **kwargs):
254 super(Result, self).__init__(*args, **kwargs)
255 self.mouse = get_mouse()
256 self.keyboard = get_keyboard()
257
247 def activate(self):258 def activate(self):
248 tx = self.x + (self.width / 2)259 tx = self.x + (self.width / 2)
249 ty = self.y + (self.height / 2)260 ty = self.y + (self.height / 2)
250 m = Mouse()261 self.mouse.move(tx, ty)
251 m.move(tx, ty)262 self.mouse.click(1)
252 m.click(1)
253263
254 def preview(self):264 def preview(self):
255 tx = self.x + (self.width / 2)265 tx = self.x + (self.width / 2)
256 ty = self.y + (self.height / 2)266 ty = self.y + (self.height / 2)
257 m = Mouse()267 self.mouse.move(tx, ty)
258 m.move(tx, ty)268 self.mouse.click(3)
259 m.click(3)
260269
261 def preview_key(self):270 def preview_key(self):
262 tx = self.x + (self.width / 2)271 tx = self.x + (self.width / 2)
263 ty = self.y + (self.height / 2)272 ty = self.y + (self.height / 2)
264 m = Mouse()273 self.mouse.move(tx, ty)
265 m.move(tx, ty)
266274
267 k = Keyboard()275 self.keyboard.press_and_release('Menu')
268 k.press_and_release('Menu')
269276
270class FilterBar(UnityIntrospectionObject):277class FilterBar(UnityIntrospectionObject):
271 """A filterbar, as shown inside a lens."""278 """A filterbar, as shown inside a scope."""
279
280 def __init__(self, *args, **kwargs):
281 super(FilterBar, self).__init__(*args, **kwargs)
282 self.mouse = get_mouse()
272283
273 def get_num_filters(self):284 def get_num_filters(self):
274 """Get the number of filters in this filter bar."""285 """Get the number of filters in this filter bar."""
@@ -285,7 +296,7 @@
285296
286 @property297 @property
287 def expanded(self):298 def expanded(self):
288 """Return True if the filterbar on this lens is expanded, False otherwise.299 """Return True if the filterbar on this scope is expanded, False otherwise.
289 """300 """
290 searchbar = self._get_searchbar()301 searchbar = self._get_searchbar()
291 return searchbar.showing_filters302 return searchbar.showing_filters
@@ -296,9 +307,8 @@
296 searchbar = self._get_searchbar()307 searchbar = self._get_searchbar()
297 tx = searchbar.filter_label_x + (searchbar.filter_label_width / 2)308 tx = searchbar.filter_label_x + (searchbar.filter_label_width / 2)
298 ty = searchbar.filter_label_y + (searchbar.filter_label_height / 2)309 ty = searchbar.filter_label_y + (searchbar.filter_label_height / 2)
299 m = Mouse()310 self.mouse.move(tx, ty)
300 m.move(tx, ty)311 self.mouse.click()
301 m.click()
302 self.expanded.wait_for(True)312 self.expanded.wait_for(True)
303313
304 def ensure_collapsed(self):314 def ensure_collapsed(self):
@@ -307,9 +317,8 @@
307 searchbar = self._get_searchbar()317 searchbar = self._get_searchbar()
308 tx = searchbar.filter_label_x + (searchbar.filter_label_width / 2)318 tx = searchbar.filter_label_x + (searchbar.filter_label_width / 2)
309 ty = searchbar.filter_label_y + (searchbar.filter_label_height / 2)319 ty = searchbar.filter_label_y + (searchbar.filter_label_height / 2)
310 m = Mouse()320 self.mouse.move(tx, ty)
311 m.move(tx, ty)321 self.mouse.click()
312 m.click()
313 self.expanded.wait_for(False)322 self.expanded.wait_for(False)
314323
315 def _get_searchbar(self):324 def _get_searchbar(self):
@@ -327,14 +336,17 @@
327class FilterExpanderLabel(UnityIntrospectionObject):336class FilterExpanderLabel(UnityIntrospectionObject):
328 """A label that expands into a filter within a filter bar."""337 """A label that expands into a filter within a filter bar."""
329338
339 def __init__(self, *args, **kwargs):
340 super(FilterExpanderLabel, self).__init__(*args, **kwargs)
341 self.mouse = get_mouse()
342
330 def ensure_expanded(self):343 def ensure_expanded(self):
331 """Expand the filter expander label, if it's not already"""344 """Expand the filter expander label, if it's not already"""
332 if not self.expanded:345 if not self.expanded:
333 tx = self.x + self.width / 2346 tx = self.x + self.width / 2
334 ty = self.y + self.height / 2347 ty = self.y + self.height / 2
335 m = Mouse()348 self.mouse.move(tx, ty)
336 m.move(tx, ty)349 self.mouse.click()
337 m.click()
338 self.expanded.wait_for(True)350 self.expanded.wait_for(True)
339351
340 def ensure_collapsed(self):352 def ensure_collapsed(self):
@@ -342,9 +354,8 @@
342 if self.expanded:354 if self.expanded:
343 tx = self.x + self.width / 2355 tx = self.x + self.width / 2
344 ty = self.y + self.height / 2356 ty = self.y + self.height / 2
345 m = Mouse()357 self.mouse.move(tx, ty)
346 m.move(tx, ty)358 self.mouse.click()
347 m.click()
348 self.expanded.wait_for(False)359 self.expanded.wait_for(False)
349360
350361
@@ -357,7 +368,7 @@
357368
358369
359class Preview(UnityIntrospectionObject):370class Preview(UnityIntrospectionObject):
360 """A preview of a dash lens result."""371 """A preview of a dash scope result."""
361372
362 def get_num_actions(self):373 def get_num_actions(self):
363 """Get the number of actions for the preview."""374 """Get the number of actions for the preview."""
@@ -378,9 +389,8 @@
378 if action:389 if action:
379 tx = action.x + (searchbar.width / 2)390 tx = action.x + (searchbar.width / 2)
380 ty = action.y + (searchbar.height / 2)391 ty = action.y + (searchbar.height / 2)
381 m = Mouse()392 self.mouse.move(tx, ty)
382 m.move(tx, ty)393 self.mouse.click()
383 m.click()
384394
385 @property395 @property
386 def cover_art(self):396 def cover_art(self):
@@ -404,16 +414,16 @@
404414
405415
406class ApplicationPreview(Preview):416class ApplicationPreview(Preview):
407 """A application preview of a dash lens result."""417 """A application preview of a dash scope result."""
408418
409class GenericPreview(Preview):419class GenericPreview(Preview):
410 """A generic preview of a dash lens result."""420 """A generic preview of a dash scope result."""
411421
412class MusicPreview(Preview):422class MusicPreview(Preview):
413 """A music preview of a dash lens result."""423 """A music preview of a dash scope result."""
414424
415class MoviePreview(Preview):425class MoviePreview(Preview):
416 """A movie preview of a dash lens result."""426 """A movie preview of a dash scope result."""
417427
418class PreviewContent(UnityIntrospectionObject):428class PreviewContent(UnityIntrospectionObject):
419 """A preview content layout for the dash previews."""429 """A preview content layout for the dash previews."""
@@ -428,6 +438,10 @@
428class PreviewContainer(UnityIntrospectionObject):438class PreviewContainer(UnityIntrospectionObject):
429 """A container view for the main dash preview widget."""439 """A container view for the main dash preview widget."""
430440
441 def __init__(self, *args, **kwargs):
442 super(PreviewContainer, self).__init__(*args, **kwargs)
443 self.mouse = get_mouse()
444
431 @property445 @property
432 def content(self):446 def content(self):
433 return self.get_content()447 return self.get_content()
@@ -463,14 +477,13 @@
463477
464 tx = navigator.button_x + (navigator.button_width / 2)478 tx = navigator.button_x + (navigator.button_width / 2)
465 ty = navigator.button_y + (navigator.button_height / 2)479 ty = navigator.button_y + (navigator.button_height / 2)
466 m = Mouse()480 self.mouse.move(tx, ty)
467 m.move(tx, ty)
468481
469 old_preview_initiate_count = self.preview_initiate_count482 old_preview_initiate_count = self.preview_initiate_count
470483
471 for i in range(count):484 for i in range(count):
472 self.navigate_left_enabled.wait_for(True)485 self.navigate_left_enabled.wait_for(True)
473 m.click()486 self.mouse.click()
474 self.preview_initiate_count.wait_for(GreaterThan(old_preview_initiate_count))487 self.preview_initiate_count.wait_for(GreaterThan(old_preview_initiate_count))
475 old_preview_initiate_count = self.preview_initiate_count488 old_preview_initiate_count = self.preview_initiate_count
476489
@@ -480,14 +493,13 @@
480493
481 tx = navigator.button_x + (navigator.button_width / 2)494 tx = navigator.button_x + (navigator.button_width / 2)
482 ty = navigator.button_y + (navigator.button_height / 2)495 ty = navigator.button_y + (navigator.button_height / 2)
483 m = Mouse()496 self.mouse.move(tx, ty)
484 m.move(tx, ty)
485497
486 old_preview_initiate_count = self.preview_initiate_count498 old_preview_initiate_count = self.preview_initiate_count
487499
488 for i in range(count):500 for i in range(count):
489 self.navigate_right_enabled.wait_for(True)501 self.navigate_right_enabled.wait_for(True)
490 m.click()502 self.mouse.click()
491 self.preview_initiate_count.wait_for(GreaterThan(old_preview_initiate_count))503 self.preview_initiate_count.wait_for(GreaterThan(old_preview_initiate_count))
492 old_preview_initiate_count = self.preview_initiate_count504 old_preview_initiate_count = self.preview_initiate_count
493505
494506
=== modified file 'tests/autopilot/unity/emulators/hud.py'
--- tests/autopilot/unity/emulators/hud.py 2013-02-04 19:54:47 +0000
+++ tests/autopilot/unity/emulators/hud.py 2013-03-21 14:03:22 +0000
@@ -9,7 +9,7 @@
99
10from __future__ import absolute_import10from __future__ import absolute_import
1111
12from autopilot.emulators.X11 import Keyboard12from autopilot.emulators.input import get_keyboard
13from autopilot.keybindings import KeybindingsHelper13from autopilot.keybindings import KeybindingsHelper
14from HTMLParser import HTMLParser14from HTMLParser import HTMLParser
15import re15import re
@@ -24,7 +24,7 @@
2424
25 def __init__(self, *args, **kwargs):25 def __init__(self, *args, **kwargs):
26 super(HudController, self).__init__(*args, **kwargs)26 super(HudController, self).__init__(*args, **kwargs)
27 self.keyboard = Keyboard()27 self.keyboard = get_keyboard()
2828
29 def get_hud_view(self):29 def get_hud_view(self):
30 views = self.get_children_by_type(HudView)30 views = self.get_children_by_type(HudView)
3131
=== modified file 'tests/autopilot/unity/emulators/launcher.py'
--- tests/autopilot/unity/emulators/launcher.py 2013-03-18 19:58:05 +0000
+++ tests/autopilot/unity/emulators/launcher.py 2013-03-21 14:03:22 +0000
@@ -9,7 +9,8 @@
99
10from __future__ import absolute_import10from __future__ import absolute_import
1111
12from autopilot.emulators.X11 import Mouse, ScreenGeometry12from autopilot.emulators.input import get_mouse
13from autopilot.emulators.X11 import ScreenGeometry
13from autopilot.keybindings import KeybindingsHelper14from autopilot.keybindings import KeybindingsHelper
14from autopilot.utilities import get_compiz_option15from autopilot.utilities import get_compiz_option
15import logging16import logging
@@ -67,7 +68,7 @@
67 self.in_keynav_mode = False68 self.in_keynav_mode = False
68 self.in_switcher_mode = False69 self.in_switcher_mode = False
6970
70 self._mouse = Mouse()71 self._mouse = get_mouse()
71 self._screen = ScreenGeometry()72 self._screen = ScreenGeometry()
7273
73 def _perform_key_nav_binding(self, keybinding):74 def _perform_key_nav_binding(self, keybinding):
7475
=== modified file 'tests/autopilot/unity/emulators/panel.py'
--- tests/autopilot/unity/emulators/panel.py 2012-12-18 11:27:43 +0000
+++ tests/autopilot/unity/emulators/panel.py 2013-03-21 14:03:22 +0000
@@ -12,7 +12,7 @@
12import logging12import logging
13from time import sleep13from time import sleep
1414
15from autopilot.emulators.X11 import Mouse15from autopilot.emulators.input import get_mouse
16from autopilot.keybindings import KeybindingsHelper16from autopilot.keybindings import KeybindingsHelper
1717
18from unity.emulators import UnityIntrospectionObject18from unity.emulators import UnityIntrospectionObject
@@ -53,7 +53,7 @@
5353
54 def __init__(self, *args, **kwargs):54 def __init__(self, *args, **kwargs):
55 super(UnityPanel, self).__init__(*args, **kwargs)55 super(UnityPanel, self).__init__(*args, **kwargs)
56 self._mouse = Mouse()56 self._mouse = get_mouse()
5757
58 def __get_menu_view(self):58 def __get_menu_view(self):
59 """Return the menu view."""59 """Return the menu view."""
@@ -261,7 +261,7 @@
261261
262 def __init__(self, *args, **kwargs):262 def __init__(self, *args, **kwargs):
263 super(WindowButton, self).__init__(*args, **kwargs)263 super(WindowButton, self).__init__(*args, **kwargs)
264 self._mouse = Mouse()264 self._mouse = get_mouse()
265265
266 def mouse_move_to(self):266 def mouse_move_to(self):
267 target_x = self.x + self.width / 2267 target_x = self.x + self.width / 2
@@ -319,7 +319,7 @@
319319
320 def __init__(self, *args, **kwargs):320 def __init__(self, *args, **kwargs):
321 super(IndicatorEntry, self).__init__(*args, **kwargs)321 super(IndicatorEntry, self).__init__(*args, **kwargs)
322 self._mouse = Mouse()322 self._mouse = get_mouse()
323323
324 def mouse_move_to(self):324 def mouse_move_to(self):
325 target_x = self.x + self.width / 2325 target_x = self.x + self.width / 2
326326
=== modified file 'tests/autopilot/unity/emulators/quicklist.py'
--- tests/autopilot/unity/emulators/quicklist.py 2012-08-01 23:35:56 +0000
+++ tests/autopilot/unity/emulators/quicklist.py 2013-03-21 14:03:22 +0000
@@ -11,7 +11,7 @@
1111
12import logging12import logging
1313
14from autopilot.emulators.X11 import Mouse14from autopilot.emulators.input import get_mouse
1515
16from unity.emulators import UnityIntrospectionObject16from unity.emulators import UnityIntrospectionObject
1717
@@ -21,6 +21,10 @@
21class Quicklist(UnityIntrospectionObject):21class Quicklist(UnityIntrospectionObject):
22 """Represents a quicklist."""22 """Represents a quicklist."""
2323
24 def __init__(self, *args, **kwargs):
25 super(Quicklist, self).__init__(*args, **kwargs)
26 self._mouse = get_mouse()
27
24 @property28 @property
25 def items(self):29 def items(self):
26 """Individual items in the quicklist."""30 """Individual items in the quicklist."""
@@ -56,7 +60,7 @@
56 logger.debug("Moving mouse outside the quicklist %r", self)60 logger.debug("Moving mouse outside the quicklist %r", self)
57 target_x = self.x + self.width + 1061 target_x = self.x + self.width + 10
58 target_y = self.y + self.height / 262 target_y = self.y + self.height / 2
59 Mouse().move(target_x, target_y, animate=False)63 self._mouse.move(target_x, target_y, animate=False)
6064
61 @property65 @property
62 def selected_item(self):66 def selected_item(self):
@@ -75,7 +79,7 @@
7579
76 def __init__(self, *args, **kwargs):80 def __init__(self, *args, **kwargs):
77 super(QuicklistMenuItem, self).__init__(*args, **kwargs)81 super(QuicklistMenuItem, self).__init__(*args, **kwargs)
78 self._mouse = Mouse()82 self._mouse = get_mouse()
7983
80 @property84 @property
81 def geometry(self):85 def geometry(self):
8286
=== modified file 'tests/autopilot/unity/emulators/switcher.py'
--- tests/autopilot/unity/emulators/switcher.py 2013-02-04 20:28:02 +0000
+++ tests/autopilot/unity/emulators/switcher.py 2013-03-21 14:03:22 +0000
@@ -11,7 +11,7 @@
1111
12import logging12import logging
1313
14from autopilot.emulators.X11 import Mouse14from autopilot.emulators.input import get_mouse
15from autopilot.keybindings import KeybindingsHelper15from autopilot.keybindings import KeybindingsHelper
1616
17from unity.emulators import UnityIntrospectionObject17from unity.emulators import UnityIntrospectionObject
@@ -45,7 +45,7 @@
4545
46 def __init__(self, *args, **kwargs):46 def __init__(self, *args, **kwargs):
47 super(SwitcherController, self).__init__(*args, **kwargs)47 super(SwitcherController, self).__init__(*args, **kwargs)
48 self._mouse = Mouse()48 self._mouse = get_mouse()
4949
50 def get_switcher_view(self):50 def get_switcher_view(self):
51 views = self.get_children_by_type(SwitcherView)51 views = self.get_children_by_type(SwitcherView)
5252
=== modified file 'tests/autopilot/unity/tests/test_command_lens.py'
--- tests/autopilot/unity/tests/test_command_lens.py 2013-02-21 10:03:21 +0000
+++ tests/autopilot/unity/tests/test_command_lens.py 2013-03-21 14:03:22 +0000
@@ -16,47 +16,47 @@
1616
17import gettext17import gettext
1818
19class CommandLensSearchTests(UnityTestCase):19class CommandScopeSearchTests(UnityTestCase):
20 """Test the command lense search bahavior."""20 """Test the command scope search bahavior."""
2121
22 def setUp(self):22 def setUp(self):
23 super(CommandLensSearchTests, self).setUp()23 super(CommandScopeSearchTests, self).setUp()
24 gettext.install("unity-lens-applications")24 gettext.install("unity-scope-applications")
2525
26 def tearDown(self):26 def tearDown(self):
27 self.unity.dash.ensure_hidden()27 self.unity.dash.ensure_hidden()
28 super(CommandLensSearchTests, self).tearDown()28 super(CommandScopeSearchTests, self).tearDown()
2929
30 def test_no_results(self):30 def test_no_results(self):
31 """An empty string should get no results."""31 """An empty string should get no results."""
32 self.unity.dash.reveal_command_lens()32 self.unity.dash.reveal_command_scope()
33 command_lens = self.unity.dash.get_current_lens()33 command_scope = self.unity.dash.get_current_scope()
3434
35 if self.unity.dash.search_string != "":35 if self.unity.dash.search_string != "":
36 self.keyboard.press_and_release("Delete")36 self.keyboard.press_and_release("Delete")
3737
38 self.assertThat(self.unity.dash.search_string, Eventually(Equals("")))38 self.assertThat(self.unity.dash.search_string, Eventually(Equals("")))
39 results_category = command_lens.get_category_by_name(_("Results"))39 results_category = command_scope.get_category_by_name(_("Results"))
40 self.assertThat(results_category.is_visible, Eventually(Equals(False)))40 self.assertThat(results_category.is_visible, Eventually(Equals(False)))
4141
42 def test_results_category_appears(self):42 def test_results_category_appears(self):
43 """Results category must appear when there are some results."""43 """Results category must appear when there are some results."""
44 self.unity.dash.reveal_command_lens()44 self.unity.dash.reveal_command_scope()
45 command_lens = self.unity.dash.get_current_lens()45 command_scope = self.unity.dash.get_current_scope()
46 # lots of apps start with 'a'...46 # lots of apps start with 'a'...
47 self.keyboard.type("a")47 self.keyboard.type("a")
48 self.assertThat(self.unity.dash.search_string, Eventually(Equals("a")))48 self.assertThat(self.unity.dash.search_string, Eventually(Equals("a")))
49 results_category = command_lens.get_category_by_name(_("Results"))49 results_category = command_scope.get_category_by_name(_("Results"))
50 self.assertThat(results_category.is_visible, Eventually(Equals(True)))50 self.assertThat(results_category.is_visible, Eventually(Equals(True)))
5151
52 def test_result_category_actually_contains_results(self):52 def test_result_category_actually_contains_results(self):
53 """With a search string of 'a', the results category must contain some results."""53 """With a search string of 'a', the results category must contain some results."""
54 self.unity.dash.reveal_command_lens()54 self.unity.dash.reveal_command_scope()
55 command_lens = self.unity.dash.get_current_lens()55 command_scope = self.unity.dash.get_current_scope()
56 # lots of apps start with 'a'...56 # lots of apps start with 'a'...
57 self.keyboard.type("a")57 self.keyboard.type("a")
58 self.assertThat(self.unity.dash.search_string, Eventually(Equals("a")))58 self.assertThat(self.unity.dash.search_string, Eventually(Equals("a")))
59 results_category = command_lens.get_category_by_name(_("Results"))59 results_category = command_scope.get_category_by_name(_("Results"))
60 results = results_category.get_results()60 results = results_category.get_results()
61 self.assertTrue(results)61 self.assertTrue(results)
6262
@@ -66,7 +66,7 @@
66 self.close_all_app("Text Editor")66 self.close_all_app("Text Editor")
67 sleep(1)67 sleep(1)
6868
69 self.unity.dash.reveal_command_lens()69 self.unity.dash.reveal_command_scope()
70 self.keyboard.type("g")70 self.keyboard.type("g")
71 sleep(1)71 sleep(1)
72 self.keyboard.type("edit", 0.1)72 self.keyboard.type("edit", 0.1)
@@ -76,13 +76,13 @@
76 self.assertTrue(app_found)76 self.assertTrue(app_found)
7777
78 def test_ctrl_tab_switching(self):78 def test_ctrl_tab_switching(self):
79 """Pressing Ctrl+Tab after launching command lens must switch to Home lens."""79 """Pressing Ctrl+Tab after launching command scope must switch to Home scope."""
80 self.unity.dash.reveal_command_lens()80 self.unity.dash.reveal_command_scope()
81 self.keybinding("dash/lens/next")81 self.keybinding("dash/scope/next")
82 self.assertThat(self.unity.dash.active_lens, Eventually(Equals("home.lens")))82 self.assertThat(self.unity.dash.active_scope, Eventually(Equals("home.scope")))
8383
84 def test_ctrl_shift_tab_switching(self):84 def test_ctrl_shift_tab_switching(self):
85 """Pressing Ctrl+Shift+Tab after launching command lens must switch to Video lens."""85 """Pressing Ctrl+Shift+Tab after launching command scope must switch to Video scope."""
86 self.unity.dash.reveal_command_lens()86 self.unity.dash.reveal_command_scope()
87 self.keybinding("dash/lens/prev")87 self.keybinding("dash/scope/prev")
88 self.assertThat(self.unity.dash.active_lens, Eventually(Equals("video.lens")))88 self.assertThat(self.unity.dash.active_scope, Eventually(Equals("video.scope")))
8989
=== modified file 'tests/autopilot/unity/tests/test_dash.py'
--- tests/autopilot/unity/tests/test_dash.py 2013-03-18 17:23:42 +0000
+++ tests/autopilot/unity/tests/test_dash.py 2013-03-21 14:03:22 +0000
@@ -44,36 +44,36 @@
44 self.unity.dash.ensure_visible()44 self.unity.dash.ensure_visible()
45 self.unity.dash.ensure_hidden()45 self.unity.dash.ensure_hidden()
4646
47 def test_application_lens_shortcut(self):47 def test_application_scope_shortcut(self):
48 """Application lense must reveal when Super+a is pressed."""48 """Application scope must reveal when Super+a is pressed."""
49 self.unity.dash.reveal_application_lens()49 self.unity.dash.reveal_application_scope()
50 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('applications.lens')))50 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('applications.scope')))
5151
52 def test_music_lens_shortcut(self):52 def test_music_scope_shortcut(self):
53 """Music lense must reveal when Super+w is pressed."""53 """Music scope must reveal when Super+w is pressed."""
54 self.unity.dash.reveal_music_lens()54 self.unity.dash.reveal_music_scope()
55 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('music.lens')))55 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('music.scope')))
5656
57 def test_file_lens_shortcut(self):57 def test_file_scope_shortcut(self):
58 """File lense must reveal when Super+f is pressed."""58 """File scope must reveal when Super+f is pressed."""
59 self.unity.dash.reveal_file_lens()59 self.unity.dash.reveal_file_scope()
60 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('files.lens')))60 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('files.scope')))
6161
62 def test_video_lens_shortcut(self):62 def test_video_scope_shortcut(self):
63 """Video lens must reveal when super+v is pressed."""63 """Video scope must reveal when super+v is pressed."""
64 self.unity.dash.reveal_video_lens()64 self.unity.dash.reveal_video_scope()
65 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('video.lens')))65 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('video.scope')))
6666
67 def test_command_lens_shortcut(self):67 def test_command_scope_shortcut(self):
68 """Run Command lens must reveat on alt+F2."""68 """Run Command scope must reveat on alt+F2."""
69 self.unity.dash.reveal_command_lens()69 self.unity.dash.reveal_command_scope()
70 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('commands.lens')))70 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('commands.scope')))
7171
72 def test_can_go_from_dash_to_command_lens(self):72 def test_can_go_from_dash_to_command_scope(self):
73 """Switch to command lens without closing the dash."""73 """Switch to command scope without closing the dash."""
74 self.unity.dash.ensure_visible()74 self.unity.dash.ensure_visible()
75 self.unity.dash.reveal_command_lens()75 self.unity.dash.reveal_command_scope()
76 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('commands.lens')))76 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('commands.scope')))
7777
78 def test_alt_f4_close_dash(self):78 def test_alt_f4_close_dash(self):
79 """Dash must close on alt+F4."""79 """Dash must close on alt+F4."""
@@ -156,23 +156,23 @@
156 self.unity.dash.ensure_visible()156 self.unity.dash.ensure_visible()
157 self.assertThat(self.unity.dash.visible, Eventually(Equals(True)))157 self.assertThat(self.unity.dash.visible, Eventually(Equals(True)))
158158
159 def test_command_lens_opens_when_in_spread(self):159 def test_command_scope_opens_when_in_spread(self):
160 """This test shows the command lens opens when in spread mode."""160 """This test shows the command scope opens when in spread mode."""
161 self.start_placeholder_app()161 self.start_placeholder_app()
162 self.keybinding("spread/start")162 self.keybinding("spread/start")
163 self.assertThat(self.unity.window_manager.scale_active, Eventually(Equals(True)))163 self.assertThat(self.unity.window_manager.scale_active, Eventually(Equals(True)))
164164
165 self.unity.dash.reveal_command_lens()165 self.unity.dash.reveal_command_scope()
166 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('commands.lens')))166 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('commands.scope')))
167167
168 def test_lens_opens_when_in_spread(self):168 def test_scope_opens_when_in_spread(self):
169 """This test shows that any lens opens when in spread mode."""169 """This test shows that any scope opens when in spread mode."""
170 self.start_placeholder_app()170 self.start_placeholder_app()
171 self.keybinding("spread/start")171 self.keybinding("spread/start")
172 self.assertThat(self.unity.window_manager.scale_active, Eventually(Equals(True)))172 self.assertThat(self.unity.window_manager.scale_active, Eventually(Equals(True)))
173173
174 self.unity.dash.reveal_application_lens()174 self.unity.dash.reveal_application_scope()
175 self.assertThat(self.unity.dash.active_lens, Eventually(Equals('applications.lens')))175 self.assertThat(self.unity.dash.active_scope, Eventually(Equals('applications.scope')))
176176
177177
178class DashSearchInputTests(DashTestCase):178class DashSearchInputTests(DashTestCase):
@@ -199,28 +199,28 @@
199199
200 def test_multi_key(self):200 def test_multi_key(self):
201 """Pressing 'Multi_key' must not add any characters to the search."""201 """Pressing 'Multi_key' must not add any characters to the search."""
202 self.unity.dash.reveal_application_lens()202 self.unity.dash.reveal_application_scope()
203 self.keyboard.press_and_release('Multi_key')203 self.keyboard.press_and_release('Multi_key')
204 self.keyboard.type("o")204 self.keyboard.type("o")
205 self.assertSearchText("")205 self.assertSearchText("")
206206
207 def test_multi_key_o(self):207 def test_multi_key_o(self):
208 """Pressing the sequences 'Multi_key' + '^' + 'o' must produce 'ô'."""208 """Pressing the sequences 'Multi_key' + '^' + 'o' must produce 'ô'."""
209 self.unity.dash.reveal_application_lens()209 self.unity.dash.reveal_application_scope()
210 self.keyboard.press_and_release('Multi_key')210 self.keyboard.press_and_release('Multi_key')
211 self.keyboard.type("^o")211 self.keyboard.type("^o")
212 self.assertSearchText(u'\xf4')212 self.assertSearchText(u'\xf4')
213213
214 def test_multi_key_copyright(self):214 def test_multi_key_copyright(self):
215 """Pressing the sequences 'Multi_key' + 'c' + 'o' must produce '©'."""215 """Pressing the sequences 'Multi_key' + 'c' + 'o' must produce '©'."""
216 self.unity.dash.reveal_application_lens()216 self.unity.dash.reveal_application_scope()
217 self.keyboard.press_and_release('Multi_key')217 self.keyboard.press_and_release('Multi_key')
218 self.keyboard.type("oc")218 self.keyboard.type("oc")
219 self.assertSearchText(u'\xa9')219 self.assertSearchText(u'\xa9')
220220
221 def test_multi_key_delete(self):221 def test_multi_key_delete(self):
222 """Pressing 'Multi_key' must not get stuck looking for a sequence."""222 """Pressing 'Multi_key' must not get stuck looking for a sequence."""
223 self.unity.dash.reveal_application_lens()223 self.unity.dash.reveal_application_scope()
224 self.keyboard.type("dd")224 self.keyboard.type("dd")
225 self.keyboard.press_and_release('Multi_key')225 self.keyboard.press_and_release('Multi_key')
226 self.keyboard.press_and_release('BackSpace')226 self.keyboard.press_and_release('BackSpace')
@@ -231,64 +231,64 @@
231class DashKeyNavTests(DashTestCase):231class DashKeyNavTests(DashTestCase):
232 """Test the unity Dash keyboard navigation."""232 """Test the unity Dash keyboard navigation."""
233233
234 def test_lensbar_gets_keyfocus(self):234 def test_scopebar_gets_keyfocus(self):
235 """Test that the lensbar gets key focus after using Down keypresses."""235 """Test that the scopebar gets key focus after using Down keypresses."""
236 self.unity.dash.ensure_visible()236 self.unity.dash.ensure_visible()
237237
238 # Make sure that the lens bar can get the focus238 # Make sure that the scope bar can get the focus
239 for i in range(self.unity.dash.get_num_rows()):239 for i in range(self.unity.dash.get_num_rows()):
240 self.keyboard.press_and_release("Down")240 self.keyboard.press_and_release("Down")
241 lensbar = self.unity.dash.view.get_lensbar()241 scopebar = self.unity.dash.view.get_scopebar()
242 self.assertThat(lensbar.focused_lens_icon, Eventually(NotEquals('')))242 self.assertThat(scopebar.focused_scope_icon, Eventually(NotEquals('')))
243243
244 def test_lensbar_focus_changes(self):244 def test_scopebar_focus_changes(self):
245 """Lensbar focused icon should change with Left and Right keypresses."""245 """Scopebar focused icon should change with Left and Right keypresses."""
246 self.unity.dash.ensure_visible()246 self.unity.dash.ensure_visible()
247247
248 for i in range(self.unity.dash.get_num_rows()):248 for i in range(self.unity.dash.get_num_rows()):
249 self.keyboard.press_and_release("Down")249 self.keyboard.press_and_release("Down")
250 lensbar = self.unity.dash.view.get_lensbar()250 scopebar = self.unity.dash.view.get_scopebar()
251251
252 current_focused_icon = lensbar.focused_lens_icon252 current_focused_icon = scopebar.focused_scope_icon
253253
254 self.keyboard.press_and_release("Right")254 self.keyboard.press_and_release("Right")
255 self.assertThat(lensbar.focused_lens_icon, Eventually(NotEquals(current_focused_icon)))255 self.assertThat(scopebar.focused_scope_icon, Eventually(NotEquals(current_focused_icon)))
256256
257 self.keyboard.press_and_release("Left")257 self.keyboard.press_and_release("Left")
258 self.assertThat(lensbar.focused_lens_icon, Eventually(Equals(current_focused_icon)))258 self.assertThat(scopebar.focused_scope_icon, Eventually(Equals(current_focused_icon)))
259259
260 def test_lensbar_enter_activation(self):260 def test_scopebar_enter_activation(self):
261 """Must be able to activate LensBar icons that have focus with an Enter keypress."""261 """Must be able to activate ScopeBar icons that have focus with an Enter keypress."""
262 self.unity.dash.ensure_visible()262 self.unity.dash.ensure_visible()
263263
264 for i in range(self.unity.dash.get_num_rows()):264 for i in range(self.unity.dash.get_num_rows()):
265 self.keyboard.press_and_release("Down")265 self.keyboard.press_and_release("Down")
266 self.keyboard.press_and_release("Right")266 self.keyboard.press_and_release("Right")
267 lensbar = self.unity.dash.view.get_lensbar()267 scopebar = self.unity.dash.view.get_scopebar()
268 focused_icon = lensbar.focused_lens_icon268 focused_icon = scopebar.focused_scope_icon
269 self.keyboard.press_and_release("Enter")269 self.keyboard.press_and_release("Enter")
270270
271 self.assertThat(lensbar.active_lens, Eventually(Equals(focused_icon)))271 self.assertThat(scopebar.active_scope, Eventually(Equals(focused_icon)))
272272
273 # lensbar should lose focus after activation.273 # scopebar should lose focus after activation.
274 self.assertThat(lensbar.focused_lens_icon, Eventually(Equals("")))274 self.assertThat(scopebar.focused_scope_icon, Eventually(Equals("")))
275275
276 def test_focus_returns_to_searchbar(self):276 def test_focus_returns_to_searchbar(self):
277 """This test makes sure that the focus is returned to the searchbar of the newly277 """This test makes sure that the focus is returned to the searchbar of the newly
278 activated lens."""278 activated scope."""
279 self.unity.dash.ensure_visible()279 self.unity.dash.ensure_visible()
280280
281 for i in range(self.unity.dash.get_num_rows()):281 for i in range(self.unity.dash.get_num_rows()):
282 self.keyboard.press_and_release("Down")282 self.keyboard.press_and_release("Down")
283 self.keyboard.press_and_release("Right")283 self.keyboard.press_and_release("Right")
284 lensbar = self.unity.dash.view.get_lensbar()284 scopebar = self.unity.dash.view.get_scopebar()
285 focused_icon = lensbar.focused_lens_icon285 focused_icon = scopebar.focused_scope_icon
286 self.keyboard.press_and_release("Enter")286 self.keyboard.press_and_release("Enter")
287287
288 self.assertThat(lensbar.active_lens, Eventually(Equals(focused_icon)))288 self.assertThat(scopebar.active_scope, Eventually(Equals(focused_icon)))
289 self.assertThat(lensbar.focused_lens_icon, Eventually(Equals("")))289 self.assertThat(scopebar.focused_scope_icon, Eventually(Equals("")))
290290
291 # Now we make sure if the newly activated lens searchbar have the focus.291 # Now we make sure if the newly activated scope searchbar have the focus.
292 self.keyboard.type("HasFocus")292 self.keyboard.type("HasFocus")
293293
294 self.assertThat(self.unity.dash.search_string, Eventually(Equals("HasFocus")))294 self.assertThat(self.unity.dash.search_string, Eventually(Equals("HasFocus")))
@@ -304,22 +304,22 @@
304 self.unity.dash.ensure_visible()304 self.unity.dash.ensure_visible()
305 # Make sure that a category have the focus.305 # Make sure that a category have the focus.
306 self.keyboard.press_and_release("Down")306 self.keyboard.press_and_release("Down")
307 lens = self.unity.dash.get_current_lens()307 scope = self.unity.dash.get_current_scope()
308 category = lens.get_focused_category()308 category = scope.get_focused_category()
309 self.assertIsNot(category, None)309 self.assertIsNot(category, None)
310 # Make sure that the category is highlighted.310 # Make sure that the category is highlighted.
311 self.assertTrue(category.header_is_highlighted)311 self.assertTrue(category.header_is_highlighted)
312312
313 def test_control_tab_lens_cycle(self):313 def test_control_tab_scope_cycle(self):
314 """This test makes sure that Ctrl+Tab cycles lenses."""314 """This test makes sure that Ctrl+Tab cycles scopes."""
315 self.unity.dash.ensure_visible()315 self.unity.dash.ensure_visible()
316316
317 self.keyboard.press('Control')317 self.keyboard.press('Control')
318 self.keyboard.press_and_release('Tab')318 self.keyboard.press_and_release('Tab')
319 self.keyboard.release('Control')319 self.keyboard.release('Control')
320320
321 lensbar = self.unity.dash.view.get_lensbar()321 scopebar = self.unity.dash.view.get_scopebar()
322 self.assertEqual(lensbar.active_lens, u'applications.lens')322 self.assertEqual(scopebar.active_scope, u'applications.scope')
323323
324 self.keyboard.press('Control')324 self.keyboard.press('Control')
325 self.keyboard.press('Shift')325 self.keyboard.press('Shift')
@@ -327,33 +327,33 @@
327 self.keyboard.release('Control')327 self.keyboard.release('Control')
328 self.keyboard.release('Shift')328 self.keyboard.release('Shift')
329329
330 self.assertThat(lensbar.active_lens, Eventually(Equals('home.lens')))330 self.assertThat(scopebar.active_scope, Eventually(Equals('home.scope')))
331331
332 def test_tab_cycle_category_headers(self):332 def test_tab_cycle_category_headers(self):
333 """ Makes sure that pressing tab cycles through the category headers"""333 """ Makes sure that pressing tab cycles through the category headers"""
334 self.unity.dash.ensure_visible()334 self.unity.dash.ensure_visible()
335 lens = self.unity.dash.get_current_lens()335 scope = self.unity.dash.get_current_scope()
336336
337 # Test that tab cycles through the categories.337 # Test that tab cycles through the categories.
338 # + 1 is to cycle back to first header338 # + 1 is to cycle back to first header
339 for i in range(lens.get_num_visible_categories() + 1):339 for i in range(scope.get_num_visible_categories() + 1):
340 self.keyboard.press_and_release('Tab')340 self.keyboard.press_and_release('Tab')
341 category = lens.get_focused_category()341 category = scope.get_focused_category()
342 self.assertIsNot(category, None)342 self.assertIsNot(category, None)
343343
344 def test_tab_with_filter_bar(self):344 def test_tab_with_filter_bar(self):
345 """ This test makes sure that Tab works well with the filter bara."""345 """ This test makes sure that Tab works well with the filter bara."""
346 self.unity.dash.reveal_application_lens()346 self.unity.dash.reveal_application_scope()
347 lens = self.unity.dash.get_current_lens()347 scope = self.unity.dash.get_current_scope()
348348
349 # Tabs to last category349 # Tabs to last category
350 for i in range(lens.get_num_visible_categories()):350 for i in range(scope.get_num_visible_categories()):
351 self.keyboard.press_and_release('Tab')351 self.keyboard.press_and_release('Tab')
352352
353 self.keyboard.press_and_release('Tab')353 self.keyboard.press_and_release('Tab')
354 self.assertThat(self.unity.dash.searchbar.expander_has_focus, Eventually(Equals(True)))354 self.assertThat(self.unity.dash.searchbar.expander_has_focus, Eventually(Equals(True)))
355355
356 filter_bar = lens.get_filterbar()356 filter_bar = scope.get_filterbar()
357 if not self.unity.dash.searchbar.showing_filters:357 if not self.unity.dash.searchbar.showing_filters:
358 self.keyboard.press_and_release('Enter')358 self.keyboard.press_and_release('Enter')
359 self.assertThat(self.unity.dash.searchbar.showing_filters, Eventually(Equals(True)))359 self.assertThat(self.unity.dash.searchbar.showing_filters, Eventually(Equals(True)))
@@ -366,17 +366,17 @@
366366
367 # Ensure that tab cycles back to a category header367 # Ensure that tab cycles back to a category header
368 self.keyboard.press_and_release('Tab')368 self.keyboard.press_and_release('Tab')
369 category = lens.get_focused_category()369 category = scope.get_focused_category()
370 self.assertIsNot(category, None)370 self.assertIsNot(category, None)
371371
372 def test_bottom_up_keynav_with_filter_bar(self):372 def test_bottom_up_keynav_with_filter_bar(self):
373 """This test makes sure that bottom-up key navigation works well373 """This test makes sure that bottom-up key navigation works well
374 in the dash filter bar.374 in the dash filter bar.
375 """375 """
376 self.unity.dash.reveal_application_lens()376 self.unity.dash.reveal_application_scope()
377 lens = self.unity.dash.get_current_lens()377 scope = self.unity.dash.get_current_scope()
378378
379 filter_bar = lens.get_filterbar()379 filter_bar = scope.get_filterbar()
380 # Need to ensure the filter expander has focus, so if it's already380 # Need to ensure the filter expander has focus, so if it's already
381 # expanded, we collapse it first:381 # expanded, we collapse it first:
382 filter_bar.ensure_collapsed()382 filter_bar.ensure_collapsed()
@@ -496,8 +496,8 @@
496 """Expanding or collapsing the filterbar must keave keyboard focus in the496 """Expanding or collapsing the filterbar must keave keyboard focus in the
497 search bar.497 search bar.
498 """498 """
499 self.unity.dash.reveal_application_lens()499 self.unity.dash.reveal_application_scope()
500 filter_bar = self.unity.dash.get_current_lens().get_filterbar()500 filter_bar = self.unity.dash.get_current_scope().get_filterbar()
501 filter_bar.ensure_collapsed()501 filter_bar.ensure_collapsed()
502502
503 self.keyboard.type("hello")503 self.keyboard.type("hello")
@@ -519,39 +519,39 @@
519 self.assertSearchText("HasFocus")519 self.assertSearchText("HasFocus")
520520
521521
522class DashLensResultsTests(DashTestCase):522class DashScopeResultsTests(DashTestCase):
523 """Tests results from the lens view."""523 """Tests results from the scope view."""
524524
525 def test_results_message_empty_search(self):525 def test_results_message_empty_search(self):
526 """This tests a message is not shown when there is no text."""526 """This tests a message is not shown when there is no text."""
527 self.unity.dash.reveal_application_lens()527 self.unity.dash.reveal_application_scope()
528 lens = self.unity.dash.get_current_lens()528 scope = self.unity.dash.get_current_scope()
529 self.assertThat(lens.no_results_active, Eventually(Equals(False)))529 self.assertThat(scope.no_results_active, Eventually(Equals(False)))
530530
531 def test_results_message(self):531 def test_results_message(self):
532 """This test no mesage will be shown when results are there."""532 """This test no mesage will be shown when results are there."""
533 self.unity.dash.reveal_application_lens()533 self.unity.dash.reveal_application_scope()
534 self.keyboard.type("Terminal")534 self.keyboard.type("Terminal")
535 self.assertThat(self.unity.dash.search_string, Eventually(Equals("Terminal")))535 self.assertThat(self.unity.dash.search_string, Eventually(Equals("Terminal")))
536 lens = self.unity.dash.get_current_lens()536 scope = self.unity.dash.get_current_scope()
537 self.assertThat(lens.no_results_active, Eventually(Equals(False)))537 self.assertThat(scope.no_results_active, Eventually(Equals(False)))
538538
539 def test_no_results_message(self):539 def test_no_results_message(self):
540 """This test shows a message will appear in the lens."""540 """This test shows a message will appear in the scope."""
541 self.unity.dash.reveal_application_lens()541 self.unity.dash.reveal_application_scope()
542 self.keyboard.type("qwerlkjzvxc")542 self.keyboard.type("qwerlkjzvxc")
543 self.assertThat(self.unity.dash.search_string, Eventually(Equals("qwerlkjzvxc")))543 self.assertThat(self.unity.dash.search_string, Eventually(Equals("qwerlkjzvxc")))
544 lens = self.unity.dash.get_current_lens()544 scope = self.unity.dash.get_current_scope()
545 self.assertThat(lens.no_results_active, Eventually(Equals(True)))545 self.assertThat(scope.no_results_active, Eventually(Equals(True)))
546546
547 def test_results_update_on_filter_changed(self):547 def test_results_update_on_filter_changed(self):
548 """This test makes sure the results change when filters change."""548 """This test makes sure the results change when filters change."""
549 gettext.install("unity-lens-applications")549 gettext.install("unity-scope-applications")
550 self.unity.dash.reveal_application_lens()550 self.unity.dash.reveal_application_scope()
551 lens = self.unity.dash.get_current_lens()551 scope = self.unity.dash.get_current_scope()
552 self.keyboard.type(" ")552 self.keyboard.type(" ")
553 self.assertThat(self.unity.dash.search_string, Eventually(Equals(" ")))553 self.assertThat(self.unity.dash.search_string, Eventually(Equals(" ")))
554 results_category = lens.get_category_by_name(_("Installed"))554 results_category = scope.get_category_by_name(_("Installed"))
555 old_results = results_category.get_results()555 old_results = results_category.get_results()
556556
557 # FIXME: This should be a method on the dash emulator perhaps, or557 # FIXME: This should be a method on the dash emulator perhaps, or
@@ -559,20 +559,20 @@
559 # function that is only called once!559 # function that is only called once!
560 def activate_filter(add_cleanup = False):560 def activate_filter(add_cleanup = False):
561 # Tabs to last category561 # Tabs to last category
562 for i in range(lens.get_num_visible_categories()):562 for i in range(scope.get_num_visible_categories()):
563 self.keyboard.press_and_release('Tab')563 self.keyboard.press_and_release('Tab')
564564
565 self.keyboard.press_and_release('Tab')565 self.keyboard.press_and_release('Tab')
566 self.assertThat(self.unity.dash.searchbar.expander_has_focus, Eventually(Equals(True)))566 self.assertThat(self.unity.dash.searchbar.expander_has_focus, Eventually(Equals(True)))
567567
568 filter_bar = lens.get_filterbar()568 filter_bar = scope.get_filterbar()
569 if not self.unity.dash.searchbar.showing_filters:569 if not self.unity.dash.searchbar.showing_filters:
570 self.keyboard.press_and_release('Enter')570 self.keyboard.press_and_release('Enter')
571 self.assertThat(self.unity.dash.searchbar.showing_filters, Eventually(Equals(True)))571 self.assertThat(self.unity.dash.searchbar.showing_filters, Eventually(Equals(True)))
572 if add_cleanup:572 if add_cleanup:
573 self.addCleanup(filter_bar.ensure_collapsed)573 self.addCleanup(filter_bar.ensure_collapsed)
574574
575 # Tab to the "Type" filter in apps lens575 # Tab to the "Type" filter in apps scope
576 self.keyboard.press_and_release('Tab')576 self.keyboard.press_and_release('Tab')
577 new_focused_filter = filter_bar.get_focused_filter()577 new_focused_filter = filter_bar.get_focused_filter()
578 self.assertIsNotNone(new_focused_filter)578 self.assertIsNotNone(new_focused_filter)
@@ -586,7 +586,7 @@
586 activate_filter(True)586 activate_filter(True)
587 self.addCleanup(activate_filter)587 self.addCleanup(activate_filter)
588588
589 results_category = lens.get_category_by_name(_("Installed"))589 results_category = scope.get_category_by_name(_("Installed"))
590 results = results_category.get_results()590 results = results_category.get_results()
591 self.assertIsNot(results, old_results)591 self.assertIsNot(results, old_results)
592592
@@ -597,14 +597,14 @@
597class DashVisualTests(DashTestCase):597class DashVisualTests(DashTestCase):
598 """Tests that the dash visual is correct."""598 """Tests that the dash visual is correct."""
599599
600 def test_closing_dash_hides_current_lens(self):600 def test_closing_dash_hides_current_scope(self):
601 """When exiting from the dash the current lens must set it self to not visible."""601 """When exiting from the dash the current scope must set it self to not visible."""
602602
603 self.unity.dash.ensure_visible()603 self.unity.dash.ensure_visible()
604 lens = self.unity.dash.get_current_lens()604 scope = self.unity.dash.get_current_scope()
605 self.unity.dash.ensure_hidden()605 self.unity.dash.ensure_hidden()
606606
607 self.assertThat(lens.visible, Eventually(Equals(False)))607 self.assertThat(scope.visible, Eventually(Equals(False)))
608608
609 def test_dash_position_with_non_default_launcher_width(self):609 def test_dash_position_with_non_default_launcher_width(self):
610 """"There should be no empty space between launcher and dash when the launcher610 """"There should be no empty space between launcher and dash when the launcher
@@ -625,10 +625,10 @@
625 """The see more results label should be baseline aligned625 """The see more results label should be baseline aligned
626 with the category name label.626 with the category name label.
627 """627 """
628 self.unity.dash.reveal_application_lens()628 self.unity.dash.reveal_application_scope()
629629
630 lens = self.unity.dash.get_current_lens()630 scope = self.unity.dash.get_current_scope()
631 groups = lens.get_groups()631 groups = scope.get_groups()
632632
633 for group in groups:633 for group in groups:
634 if (group.is_visible and group.expand_label_is_visible):634 if (group.is_visible and group.expand_label_is_visible):
@@ -637,25 +637,25 @@
637 self.assertThat(expand_label_y, Equals(name_label_y))637 self.assertThat(expand_label_y, Equals(name_label_y))
638638
639639
640class DashLensBarTests(DashTestCase):640class DashScopeBarTests(DashTestCase):
641 """Tests that the lensbar works well."""641 """Tests that the scopebar works well."""
642642
643 def setUp(self):643 def setUp(self):
644 super(DashLensBarTests, self).setUp()644 super(DashScopeBarTests, self).setUp()
645 self.unity.dash.ensure_visible()645 self.unity.dash.ensure_visible()
646 self.lensbar = self.unity.dash.view.get_lensbar()646 self.scopebar = self.unity.dash.view.get_scopebar()
647647
648 def test_click_inside_highlight(self):648 def test_click_inside_highlight(self):
649 """Lens selection should work when clicking in649 """Scope selection should work when clicking in
650 the rectangle outside of the icon.650 the rectangle outside of the icon.
651 """651 """
652 app_icon = self.lensbar.get_icon_by_name(u'applications.lens')652 app_icon = self.scopebar.get_icon_by_name(u'applications.scope')
653653
654 self.mouse.move(app_icon.x + (app_icon.width / 2),654 self.mouse.move(app_icon.x + (app_icon.width / 2),
655 app_icon.y + (app_icon.height / 2))655 app_icon.y + (app_icon.height / 2))
656 self.mouse.click()656 self.mouse.click()
657657
658 self.assertThat(self.lensbar.active_lens, Eventually(Equals('applications.lens')))658 self.assertThat(self.scopebar.active_scope, Eventually(Equals('applications.scope')))
659659
660660
661class DashBorderTests(DashTestCase):661class DashBorderTests(DashTestCase):
@@ -703,11 +703,11 @@
703 """Clicking into a category highlight must expand/collapse703 """Clicking into a category highlight must expand/collapse
704 the view.704 the view.
705 """705 """
706 gettext.install("unity-lens-applications", unicode=True)706 gettext.install("unity-scope-applications", unicode=True)
707 lens = self.unity.dash.reveal_application_lens()707 scope = self.unity.dash.reveal_application_scope()
708 self.addCleanup(self.unity.dash.ensure_hidden)708 self.addCleanup(self.unity.dash.ensure_hidden)
709709
710 category = lens.get_category_by_name(_("Installed"))710 category = scope.get_category_by_name(_("Installed"))
711 is_expanded = category.is_expanded711 is_expanded = category.is_expanded
712712
713 self.mouse.move(self.unity.dash.view.x + self.unity.dash.view.width / 2,713 self.mouse.move(self.unity.dash.view.x + self.unity.dash.view.width / 2,
@@ -722,18 +722,18 @@
722722
723class PreviewInvocationTests(DashTestCase):723class PreviewInvocationTests(DashTestCase):
724 """Tests that dash previews can be opened and closed in different724 """Tests that dash previews can be opened and closed in different
725 lenses.725 scopes.
726 """726 """
727 def test_app_lens_preview_open_close(self):727 def test_app_scope_preview_open_close(self):
728 """Right-clicking on an application lens result must show728 """Right-clicking on an application scope result must show
729 its preview.729 its preview.
730730
731 """731 """
732 gettext.install("unity-lens-applications", unicode=True)732 gettext.install("unity-scope-applications", unicode=True)
733 lens = self.unity.dash.reveal_application_lens()733 scope = self.unity.dash.reveal_application_scope()
734 self.addCleanup(self.unity.dash.ensure_hidden)734 self.addCleanup(self.unity.dash.ensure_hidden)
735735
736 category = lens.get_category_by_name(_("More suggestions"))736 category = scope.get_category_by_name(_("More suggestions"))
737 results = category.get_results()737 results = category.get_results()
738 result = results[0]738 result = results[0]
739 # result.preview handles finding xy co-ords and right mouse-click739 # result.preview handles finding xy co-ords and right mouse-click
@@ -744,24 +744,24 @@
744744
745 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))745 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))
746746
747 def test_files_lens_preview_open_close(self):747 def test_files_scope_preview_open_close(self):
748 """Right-clicking on a files lens result must show its748 """Right-clicking on a files scope result must show its
749 preview.749 preview.
750 """750 """
751 gettext.install("unity-lens-files", unicode=True)751 gettext.install("unity-scope-files", unicode=True)
752752
753 # Instead of skipping the test, here we can create a dummy file to open and753 # Instead of skipping the test, here we can create a dummy file to open and
754 # make sure the lens result is non-empty754 # make sure the scope result is non-empty
755 (file_handle, file_path) = mkstemp()755 (file_handle, file_path) = mkstemp()
756 self.addCleanup(remove, file_path)756 self.addCleanup(remove, file_path)
757 gedit_win = self.start_app_window('Text Editor', files=[file_path], locale='C')757 gedit_win = self.start_app_window('Text Editor', files=[file_path], locale='C')
758 self.addCleanup(self.close_all_app, 'Text Editor')758 self.addCleanup(self.close_all_app, 'Text Editor')
759 self.assertProperty(gedit_win, is_focused=True)759 self.assertProperty(gedit_win, is_focused=True)
760760
761 lens = self.unity.dash.reveal_file_lens()761 scope = self.unity.dash.reveal_file_scope()
762 self.addCleanup(self.unity.dash.ensure_hidden)762 self.addCleanup(self.unity.dash.ensure_hidden)
763763
764 category = lens.get_category_by_name(_("Recent"))764 category = scope.get_category_by_name(_("Recent"))
765 refresh_results_fn = lambda: len(category.get_results())765 refresh_results_fn = lambda: len(category.get_results())
766 self.assertThat(refresh_results_fn, Eventually(GreaterThan(0)))766 self.assertThat(refresh_results_fn, Eventually(GreaterThan(0)))
767 results = category.get_results()767 results = category.get_results()
@@ -774,18 +774,18 @@
774774
775 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))775 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))
776776
777 def test_music_lens_preview_open_close(self):777 def test_music_scope_preview_open_close(self):
778 """Right-clicking on a music lens result must show its778 """Right-clicking on a music scope result must show its
779 preview.779 preview.
780 """780 """
781 lens = self.unity.dash.reveal_music_lens()781 scope = self.unity.dash.reveal_music_scope()
782 self.addCleanup(self.unity.dash.ensure_hidden)782 self.addCleanup(self.unity.dash.ensure_hidden)
783783
784 category = lens.get_category_by_name("Songs")784 category = scope.get_category_by_name("Songs")
785 # Incase there was no music ever played we skip the test instead785 # Incase there was no music ever played we skip the test instead
786 # of failing.786 # of failing.
787 if category is None or not category.is_visible:787 if category is None or not category.is_visible:
788 self.skipTest("This lens is probably empty")788 self.skipTest("This scope is probably empty")
789789
790 results = category.get_results()790 results = category.get_results()
791791
@@ -798,28 +798,28 @@
798798
799 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))799 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False)))
800800
801 def test_video_lens_preview_open_close(self):801 def test_video_scope_preview_open_close(self):
802 """Right-clicking on a video lens result must show its802 """Right-clicking on a video scope result must show its
803 preview.803 preview.
804 """804 """
805 gettext.install("unity-lens-video", unicode=True)805 gettext.install("unity-scope-video", unicode=True)
806806
807 def get_category(lens):807 def get_category(scope):
808 category = lens.get_category_by_name(_("Recently Viewed"))808 category = scope.get_category_by_name(_("Recently Viewed"))
809 # If there was no video played on this system this category is expected809 # If there was no video played on this system this category is expected
810 # to be empty, if its empty we check if the 'Online' category have any810 # to be empty, if its empty we check if the 'Online' category have any
811 # contents, if not then we skip the test.811 # contents, if not then we skip the test.
812 if category is None or not category.is_visible:812 if category is None or not category.is_visible:
813 category = lens.get_category_by_name("Online")813 category = scope.get_category_by_name("Online")
814 if category is None or not category.is_visible:814 if category is None or not category.is_visible:
815 self.skipTest("This lens is probably empty")815 self.skipTest("This scope is probably empty")
816 return category816 return category
817817
818 lens = self.unity.dash.reveal_video_lens()818 scope = self.unity.dash.reveal_video_scope()
819 self.addCleanup(self.unity.dash.ensure_hidden)819 self.addCleanup(self.unity.dash.ensure_hidden)
820820
821 self.assertThat(lambda: get_category(lens), Eventually(NotEquals(None)))821 self.assertThat(lambda: get_category(scope), Eventually(NotEquals(None)))
822 category = get_category(lens)822 category = get_category(scope)
823823
824 results = category.get_results()824 results = category.get_results()
825825
@@ -836,11 +836,11 @@
836 """Pressing menu key on a selected dash result must show836 """Pressing menu key on a selected dash result must show
837 its preview.837 its preview.
838 """838 """
839 gettext.install("unity-lens-applications", unicode=True)839 gettext.install("unity-scope-applications", unicode=True)
840 lens = self.unity.dash.reveal_application_lens()840 scope = self.unity.dash.reveal_application_scope()
841 self.addCleanup(self.unity.dash.ensure_hidden)841 self.addCleanup(self.unity.dash.ensure_hidden)
842842
843 category = lens.get_category_by_name(_("More suggestions"))843 category = scope.get_category_by_name(_("More suggestions"))
844 results = category.get_results()844 results = category.get_results()
845 result = results[0]845 result = results[0]
846 # result.preview_key() handles finding xy co-ords and key press846 # result.preview_key() handles finding xy co-ords and key press
@@ -853,12 +853,12 @@
853853
854 def setUp(self):854 def setUp(self):
855 super(PreviewNavigateTests, self).setUp()855 super(PreviewNavigateTests, self).setUp()
856 gettext.install("unity-lens-applications", unicode=True)856 gettext.install("unity-scope-applications", unicode=True)
857857
858 lens = self.unity.dash.reveal_application_lens()858 scope = self.unity.dash.reveal_application_scope()
859 self.addCleanup(self.unity.dash.ensure_hidden)859 self.addCleanup(self.unity.dash.ensure_hidden)
860860
861 results_category = lens.get_category_by_name(_("More suggestions"))861 results_category = scope.get_category_by_name(_("More suggestions"))
862 # wait for results (we need 4 results to perorm the multi-navigation tests)862 # wait for results (we need 4 results to perorm the multi-navigation tests)
863 refresh_fn = lambda: len(results_category.get_results())863 refresh_fn = lambda: len(results_category.get_results())
864 self.assertThat(refresh_fn, Eventually(GreaterThan(4)))864 self.assertThat(refresh_fn, Eventually(GreaterThan(4)))
@@ -984,12 +984,12 @@
984984
985 def setUp(self):985 def setUp(self):
986 super(PreviewClickCancelTests, self).setUp()986 super(PreviewClickCancelTests, self).setUp()
987 gettext.install("unity-lens-applications")987 gettext.install("unity-scope-applications")
988 lens = self.unity.dash.reveal_application_lens()988 scope = self.unity.dash.reveal_application_scope()
989 self.addCleanup(self.unity.dash.ensure_hidden)989 self.addCleanup(self.unity.dash.ensure_hidden)
990 # Only testing an application preview for this test.990 # Only testing an application preview for this test.
991 self.keyboard.type("Software Updater")991 self.keyboard.type("Software Updater")
992 results_category = lens.get_category_by_name(_("Installed"))992 results_category = scope.get_category_by_name(_("Installed"))
993 results = results_category.get_results()993 results = results_category.get_results()
994994
995 result = results[0]995 result = results[0]
996996
=== modified file 'tests/autopilot/unity/tests/test_home_lens.py'
--- tests/autopilot/unity/tests/test_home_lens.py 2013-02-21 10:03:21 +0000
+++ tests/autopilot/unity/tests/test_home_lens.py 2013-03-21 14:03:22 +0000
@@ -15,15 +15,15 @@
15from unity.tests import UnityTestCase15from unity.tests import UnityTestCase
1616
1717
18class HomeLensSearchTests(UnityTestCase):18class HomeScopeSearchTests(UnityTestCase):
19 """Test the command lense search bahavior."""19 """Test the command scope search bahavior."""
2020
21 def setUp(self):21 def setUp(self):
22 super(HomeLensSearchTests, self).setUp()22 super(HomeScopeSearchTests, self).setUp()
2323
24 def tearDown(self):24 def tearDown(self):
25 self.unity.dash.ensure_hidden()25 self.unity.dash.ensure_hidden()
26 super(HomeLensSearchTests, self).tearDown()26 super(HomeScopeSearchTests, self).tearDown()
2727
28 def test_quick_run_app(self):28 def test_quick_run_app(self):
29 """Hitting enter runs an application even though a search might not have fully29 """Hitting enter runs an application even though a search might not have fully
3030
=== modified file 'tests/autopilot/unity/tests/test_search.py'
--- tests/autopilot/unity/tests/test_search.py 2013-03-12 13:31:41 +0000
+++ tests/autopilot/unity/tests/test_search.py 2013-03-21 14:03:22 +0000
@@ -20,8 +20,8 @@
2020
21# XXX: Ugly workaround for a really annoying bug (LP: #1152517) which breaks21# XXX: Ugly workaround for a really annoying bug (LP: #1152517) which breaks
22# this test suite. So, to workaround, we toggle the dash once before doing any22# this test suite. So, to workaround, we toggle the dash once before doing any
23# app lens search tests23# app scope search tests
24workaround_lenses_load_done = False24workaround_scopes_load_done = False
2525
26class SearchTestsBase(UnityTestCase):26class SearchTestsBase(UnityTestCase):
27 """Base class for testing searching in search fields.27 """Base class for testing searching in search fields.
@@ -59,28 +59,28 @@
59 self.input_and_check_result(self.input, self.result) 59 self.input_and_check_result(self.input, self.result)
6060
6161
62# Lens tests62# Scope tests
6363
64class ApplicationLensSearchTestBase(SearchTestsBase):64class ApplicationScopeSearchTestBase(SearchTestsBase):
65 """Common class for all tests for searching in the application lens."""65 """Common class for all tests for searching in the application scope."""
6666
67 def setUp(self):67 def setUp(self):
68 super(ApplicationLensSearchTestBase, self).setUp()68 super(ApplicationScopeSearchTestBase, self).setUp()
69 # XXX: Temporary workaround for LP: #115251769 # XXX: Temporary workaround for LP: #1152517
70 global workaround_lenses_load_done70 global workaround_scopes_load_done
71 if not workaround_lenses_load_done:71 if not workaround_scopes_load_done:
72 self.unity.dash.ensure_visible()72 self.unity.dash.ensure_visible()
73 self.unity.dash.ensure_hidden()73 self.unity.dash.ensure_hidden()
74 workaround_lenses_load_done = True74 workaround_scopes_load_done = True
7575
76 self.app_lens = self.unity.dash.reveal_application_lens()76 self.app_scope = self.unity.dash.reveal_application_scope()
77 self.addCleanup(self.unity.dash.ensure_hidden)77 self.addCleanup(self.unity.dash.ensure_hidden)
78 gettext.install("unity-lens-applications", unicode=True)78 gettext.install("unity-lens-applications", unicode=True)
7979
80 def input_and_check_result(self, string, expected):80 def input_and_check_result(self, string, expected):
81 self.keyboard.type(string)81 self.keyboard.type(string)
82 self.assertThat(self.unity.dash.search_string, Eventually(Equals(string)))82 self.assertThat(self.unity.dash.search_string, Eventually(Equals(string)))
83 category = self.app_lens.get_category_by_name(_("Installed"))83 category = self.app_scope.get_category_by_name(_("Installed"))
84 refresh_results_fn = lambda: len(category.get_results())84 refresh_results_fn = lambda: len(category.get_results())
85 self.assertThat(refresh_results_fn, Eventually(GreaterThan(0)))85 self.assertThat(refresh_results_fn, Eventually(GreaterThan(0)))
86 results = category.get_results()86 results = category.get_results()
@@ -92,8 +92,8 @@
92 self.assertTrue(found)92 self.assertTrue(found)
93 93
9494
95class ApplicationLensSearchTests(ApplicationLensSearchTestBase):95class ApplicationScopeSearchTests(ApplicationScopeSearchTestBase):
96 """Simple search tests for the application lens."""96 """Simple search tests for the application scope."""
9797
98 scenarios = [98 scenarios = [
99 ('basic', {'input': 'Window Mocker', 'result': 'Window Mocker'}),99 ('basic', {'input': 'Window Mocker', 'result': 'Window Mocker'}),
@@ -104,15 +104,15 @@
104 ]104 ]
105105
106 def setUp(self):106 def setUp(self):
107 super(ApplicationLensSearchTests, self).setUp()107 super(ApplicationScopeSearchTests, self).setUp()
108108
109 def test_application_lens_search(self):109 def test_application_scope_search(self):
110 self.do_search_test()110 self.do_search_test()
111111
112112
113class ApplicationLensFuzzySearchTests(ApplicationLensSearchTestBase):113class ApplicationScopeFuzzySearchTests(ApplicationScopeSearchTestBase):
114 """Fuzzy, erroneous search tests for the application lens.114 """Fuzzy, erroneous search tests for the application scope.
115 This checks if the application lens will find the searched application115 This checks if the application scope will find the searched application
116 (windowmocker here, since we want some app that has the name 116 (windowmocker here, since we want some app that has the name
117 locale-independent) when small spelling errors are made.117 locale-independent) when small spelling errors are made.
118 """118 """
@@ -125,9 +125,9 @@
125 ] 125 ]
126126
127 def setUp(self):127 def setUp(self):
128 super(ApplicationLensFuzzySearchTests, self).setUp()128 super(ApplicationScopeFuzzySearchTests, self).setUp()
129129
130 def test_application_lens_fuzzy_search(self):130 def test_application_scope_fuzzy_search(self):
131 self.do_search_test()131 self.do_search_test()
132132
133133
134134
=== modified file 'tests/autopilot/unity/tests/test_shopping_lens.py'
--- tests/autopilot/unity/tests/test_shopping_lens.py 2013-02-21 10:03:21 +0000
+++ tests/autopilot/unity/tests/test_shopping_lens.py 2013-03-21 14:03:22 +0000
@@ -17,70 +17,70 @@
17from unity.tests import UnityTestCase17from unity.tests import UnityTestCase
1818
1919
20class ShoppingLensTests(UnityTestCase):20class ShoppingScopeTests(UnityTestCase):
21 """Test the shopping lens bahavior."""21 """Test the shopping scope bahavior."""
2222
23 def setUp(self):23 def setUp(self):
24 super(ShoppingLensTests, self).setUp()24 super(ShoppingScopeTests, self).setUp()
25 try:25 try:
26 urllib2.urlopen("http://www.google.com", timeout=2)26 urllib2.urlopen("http://www.google.com", timeout=2)
27 except urllib2.URLError, e:27 except urllib2.URLError, e:
28 self.skip("Skipping test, no internet connection")28 self.skip("Skipping test, no internet connection")
29 gettext.install("unity-lens-shopping")29 gettext.install("unity-scope-shopping")
3030
31 def tearDown(self):31 def tearDown(self):
32 self.unity.dash.ensure_hidden()32 self.unity.dash.ensure_hidden()
33 super(ShoppingLensTests, self).tearDown()33 super(ShoppingScopeTests, self).tearDown()
3434
35 def test_no_results_in_home_lens_if_empty_search(self):35 def test_no_results_in_home_scope_if_empty_search(self):
36 """Test that the home lens contains no results if the search bar is empty."""36 """Test that the home scope contains no results if the search bar is empty."""
37 self.unity.dash.ensure_visible()37 self.unity.dash.ensure_visible()
38 lens = self.unity.dash.get_current_lens()38 scope = self.unity.dash.get_current_scope()
3939
40 results_category = lens.get_category_by_name(_("More suggestions"))40 results_category = scope.get_category_by_name(_("More suggestions"))
41 refresh_results_fn = lambda: len(results_category.get_results())41 refresh_results_fn = lambda: len(results_category.get_results())
42 self.assertThat(refresh_results_fn, Eventually(Equals(0)))42 self.assertThat(refresh_results_fn, Eventually(Equals(0)))
4343
44 def test_home_lens_has_shopping_results(self):44 def test_home_scope_has_shopping_results(self):
45 """Test that the home lens contains results."""45 """Test that the home scope contains results."""
46 self.unity.dash.ensure_visible()46 self.unity.dash.ensure_visible()
47 lens = self.unity.dash.get_current_lens()47 scope = self.unity.dash.get_current_scope()
4848
49 self.keyboard.type("playstation")49 self.keyboard.type("playstation")
50 results_category = lens.get_category_by_name(_("More suggestions"))50 results_category = scope.get_category_by_name(_("More suggestions"))
5151
52 refresh_results_fn = lambda: len(results_category.get_results())52 refresh_results_fn = lambda: len(results_category.get_results())
53 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))53 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))
5454
55 def test_application_lens_has_shopping_results(self):55 def test_application_scope_has_shopping_results(self):
56 """Test that the application lens contains results."""56 """Test that the application scope contains results."""
57 self.unity.dash.reveal_application_lens()57 self.unity.dash.reveal_application_scope()
58 lens = self.unity.dash.get_current_lens()58 scope = self.unity.dash.get_current_scope()
5959
60 self.keyboard.type("Text Editor")60 self.keyboard.type("Text Editor")
61 results_category = lens.get_category_by_name(_("More suggestions"))61 results_category = scope.get_category_by_name(_("More suggestions"))
6262
63 refresh_results_fn = lambda: len(results_category.get_results())63 refresh_results_fn = lambda: len(results_category.get_results())
64 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))64 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))
6565
66 def test_music_lens_has_shopping_results(self):66 def test_music_scope_has_shopping_results(self):
67 """Test that the music lens contains results."""67 """Test that the music scope contains results."""
68 self.unity.dash.reveal_music_lens()68 self.unity.dash.reveal_music_scope()
69 lens = self.unity.dash.get_current_lens()69 scope = self.unity.dash.get_current_scope()
7070
71 self.keyboard.type("megadeth")71 self.keyboard.type("megadeth")
72 results_category = lens.get_category_by_name(_("More suggestions"))72 results_category = scope.get_category_by_name(_("More suggestions"))
7373
74 refresh_results_fn = lambda: len(results_category.get_results())74 refresh_results_fn = lambda: len(results_category.get_results())
75 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))75 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))
7676
77 def test_preview_works_with_shopping_lens(self):77 def test_preview_works_with_shopping_scope(self):
78 """This test shows the dash preview works with shopping lens results."""78 """This test shows the dash preview works with shopping scope results."""
79 self.unity.dash.ensure_visible()79 self.unity.dash.ensure_visible()
80 lens = self.unity.dash.get_current_lens()80 scope = self.unity.dash.get_current_scope()
8181
82 self.keyboard.type("playstation")82 self.keyboard.type("playstation")
83 results_category = lens.get_category_by_name(_("More suggestions"))83 results_category = scope.get_category_by_name(_("More suggestions"))
8484
85 refresh_results_fn = lambda: len(results_category.get_results())85 refresh_results_fn = lambda: len(results_category.get_results())
86 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))86 self.assertThat(refresh_results_fn, Eventually(GreaterThan(1)))
@@ -90,15 +90,15 @@
9090
91 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(True)))91 self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(True)))
9292
93 def test_shopping_lens_preview_navigate_right(self):93 def test_shopping_scope_preview_navigate_right(self):
94 """This test shows that shopping lens results can open previews,94 """This test shows that shopping scope results can open previews,
95 then move to the next shopping result.95 then move to the next shopping result.
96 """96 """
97 self.unity.dash.ensure_visible()97 self.unity.dash.ensure_visible()
98 lens = self.unity.dash.get_current_lens()98 scope = self.unity.dash.get_current_scope()
9999
100 self.keyboard.type("playstation")100 self.keyboard.type("playstation")
101 results_category = lens.get_category_by_name(_("More suggestions"))101 results_category = scope.get_category_by_name(_("More suggestions"))
102102
103 refresh_results_fn = lambda: len(results_category.get_results())103 refresh_results_fn = lambda: len(results_category.get_results())
104 self.assertThat(refresh_results_fn, Eventually(GreaterThan(2)))104 self.assertThat(refresh_results_fn, Eventually(GreaterThan(2)))
105105
=== added directory 'tests/data/unity'
=== added directory 'tests/data/unity/scopes'
=== added file 'tests/data/unity/scopes/testscope1.scope'
--- tests/data/unity/scopes/testscope1.scope 1970-01-01 00:00:00 +0000
+++ tests/data/unity/scopes/testscope1.scope 2013-03-21 14:03:22 +0000
@@ -0,0 +1,13 @@
1[Scope]
2DBusName=com.canonical.Unity.Test.Scope
3DBusPath=/com/canonical/unity/scope/testscope1
4Icon=/usr/share/unity/6/icon-sub1.svg
5RequiredMetadata=
6OptionalMetadata=
7Keywords=misc;
8Type=varia
9QueryPattern=^@
10Name=TestScope1
11Description=Find various stuff 1
12SearchHint=Search stuff 1
13Shortcut=q
014
=== added file 'tests/data/unity/scopes/testscope2.scope'
--- tests/data/unity/scopes/testscope2.scope 1970-01-01 00:00:00 +0000
+++ tests/data/unity/scopes/testscope2.scope 2013-03-21 14:03:22 +0000
@@ -0,0 +1,13 @@
1[Scope]
2DBusName=com.canonical.Unity.Test.Scope
3DBusPath=/com/canonical/unity/scope/testscope2
4Icon=/usr/share/unity/6/icon-sub2.svg
5RequiredMetadata=
6OptionalMetadata=
7Keywords=misc;
8Type=varia
9QueryPattern=^@
10Name=TestScope2
11Description=Find various stuff 2
12SearchHint=Search stuff 2
13Shortcut=w
014
=== added file 'tests/data/unity/scopes/testscope3.scope'
--- tests/data/unity/scopes/testscope3.scope 1970-01-01 00:00:00 +0000
+++ tests/data/unity/scopes/testscope3.scope 2013-03-21 14:03:22 +0000
@@ -0,0 +1,13 @@
1[Scope]
2DBusName=com.canonical.Unity.Test.Scope
3DBusPath=/com/canonical/unity/scope/testscope3
4Icon=/usr/share/unity/6/icon-sub3.svg
5RequiredMetadata=
6OptionalMetadata=
7Keywords=misc;
8Type=varia
9QueryPattern=^@
10Name=TestScope3
11Description=Find various stuff 3
12SearchHint=Search stuff 3
13Shortcut=e
014
=== added file 'tests/data/unity/scopes/testscope4.scope'
--- tests/data/unity/scopes/testscope4.scope 1970-01-01 00:00:00 +0000
+++ tests/data/unity/scopes/testscope4.scope 2013-03-21 14:03:22 +0000
@@ -0,0 +1,13 @@
1[Scope]
2DBusName=com.canonical.Unity.Test.Scope
3DBusPath=/com/canonical/unity/scope/testscope4
4Icon=/usr/share/unity/6/icon-sub4.svg
5RequiredMetadata=
6OptionalMetadata=
7Keywords=misc;
8Type=varia
9QueryPattern=^@
10Name=TestScope4
11Description=Find various stuff 4
12SearchHint=Search stuff 4
13Shortcut=r
014
=== added directory 'tests/data/unity/sounds'
=== added file 'tests/data/unity/sounds/brownnoise.mp3'
1Binary files tests/data/unity/sounds/brownnoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/brownnoise.mp3 2013-03-21 14:03:22 +0000 differ15Binary files tests/data/unity/sounds/brownnoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/brownnoise.mp3 2013-03-21 14:03:22 +0000 differ
=== added file 'tests/data/unity/sounds/pinknoise.mp3'
2Binary files tests/data/unity/sounds/pinknoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/pinknoise.mp3 2013-03-21 14:03:22 +0000 differ16Binary files tests/data/unity/sounds/pinknoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/pinknoise.mp3 2013-03-21 14:03:22 +0000 differ
=== added file 'tests/data/unity/sounds/whitenoise.mp3'
3Binary files tests/data/unity/sounds/whitenoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/whitenoise.mp3 2013-03-21 14:03:22 +0000 differ17Binary files tests/data/unity/sounds/whitenoise.mp3 1970-01-01 00:00:00 +0000 and tests/data/unity/sounds/whitenoise.mp3 2013-03-21 14:03:22 +0000 differ
=== modified file 'tests/test_categories.cpp'
--- tests/test_categories.cpp 2013-03-12 13:49:41 +0000
+++ tests/test_categories.cpp 2013-03-21 14:03:22 +0000
@@ -13,6 +13,7 @@
13{13{
1414
15static const string swarm_name = "com.canonical.test.categoriesmodel";15static const string swarm_name = "com.canonical.test.categoriesmodel";
16static const string swarm_name_changing = "com.canonical.test.categoriesmodel_changing";
16static const unsigned int n_rows = 5;17static const unsigned int n_rows = 5;
1718
18static void WaitForSynchronize(Categories& model)19static void WaitForSynchronize(Categories& model)
@@ -46,12 +47,17 @@
46 {47 {
47 Category adaptor = model.RowAtIndex(i);48 Category adaptor = model.RowAtIndex(i);
4849
49 unity::glib::String tmp(g_strdup_printf("Category %d", i));50 unity::glib::String tmp(g_strdup_printf("cat%d", i));
50 string value = tmp.Str();51 string id = tmp.Str();
51 EXPECT_EQ(adaptor.name(), value);52
53 unity::glib::String tmp2(g_strdup_printf("Category %d", i));
54 string name = tmp2.Str();
55
56 EXPECT_EQ(adaptor.id(), id);
57 EXPECT_EQ(adaptor.name(), name);
52 EXPECT_EQ(adaptor.icon_hint(), "gtk-apply");58 EXPECT_EQ(adaptor.icon_hint(), "gtk-apply");
59 EXPECT_EQ(adaptor.renderer_name(), "grid");
53 EXPECT_EQ(adaptor.index(), i);60 EXPECT_EQ(adaptor.index(), i);
54 EXPECT_EQ(adaptor.renderer_name(), "grid");
55 }61 }
56}62}
5763
@@ -82,4 +88,80 @@
82 }88 }
83}89}
8490
91// We're testing the model's ability to store and retrieve random pointers
92TEST(TestCategories, TestOnRowChanged)
93{
94 Categories model;
95 model.swarm_name = swarm_name_changing;
96 WaitForSynchronize(model);
97
98 bool changed = false;
99 model.category_changed.connect([&changed] (Category const&) { changed = true;});
100 Utils::WaitUntilMSec(changed,
101 2000,
102 []() { return g_strdup_printf("Did not detect row change from %s.", swarm_name_changing.c_str()); });
103}
104
105
106// We're testing the model's ability to store and retrieve random pointers
107TEST(TestCategories, TestOnRowAdded)
108{
109 Categories model;
110 model.swarm_name = swarm_name_changing;
111 WaitForSynchronize(model);
112
113 bool added = false;
114 model.category_added.connect([&added] (Category const&) { added = true;});
115 Utils::WaitUntilMSec(added,
116 2000,
117 []() { return g_strdup_printf("Did not detect row add %s.", swarm_name_changing.c_str()); });
118}
119
120// We're testing the model's ability to store and retrieve random pointers
121TEST(TestCategories, TestOnRowRemoved)
122{
123 Categories model;
124 model.swarm_name = swarm_name_changing;
125 WaitForSynchronize(model);
126
127 bool removed = false;
128 model.category_removed.connect([&removed] (Category const&) { removed = true;});
129 Utils::WaitUntilMSec(removed,
130 2000,
131 []() { return g_strdup_printf("Did not detect row remove %s.", swarm_name_changing.c_str()); });
132}
133
134TEST(TestCategories, TestCategoryCopy)
135{
136 Categories model;
137 model.swarm_name = swarm_name_changing;
138 WaitForSynchronize(model);
139
140 Category category = model.RowAtIndex(0);
141 Category category_2(category);
142
143 EXPECT_EQ(category.id(), category_2.id());
144 EXPECT_EQ(category.name(), category_2.name());
145 EXPECT_EQ(category.icon_hint(), category_2.icon_hint());
146 EXPECT_EQ(category.renderer_name(), category_2.renderer_name());
147 EXPECT_EQ(category.index(), category_2.index());
148}
149
150TEST(TestCategories, TestCategoryEqual)
151{
152 Categories model;
153 model.swarm_name = swarm_name_changing;
154 WaitForSynchronize(model);
155
156 Category category = model.RowAtIndex(0);
157 Category category_2(NULL, NULL, NULL);
158 category_2 = category;
159
160 EXPECT_EQ(category.id(), category_2.id());
161 EXPECT_EQ(category.name(), category_2.name());
162 EXPECT_EQ(category.icon_hint(), category_2.icon_hint());
163 EXPECT_EQ(category.renderer_name(), category_2.renderer_name());
164 EXPECT_EQ(category.index(), category_2.index());
165}
166
85}167}
86168
=== removed file 'tests/test_dash_view.cpp'
--- tests/test_dash_view.cpp 2013-03-12 21:45:58 +0000
+++ tests/test_dash_view.cpp 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include <gmock/gmock.h>
20
21#include <UnityCore/Lenses.h>
22
23#include "ApplicationStarter.h"
24#include "DashView.h"
25#include "unity-shared/DashStyle.h"
26#include "unity-shared/PanelStyle.h"
27#include "unity-shared/UnitySettings.h"
28
29#include "mock-lenses.h"
30
31using namespace unity::dash;
32using namespace testing;
33
34namespace {
35
36struct MockApplicationStarter : public unity::ApplicationStarter {
37 typedef std::shared_ptr<MockApplicationStarter> Ptr;
38 MOCK_METHOD2(Launch, bool(std::string const&, Time));
39};
40
41
42struct TestDashView : public testing::Test {
43 TestDashView()
44 : lenses_(std::make_shared<testmocks::ThreeMockTestLenses>())
45 , application_starter_(std::make_shared<MockApplicationStarter>())
46 , dash_view_(new DashView(lenses_, application_starter_))
47 {}
48
49 unity::Settings unity_settings_;
50 Style dash_style;
51 unity::panel::Style panel_style;
52 Lenses::Ptr lenses_;
53 MockApplicationStarter::Ptr application_starter_;
54 nux::ObjectPtr<DashView> dash_view_;
55};
56
57
58TEST_F(TestDashView, LensActivatedSignal)
59{
60 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
61 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:application://uri", NOT_HANDLED, Lens::Hints());
62
63 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
64 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:unity-runner://uri", NOT_HANDLED, Lens::Hints());
65}
66
67}
680
=== added file 'tests/test_dashview.cpp'
--- tests/test_dashview.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_dashview.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,116 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
19 *
20 */
21
22#include <list>
23
24#include <gtest/gtest.h>
25#include <gmock/gmock.h>
26
27#include <Nux/Nux.h>
28#include <NuxCore/ObjectPtr.h>
29
30#include "dash/DashView.h"
31#include "dash/ApplicationStarter.h"
32#include "unity-shared/DashStyle.h"
33#include "unity-shared/PanelStyle.h"
34#include "unity-shared/UnitySettings.h"
35
36#include "test_mock_scope.h"
37#include "test_utils.h"
38
39using namespace unity;
40using namespace unity::dash;
41using namespace testing;
42
43namespace unity
44{
45namespace dash
46{
47
48namespace
49{
50const char* scopes_default[] = { "testscope1.scope",
51 "testscope2.scope",
52 "testscope3.scope",
53 "testscope4.scope",
54 NULL };
55
56}
57
58struct MockApplicationStarter : public unity::ApplicationStarter {
59 typedef std::shared_ptr<MockApplicationStarter> Ptr;
60 MOCK_METHOD2(Launch, bool(std::string const&, Time));
61};
62
63class TestDashView : public ::testing::Test
64{
65public:
66 TestDashView()
67 : application_starter_(std::make_shared<MockApplicationStarter>())
68 {}
69
70 virtual void SetUp() { Utils::init_gsettings_test_environment(); }
71 virtual void TearDown() { Utils::reset_gsettings_test_environment(); }
72
73 class MockDashView : public DashView
74 {
75 public:
76 MockDashView(Scopes::Ptr const& scopes, ApplicationStarter::Ptr const& application_starter)
77 : DashView(scopes, application_starter)
78 {
79 }
80
81 using DashView::scope_views_;
82 };
83
84protected:
85 Settings unity_settings_;
86 dash::Style dash_style_;
87 panel::Style panel_style_;
88 MockApplicationStarter::Ptr application_starter_;
89};
90
91TEST_F(TestDashView, TestConstruct)
92{
93 Scopes::Ptr scopes(new MockGSettingsScopes(scopes_default));
94 nux::ObjectPtr<MockDashView> view(new MockDashView(scopes, application_starter_));
95
96 EXPECT_EQ(view->scope_views_.size(), 4) << "Error: Incorrect number of scope views (" << view->scope_views_.size() << " != 4)";
97}
98
99
100TEST_F(TestDashView, LensActivatedSignal)
101{
102 Scopes::Ptr scopes(new MockGSettingsScopes(scopes_default));
103 nux::ObjectPtr<MockDashView> view(new MockDashView(scopes, application_starter_));
104
105 LocalResult result;
106 result.uri = "application://uri";
107
108 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
109 scopes->GetScopeAtIndex(0)->activated.emit(result, NOT_HANDLED, glib::HintsMap());
110
111 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
112 scopes->GetScopeAtIndex(0)->activated.emit(result, NOT_HANDLED, glib::HintsMap());
113}
114
115}
116}
0117
=== modified file 'tests/test_dashview_impl.cpp'
--- tests/test_dashview_impl.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_dashview_impl.cpp 2013-03-21 14:03:22 +0000
@@ -27,52 +27,52 @@
27namespace27namespace
28{28{
2929
30TEST(TestParseLensFilter, TestSimpleString)30TEST(TestParseScopeFilter, TestSimpleString)
31{31{
32 LensFilter filter = parse_lens_uri("simple");32 ScopeFilter filter = parse_scope_uri("simple");
3333
34 EXPECT_THAT(filter.id, Eq("simple"));34 EXPECT_THAT(filter.id, Eq("simple"));
35 EXPECT_TRUE(filter.filters.empty());35 EXPECT_TRUE(filter.filters.empty());
36}36}
3737
38TEST(TestParseLensFilter, TestNonFilterParameter)38TEST(TestParseScopeFilter, TestNonFilterParameter)
39{39{
40 // Only params that start with "filter_" are added.40 // Only params that start with "filter_" are added.
41 LensFilter filter = parse_lens_uri("uri?param=test");41 ScopeFilter filter = parse_scope_uri("uri?param=test");
4242
43 EXPECT_THAT(filter.id, Eq("uri"));43 EXPECT_THAT(filter.id, Eq("uri"));
44 EXPECT_TRUE(filter.filters.empty());44 EXPECT_TRUE(filter.filters.empty());
45}45}
4646
47TEST(TestParseLensFilter, TestSingleParameter)47TEST(TestParseScopeFilter, TestSingleParameter)
48{48{
49 LensFilter filter = parse_lens_uri("uri?filter_param=test");49 ScopeFilter filter = parse_scope_uri("uri?filter_param=test");
5050
51 EXPECT_THAT(filter.id, Eq("uri"));51 EXPECT_THAT(filter.id, Eq("uri"));
52 EXPECT_THAT(filter.filters.size(), Eq(1));52 EXPECT_THAT(filter.filters.size(), Eq(1));
53 EXPECT_THAT(filter.filters["param"], Eq("test"));53 EXPECT_THAT(filter.filters["param"], Eq("test"));
54}54}
5555
56TEST(TestParseLensFilter, TestNoEquals)56TEST(TestParseScopeFilter, TestNoEquals)
57{57{
58 LensFilter filter = parse_lens_uri("uri?filter_param");58 ScopeFilter filter = parse_scope_uri("uri?filter_param");
5959
60 EXPECT_THAT(filter.id, Eq("uri"));60 EXPECT_THAT(filter.id, Eq("uri"));
61 EXPECT_TRUE(filter.filters.empty());61 EXPECT_TRUE(filter.filters.empty());
62}62}
6363
64TEST(TestParseLensFilter, TestEmbeddedEquals)64TEST(TestParseScopeFilter, TestEmbeddedEquals)
65{65{
66 LensFilter filter = parse_lens_uri("uri?filter_param=a=b");66 ScopeFilter filter = parse_scope_uri("uri?filter_param=a=b");
6767
68 EXPECT_THAT(filter.id, Eq("uri"));68 EXPECT_THAT(filter.id, Eq("uri"));
69 EXPECT_THAT(filter.filters.size(), Eq(1));69 EXPECT_THAT(filter.filters.size(), Eq(1));
70 EXPECT_THAT(filter.filters["param"], Eq("a=b"));70 EXPECT_THAT(filter.filters["param"], Eq("a=b"));
71}71}
7272
73TEST(TestParseLensFilter, TestMultipleParameters)73TEST(TestParseScopeFilter, TestMultipleParameters)
74{74{
75 LensFilter filter = parse_lens_uri("uri?filter_param1=first&filter_param2=second");75 ScopeFilter filter = parse_scope_uri("uri?filter_param1=first&filter_param2=second");
7676
77 EXPECT_THAT(filter.id, Eq("uri"));77 EXPECT_THAT(filter.id, Eq("uri"));
78 EXPECT_THAT(filter.filters.size(), Eq(2));78 EXPECT_THAT(filter.filters.size(), Eq(2));
7979
=== modified file 'tests/test_dbus_indicators.cpp'
--- tests/test_dbus_indicators.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_dbus_indicators.cpp 2013-03-21 14:03:22 +0000
@@ -39,7 +39,7 @@
39 dbus_indicators.reset(new DBusIndicatorsTest ());39 dbus_indicators.reset(new DBusIndicatorsTest ());
4040
41 // wait until the dbus indicator has connected to the panel service41 // wait until the dbus indicator has connected to the panel service
42 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::IsConnected));42 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::IsConnected), true, 5);
43 }43 }
4444
45 bool TriggerResync1Sent() const45 bool TriggerResync1Sent() const
@@ -75,7 +75,7 @@
75TEST_F(TestDBusIndicators, TestSync)75TEST_F(TestDBusIndicators, TestSync)
76{76{
77 // wait until the dbus indicator gets any indicator from the panel service77 // wait until the dbus indicator gets any indicator from the panel service
78 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::HasIndicators));78 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::HasIndicators), true, 5);
7979
80 EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);80 EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
81 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);81 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
@@ -85,7 +85,7 @@
85 // Tell the service to trigger a resync and to send the entries in the reverse order85 // Tell the service to trigger a resync and to send the entries in the reverse order
86 CallPanelMethod("TriggerResync1");86 CallPanelMethod("TriggerResync1");
8787
88 Utils::WaitUntil(sigc::mem_fun(this, &TestDBusIndicators::TriggerResync1Sent));88 Utils::WaitUntil(sigc::mem_fun(this, &TestDBusIndicators::TriggerResync1Sent), true, 5);
89 // We know the resync has been sent, but it may have not been processed89 // We know the resync has been sent, but it may have not been processed
90 // so do one interation of the main loop more90 // so do one interation of the main loop more
91 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);91 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
9292
=== modified file 'tests/test_desktop_utilities.cpp'
--- tests/test_desktop_utilities.cpp 2012-11-06 18:19:09 +0000
+++ tests/test_desktop_utilities.cpp 2013-03-21 14:03:22 +0000
@@ -106,61 +106,73 @@
106 Eq("subdir1-subdir2-to.desktop"));106 Eq("subdir1-subdir2-to.desktop"));
107}107}
108108
109TEST(TestDesktopUtilitiesDataDirectories, TestGetUserDataDirectory)109// We can't test this. GetUserDataDirectory uses g_get_user_data_dir which caches data dir.
110{110// If we perform a DesktopUtilities::GetUserDataDirectory(); before running this test, the test will fail, because setting the XDG_DATA_HOME
111 const gchar* env = g_getenv("XDG_DATA_HOME");111// will not change the cached value.
112 std::string old_home = env ? env : "";112
113113// TEST(TestDesktopUtilitiesDataDirectories, TestGetUserDataDirectory)
114 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);114// {
115115// const gchar* env = g_getenv("XDG_DATA_HOME");
116 std::string const& user_data_dir = DesktopUtilities::GetUserDataDirectory();116// std::string old_home = env ? env : "";
117117
118 g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);118// g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);
119119
120 EXPECT_THAT(user_data_dir, Eq("UnityUserConfig"));120// std::string const& user_data_dir = DesktopUtilities::GetUserDataDirectory();
121}121
122122// g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);
123TEST(TestDesktopUtilitiesDataDirectories, TestGetSystemDataDirectory)123
124{124// EXPECT_THAT(user_data_dir, Eq("UnityUserConfig"));
125 const gchar* env = g_getenv("XDG_DATA_DIRS");125// }
126 std::string old_dirs = env ? env : "";126
127 g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);127// We can't test this. GetSystemDataDirectories uses g_get_system_data_dirs which caches the values.
128128// If we perform a DesktopUtilities::GetSystemDataDirectories(); before running this test, the test will fail, because setting the XDG_DATA_DIRS
129 std::vector<std::string> const& system_dirs = DesktopUtilities::GetSystemDataDirectories();129// will not change the cached value.
130130
131 g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);131// TEST(TestDesktopUtilitiesDataDirectories, TestGetSystemDataDirectory)
132132// {
133 ASSERT_THAT(system_dirs.size(), Eq(5));133// const gchar* env = g_getenv("XDG_DATA_DIRS");
134 EXPECT_THAT(system_dirs[0], Eq("dir1"));134// std::string old_dirs = env ? env : "";
135 EXPECT_THAT(system_dirs[1], Eq("dir2"));135// g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);
136 EXPECT_THAT(system_dirs[2], Eq("dir3"));136
137 EXPECT_THAT(system_dirs[3], Eq("dir4"));137// std::vector<std::string> const& system_dirs = DesktopUtilities::GetSystemDataDirectories();
138 EXPECT_THAT(system_dirs[4], Eq(LOCAL_DATA_DIR));138
139}139// g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);
140140
141TEST(TestDesktopUtilitiesDataDirectories, TestGetDataDirectory)141// ASSERT_THAT(system_dirs.size(), Eq(5));
142{142// EXPECT_THAT(system_dirs[0], Eq("dir1"));
143 const gchar* env = g_getenv("XDG_DATA_DIRS");143// EXPECT_THAT(system_dirs[1], Eq("dir2"));
144 std::string old_dirs = env ? env : "";144// EXPECT_THAT(system_dirs[2], Eq("dir3"));
145 env = g_getenv("XDG_DATA_HOME");145// EXPECT_THAT(system_dirs[3], Eq("dir4"));
146 std::string old_home = env ? env : "";146// EXPECT_THAT(system_dirs[4], Eq(LOCAL_DATA_DIR));
147147// }
148 g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);148
149 g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);149// We can't test this. TestGetDataDirectory uses g_get_system_data_dirs which caches the values.
150150// If we perform a DesktopUtilities::TestGetDataDirectory(); before running this test, the test will fail, because setting the XDG_DATA_DIRS or XDG_DATA_HOME
151 std::vector<std::string> const& data_dirs = DesktopUtilities::GetDataDirectories();151// will not change the cached value.
152152
153 g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);153// TEST(TestDesktopUtilitiesDataDirectories, TestGetDataDirectory)
154 g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);154// {
155155// const gchar* env = g_getenv("XDG_DATA_DIRS");
156 ASSERT_THAT(data_dirs.size(), Eq(6));156// std::string old_dirs = env ? env : "";
157 EXPECT_THAT(data_dirs[0], Eq("dir1"));157// env = g_getenv("XDG_DATA_HOME");
158 EXPECT_THAT(data_dirs[1], Eq("dir2"));158// std::string old_home = env ? env : "";
159 EXPECT_THAT(data_dirs[2], Eq("dir3"));159
160 EXPECT_THAT(data_dirs[3], Eq("dir4"));160// g_setenv("XDG_DATA_DIRS", ("dir1:dir2::dir3:dir4:"+LOCAL_DATA_DIR).c_str(), TRUE);
161 EXPECT_THAT(data_dirs[4], Eq(LOCAL_DATA_DIR));161// g_setenv("XDG_DATA_HOME", "UnityUserConfig", TRUE);
162 EXPECT_THAT(data_dirs[5], Eq("UnityUserConfig"));162
163}163// std::vector<std::string> const& data_dirs = DesktopUtilities::GetDataDirectories();
164
165// g_setenv("XDG_DATA_DIRS", old_dirs.c_str(), TRUE);
166// g_setenv("XDG_DATA_HOME", old_home.c_str(), TRUE);
167
168// ASSERT_THAT(data_dirs.size(), Eq(6));
169// EXPECT_THAT(data_dirs[0], Eq("dir1"));
170// EXPECT_THAT(data_dirs[1], Eq("dir2"));
171// EXPECT_THAT(data_dirs[2], Eq("dir3"));
172// EXPECT_THAT(data_dirs[3], Eq("dir4"));
173// EXPECT_THAT(data_dirs[4], Eq(LOCAL_DATA_DIR));
174// EXPECT_THAT(data_dirs[5], Eq("UnityUserConfig"));
175// }
164176
165TEST(TestDesktopUtilities, TestGetDesktopPathById)177TEST(TestDesktopUtilities, TestGetDesktopPathById)
166{178{
167179
=== modified file 'tests/test_glib_source.cpp'
--- tests/test_glib_source.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_glib_source.cpp 2013-03-21 14:03:22 +0000
@@ -437,7 +437,7 @@
437 idle.Run(&OnSourceCallbackStop);437 idle.Run(&OnSourceCallbackStop);
438 EXPECT_TRUE(idle.IsRunning());438 EXPECT_TRUE(idle.IsRunning());
439439
440 Utils::WaitUntilMSec([&idle] {return idle.IsRunning();}, false, 300);440 Utils::WaitUntilMSec([&idle] {return idle.IsRunning();}, false, 20000);
441 EXPECT_TRUE(callback_called);441 EXPECT_TRUE(callback_called);
442 EXPECT_EQ(callback_call_count, 1);442 EXPECT_EQ(callback_call_count, 1);
443}443}
444444
=== modified file 'tests/test_glib_variant.cpp'
--- tests/test_glib_variant.cpp 2013-03-12 13:31:41 +0000
+++ tests/test_glib_variant.cpp 2013-03-21 14:03:22 +0000
@@ -118,10 +118,16 @@
118118
119 g_variant_builder_init (&b, G_VARIANT_TYPE ("a{sv}"));119 g_variant_builder_init (&b, G_VARIANT_TYPE ("a{sv}"));
120 variant::BuilderWrapper bw (&b);120 variant::BuilderWrapper bw (&b);
121 bw.add ("string-key", "string-value");121 bw.add ("charstring-key", "charstring-value");
122 bw.add ("int-key", 123);122 bw.add ("string-key", std::string("string-value"));
123 bw.add ("gint32-key", (gint32)-1);
124 bw.add ("guint32-key", (guint32)-2);
125 bw.add ("gint64-key", (gint64)-3);
126 bw.add ("guint64-key", (guint64)-4);
127 bw.add ("float-key", (float)1.1);
128 bw.add ("double-key", (double)2.2);
123 bw.add ("bool-key", true);129 bw.add ("bool-key", true);
124 bw.add ("last", "foo");130 bw.add ("variant-key", g_variant_new_int32(123));
125131
126 GVariant *dict_variant = g_variant_builder_end (&b);132 GVariant *dict_variant = g_variant_builder_end (&b);
127 Variant dict (g_variant_new_tuple (&dict_variant, 1));133 Variant dict (g_variant_new_tuple (&dict_variant, 1));
@@ -132,10 +138,15 @@
132 HintsMap hints;138 HintsMap hints;
133 EXPECT_TRUE(dict.ASVToHints (hints));139 EXPECT_TRUE(dict.ASVToHints (hints));
134140
141 EXPECT_EQ(hints["charstring-key"].GetString(), "charstring-value");
135 EXPECT_EQ(hints["string-key"].GetString(), "string-value");142 EXPECT_EQ(hints["string-key"].GetString(), "string-value");
136 EXPECT_EQ(hints["int-key"].GetInt32(), 123);143 EXPECT_EQ(hints["gint32-key"].GetInt32(), (gint32)-1);
144 EXPECT_EQ(hints["guint32-key"].GetUInt32(), (guint32)-2);
145 EXPECT_EQ(hints["gint64-key"].GetInt64(), (gint64)-3);
146 EXPECT_EQ(hints["guint64-key"].GetUInt64(), (guint64)-4);
147 EXPECT_EQ(hints["float-key"].GetFloat(), (float)1.1);
148 EXPECT_EQ(hints["double-key"].GetDouble(), (double)2.2);
137 EXPECT_EQ(hints["bool-key"].GetBool(), true);149 EXPECT_EQ(hints["bool-key"].GetBool(), true);
138 EXPECT_EQ(hints["last"].GetString(), "foo");
139150
140 // throw away all references to the original variant151 // throw away all references to the original variant
141 dict = g_variant_new_string ("bar");152 dict = g_variant_new_string ("bar");
@@ -144,10 +155,15 @@
144 EXPECT_EQ(dict.GetString(), "bar");155 EXPECT_EQ(dict.GetString(), "bar");
145156
146 // this has to still work157 // this has to still work
158 EXPECT_EQ(hints["charstring-key"].GetString(), "charstring-value");
147 EXPECT_EQ(hints["string-key"].GetString(), "string-value");159 EXPECT_EQ(hints["string-key"].GetString(), "string-value");
148 EXPECT_EQ(hints["int-key"].GetInt32(), 123);160 EXPECT_EQ(hints["gint32-key"].GetInt32(), (gint32)-1);
161 EXPECT_EQ(hints["guint32-key"].GetUInt32(), (guint32)-2);
162 EXPECT_EQ(hints["gint64-key"].GetInt64(), (gint64)-3);
163 EXPECT_EQ(hints["guint64-key"].GetUInt64(), (guint64)-4);
164 EXPECT_EQ(hints["float-key"].GetFloat(), (float)1.1);
165 EXPECT_EQ(hints["double-key"].GetDouble(), (double)2.2);
149 EXPECT_EQ(hints["bool-key"].GetBool(), true);166 EXPECT_EQ(hints["bool-key"].GetBool(), true);
150 EXPECT_EQ(hints["last"].GetString(), "foo");
151}167}
152168
153TEST(TestGLibVariant, GetString)169TEST(TestGLibVariant, GetString)
@@ -205,6 +221,4 @@
205}221}
206222
207223
208
209
210} // Namespace224} // Namespace
211225
=== added file 'tests/test_gsettings_scopes.cpp'
--- tests/test_gsettings_scopes.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_gsettings_scopes.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,230 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
17 */
18
19#include <gtest/gtest.h>
20#include <glib-object.h>
21#include "test_mock_scope.h"
22#include "test_utils.h"
23
24using namespace std;
25using namespace unity;
26using namespace unity::dash;
27
28namespace
29{
30
31const char* scopes_default[] = { "testscope1.scope",
32 "testscope2.scope",
33 "testscope3.scope",
34 "testscope4.scope",
35 NULL
36 };
37
38const char* scopes_test_update[] = { "testscope1.scope",
39 "testscope4.scope",
40 NULL
41 };
42
43const char* scopes_updated[] = { "testscope1.scope",
44 "testscope2.scope",
45 "testscope3.scope",
46 NULL
47 };
48
49// A new one of these is created for each test
50class TestGSettingsScopes : public testing::Test
51{
52public:
53 TestGSettingsScopes():scope_added(0),scope_removed(0),scopes_reordered(0)
54 {}
55
56 virtual void SetUp() { Utils::init_gsettings_test_environment(); }
57 virtual void TearDown() { Utils::reset_gsettings_test_environment(); }
58
59 void ConnectScope(Scopes* scopes)
60 {
61 scopes->scope_added.connect([this](Scope::Ptr const& scope, int)
62 {
63 ++scope_added;
64 });
65 scopes->scope_removed.connect([this](Scope::Ptr const& scope)
66 {
67 ++scope_removed;
68 });
69 scopes->scopes_reordered.connect([this](Scopes::ScopeList const& list)
70 {
71 ++scopes_reordered;
72 });
73 }
74
75 int scope_added;
76 int scope_removed;
77 int scopes_reordered;
78};
79
80TEST_F(TestGSettingsScopes, TestAdded)
81{
82 MockGSettingsScopes scopes(scopes_default);
83 ConnectScope(&scopes);
84
85 scopes.InsertScope("testscope1.scope", 0);
86 EXPECT_EQ(scopes.count, (unsigned int)1);
87 EXPECT_EQ(scopes_reordered, (unsigned int)0);
88
89 // add another
90 scopes.InsertScope("testscope2.scope", 1);
91 EXPECT_EQ(scopes.count, (unsigned int)2);
92 EXPECT_EQ(scopes_reordered, (unsigned int)0);
93
94 int position = -1;
95 EXPECT_TRUE(scopes.GetScope("testscope1.scope", &position) && position == 0);
96 EXPECT_TRUE(scopes.GetScope("testscope2.scope", &position) && position == 1);
97}
98
99TEST_F(TestGSettingsScopes, TestReorderBefore)
100{
101 MockGSettingsScopes scopes(scopes_default);
102 ConnectScope(&scopes);
103
104 scopes.InsertScope("testscope1.scope", 0);
105 scopes.InsertScope("testscope2.scope", 1);
106 scopes.InsertScope("testscope3.scope", 2);
107 scopes.InsertScope("testscope4.scope", 3);
108 EXPECT_EQ(scopes.count, (unsigned int)4);
109 EXPECT_EQ(scopes_reordered, (unsigned int)0);
110
111 // change position
112 scopes.InsertScope("testscope3.scope", 0);
113 EXPECT_EQ(scopes_reordered, (unsigned int)1);
114
115 int position = -1;
116 EXPECT_TRUE(scopes.GetScope("testscope3.scope", &position) && position == 0);
117 EXPECT_TRUE(scopes.GetScope("testscope1.scope", &position) && position == 1);
118 EXPECT_TRUE(scopes.GetScope("testscope2.scope", &position) && position == 2);
119 EXPECT_TRUE(scopes.GetScope("testscope4.scope", &position) && position == 3);
120}
121
122TEST_F(TestGSettingsScopes, TestReorderAfter)
123{
124 MockGSettingsScopes scopes(scopes_default);
125 ConnectScope(&scopes);
126
127 scopes.InsertScope("testscope1.scope", 0);
128 scopes.InsertScope("testscope2.scope", 1);
129 scopes.InsertScope("testscope3.scope", 2);
130 scopes.InsertScope("testscope4.scope", 3);
131 EXPECT_EQ(scopes.count, (unsigned int)4);
132 EXPECT_EQ(scopes_reordered, (unsigned int)0);
133
134 // change position
135 scopes.InsertScope("testscope2.scope", 3);
136 EXPECT_EQ(scopes_reordered, (unsigned int)1);
137
138 int position = -1;
139 EXPECT_TRUE(scopes.GetScope("testscope1.scope", &position) && position == 0);
140 EXPECT_TRUE(scopes.GetScope("testscope3.scope", &position) && position == 1);
141 EXPECT_TRUE(scopes.GetScope("testscope4.scope", &position) && position == 2);
142 EXPECT_TRUE(scopes.GetScope("testscope2.scope", &position) && position == 3);
143}
144
145
146TEST_F(TestGSettingsScopes, TestAddNonExists)
147{
148 MockGSettingsScopes scopes(scopes_default);
149 ConnectScope(&scopes);
150
151 scopes.InsertScope("non-existing.scope", 0);
152 EXPECT_EQ(scope_added, (unsigned int)0);
153 EXPECT_EQ(scopes.count, (unsigned int)0);
154}
155
156TEST_F(TestGSettingsScopes, TestAddSame)
157{
158 MockGSettingsScopes scopes(scopes_default);
159 ConnectScope(&scopes);
160
161 scopes.InsertScope("testscope1.scope", 0);
162 EXPECT_EQ(scope_added, (unsigned int)1);
163 EXPECT_EQ(scopes.count, (unsigned int)1);
164
165 // shouldnt add another
166 scopes.InsertScope("testscope1.scope", 1);
167
168 EXPECT_EQ(scope_added, (unsigned int)1);
169 EXPECT_EQ(scopes.count, (unsigned int)1);
170 EXPECT_EQ(scopes_reordered, (unsigned int)0);
171}
172
173TEST_F(TestGSettingsScopes, TestAddRemove)
174{
175 MockGSettingsScopes scopes(scopes_default);
176 ConnectScope(&scopes);
177
178 scopes.InsertScope("testscope1.scope", 0);
179 EXPECT_EQ(scope_added, (unsigned int)1);
180 EXPECT_EQ(scopes.count, (unsigned int)1);
181
182 scopes.RemoveScope("testscope1.scope");
183 EXPECT_EQ(scope_removed, (unsigned int)1);
184 EXPECT_EQ(scopes.count, (unsigned int)0);
185}
186
187TEST_F(TestGSettingsScopes, TestRemoveNonExists)
188{
189 MockGSettingsScopes scopes(scopes_default);
190 ConnectScope(&scopes);
191
192 scopes.RemoveScope("non-existing.scope");
193 EXPECT_EQ(scope_removed, (unsigned int)0);
194 EXPECT_EQ(scopes.count, (unsigned int)0);
195}
196
197TEST_F(TestGSettingsScopes, TestLoad)
198{
199 MockGSettingsScopes scopes(scopes_default);
200 ConnectScope(&scopes);
201
202 scopes.LoadScopes();
203 EXPECT_EQ(scope_added, (unsigned int)4);
204
205 int position = -1;
206 EXPECT_TRUE(scopes.GetScope("testscope1.scope", &position) && position == 0);
207 EXPECT_TRUE(scopes.GetScope("testscope2.scope", &position) && position == 1);
208 EXPECT_TRUE(scopes.GetScope("testscope3.scope", &position) && position == 2);
209 EXPECT_TRUE(scopes.GetScope("testscope4.scope", &position) && position == 3);
210}
211
212TEST_F(TestGSettingsScopes, TestLoadUpdateGSettings)
213{
214 MockGSettingsScopes scopes(scopes_test_update);
215 ConnectScope(&scopes);
216
217 scopes.LoadScopes();
218 EXPECT_EQ(scope_added, (unsigned int)2);
219 EXPECT_EQ(scopes.count, (unsigned int)2);
220
221 scopes.UpdateScopes(scopes_updated);
222 Utils::WaitUntilMSec([this] { return scope_removed > 0; }, true, 2000);
223
224 EXPECT_EQ(scope_added, (unsigned int)4);
225 EXPECT_EQ(scope_removed, (unsigned int)1);
226 EXPECT_EQ(scopes.count, (unsigned int)3);
227}
228
229
230}
0231
=== modified file 'tests/test_hud.cpp'
--- tests/test_hud.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_hud.cpp 2013-03-21 14:03:22 +0000
@@ -3,140 +3,96 @@
3#include <UnityCore/GLibWrapper.h>3#include <UnityCore/GLibWrapper.h>
4#include <UnityCore/Hud.h>4#include <UnityCore/Hud.h>
5#include <sigc++/connection.h>5#include <sigc++/connection.h>
6#include "test_utils.h"
67
7using namespace std;8using namespace std;
89
10namespace unity
11{
12namespace hud
13{
14
15
9namespace16namespace
10{17{
1118
12GMainLoop* loop_ = NULL;19static void WaitForConnect(Hud::Ptr hud)
13unity::hud::Hud *hud;20{
1421 ::Utils::WaitUntil([hud]() { return hud->connected(); },
15class TestHud : public ::testing::Test22 true,
16{23 10,
17public:24 []() { return g_strdup("Timed out waiting for hud connection"); });
18 TestHud()25}
19 : query_return_result(false)26
20 , connected_result(false)27}
21 {28
22 }29TEST(TestHud, TestConstruction)
23 unity::hud::Hud::Queries queries;30{
24 bool query_return_result;31 Hud::Ptr hud(new Hud("com.canonical.Unity.Test", "/com/canonical/hud"));
25 bool connected_result;32 WaitForConnect(hud);
26 int number_signals_found;33}
27};34
2835TEST(TestHud, TestQueryReturn)
29TEST_F(TestHud, TestConstruction)36{
30{37 Hud::Ptr hud(new Hud("com.canonical.Unity.Test", "/com/canonical/hud"));
31 loop_ = g_main_loop_new(NULL, FALSE);38 WaitForConnect(hud);
32 hud = new unity::hud::Hud("com.canonical.Unity.Test", "/com/canonical/hud");39
33 40 bool query_return_result = false;
34 // performs a check on the hud, if the hud is connected, report a sucess41 Hud::Queries queries;
35 auto timeout_check = [] (gpointer data) -> gboolean
36 {
37 TestHud* self = static_cast<TestHud*>(data);
38 if (hud->connected)
39 {
40 self->connected_result = true;
41 g_main_loop_quit(loop_);
42 return FALSE;
43 }
44 else
45 {
46 self->connected_result = false;
47 return TRUE;
48 }
49 };
50
51
52 // if the hud is not connected when this lambda runs, fail.
53 auto timeout_bailout = [] (gpointer data) -> gboolean
54 {
55 TestHud* self = static_cast<TestHud*>(data);
56 // reached timeout, failed testing
57 self->connected_result = false;
58 g_main_loop_quit(loop_);
59 return FALSE;
60 };
61
62 g_timeout_add(1000, timeout_check, this);
63 g_timeout_add(10000, timeout_bailout, this);
64
65 g_main_loop_run(loop_);
66
67 EXPECT_EQ(connected_result, true);
68}
69
70TEST_F(TestHud, TestQueryReturn)
71{
72 query_return_result = false;
73 42
74 // make sure we receive the queries43 // make sure we receive the queries
75 auto query_connection = [this](unity::hud::Hud::Queries queries_) 44 auto query_connection = [&query_return_result, &queries](Hud::Queries const& queries_)
76 { 45 {
77 query_return_result = true;46 query_return_result = true;
78 g_main_loop_quit(loop_);
79 queries = queries_;47 queries = queries_;
80 };48 };
81
82 auto timeout_bailout = [] (gpointer data) -> gboolean
83 {
84 TestHud* self = static_cast<TestHud*>(data);
85 self->query_return_result = false;
86 g_main_loop_quit(loop_);
87 return FALSE;
88 };
89 49
90 sigc::connection connection = hud->queries_updated.connect(query_connection);50 sigc::connection connection = hud->queries_updated.connect(query_connection);
91 51
92 guint source_id = g_timeout_add(10000, timeout_bailout, this);
93
94 // next check we get 30 entries from this specific known callback52 // next check we get 30 entries from this specific known callback
95 hud->RequestQuery("Request30Queries");53 hud->RequestQuery("Request30Queries");
96 g_main_loop_run(loop_);54
97 EXPECT_EQ(query_return_result, true);55 ::Utils::WaitUntil([&queries, &query_return_result]() { return query_return_result && queries.size() > 0; },
98 EXPECT_NE(queries.size(), 0);56 true,
99 g_source_remove(source_id);57 10,
58 []() { return g_strdup("Timed out waiting for hud queries"); });
10059
101 // finally close the connection - Nothing to check for here60 // finally close the connection - Nothing to check for here
102 hud->CloseQuery();61 hud->CloseQuery();
103 connection.disconnect();62 connection.disconnect();
104}63}
10564
106TEST_F(TestHud, TestSigEmission)65TEST(TestHud, TestSigEmission)
107{66{
67 Hud::Ptr hud(new Hud("com.canonical.Unity.Test", "/com/canonical/hud"));
68 WaitForConnect(hud);
69
108 // checks that the signal emission from Hud is working correctly70 // checks that the signal emission from Hud is working correctly
109 // the service is setup to emit the same signal every 1000ms71 // the service is setup to emit the same signal every 1000ms
110 // using the same query key as its StarQuery method72 // using the same query key as its StarQuery method
111 // so calling StartQuery and listening we expect > 1 73 // so calling StartQuery and listening we expect > 1
112 // signal emission74 // signal emission
113 number_signals_found = 0;75 int number_signals_found = 0;
11476
115 // make sure we receive the queries77 // make sure we receive the queries
116 auto query_connection = [this](unity::hud::Hud::Queries queries_) 78 auto query_connection = [&number_signals_found](Hud::Queries const&)
117 { 79 {
118 number_signals_found += 1;80 number_signals_found += 1;
119 };81 };
120
121 auto timeout_bailout = [] (gpointer data) -> gboolean
122 {
123 g_main_loop_quit(loop_);
124 return FALSE;
125 };
126 82
127 sigc::connection connection = hud->queries_updated.connect(query_connection);83 sigc::connection connection = hud->queries_updated.connect(query_connection);
128 84
129 hud->RequestQuery("Request30Queries");85 hud->RequestQuery("Request30Queries");
130 guint source_id = g_timeout_add(10000, timeout_bailout, this);86
131 87 ::Utils::WaitUntil([&number_signals_found]() { return number_signals_found > 1; },
132 g_main_loop_run(loop_);88 true,
133 EXPECT_GT(number_signals_found, 1);89 10,
134 g_source_remove(source_id);90 []() { return g_strdup("Timed out waiting for hud signals"); });
13591
136 // finally close the connection - Nothing to check for here92 // finally close the connection - Nothing to check for here
137 hud->CloseQuery();93 hud->CloseQuery();
138 connection.disconnect();94 connection.disconnect();
139
140}95}
14196
142}97}
98}
14399
=== modified file 'tests/test_hud_view.cpp'
--- tests/test_hud_view.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_hud_view.cpp 2013-03-21 14:03:22 +0000
@@ -32,6 +32,7 @@
32#include "unity-shared/DashStyle.h"32#include "unity-shared/DashStyle.h"
33#include "unity-shared/PanelStyle.h"33#include "unity-shared/PanelStyle.h"
34#include "unity-shared/UnitySettings.h"34#include "unity-shared/UnitySettings.h"
35
35using namespace unity;36using namespace unity;
3637
37namespace38namespace
3839
=== removed file 'tests/test_lensview.cpp'
--- tests/test_lensview.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_lensview.cpp 1970-01-01 00:00:00 +0000
@@ -1,98 +0,0 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include <gtest/gtest.h>
21#include <gmock/gmock.h>
22#include <dash/LensView.h>
23#include <dash/PlacesGroup.h>
24#include <unity-shared/DashStyle.h>
25#include <unity-shared/UnitySettings.h>
26#include <UnityCore/Category.h>
27
28using namespace unity;
29using namespace unity::dash;
30
31namespace unity
32{
33namespace dash
34{
35
36class TestLensView : public ::testing::Test
37{
38public:
39
40 class FakePlacesGroup : public PlacesGroup
41 {
42 public:
43 FakePlacesGroup():PlacesGroup(dash::Style::Instance()) {}
44
45 using PlacesGroup::_using_filters_background;
46 };
47
48 class FakeLensView : public LensView
49 {
50 public:
51 FakeLensView():LensView(Lens::Ptr(), nullptr) {}
52
53 using LensView::OnCategoryAdded;
54
55 PlacesGroup* CreatePlacesGroup()
56 {
57 FakePlacesGroup* category = new FakePlacesGroup();
58 fake_categories_.push_back(category);
59 return category;
60 }
61
62 std::vector<FakePlacesGroup*> fake_categories_;
63 };
64
65 TestLensView()
66 : lens_view_(new FakeLensView())
67 {
68 }
69
70 unity::Settings settings;
71 dash::Style style;
72 std::unique_ptr<FakeLensView> lens_view_;
73};
74
75TEST_F(TestLensView, TestCategoryInsert)
76{
77 Category cat(NULL, NULL, NULL);
78 lens_view_->OnCategoryAdded(cat);
79
80 ASSERT_TRUE(lens_view_->categories().size() > 0);
81}
82
83TEST_F(TestLensView, TestFilterExpansion)
84{
85 Category cat(NULL, NULL, NULL);
86 lens_view_->OnCategoryAdded(cat);
87 lens_view_->OnCategoryAdded(cat);
88 lens_view_->OnCategoryAdded(cat);
89
90 lens_view_->filters_expanded = true;
91 for (unsigned i = 0; i < lens_view_->fake_categories_.size(); i++)
92 {
93 EXPECT_EQ(lens_view_->fake_categories_[i]->_using_filters_background, true);
94 }
95}
96
97}
98}
990
=== modified file 'tests/test_main.cpp'
--- tests/test_main.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_main.cpp 2013-03-21 14:03:22 +0000
@@ -6,6 +6,11 @@
6#include <config.h>6#include <config.h>
77
8#include "logger_helper.h"8#include "logger_helper.h"
9#include "test_utils.h"
10
11
12const gchar* LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
13const gchar* SCHEMA_DIRECTORY = BUILDDIR"/settings";
914
10int main(int argc, char** argv)15int main(int argc, char** argv)
11{16{
@@ -16,6 +21,7 @@
16 const std::string LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";21 const std::string LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
17 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR.c_str(), TRUE);22 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR.c_str(), TRUE);
18 g_setenv("LC_ALL", "C", TRUE);23 g_setenv("LC_ALL", "C", TRUE);
24 Utils::init_gsettings_test_environment();
1925
20 gtk_init(&argc, &argv);26 gtk_init(&argc, &argv);
21 setlocale(LC_ALL, "C");27 setlocale(LC_ALL, "C");
@@ -33,6 +39,8 @@
33 // StandaloneWindowManager brought in at link time.39 // StandaloneWindowManager brought in at link time.
34 int ret = RUN_ALL_TESTS();40 int ret = RUN_ALL_TESTS();
3541
42 Utils::reset_gsettings_test_environment();
43
36 return ret;44 return ret;
37}45}
3846
3947
=== modified file 'tests/test_main_dbus.cpp'
--- tests/test_main_dbus.cpp 2013-03-12 13:31:41 +0000
+++ tests/test_main_dbus.cpp 2013-03-21 14:03:22 +0000
@@ -4,9 +4,20 @@
4#include <Nux/Nux.h>4#include <Nux/Nux.h>
5#include "test_utils.h"5#include "test_utils.h"
66
7#include "config.h"
8
7static bool wait_until_test_service_appears();9static bool wait_until_test_service_appears();
8static void tell_service_to_exit();10static void tell_service_to_exit();
911
12static gboolean no_exit = FALSE;
13
14static GOptionEntry entries[] =
15{
16 { "no-exit", 'n', 0, G_OPTION_ARG_NONE, &no_exit, "Do not handle exit call", NULL },
17 { NULL }
18};
19
20
10int main(int argc, char** argv)21int main(int argc, char** argv)
11{22{
12 ::testing::InitGoogleTest(&argc, argv);23 ::testing::InitGoogleTest(&argc, argv);
@@ -14,8 +25,20 @@
14 g_type_init();25 g_type_init();
15#endif26#endif
1627
28 GError *error = NULL;
29 GOptionContext *context;
30 context = g_option_context_new ("- DBus tests");
31 g_option_context_add_main_entries (context, entries, NULL);
32 if (!g_option_context_parse (context, &argc, &argv, &error))
33 {
34 g_print ("option parsing failed: %s\n", error->message);
35 return 1;
36 }
37
17 nux::NuxInitialize (0);38 nux::NuxInitialize (0);
1839
40 g_setenv("XDG_DATA_HOME", BUILDDIR"/tests/data", TRUE);
41
19 // We need the service to be ready before we are42 // We need the service to be ready before we are
2043
21 if (!wait_until_test_service_appears())44 if (!wait_until_test_service_appears())
@@ -32,7 +55,8 @@
3255
33 int ret = RUN_ALL_TESTS();56 int ret = RUN_ALL_TESTS();
3457
35 tell_service_to_exit();58 if (!no_exit)
59 tell_service_to_exit();
3660
37 return ret;61 return ret;
38}62}
3963
=== modified file 'tests/test_main_xless.cpp'
--- tests/test_main_xless.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_main_xless.cpp 2013-03-21 14:03:22 +0000
@@ -2,6 +2,10 @@
2#include <gio/gio.h>2#include <gio/gio.h>
3#include <NuxCore/Logger.h>3#include <NuxCore/Logger.h>
4#include <Nux/Nux.h>4#include <Nux/Nux.h>
5#include <config.h>
6
7
8const gchar* LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
59
6int main(int argc, char** argv)10int main(int argc, char** argv)
7{11{
@@ -11,6 +15,8 @@
11#endif15#endif
12 setlocale(LC_ALL, "C");16 setlocale(LC_ALL, "C");
1317
18 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR, TRUE);
19
14 // Slightly higher as we're more likely to test things we know will fail20 // Slightly higher as we're more likely to test things we know will fail
15 nux::logging::configure_logging("<root>=error");21 nux::logging::configure_logging("<root>=error");
1622
1723
=== added file 'tests/test_mock_scope.h'
--- tests/test_mock_scope.h 1970-01-01 00:00:00 +0000
+++ tests/test_mock_scope.h 2013-03-21 14:03:22 +0000
@@ -0,0 +1,178 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
20 *
21 */
22
23#ifndef TEST_MOCK_SCOPE_H
24#define TEST_MOCK_SCOPE_H
25
26#include <gmock/gmock.h>
27#include <UnityCore/GSettingsScopes.h>
28#include <UnityCore/GLibSource.h>
29
30#include <unity-protocol.h>
31
32namespace unity
33{
34namespace dash
35{
36
37namespace
38{
39const gchar* SETTINGS_NAME = "com.canonical.Unity.Dash";
40const gchar* SCOPES_SETTINGS_KEY = "scopes";
41}
42
43// Mock Scopes for use in xless tests. (no dbus!)
44class MockScopeProxy : public ScopeProxyInterface
45{
46public:
47 MockScopeProxy(std::string const& _name, std::string const& _icon_hint)
48 : connected_(true)
49 {
50 connected.SetGetterFunction([this] () { return connected_; });
51 name.SetGetterFunction([_name] () { return _name; });
52 icon_hint.SetGetterFunction([_icon_hint] () { return _icon_hint; });
53 visible.SetGetterFunction([]() { return true; });
54 }
55
56 virtual void ConnectProxy() { connected_ = true; }
57 virtual void DisconnectProxy() { connected_ = false; }
58
59 virtual void Search(std::string const& search_hint, SearchCallback const& callback = nullptr, GCancellable* cancellable = nullptr)
60 {
61 source_manager.AddIdle([search_hint, callback] () {
62 callback(search_hint, glib::HintsMap(), glib::Error());
63 return true;
64 }, "Search");
65 }
66
67 virtual void Activate(LocalResult const& result, uint activate_type, glib::HintsMap const& hints, ActivateCallback const& callback = nullptr, GCancellable* cancellable = nullptr)
68 {
69 source_manager.AddIdle([activate_type, callback, result] ()
70 {
71 switch (activate_type)
72 {
73 case UNITY_PROTOCOL_ACTION_TYPE_ACTIVATE_RESULT:
74 callback(result, ScopeHandledType::NOT_HANDLED, glib::HintsMap(), glib::Error());
75 break;
76
77 case UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_RESULT:
78 callback(result, ScopeHandledType::SHOW_PREVIEW, glib::HintsMap(), glib::Error());
79 break;
80
81 case UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_ACTION:
82 callback(result, ScopeHandledType::HIDE_DASH, glib::HintsMap(), glib::Error());
83 break;
84
85 default:
86 {
87 glib::Error error;
88 GError** real_err = &error;
89 *real_err = g_error_new_literal(G_SCOPE_ERROR, G_SCOPE_ERROR_NO_ACTIVATION_HANDLER, "Invalid scope activation typehandler");
90 callback(result, ScopeHandledType::NOT_HANDLED, glib::HintsMap(), error);
91 } break;
92 }
93 return true;
94 }, "Activate");
95 }
96
97 virtual Results::Ptr GetResultsForCategory(unsigned category) const
98 {
99 return Results::Ptr();
100 }
101
102protected:
103 glib::SourceManager source_manager;
104 bool connected_;
105};
106
107class MockScopeData : public ScopeData
108{
109public:
110 MockScopeData(std::string const& scope_id,
111 std::string const& _dbus_name = "",
112 std::string const& _dbus_path = "")
113 {
114 id = scope_id;
115 dbus_name = _dbus_name;
116 dbus_path = _dbus_path;
117 }
118};
119
120class MockScope : public Scope
121{
122public:
123 typedef std::shared_ptr<MockScope> Ptr;
124
125 MockScope(ScopeData::Ptr const& scope_data,
126 std::string const& name = "",
127 std::string const& icon_hint = "")
128 : Scope(scope_data)
129 {
130 proxy_func = [name, icon_hint]()
131 {
132 return ScopeProxyInterface::Ptr(new MockScopeProxy(name, icon_hint));
133 };
134
135 Init();
136 }
137
138 virtual ScopeProxyInterface::Ptr CreateProxyInterface() const
139 {
140 return proxy_func();
141 }
142
143 std::function<ScopeProxyInterface::Ptr(void)> proxy_func;
144};
145
146class MockGSettingsScopes : public GSettingsScopes
147{
148public:
149 MockGSettingsScopes(const char* scopes_settings[])
150 {
151 gsettings_client = g_settings_new(SETTINGS_NAME);
152 UpdateScopes(scopes_settings);
153 }
154
155 using GSettingsScopes::InsertScope;
156 using GSettingsScopes::RemoveScope;
157
158 void UpdateScopes(const char* scopes_settings[])
159 {
160 g_settings_set_strv(gsettings_client, SCOPES_SETTINGS_KEY, scopes_settings);
161 }
162
163protected:
164 virtual Scope::Ptr CreateScope(ScopeData::Ptr const& scope_data)
165 {
166 Scope::Ptr scope(new MockScope(scope_data));
167 return scope;
168 }
169
170private:
171 glib::Object<GSettings> gsettings_client;
172};
173
174} // namesapce dash
175} // namesapce unity
176
177
178#endif // TEST_MOCK_SCOPE_H
0179
=== modified file 'tests/test_model_iterator.cpp'
--- tests/test_model_iterator.cpp 2013-03-19 14:05:51 +0000
+++ tests/test_model_iterator.cpp 2013-03-21 14:03:22 +0000
@@ -110,6 +110,20 @@
110 EXPECT_NE(one, two);110 EXPECT_NE(one, two);
111}111}
112112
113TEST_F(TestResultIterator, TestEqual)
114{
115 AddResult("mailto:nospam@example.org", "Email");
116
117 ResultIterator one(results->model());
118 ResultIterator two = one;
119
120 EXPECT_EQ(one, two);
121
122 ResultIterator const& original = two++;
123 EXPECT_EQ(original, one);
124 EXPECT_NE(one, two);
125}
126
113TEST_F(TestResultIterator, TestIncrement)127TEST_F(TestResultIterator, TestIncrement)
114{128{
115 AddResult("file:///foo.txt", "Result #1");129 AddResult("file:///foo.txt", "Result #1");
@@ -129,5 +143,77 @@
129 EXPECT_FALSE(it.IsFirst());143 EXPECT_FALSE(it.IsFirst());
130}144}
131145
132146TEST_F(TestResultIterator, TestDecrement)
147{
148 AddResult("file:///foo.txt", "Result #1");
149 AddResult("file:///qoo.txt", "Result #2");
150
151 ResultIterator it(results->end());
152 EXPECT_TRUE(it.IsLast());
153
154 it--;
155 EXPECT_EQ((*it).uri, "file:///qoo.txt");
156 EXPECT_EQ((*it).name, "Result #2");
157
158 it--;
159 EXPECT_EQ((*it).uri, "file:///foo.txt");
160 EXPECT_EQ((*it).name, "Result #1");
161
162 EXPECT_TRUE(it.IsFirst());
163 EXPECT_FALSE(it.IsLast());
164}
165
166TEST_F(TestResultIterator, TestAdd)
167{
168 AddResult("file:///foo.txt", "Result #1");
169 AddResult("file:///qoo.txt", "Result #2");
170 AddResult("file:///bar.txt", "Result #3");
171
172 ResultIterator it(results->model());
173 EXPECT_EQ((*it).uri, "file:///foo.txt");
174 EXPECT_EQ((*it).name, "Result #1");
175
176 it+=2;
177 EXPECT_EQ((*it).uri, "file:///bar.txt");
178 EXPECT_EQ((*it).name, "Result #3");
179 EXPECT_FALSE(it.IsLast());
180
181 it+=1;
182 EXPECT_TRUE(it.IsLast());
183 EXPECT_FALSE(it.IsFirst());
184}
185
186TEST_F(TestResultIterator, TestSubtract)
187{
188 AddResult("file:///foo.txt", "Result #1");
189 AddResult("file:///qoo.txt", "Result #2");
190 AddResult("file:///bar.txt", "Result #3");
191
192 ResultIterator it(results->end());
193 EXPECT_TRUE(it.IsLast());
194
195 it--;
196 EXPECT_EQ((*it).uri, "file:///bar.txt");
197 EXPECT_EQ((*it).name, "Result #3");
198
199 it-=2;
200 EXPECT_EQ((*it).uri, "file:///foo.txt");
201 EXPECT_EQ((*it).name, "Result #1");
202 EXPECT_TRUE(it.IsFirst());
203 EXPECT_FALSE(it.IsLast());
204}
205
206TEST_F(TestResultIterator, TestOperatorAt)
207{
208 AddResult("file:///foo.txt", "Result #1");
209 AddResult("file:///qoo.txt", "Result #2");
210 AddResult("file:///bar.txt", "Result #3");
211
212 ResultIterator it(results->begin());
213 it = it[1];
214
215 EXPECT_EQ((*it).uri, "file:///qoo.txt");
216 EXPECT_EQ((*it).name, "Result #2");
133} // Namespace217} // Namespace
218
219}
134220
=== added file 'tests/test_preview_player.cpp'
--- tests/test_preview_player.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_preview_player.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,151 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekinc@canonical.com>
18 */
19
20#include <gmock/gmock.h>
21#include "UnityCore/PreviewPlayer.h"
22#include "test_utils.h"
23#include "config.h"
24#include "sigc++/connection.h"
25
26namespace unity
27{
28
29const gchar* WHITE_NOISE = "file://" BUILDDIR "/tests/data/unity/sounds/whitenoise.mp3";
30
31
32namespace
33{
34 void PlayAndWait(PreviewPlayer* player, std::string const& uri)
35 {
36 bool play_returned = false;
37 auto play_callback = [&play_returned] (glib::Error const& error) {
38 play_returned = true;
39 EXPECT_TRUE(!error) << "Error: " << error.Message();
40 };
41
42 bool updated_called = false;
43 auto updated_callback = [uri, &updated_called] (std::string const& _uri, PlayerState state, double) {
44 updated_called = true;
45 EXPECT_EQ(_uri, uri) << "Uri for PLAY not correct (" << _uri << " != " << _uri << ")";
46 EXPECT_EQ((int)state, (int)PlayerState::PLAYING) << "Incorrect state returned on PLAY.";
47 };
48
49 sigc::connection conn = player->updated.connect(updated_callback);
50 player->Play(uri, play_callback);
51 ::Utils::WaitUntilMSec(play_returned, 3000, []() { return g_strdup("PLAY did not return"); });
52 ::Utils::WaitUntilMSec(updated_called, 5000, []() { return g_strdup("Update not called on PLAY"); });
53 conn.disconnect();
54 }
55
56 void PauseAndWait(PreviewPlayer* player)
57 {
58 bool pause_returned = false;
59 auto callback = [&pause_returned] (glib::Error const& error) {
60 pause_returned = true;
61 EXPECT_TRUE(!error) << "Error: " << error.Message();
62 };
63
64 bool updated_called = false;
65 auto updated_callback = [&updated_called] (std::string const&, PlayerState state, double) {
66 updated_called = true;
67 EXPECT_EQ((int)state, (int)PlayerState::PAUSED) << "Incorrect state returned on PAUSE.";
68 };
69
70 sigc::connection conn = player->updated.connect(updated_callback);
71 player->Pause(callback);
72 ::Utils::WaitUntilMSec(pause_returned, 3000, []() { return g_strdup("PAUSE did not return"); });
73 ::Utils::WaitUntilMSec(updated_called, 5000, []() { return g_strdup("Update not called om PAUSE"); });
74 conn.disconnect();
75 }
76
77 void ResumeAndWait(PreviewPlayer* player)
78 {
79 bool resume_returned = false;
80 auto callback = [&resume_returned] (glib::Error const& error) {
81 resume_returned = true;
82 EXPECT_TRUE(!error) << "Error: " << error.Message();
83 };
84
85 bool updated_called = false;
86 auto updated_callback = [&updated_called] (std::string const&, PlayerState state, double) {
87 updated_called = true;
88 EXPECT_EQ((int)state, (int)PlayerState::PLAYING) << "Incorrect state returned on RESUME.";
89 };
90
91 sigc::connection conn = player->updated.connect(updated_callback);
92 player->Resume(callback);
93 ::Utils::WaitUntilMSec(resume_returned, 3000, []() { return g_strdup("RESUME did not return"); });
94 ::Utils::WaitUntilMSec(updated_called, 5000, []() { return g_strdup("Update not called on RESUME"); });
95 conn.disconnect();
96 }
97
98 void StopAndWait(PreviewPlayer* player)
99 {
100 bool stop_returned = false;
101 auto callback = [&stop_returned] (glib::Error const& error) {
102 stop_returned = true;
103 EXPECT_TRUE(!error) << "Error: " << error.Message();
104 };
105
106 bool updated_called = false;
107 auto updated_callback = [&updated_called] (std::string const&, PlayerState state, double) {
108 updated_called = true;
109 EXPECT_EQ((int)state, (int)PlayerState::STOPPED) << "Incorrect state returned on STOP.";
110 };
111
112 sigc::connection conn = player->updated.connect(updated_callback);
113 player->Stop(callback);
114 ::Utils::WaitUntilMSec(stop_returned, 3000, []() { return g_strdup("STOP did not return"); });
115 ::Utils::WaitUntilMSec(updated_called, 5000, []() { return g_strdup("Update not called on STOP"); });
116 conn.disconnect();
117 }
118}
119
120TEST(TestPreviewPlayer, TestConstruct)
121{
122 PreviewPlayer player1;
123 PreviewPlayer player2;
124}
125
126TEST(TestPreviewPlayer, TestPlayerControl)
127{
128 PreviewPlayer player;
129
130 PlayAndWait(&player, WHITE_NOISE);
131
132 PauseAndWait(&player);
133
134 ResumeAndWait(&player);
135
136 StopAndWait(&player);
137}
138
139TEST(TestPreviewPlayer, TestMultiPlayer)
140{
141 PreviewPlayer player1;
142 {
143 PreviewPlayer player2;
144 PlayAndWait(&player2, WHITE_NOISE);
145 }
146
147 StopAndWait(&player1);
148}
149
150
151} // namespace unity
0\ No newline at end of file152\ No newline at end of file
1153
=== modified file 'tests/test_results.cpp'
--- tests/test_results.cpp 2013-03-19 14:05:51 +0000
+++ tests/test_results.cpp 2013-03-21 14:03:22 +0000
@@ -74,10 +74,21 @@
74 EXPECT_EQ(result.uri(), value);74 EXPECT_EQ(result.uri(), value);
75 EXPECT_EQ(result.icon_hint(), value);75 EXPECT_EQ(result.icon_hint(), value);
76 EXPECT_EQ(result.category_index(), (i / 50));76 EXPECT_EQ(result.category_index(), (i / 50));
77 EXPECT_EQ(result.result_type(), 0);
77 EXPECT_EQ(result.mimetype(), value);78 EXPECT_EQ(result.mimetype(), value);
78 EXPECT_EQ(result.name(), value);79 EXPECT_EQ(result.name(), value);
79 EXPECT_EQ(result.comment(), value);80 EXPECT_EQ(result.comment(), value);
80 EXPECT_EQ(result.dnd_uri(), value);81 EXPECT_EQ(result.dnd_uri(), value);
82
83 glib::HintsMap hints = result.hints();
84 auto iter = hints.find("key");
85 EXPECT_TRUE(iter != hints.end());
86 if (iter != hints.end())
87 {
88 std::string value = glib::gchar_to_string(g_variant_get_string(iter->second, NULL));
89 EXPECT_EQ(value, "value");
90 }
91
81 i++;92 i++;
82 }93 }
8394
@@ -156,4 +167,133 @@
156 }167 }
157}168}
158169
170// We're testing the model's ability to store and retrieve random pointers
171TEST(TestResults, TestResultEqual)
172{
173 Results model;
174 model.swarm_name = swarm_name;
175
176 WaitForSynchronize(model);
177
178 Result result_1(*model.begin());
179 Result result_2(NULL, NULL, NULL);
180 result_2 = result_1;
181
182 EXPECT_EQ(result_2.uri(), result_1.uri());
183 EXPECT_EQ(result_2.icon_hint(), result_1.icon_hint());
184 EXPECT_EQ(result_2.category_index(), result_1.category_index());
185 EXPECT_EQ(result_2.result_type(), result_1.result_type());
186 EXPECT_EQ(result_2.mimetype(), result_1.mimetype());
187 EXPECT_EQ(result_2.name(), result_1.name());
188 EXPECT_EQ(result_2.comment(), result_1.comment());
189 EXPECT_EQ(result_2.dnd_uri(), result_1.dnd_uri());
190}
191
192// We're testing the model's ability to store and retrieve random pointers
193TEST(TestResults, LocalResult_Construct)
194{
195 Results model;
196 model.swarm_name = swarm_name;
197
198 WaitForSynchronize(model);
199
200 ResultIterator iter(model.model);
201 for (Result const& result : model)
202 {
203 LocalResult local_result_1(result);
204 LocalResult local_result_2(local_result_1);
205
206 EXPECT_EQ(local_result_1.uri, result.uri());
207 EXPECT_EQ(local_result_1.icon_hint, result.icon_hint());
208 EXPECT_EQ(local_result_1.category_index, result.category_index());
209 EXPECT_EQ(local_result_1.result_type, result.result_type());
210 EXPECT_EQ(local_result_1.mimetype, result.mimetype());
211 EXPECT_EQ(local_result_1.name, result.name());
212 EXPECT_EQ(local_result_1.comment, result.comment());
213 EXPECT_EQ(local_result_1.dnd_uri, result.dnd_uri());
214
215 EXPECT_EQ(local_result_2.uri, result.uri());
216 EXPECT_EQ(local_result_2.icon_hint, result.icon_hint());
217 EXPECT_EQ(local_result_2.category_index, result.category_index());
218 EXPECT_EQ(local_result_2.result_type, result.result_type());
219 EXPECT_EQ(local_result_2.mimetype, result.mimetype());
220 EXPECT_EQ(local_result_2.name, result.name());
221 EXPECT_EQ(local_result_2.comment, result.comment());
222 EXPECT_EQ(local_result_2.dnd_uri, result.dnd_uri());
223 }
224}
225
226
227// We're testing the model's ability to store and retrieve random pointers
228TEST(TestResults, LocalResult_OperatorEqual)
229{
230 Results model;
231 model.swarm_name = swarm_name;
232
233 WaitForSynchronize(model);
234
235 ResultIterator iter(model.model);
236 for (Result const& result : model)
237 {
238 LocalResult local_result_1(result);
239 LocalResult local_result_2(local_result_1);
240
241 EXPECT_TRUE(local_result_1 == local_result_2);
242 EXPECT_FALSE(local_result_1 != local_result_2);
243 }
244}
245
246
247// We're testing the model's ability to store and retrieve random pointers
248TEST(TestResults, LocalResult_FromToVariant)
249{
250 LocalResult local_result_1;
251 local_result_1.uri = "uri";
252 local_result_1.icon_hint = "icon_hint";
253 local_result_1.category_index = 1;
254 local_result_1.result_type = 2;
255 local_result_1.mimetype = "mimetype";
256 local_result_1.name = "name";
257 local_result_1.comment = "comment";
258 local_result_1.dnd_uri = "dnd_uri";
259
260 local_result_1.hints["key1"] = g_variant_new_string("value1");
261 local_result_1.hints["key2"] = g_variant_new_string("value2");
262
263 glib::Variant variant_value = local_result_1.Variant();
264 LocalResult local_result_2 = LocalResult::FromVariant(variant_value);
265
266 EXPECT_EQ(local_result_2.uri, "uri");
267 EXPECT_EQ(local_result_2.icon_hint, "icon_hint");
268 EXPECT_EQ(local_result_2.category_index, 1);
269 EXPECT_EQ(local_result_2.result_type, 2);
270 EXPECT_EQ(local_result_2.mimetype, "mimetype");
271 EXPECT_EQ(local_result_2.name, "name");
272 EXPECT_EQ(local_result_2.comment, "comment");
273 EXPECT_EQ(local_result_2.dnd_uri, "dnd_uri");
274
275 auto iter = local_result_2.hints.find("key1");
276 EXPECT_TRUE(iter != local_result_2.hints.end());
277 if (iter != local_result_2.hints.end())
278 {
279 std::string value = glib::gchar_to_string(g_variant_get_string(iter->second, NULL));
280 EXPECT_EQ(value, "value1");
281 }
282 iter = local_result_2.hints.find("key2");
283 EXPECT_TRUE(iter != local_result_2.hints.end());
284 if (iter != local_result_2.hints.end())
285 {
286 std::string value = glib::gchar_to_string(g_variant_get_string(iter->second, NULL));
287 EXPECT_EQ(value, "value2");
288 }
289}
290
291
292// We're testing the model's ability to store and retrieve random pointers
293TEST(TestResults, LocalResult_Variants)
294{
295 LocalResult local_result;
296 EXPECT_EQ(local_result.Variants().size(), 9);
297}
298
159}299}
160300
=== modified file 'tests/test_resultviewgrid.cpp'
--- tests/test_resultviewgrid.cpp 2013-02-21 10:03:21 +0000
+++ tests/test_resultviewgrid.cpp 2013-03-21 14:03:22 +0000
@@ -49,7 +49,7 @@
49public:49public:
50 virtual void SetUp()50 virtual void SetUp()
51 {51 {
52 view.Adopt(new MockResultViewGrid(NUX_TRACKER_LOCATION));52 view.Adopt(new NiceMock<MockResultViewGrid>(NUX_TRACKER_LOCATION));
53 renderer.Adopt(new dash::ResultRenderer(NUX_TRACKER_LOCATION));53 renderer.Adopt(new dash::ResultRenderer(NUX_TRACKER_LOCATION));
5454
55 view->SetModelRenderer(renderer.GetPointer());55 view->SetModelRenderer(renderer.GetPointer());
5656
=== added file 'tests/test_scope.cpp'
--- tests/test_scope.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_scope.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,236 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include <boost/lexical_cast.hpp>
21#include <gtest/gtest.h>
22#include <glib-object.h>
23#include <unity-protocol.h>
24
25#include <UnityCore/GLibWrapper.h>
26#include <UnityCore/Scope.h>
27 #include <UnityCore/CheckOptionFilter.h>
28
29#include "test_utils.h"
30#include "RadioOptionFilter.h"
31
32using namespace std;
33using namespace unity;
34using namespace unity::dash;
35
36namespace unity
37{
38namespace dash
39{
40
41namespace
42{
43const std::string SCOPE_NAME = "testscope1.scope";
44}
45
46class TestScope : public ::testing::Test
47{
48public:
49 TestScope() { }
50
51 virtual void SetUp()
52 {
53 glib::Error err;
54 ScopeData::Ptr data(ScopeData::ReadProtocolDataForId(SCOPE_NAME, err));
55 ASSERT_TRUE(err ? false : true);
56
57 scope_.reset(new Scope(data));
58 scope_->Init();
59 }
60
61 void ConnectAndWait()
62 {
63 scope_->Connect();
64 Utils::WaitUntilMSec([this] { return scope_->connected() == true; }, true, 2000);
65 }
66
67 Filter::Ptr WaitForFilter(std::string const& filter_to_wait_for)
68 {
69 Filter::Ptr filter_ret;
70 Filters::Ptr filters = scope_->filters();
71 Utils::WaitUntilMSec([filters, filter_to_wait_for, &filter_ret]
72 {
73 for (std::size_t i = 0; i < filters->count(); i++)
74 {
75 Filter::Ptr filter = filters->FilterAtIndex(i);
76 if (filter && filter->id == filter_to_wait_for)
77 {
78 filter_ret = filter;
79 return true;
80 }
81 }
82 return false;
83 },
84 true,
85 2000,
86 [filter_to_wait_for] { return g_strdup_printf("Filter '%s' not found", filter_to_wait_for.c_str()); });
87 return filter_ret;
88 }
89
90 Scope::Ptr scope_;
91};
92
93TEST_F(TestScope, TestConnection)
94{
95 ConnectAndWait();
96 ASSERT_TRUE(scope_->connected);
97}
98
99TEST_F(TestScope, Search)
100{
101 // Auto-connect on search
102 bool search_ok = false;
103 auto search_callback = [&search_ok] (std::string const& search_string, glib::HintsMap const&, glib::Error const&) {
104 search_ok = true;
105 };
106
107 scope_->Search("12:test_search", search_callback, nullptr);
108 Utils::WaitUntilMSec(search_ok,
109 2000,
110 [] { return g_strdup("Search did not finish sucessfully"); });
111}
112
113TEST_F(TestScope, ActivateUri)
114{
115 // Auto-connect on activate
116 bool activated_return = false;
117 auto activate_callback = [&activated_return] (LocalResult const&, ScopeHandledType, glib::Error const&) {
118 activated_return = true;
119 };
120
121 LocalResult result; result.uri = "file:://test";
122 scope_->Activate(result,
123 activate_callback);
124
125 Utils::WaitUntilMSec(activated_return,
126 2000,
127 [] { return g_strdup("Failed to activate"); });
128}
129
130TEST_F(TestScope, PreviewPerformAction)
131{
132 Preview::Ptr preview;
133 // Auto-connect on preview
134 bool preview_ok = false;
135 auto preview_callback = [&preview_ok, &preview] (LocalResult const&, Preview::Ptr const& _preview, glib::Error const&) {
136 preview_ok = true;
137 preview = _preview;
138 };
139
140 LocalResult result; result.uri = "file:://test";
141 scope_->Preview(result,
142 preview_callback);
143
144 Utils::WaitUntilMSec(preview_ok,
145 2000,
146 [] { return g_strdup("Failed to preview"); });
147 EXPECT_TRUE(preview ? true : false);
148 if (preview)
149 {
150 Preview::ActionPtrList actions = preview->GetActions();
151 // EXPECT_TRUE(actions.size() > 0);
152 for (auto action : actions)
153 preview->PerformAction(action->id);
154 }
155}
156
157TEST_F(TestScope, ActivatePreviewAction)
158{
159 // Auto-connect on preview
160 bool preview_action_ok = false;
161 auto preview_action_callback = [&preview_action_ok] (LocalResult const&, ScopeHandledType, glib::Error const&) {
162 preview_action_ok = true;
163 };
164
165 LocalResult result; result.uri = "file:://test";
166 scope_->ActivatePreviewAction("play",
167 result,
168 glib::HintsMap(),
169 preview_action_callback);
170
171 Utils::WaitUntilMSec(preview_action_ok,
172 2000,
173 [] { return g_strdup("Failed to activate preview action"); });
174}
175
176TEST_F(TestScope, UpdateSearchCategoryWorkflow)
177{
178 bool search_ok = false;
179 bool search_finished = false;
180 auto search_callback = [&search_ok, &search_finished] (std::string const& search_string, glib::HintsMap const&, glib::Error const& error) {
181 search_finished = true;
182 search_ok = error ? false : true;
183 };
184
185 // 1. First search
186 scope_->Search("13:cat", search_callback);
187
188 Results::Ptr results = scope_->results();
189 Utils::WaitUntilMSec(search_ok, 2000, [] { return g_strdup("First search failed."); });
190 Utils::WaitUntilMSec([results] { return results->count() == 13; },
191 true,
192 2000,
193 [results] { return g_strdup_printf("First search. Either search didn't finish, or result count is not as expected (%u != 13).", static_cast<int>(results->count())); });
194 EXPECT_EQ(search_ok, true);
195
196 Results::Ptr category_model0 = scope_->GetResultsForCategory(0);
197 Results::Ptr category_model1 = scope_->GetResultsForCategory(1);
198 Results::Ptr category_model2 = scope_->GetResultsForCategory(2);
199
200 EXPECT_EQ(category_model0->count(), 5) << "Category 0 result count not as expected (" << category_model0->count() << " != 5)";
201 EXPECT_EQ(category_model1->count(), 4) << "Category 1 result count not as expected (" << category_model1->count() << " != 4)";
202 EXPECT_EQ(category_model2->count(), 4) << "Category 2 result count not as expected (" << category_model2->count() << " != 4)";
203
204 // 2. Update the filter.
205 CheckOptionFilter::Ptr type_filter = std::static_pointer_cast<CheckOptionFilter>(WaitForFilter("categories"));
206 ASSERT_TRUE(type_filter ? true : false);
207
208 bool filter_updated = false;
209 std::vector<FilterOption::Ptr> options = type_filter->options();
210 for (FilterOption::Ptr const& option : options)
211 {
212 if (option->id == "cat1")
213 {
214 option->active = true;
215 filter_updated = true;
216 }
217 }
218 EXPECT_TRUE(filter_updated) << "Could not update filter opiton 'cat1' of filter 'categories'";
219
220 // Results should be updated for fulter.
221 Utils::WaitUntilMSec([results] { return results->count() == 4; },
222 true,
223 2000,
224 [results] { return g_strdup_printf("First search. Either search didn't finish, or result count is not as expected (%u != 4).", static_cast<int>(results->count())); });
225
226 category_model0 = scope_->GetResultsForCategory(0);
227 category_model1 = scope_->GetResultsForCategory(1);
228 category_model2 = scope_->GetResultsForCategory(2);
229
230 EXPECT_EQ(category_model0->count(), 0) << "Category 0 result count not as expected (" << category_model0->count() << " != 0)";
231 EXPECT_EQ(category_model1->count(), 4) << "Category 1 result count not as expected (" << category_model1->count() << " != 4)";
232 EXPECT_EQ(category_model2->count(), 0) << "Category 2 result count not as expected (" << category_model2->count() << " != 0)";
233}
234
235} // namespace dash
236} // namespace unity
0237
=== added file 'tests/test_scope_bar.cpp'
--- tests/test_scope_bar.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_scope_bar.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,134 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include <gtest/gtest.h>
21#include <gmock/gmock.h>
22#include <dash/ScopeBar.h>
23
24#include "unity-shared/DashStyle.h"
25#include "unity-shared/UnitySettings.h"
26#include "test_mock_scope.h"
27
28using namespace unity;
29using namespace unity::dash;
30
31namespace unity
32{
33namespace dash
34{
35
36class TestScopeBar : public ::testing::Test
37{
38public:
39 TestScopeBar()
40 {
41 }
42
43 void CheckSize(ScopeBar const& scope_bar, int size)
44 {
45 EXPECT_EQ(scope_bar.icons_.size(), size);
46 }
47
48 unity::Settings settings;
49 dash::Style style;
50};
51
52TEST_F(TestScopeBar, TestAddScopes)
53{
54 ScopeBar scope_bar;
55
56 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
57 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
58 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));
59
60 CheckSize(scope_bar, 3);
61}
62
63TEST_F(TestScopeBar, TestActivate)
64{
65 ScopeBar scope_bar;
66
67 std::string active_scope = "";
68 scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );
69
70 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
71 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
72 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));
73
74 scope_bar.Activate("testscope1.scope");
75 EXPECT_EQ(active_scope, "testscope1.scope");
76
77 scope_bar.Activate("testscope2.scope");
78 EXPECT_EQ(active_scope, "testscope2.scope");
79
80 scope_bar.Activate("testscope3.scope");
81 EXPECT_EQ(active_scope, "testscope3.scope");
82}
83
84TEST_F(TestScopeBar, TestActivateNext)
85{
86 ScopeBar scope_bar;
87
88 std::string active_scope = "";
89 scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );
90
91 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
92 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
93 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));
94
95 scope_bar.ActivateNext();
96 EXPECT_EQ(active_scope, "testscope1.scope");
97
98 scope_bar.ActivateNext();
99 EXPECT_EQ(active_scope, "testscope2.scope");
100
101 scope_bar.ActivateNext();
102 EXPECT_EQ(active_scope, "testscope3.scope");
103
104 scope_bar.ActivateNext();
105 EXPECT_EQ(active_scope, "testscope1.scope");
106}
107
108TEST_F(TestScopeBar, TestActivatePrevious)
109{
110 ScopeBar scope_bar;
111
112 std::string active_scope = "";
113 scope_bar.scope_activated.connect([&active_scope](std::string const& activated) { active_scope = activated; } );
114
115 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope1.scope"), "TestScope1", "icon-sub1.svg"));
116 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope2.scope"), "TestScope2", "icon-sub2.svg"));
117 scope_bar.AddScope(std::make_shared<MockScope>(std::make_shared<MockScopeData>("testscope3.scope"), "TestScope3", "icon-sub3.svg"));
118
119 scope_bar.ActivatePrevious();
120 EXPECT_EQ(active_scope, "testscope3.scope");
121
122 scope_bar.ActivatePrevious();
123 EXPECT_EQ(active_scope, "testscope2.scope");
124
125 scope_bar.ActivatePrevious();
126 EXPECT_EQ(active_scope, "testscope1.scope");
127
128 scope_bar.ActivatePrevious();
129 EXPECT_EQ(active_scope, "testscope3.scope");
130}
131
132
133}
134}
0135
=== added file 'tests/test_scope_data.cpp'
--- tests/test_scope_data.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_scope_data.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
17 */
18
19#include <gtest/gtest.h>
20#include <glib-object.h>
21#include "test_utils.h"
22#include "UnityCore/ScopeData.cpp"
23
24using namespace std;
25using namespace unity;
26using namespace unity::dash;
27
28namespace
29{
30
31// A new one of these is created for each test
32class TestScopeData : public testing::Test
33{
34public:
35 TestScopeData()
36 {}
37};
38
39TEST_F(TestScopeData, TestReadExisting)
40{
41 glib::Error error;
42 ScopeData::Ptr scope_data(ScopeData::ReadProtocolDataForId("testscope1.scope", error));
43 ASSERT_TRUE(scope_data && !error);
44
45 EXPECT_EQ(scope_data->id(), "testscope1.scope");
46 EXPECT_EQ(scope_data->name(), "TestScope1");
47 EXPECT_EQ(scope_data->dbus_name(), "com.canonical.Unity.Test.Scope");
48 EXPECT_EQ(scope_data->dbus_path(), "/com/canonical/unity/scope/testscope1");
49 EXPECT_EQ(scope_data->icon_hint(), "/usr/share/unity/6/icon-sub1.svg");
50 EXPECT_EQ(scope_data->category_icon_hint(), "");
51 EXPECT_EQ(scope_data->type(), "varia");
52 EXPECT_EQ(scope_data->query_pattern(), "^@");
53 EXPECT_EQ(scope_data->description(), "Find various stuff 1");
54 EXPECT_EQ(scope_data->shortcut(), "q");
55 EXPECT_EQ(scope_data->search_hint(), "Search stuff 1");
56 EXPECT_TRUE(scope_data->keywords().size() == 1 && scope_data->keywords().front()=="misc");
57 // EXPECT_EQ(scope_data->full_path(), "");
58}
59
60TEST_F(TestScopeData, TestNonExisting)
61{
62 glib::Error error;
63 ScopeData::Ptr scope_data(ScopeData::ReadProtocolDataForId("non-existing.scope", error));
64 EXPECT_TRUE(scope_data && error);
65}
66
67}
068
=== added file 'tests/test_scope_filter.cpp'
--- tests/test_scope_filter.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_scope_filter.cpp 2013-03-21 14:03:22 +0000
@@ -0,0 +1,335 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include <boost/lexical_cast.hpp>
21#include <gtest/gtest.h>
22#include <glib-object.h>
23#include <unity-protocol.h>
24
25#include <UnityCore/GLibWrapper.h>
26#include <UnityCore/Scope.h>
27#include <UnityCore/Variant.h>
28
29#include <UnityCore/CheckOptionFilter.h>
30#include <UnityCore/MultiRangeFilter.h>
31#include <UnityCore/RadioOptionFilter.h>
32#include <UnityCore/RatingsFilter.h>
33
34#include "test_utils.h"
35
36using namespace std;
37using namespace unity;
38using namespace unity::dash;
39
40namespace unity
41{
42namespace dash
43{
44
45namespace
46{
47const std::string SCOPE_NAME = "testscope1.scope";
48}
49
50class TestScopeFilter : public ::testing::Test
51{
52public:
53 TestScopeFilter() { }
54
55 virtual void SetUp()
56 {
57 glib::Error err;
58 ScopeData::Ptr data(ScopeData::ReadProtocolDataForId(SCOPE_NAME, err));
59 ASSERT_TRUE(err ? false : true);
60
61 scope_.reset(new Scope(data));
62 scope_->Init();
63 ConnectAndWait();
64 }
65
66 void ConnectAndWait()
67 {
68 scope_->Connect();
69 Utils::WaitUntilMSec([this] { return scope_->connected() == true; }, true, 2000);
70 }
71
72 void WaitForSynchronize(Filters::Ptr const& model, unsigned int count)
73 {
74 Utils::WaitUntil([model,count] { return model->count == count; });
75 }
76
77 Scope::Ptr scope_;
78};
79
80TEST_F(TestScopeFilter, TestFilterCheckOption)
81{
82 Filters::Ptr filters = scope_->filters;
83 WaitForSynchronize(filters, 4);
84
85 CheckOptionFilter::Ptr filter = static_pointer_cast<CheckOptionFilter>(filters->FilterAtIndex(0));
86 EXPECT_EQ(filter->id, "categories");
87 EXPECT_EQ(filter->name, "Categories");
88 EXPECT_EQ(filter->icon_hint, "");
89 EXPECT_EQ(filter->renderer_name, "filter-checkoption");
90 EXPECT_TRUE(filter->visible);
91 EXPECT_FALSE(filter->collapsed);
92 EXPECT_FALSE(filter->filtering);
93
94 CheckOptionFilter::CheckOptions options = filter->options;
95 EXPECT_EQ(options.size(), (unsigned int)3);
96
97 EXPECT_EQ(options[0]->id, "cat0");
98 EXPECT_EQ(options[0]->name, "Category 0");
99 EXPECT_EQ(options[0]->icon_hint, "gtk-cdrom");
100 EXPECT_FALSE(options[0]->active);
101
102 EXPECT_EQ(options[1]->id, "cat1");
103 EXPECT_EQ(options[1]->name, "Category 1");
104 EXPECT_EQ(options[1]->icon_hint, "gtk-directory");
105 EXPECT_FALSE(options[1]->active);
106
107 EXPECT_EQ(options[2]->id, "cat2");
108 EXPECT_EQ(options[2]->name, "Category 2");
109 EXPECT_EQ(options[2]->icon_hint, "gtk-clear");
110 EXPECT_FALSE(options[2]->active);
111}
112
113TEST_F(TestScopeFilter, TestFilterCheckOptionLogic)
114{
115 Filters::Ptr filters = scope_->filters;
116 WaitForSynchronize(filters, 4);
117
118 CheckOptionFilter::Ptr filter = static_pointer_cast<CheckOptionFilter>(filters->FilterAtIndex(0));
119 CheckOptionFilter::CheckOptions options = filter->options;
120
121 EXPECT_FALSE (filter->filtering);
122 EXPECT_FALSE (options[0]->active);
123 EXPECT_FALSE (options[1]->active);
124 EXPECT_FALSE (options[2]->active);
125
126 options[0]->active = true;
127 options[0]->active = false;
128 EXPECT_FALSE (filter->filtering);
129 EXPECT_FALSE (options[0]->active);
130 EXPECT_FALSE (options[1]->active);
131 EXPECT_FALSE (options[2]->active);
132
133 options[0]->active = true;
134 EXPECT_TRUE (filter->filtering);
135 EXPECT_TRUE (options[0]->active);
136 EXPECT_FALSE (options[1]->active);
137 EXPECT_FALSE (options[2]->active);
138
139 options[1]->active = true;
140 EXPECT_TRUE (filter->filtering);
141 EXPECT_TRUE (options[0]->active);
142 EXPECT_TRUE (options[1]->active);
143 EXPECT_FALSE (options[2]->active);
144
145 options[2]->active = true;
146 EXPECT_TRUE (filter->filtering);
147 EXPECT_TRUE (options[0]->active);
148 EXPECT_TRUE (options[1]->active);
149 EXPECT_TRUE (options[2]->active);
150
151 filter->Clear();
152 EXPECT_FALSE (filter->filtering);
153 EXPECT_FALSE (options[0]->active);
154 EXPECT_FALSE (options[1]->active);
155 EXPECT_FALSE (options[2]->active);
156}
157
158TEST_F(TestScopeFilter, TestFilterRadioOption)
159{
160 Filters::Ptr filters = scope_->filters;
161 WaitForSynchronize(filters, 4);
162
163 RadioOptionFilter::Ptr filter = static_pointer_cast<RadioOptionFilter>(filters->FilterAtIndex(1));
164 EXPECT_EQ(filter->id, "when");
165 EXPECT_EQ(filter->name, "When");
166 EXPECT_EQ(filter->icon_hint, "");
167 EXPECT_EQ(filter->renderer_name, "filter-radiooption");
168 EXPECT_TRUE(filter->visible);
169 EXPECT_FALSE(filter->collapsed);
170 EXPECT_FALSE(filter->filtering);
171
172 RadioOptionFilter::RadioOptions options = filter->options;
173 EXPECT_EQ(options.size(), (unsigned int)3);
174
175 EXPECT_EQ(options[0]->id, "today");
176 EXPECT_EQ(options[0]->name, "Today");
177 EXPECT_EQ(options[0]->icon_hint, "");
178 EXPECT_FALSE(options[0]->active);
179
180 EXPECT_EQ(options[1]->id, "yesterday");
181 EXPECT_EQ(options[1]->name, "Yesterday");
182 EXPECT_EQ(options[1]->icon_hint, "");
183 EXPECT_FALSE(options[1]->active);
184
185 EXPECT_EQ(options[2]->id, "lastweek");
186 EXPECT_EQ(options[2]->name, "Last Week");
187 EXPECT_EQ(options[2]->icon_hint, "");
188 EXPECT_FALSE(options[2]->active);
189}
190
191TEST_F(TestScopeFilter, TestFilterRadioOptionLogic)
192{
193 Filters::Ptr filters = scope_->filters;
194 WaitForSynchronize(filters, 4);
195
196 RadioOptionFilter::Ptr filter = static_pointer_cast<RadioOptionFilter>(filters->FilterAtIndex(1));
197 RadioOptionFilter::RadioOptions options = filter->options;
198
199 EXPECT_FALSE (filter->filtering);
200 EXPECT_FALSE (options[0]->active);
201 EXPECT_FALSE (options[1]->active);
202 EXPECT_FALSE (options[2]->active);
203
204 options[0]->active = true;
205 options[0]->active = false;
206 EXPECT_FALSE (filter->filtering);
207 EXPECT_FALSE (options[0]->active);
208 EXPECT_FALSE (options[1]->active);
209 EXPECT_FALSE (options[2]->active);
210
211 options[0]->active = true;
212 EXPECT_TRUE (filter->filtering);
213 EXPECT_TRUE (options[0]->active);
214 EXPECT_FALSE (options[1]->active);
215 EXPECT_FALSE (options[2]->active);
216
217 options[1]->active = true;
218 EXPECT_TRUE (filter->filtering);
219 EXPECT_FALSE (options[0]->active);
220 EXPECT_TRUE (options[1]->active);
221 EXPECT_FALSE (options[2]->active);
222
223 options[2]->active = true;
224 EXPECT_TRUE (filter->filtering);
225 EXPECT_FALSE (options[0]->active);
226 EXPECT_FALSE (options[1]->active);
227 EXPECT_TRUE (options[2]->active);
228
229 filter->Clear();
230 EXPECT_FALSE (filter->filtering);
231 EXPECT_FALSE (options[0]->active);
232 EXPECT_FALSE (options[1]->active);
233 EXPECT_FALSE (options[2]->active);
234}
235
236TEST_F(TestScopeFilter, TestFilterRatings)
237{
238 Filters::Ptr filters = scope_->filters;
239 WaitForSynchronize(filters, 4);
240
241 RatingsFilter::Ptr filter = static_pointer_cast<RatingsFilter>(filters->FilterAtIndex(2));
242 EXPECT_EQ(filter->id, "ratings");
243 EXPECT_EQ(filter->name, "Ratings");
244 EXPECT_EQ(filter->icon_hint, "");
245 std::string tmp = filter->renderer_name;
246 EXPECT_EQ(filter->renderer_name, "filter-ratings");
247 EXPECT_TRUE(filter->visible);
248 EXPECT_FALSE(filter->collapsed);
249 EXPECT_FALSE(filter->filtering);
250
251 EXPECT_FLOAT_EQ(filter->rating, 0.0f);
252 filter->rating = 0.5f;
253 EXPECT_FLOAT_EQ(filter->rating, 0.5f);
254}
255
256TEST_F(TestScopeFilter, TestFilterMultiRange)
257{
258 Filters::Ptr filters = scope_->filters;
259 WaitForSynchronize(filters, 4);
260
261 MultiRangeFilter::Ptr filter = static_pointer_cast<MultiRangeFilter>(filters->FilterAtIndex(3));
262 EXPECT_EQ(filter->id, "size");
263 EXPECT_EQ(filter->name, "Size");
264 EXPECT_EQ(filter->icon_hint, "");
265 std::string tmp = filter->renderer_name;
266 EXPECT_EQ(filter->renderer_name, "filter-multirange");
267 EXPECT_TRUE(filter->visible);
268 EXPECT_TRUE(filter->collapsed);
269 EXPECT_FALSE(filter->filtering);
270
271 MultiRangeFilter::Options options = filter->options;
272 EXPECT_EQ(options.size(), (unsigned int)4);
273
274 EXPECT_EQ(options[0]->id, "1MB");
275 EXPECT_EQ(options[0]->name, "1MB");
276 EXPECT_EQ(options[0]->icon_hint, "");
277 EXPECT_FALSE(options[0]->active);
278
279 EXPECT_EQ(options[1]->id, "10MB");
280 EXPECT_EQ(options[1]->name, "10MB");
281 EXPECT_EQ(options[1]->icon_hint, "");
282 EXPECT_FALSE(options[1]->active);
283
284 EXPECT_EQ(options[2]->id, "100MB");
285 EXPECT_EQ(options[2]->name, "100MB");
286 EXPECT_EQ(options[2]->icon_hint, "");
287 EXPECT_FALSE(options[2]->active);
288}
289
290TEST_F(TestScopeFilter, TestFilterMultiRangeLogic)
291{
292 Filters::Ptr filters = scope_->filters;
293 WaitForSynchronize(filters, 4);
294
295 MultiRangeFilter::Ptr filter = static_pointer_cast<MultiRangeFilter>(filters->FilterAtIndex(3));
296 MultiRangeFilter::Options options = filter->options;
297
298 EXPECT_FALSE (filter->filtering);
299 EXPECT_FALSE (options[0]->active);
300 EXPECT_FALSE (options[1]->active);
301 EXPECT_FALSE (options[2]->active);
302 EXPECT_FALSE (options[3]->active);
303
304 options[0]->active = true;
305 EXPECT_TRUE (options[0]->active);
306 EXPECT_TRUE (filter->filtering);
307 options[3]->active = true;
308 EXPECT_FALSE (options[0]->active);
309 EXPECT_TRUE (options[3]->active);
310
311 options[0]->active = true;
312 options[1]->active = true;
313 EXPECT_TRUE (filter->filtering);
314 EXPECT_TRUE (options[0]->active);
315 EXPECT_TRUE (options[1]->active);
316 EXPECT_FALSE (options[2]->active);
317 EXPECT_FALSE (options[3]->active);
318
319 options[0]->active = false;
320 EXPECT_TRUE (filter->filtering);
321 EXPECT_FALSE (options[0]->active);
322 EXPECT_TRUE (options[1]->active);
323 EXPECT_FALSE (options[2]->active);
324 EXPECT_FALSE (options[3]->active);
325
326 filter->Clear();
327 EXPECT_FALSE (filter->filtering);
328 EXPECT_FALSE (options[0]->active);
329 EXPECT_FALSE (options[1]->active);
330 EXPECT_FALSE (options[2]->active);
331 EXPECT_FALSE (options[3]->active);
332}
333
334}
335}
0336
=== added file 'tests/test_scope_impl.c'
--- tests/test_scope_impl.c 1970-01-01 00:00:00 +0000
+++ tests/test_scope_impl.c 2013-03-21 14:03:22 +0000
@@ -0,0 +1,511 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include "test_scope_impl.h"
21#include <unity.h>
22
23#include <stdio.h>
24
25#define TEST_DBUS_NAME "com.canonical.Unity.Test.Scope"
26
27#define _g_object_unref_safe(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
28#define _g_free_safe(var) (var = (g_free (var), NULL))
29
30/* ------------------ Test Searcher ---------------------- */
31
32#define TEST_TYPE_SEARCHER (test_searcher_get_type ())
33#define TEST_SCOPE_SEARCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_SEARCHER, TestSearcher))
34#define TEST_SEARCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_SEARCHER, TestSearcherClass))
35#define TEST_IS_SEARCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_SEARCHER))
36#define TEST_IS_SEARCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_SEARCHER))
37#define TEST_SEARCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_SEARCHER, TestSearcherClass))
38
39typedef struct _TestSearcher TestSearcher;
40typedef struct _TestSearcherClass TestSearcherClass;
41typedef struct _TestSearcherPrivate TestSearcherPrivate;
42
43struct _TestSearcher {
44 UnityScopeSearchBase parent_instance;
45 TestSearcherPrivate * priv;
46};
47
48struct _TestSearcherClass {
49 UnityScopeSearchBaseClass parent_class;
50};
51
52struct _TestSearcherPrivate {
53 TestScope* _owner;
54};
55
56typedef struct _SearcherRunData SearcherRunData;
57
58G_DEFINE_TYPE(TestSearcher, test_searcher, UNITY_TYPE_SCOPE_SEARCH_BASE);
59
60#define TEST_SEARCHER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_SEARCHER, TestSearcherPrivate))
61enum {
62 TEST_SEARCHER_DUMMY_PROPERTY,
63 TEST_SEARCHER_OWNER
64};
65
66static TestSearcher* test_searcher_new (TestScope* scope);
67static void test_searcher_run_async (UnityScopeSearchBase* self, UnityScopeSearchBaseCallback async_callback, void* async_callback_target);
68static void test_searcher_run (UnityScopeSearchBase* base);
69static TestScope* test_searcher_get_owner (TestSearcher* self);
70static void test_searcher_set_owner (TestSearcher* self, TestScope* value);
71static void test_searcher_finalize (GObject* obj);
72static void test_searcher_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
73static void test_searcher_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
74
75static TestSearcher* test_searcher_new (TestScope* scope)
76{
77 return (TestSearcher*) g_object_new (TEST_TYPE_SEARCHER, "owner", scope, NULL);
78}
79
80static TestScope* test_searcher_get_owner (TestSearcher* self)
81{
82 g_return_val_if_fail (self != NULL, NULL);
83 return self->priv->_owner;
84}
85
86static void test_searcher_set_owner (TestSearcher* self, TestScope* value)
87{
88 g_return_if_fail (self != NULL);
89 self->priv->_owner = value;
90 g_object_notify ((GObject *) self, "owner");
91}
92
93static void test_searcher_class_init (TestSearcherClass * klass)
94{
95 g_type_class_add_private (klass, sizeof (TestSearcherPrivate));
96 UNITY_SCOPE_SEARCH_BASE_CLASS (klass)->run_async = test_searcher_run_async;
97 UNITY_SCOPE_SEARCH_BASE_CLASS (klass)->run = test_searcher_run;
98 G_OBJECT_CLASS (klass)->get_property = test_searcher_get_property;
99 G_OBJECT_CLASS (klass)->set_property = test_searcher_set_property;
100 G_OBJECT_CLASS (klass)->finalize = test_searcher_finalize;
101 g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_SEARCHER_OWNER, g_param_spec_object ("owner", "owner", "owner", TEST_TYPE_SCOPE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
102}
103
104static void test_searcher_init(TestSearcher* self)
105{
106 self->priv = TEST_SEARCHER_GET_PRIVATE (self);
107}
108
109static void test_searcher_finalize (GObject* obj)
110{
111 TestSearcher * self;
112 self = TEST_SCOPE_SEARCHER (obj);
113 G_OBJECT_CLASS (test_searcher_parent_class)->finalize (obj);
114}
115
116static void test_searcher_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
117{
118 TestSearcher * self;
119 self = TEST_SCOPE_SEARCHER (object);
120 switch (property_id) {
121 case TEST_SEARCHER_OWNER:
122 g_value_set_object (value, test_searcher_get_owner (self));
123 break;
124 default:
125 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
126 break;
127 }
128}
129
130static void test_searcher_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
131{
132 TestSearcher * self;
133 self = TEST_SCOPE_SEARCHER (object);
134 switch (property_id) {
135 case TEST_SEARCHER_OWNER:
136 test_searcher_set_owner (self, g_value_get_object (value));
137 break;
138 default:
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
140 break;
141 }
142}
143
144struct _SearcherRunData
145{
146 int _ref_count_;
147 TestSearcher * self;
148 GMainLoop* ml;
149 UnityScopeSearchBaseCallback async_callback;
150 void* async_callback_target;
151};
152
153static SearcherRunData* run_data_ref (SearcherRunData* data)
154{
155 g_atomic_int_inc (&data->_ref_count_);
156 return data;
157}
158
159static void run_data_unref (void * _userdata_)
160{
161 SearcherRunData* data;
162 data = (SearcherRunData*) _userdata_;
163 if (g_atomic_int_dec_and_test (&data->_ref_count_))
164 {
165 TestSearcher* self;
166 self = data->self;
167 g_main_loop_unref (data->ml);
168 g_object_unref (self);
169 g_slice_free (SearcherRunData, data);
170 }
171}
172
173static gboolean test_searcher_main_loop_func (gpointer data)
174{
175 SearcherRunData* search_data;
176 search_data = (SearcherRunData*) data;
177
178 TestSearcher* self;
179 self = search_data->self;
180 UNITY_SCOPE_SEARCH_BASE_GET_CLASS (self)->run(UNITY_SCOPE_SEARCH_BASE (self));
181
182 search_data->async_callback (UNITY_SCOPE_SEARCH_BASE (self), search_data->async_callback_target);
183 g_main_loop_quit (search_data->ml);
184 return FALSE;
185}
186
187static void test_searcher_run_async (UnityScopeSearchBase* base, UnityScopeSearchBaseCallback async_callback, void* async_callback_target)
188{
189 TestSearcher * self;
190 SearcherRunData* data;
191 self = TEST_SCOPE_SEARCHER (base);
192 data = g_slice_new (SearcherRunData);
193 data->_ref_count_ = 1;
194 data->self = g_object_ref (self);
195 data->ml = g_main_loop_new (NULL, FALSE);
196 data->async_callback = async_callback;
197 data->async_callback_target = async_callback_target;
198
199 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, test_searcher_main_loop_func, run_data_ref (data), run_data_unref);
200 g_main_loop_run (data->ml);
201 run_data_unref (data);
202 data = NULL;
203}
204
205static void test_searcher_run (UnityScopeSearchBase* base)
206{
207 TestSearcher* self;
208 self = TEST_SCOPE_SEARCHER (base);
209
210 g_signal_emit_by_name (self->priv->_owner, "search", base);
211}
212
213/* ------------------ Test Result Previewer ---------------------- */
214
215#define TEST_TYPE_RESULT_PREVIEWER (test_result_previewer_get_type ())
216#define TEST_RESULT_PREVIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewer))
217#define TEST_RESULT_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewerClass))
218#define TEST_IS_RESULT_PREVIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_RESULT_PREVIEWER))
219#define TEST_IS_RESULT_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_RESULT_PREVIEWER))
220#define TEST_RESULT_PREVIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewerClass))
221
222typedef struct _TestResultPreviewer TestResultPreviewer;
223typedef struct _TestResultPreviewerClass TestResultPreviewerClass;
224
225struct _TestResultPreviewer {
226 UnityResultPreviewer parent_instance;
227};
228
229struct _TestResultPreviewerClass {
230 UnityResultPreviewerClass parent_class;
231};
232
233G_DEFINE_TYPE(TestResultPreviewer, test_result_previewer, UNITY_TYPE_RESULT_PREVIEWER);
234
235static UnityAbstractPreview* test_result_previewer_run(UnityResultPreviewer* self)
236{
237 UnityAbstractPreview* preview;
238 preview = UNITY_ABSTRACT_PREVIEW (unity_generic_preview_new ("title", "description", NULL));
239
240 unity_preview_add_action(UNITY_PREVIEW (preview), unity_preview_action_new ("action1", "Action 1", NULL));
241 unity_preview_add_action(UNITY_PREVIEW (preview), unity_preview_action_new ("action2", "Action 2", NULL));
242
243 return preview;
244}
245
246static void test_result_previewer_class_init(TestResultPreviewerClass* klass)
247{
248 UNITY_RESULT_PREVIEWER_CLASS (klass)->run = test_result_previewer_run;
249}
250
251static void test_result_previewer_init(TestResultPreviewer* self)
252{
253}
254
255TestResultPreviewer* test_result_previewer_new ()
256{
257 return (TestResultPreviewer*) g_object_new (TEST_TYPE_RESULT_PREVIEWER, NULL);
258}
259
260/* ------------------ Test Scope ---------------------- */
261
262#define TEST_SCOPE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_SCOPE, TestScopePrivate))
263
264G_DEFINE_TYPE(TestScope, test_scope, UNITY_TYPE_ABSTRACT_SCOPE);
265
266struct _TestScopePrivate
267{
268 gchar* _dbus_path;
269 UnityScopeDBusConnector* _connector;
270 UnityCategorySet* _categories;
271 UnityFilterSet* _filters;
272};
273
274enum {
275 TEST_SCOPE_DUMMY_PROPERTY,
276 TEST_SCOPE_DBUS_PATH
277};
278
279static UnityScopeSearchBase* test_scope_create_search_for_query(UnityAbstractScope* self, UnitySearchContext* search_context);
280static UnityResultPreviewer* test_scope_create_previewer(UnityAbstractScope* self, UnityScopeResult* _result_, UnitySearchMetadata* metadata);
281static UnityCategorySet* test_scope_get_categories(UnityAbstractScope* self);
282static UnityFilterSet* test_scope_get_filters(UnityAbstractScope* self);
283static UnitySchema* test_scope_get_schema(UnityAbstractScope* self);
284static gchar* test_scope_get_search_hint(UnityAbstractScope* self);
285static gchar* test_scope_get_group_name(UnityAbstractScope* self);
286static gchar* test_scope_get_unique_name(UnityAbstractScope* self);
287static UnityActivationResponse* test_scope_activate(UnityAbstractScope* self, UnityScopeResult* _result_, UnitySearchMetadata* metadata, const gchar* action_id);
288static void test_scope_set_dbus_path (TestScope* self, const gchar* value);
289static const gchar* test_scope_get_dbus_path (TestScope* self);
290
291static void test_scope_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
292static void test_scope_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
293static void g_cclosure_user_marshal_OBJECT__STRING (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
294
295static void test_scope_class_init(TestScopeClass* klass)
296{
297 g_type_class_add_private (klass, sizeof (TestScopePrivate));
298
299 UNITY_ABSTRACT_SCOPE_CLASS (klass)->create_search_for_query = test_scope_create_search_for_query;
300 UNITY_ABSTRACT_SCOPE_CLASS (klass)->create_previewer = test_scope_create_previewer;
301 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_categories = test_scope_get_categories;
302 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_filters = test_scope_get_filters;
303 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_schema = test_scope_get_schema;
304 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_search_hint = test_scope_get_search_hint;
305 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_group_name = test_scope_get_group_name;
306 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_unique_name = test_scope_get_unique_name;
307 UNITY_ABSTRACT_SCOPE_CLASS (klass)->activate = test_scope_activate;
308 G_OBJECT_CLASS (klass)->get_property = test_scope_get_property;
309 G_OBJECT_CLASS (klass)->set_property = test_scope_set_property;
310
311 g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_SCOPE_DBUS_PATH, g_param_spec_string ("dbus-path", "dbus-path", "dbus-path", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
312 g_signal_new ("search", TEST_TYPE_SCOPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, UNITY_TYPE_SCOPE_SEARCH_BASE);
313 g_signal_new ("activate_uri", TEST_TYPE_SCOPE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_OBJECT__STRING, UNITY_TYPE_ACTIVATION_RESPONSE, 1, G_TYPE_STRING);
314}
315
316static void test_scope_init(TestScope* self)
317{
318 self->priv = TEST_SCOPE_GET_PRIVATE (self);
319
320 self->priv->_dbus_path = NULL;
321 self->priv->_connector = NULL;
322 self->priv->_categories = NULL;
323 self->priv->_filters = NULL;
324}
325
326static void test_scope_finalize (GObject* obj)
327{
328 TestScope * self;
329 self = G_TYPE_CHECK_INSTANCE_CAST (obj, TEST_TYPE_SCOPE, TestScope);
330 _g_free_safe (self->priv->_dbus_path);
331 _g_object_unref_safe (self->priv->_connector);
332 _g_object_unref_safe (self->priv->_categories);
333 G_OBJECT_CLASS (test_scope_parent_class)->finalize (obj);
334}
335
336static void test_scope_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
337{
338 TestScope * self;
339 self = G_TYPE_CHECK_INSTANCE_CAST (object, TEST_TYPE_SCOPE, TestScope);
340 switch (property_id)
341 {
342 case TEST_SCOPE_DBUS_PATH:
343 g_value_set_string (value, test_scope_get_dbus_path (self));
344 break;
345 default:
346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
347 break;
348 }
349}
350
351static void test_scope_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
352{
353 TestScope * self;
354 self = G_TYPE_CHECK_INSTANCE_CAST (object, TEST_TYPE_SCOPE, TestScope);
355 switch (property_id) {
356 case TEST_SCOPE_DBUS_PATH:
357 test_scope_set_dbus_path (self, g_value_get_string (value));
358 break;
359 default:
360 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
361 break;
362 }
363}
364
365static UnityScopeSearchBase* test_scope_create_search_for_query(UnityAbstractScope* base, UnitySearchContext* search_context)
366{
367 UnityScopeSearchBase* searcher;
368 TestScope* scope;
369 scope = (TestScope*) base;
370 searcher = (UnityScopeSearchBase*) test_searcher_new (scope);
371
372 UnitySearchContext ctx;
373 ctx = *search_context;
374 unity_scope_search_base_set_search_context (searcher, &ctx);
375 return searcher;
376}
377
378static UnityResultPreviewer* test_scope_create_previewer(UnityAbstractScope* self, UnityScopeResult* result, UnitySearchMetadata* metadata)
379{
380 UnityResultPreviewer* previewer;
381 previewer = UNITY_RESULT_PREVIEWER (test_result_previewer_new());
382 unity_scope_result_copy(result, &previewer->result);
383 return previewer;
384}
385
386static UnityCategorySet* test_scope_get_categories(UnityAbstractScope* base)
387{
388 TestScope* self;
389 self = G_TYPE_CHECK_INSTANCE_CAST (base, TEST_TYPE_SCOPE, TestScope);
390 g_return_if_fail (self != NULL);
391
392 return self->priv->_categories;
393}
394
395static UnityFilterSet* test_scope_get_filters(UnityAbstractScope* base)
396{
397 TestScope* self;
398 self = G_TYPE_CHECK_INSTANCE_CAST (base, TEST_TYPE_SCOPE, TestScope);
399 g_return_if_fail (self != NULL);
400
401 return self->priv->_filters;
402}
403
404static UnitySchema* test_scope_get_schema(UnityAbstractScope* self)
405{
406 UnitySchema* schema = unity_schema_new ();
407 unity_schema_add_field (schema, "required_string", "s", UNITY_SCHEMA_FIELD_TYPE_REQUIRED);
408 unity_schema_add_field (schema, "required_int", "i", UNITY_SCHEMA_FIELD_TYPE_REQUIRED);
409 unity_schema_add_field (schema, "optional_string", "s", UNITY_SCHEMA_FIELD_TYPE_OPTIONAL);
410 return schema;
411}
412
413static gchar* test_scope_get_search_hint(UnityAbstractScope* self)
414{
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: