Merge lp:~mhr3/unity/fix-scope-tests into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3435
Proposed branch: lp:~mhr3/unity/fix-scope-tests
Merge into: lp:unity
Diff against target: 1005 lines (+115/-613)
11 files modified
debian/control (+2/-1)
tests/CMakeLists.txt (+2/-4)
tests/dummy-dbus-test-runner.sh (+0/-62)
tests/test_categories.cpp (+20/-17)
tests/test_scope_impl.c (+30/-449)
tests/test_scope_impl.h (+6/-36)
tests/test_scope_proxy.cpp (+3/-3)
tests/test_service_main.cpp (+16/-12)
tests/test_service_model.cpp (+19/-5)
tests/test_service_scope.cpp (+13/-21)
tests/test_service_scope.h (+4/-3)
To merge this branch: bzr merge lp:~mhr3/unity/fix-scope-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+174447@code.launchpad.net

Commit message

Fix scope-related tests.

Description of the change

Fix scope-related tests.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

could you also re-enable te tests from tests/CMake so that the CI will check them as well? :)

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

This is awesome, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

You would probably merge this against lp:~3v1n0/unity/gdbus-interface-fix-ref-unref at this point, also what about continuing using the crafted dbus launch script?

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

> You would probably merge this against lp:~3v1n0/unity/gdbus-interface-fix-ref-
> unref at this point, also what about continuing using the crafted dbus launch
> script?

Looks like CI is fine with the dbus-test-runner, so I'd rather keep it, afterall it has some nice features that the script doesn't (like the timeout, clear separation of what's coming from the server and the client, waiting for a name before starting a task...)

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks great, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

Disabled the TestCategoriesChanging tests as they are racy.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

So unfortunately the new libdee is not in the local repo that jenkins is using for building this during CI, so we have to wait until it reaches the daily ppa... :(

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

> So unfortunately the new libdee is not in the local repo that jenkins is using
> for building this during CI, so we have to wait until it reaches the daily
> ppa... :(

Seems it's released now, let's try again.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2013-07-15 10:00:58 +0000
+++ debian/control 2013-07-19 11:30:33 +0000
@@ -5,6 +5,7 @@
5Build-Depends: cmake,5Build-Depends: cmake,
6 compiz-dev (>= 1:0.9.9~daily13.01.25bzr3586),6 compiz-dev (>= 1:0.9.9~daily13.01.25bzr3586),
7 debhelper (>= 9.0.0~),7 debhelper (>= 9.0.0~),
8 dbus-test-runner,
8 dh-migrations,9 dh-migrations,
9 dh-translations (>= 94),10 dh-translations (>= 94),
10 google-mock (>= 1.6.0+svn437),11 google-mock (>= 1.6.0+svn437),
@@ -18,7 +19,7 @@
18 libcairo2-dev,19 libcairo2-dev,
19 libcompizconfig0-dev (>= 1:0.9.9~daily12.12.05-0ubuntu2),20 libcompizconfig0-dev (>= 1:0.9.9~daily12.12.05-0ubuntu2),
20 libdbusmenu-glib-dev (>= 0.3.91),21 libdbusmenu-glib-dev (>= 0.3.91),
21 libdee-dev (>= 1.0.0),22 libdee-dev (>= 1.2.6),
22 libgee-dev (>= 0.5.0),23 libgee-dev (>= 0.5.0),
23 libgeis-dev (>= 2.0.10),24 libgeis-dev (>= 2.0.10),
24 libgl1-mesa-dri,25 libgl1-mesa-dri,
2526
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-07-12 19:37:48 +0000
+++ tests/CMakeLists.txt 2013-07-19 11:30:33 +0000
@@ -353,7 +353,6 @@
353set (TEST_RESULT_DIR ${CMAKE_BINARY_DIR}/tests)353set (TEST_RESULT_DIR ${CMAKE_BINARY_DIR}/tests)
354set (TEST_RESULT_XML ${TEST_RESULT_DIR}/test-results.xml)354set (TEST_RESULT_XML ${TEST_RESULT_DIR}/test-results.xml)
355set (TEST_RESULT_HTML ${TEST_RESULT_DIR}/test-results.html)355set (TEST_RESULT_HTML ${TEST_RESULT_DIR}/test-results.html)
356set (DUMMY_DBUS_TEST_RUNNER ${CMAKE_CURRENT_SOURCE_DIR}/dummy-dbus-test-runner.sh)
357set (DUMMY_XORG_TEST_RUNNER ${CMAKE_CURRENT_SOURCE_DIR}/dummy-xorg-test-runner.sh)356set (DUMMY_XORG_TEST_RUNNER ${CMAKE_CURRENT_SOURCE_DIR}/dummy-xorg-test-runner.sh)
358if (ENABLE_X_SUPPORT)357if (ENABLE_X_SUPPORT)
359 set (GTEST_TEST_COMMAND ./test-gtest --gtest_output=xml:./test-gtest.xml)358 set (GTEST_TEST_COMMAND ./test-gtest --gtest_output=xml:./test-gtest.xml)
@@ -361,13 +360,12 @@
361endif (ENABLE_X_SUPPORT)360endif (ENABLE_X_SUPPORT)
362set (GTEST_TEST_COMMAND_XLESS ./test-gtest-xless --gtest_output=xml:./test-gtest-xless.xml)361set (GTEST_TEST_COMMAND_XLESS ./test-gtest-xless --gtest_output=xml:./test-gtest-xless.xml)
363set (GTEST_TEST_COMMAND_SLOW ./test-gtest-slow --gtest_output=xml:./test-gtest-slow.xml)362set (GTEST_TEST_COMMAND_SLOW ./test-gtest-slow --gtest_output=xml:./test-gtest-slow.xml)
364set (GTEST_TEST_COMMAND_DBUS ${DUMMY_DBUS_TEST_RUNNER} ./test-gtest-service ./test-gtest-dbus --gtest_output=xml:./test-gtest-dbus.xml)363set (GTEST_TEST_COMMAND_DBUS dbus-test-runner --max-wait=300 --task ./test-gtest-service --task-name test-service --task=./test-gtest-dbus --task-name=test-dbus --wait-for=com.canonical.Unity.Test.Scope --parameter=--gtest_output=xml:./test-gtest-dbus.xml --parameter=--gtest_filter=-TestCategoriesChanging*)
365364
366set (TEST_COMMAND_XLESS365set (TEST_COMMAND_XLESS
367 ${GTEST_TEST_COMMAND_XLESS}366 ${GTEST_TEST_COMMAND_XLESS}
368 && ${GTEST_TEST_COMMAND_GESTURES}367 && ${GTEST_TEST_COMMAND_GESTURES}
369 && ${GTEST_TEST_COMMAND_DBUS} --gtest_filter=-TestScope*368 && ${GTEST_TEST_COMMAND_DBUS})
370 && echo "Warning, TestScope* DBus test cases are disabled!!")
371369
372set (TEST_COMMAND370set (TEST_COMMAND
373 ${GTEST_TEST_COMMAND}371 ${GTEST_TEST_COMMAND}
374372
=== removed file 'tests/dummy-dbus-test-runner.sh'
--- tests/dummy-dbus-test-runner.sh 2013-07-11 02:01:58 +0000
+++ tests/dummy-dbus-test-runner.sh 1970-01-01 00:00:00 +0000
@@ -1,62 +0,0 @@
1#!/bin/bash
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: Marco Trevisan <marco.trevisan@canonical.com>
17
18function check_command()
19{
20 local binary=$(which $1)
21
22 if [ -z "$binary" ]; then
23 if [ -z "$1" ]; then
24 echo "Invalid $2 submitted"
25 elif [ ! -x "$1" ]; then
26 echo "The provided $1 is not executable"
27 fi
28
29 exit 1
30 fi
31}
32
33check_command "$1" "service"
34service=$1
35for p in $(pidof $(basename $service)); do kill $p; done
36
37shift
38check_command "$1" "test"
39binary=$1
40
41dbusfile=$(mktemp -t dummy.dbus.sh.XXXXXXXX)
42dbus-launch --sh-syntax > $dbusfile
43source $dbusfile
44
45function do_cleanup()
46{
47 if [ -n "$service_pid" ] && (kill -0 $service_pid &> /dev/null); then kill $service_pid; fi
48 kill $DBUS_SESSION_BUS_PID
49 rm $dbusfile
50}
51
52trap "do_cleanup; exit 1" SIGHUP SIGINT SIGSEGV SIGTERM
53
54$service &> /dev/null &
55service_pid=$!
56
57shift
58$binary $@
59ret_val=$?
60
61do_cleanup
62exit $ret_val
630
=== modified file 'tests/test_categories.cpp'
--- tests/test_categories.cpp 2013-07-10 16:01:34 +0000
+++ tests/test_categories.cpp 2013-07-19 11:30:33 +0000
@@ -12,8 +12,6 @@
12namespace12namespace
13{13{
1414
15static const string swarm_name = "com.canonical.test.categoriesmodel";
16static const string swarm_name_changing = "com.canonical.test.categoriesmodel_changing";
17static const unsigned int n_rows = 5;15static const unsigned int n_rows = 5;
1816
19static void WaitForSynchronize(Categories& model)17static void WaitForSynchronize(Categories& model)
@@ -25,7 +23,17 @@
25{23{
26 TestCategories()24 TestCategories()
27 {25 {
28 model.swarm_name = swarm_name;26 model.swarm_name = "com.canonical.test.categoriesmodel";
27 }
28
29 Categories model;
30};
31
32struct TestCategoriesChanging : testing::Test
33{
34 TestCategoriesChanging()
35 {
36 model.swarm_name = "com.canonical.test.categoriesmodel_changing";
29 }37 }
3038
31 Categories model;39 Categories model;
@@ -33,7 +41,7 @@
3341
34TEST_F(TestCategories, TestConstruction)42TEST_F(TestCategories, TestConstruction)
35{43{
36 EXPECT_EQ(model.swarm_name(), swarm_name);44 EXPECT_EQ(model.swarm_name(), "com.canonical.test.categoriesmodel");
37}45}
3846
39TEST_F(TestCategories, TestSignalProxyAdded)47TEST_F(TestCategories, TestSignalProxyAdded)
@@ -122,42 +130,38 @@
122}130}
123131
124// We're testing the model's ability to store and retrieve random pointers132// We're testing the model's ability to store and retrieve random pointers
125TEST_F(TestCategories, TestOnRowChanged)133TEST_F(TestCategoriesChanging, TestOnRowChanged)
126{134{
127 model.swarm_name = swarm_name_changing;
128 WaitForSynchronize(model);135 WaitForSynchronize(model);
129136
130 unsigned changed = 0;137 unsigned changed = 0;
131 model.category_changed.connect([&changed] (Category const&) { ++changed; });138 model.category_changed.connect([&changed] (Category const&) { ++changed; });
132 Utils::WaitUntil([&changed] { return changed == 1; }, true, 2, "Did not detect row change from "+swarm_name_changing+".");139 Utils::WaitUntil([&changed] { return changed == 1; }, true, 2, "Did not detect row change.");
133}140}
134141
135142
136// We're testing the model's ability to store and retrieve random pointers143// We're testing the model's ability to store and retrieve random pointers
137TEST_F(TestCategories, TestOnRowAdded)144TEST_F(TestCategoriesChanging, TestOnRowAdded)
138{145{
139 model.swarm_name = swarm_name_changing;
140 WaitForSynchronize(model);146 WaitForSynchronize(model);
141147
142 unsigned added = 0;148 unsigned added = 0;
143 model.category_added.connect([&added] (Category const&) { ++added;});149 model.category_added.connect([&added] (Category const&) { ++added;});
144 Utils::WaitUntil([&added] { return added == 1; }, true, 2, "Did not detect row add "+swarm_name_changing+".");150 Utils::WaitUntil([&added] { return added == 1; }, true, 2, "Did not detect row add.");
145}151}
146152
147// We're testing the model's ability to store and retrieve random pointers153// We're testing the model's ability to store and retrieve random pointers
148TEST_F(TestCategories, TestOnRowRemoved)154TEST_F(TestCategoriesChanging, TestOnRowRemoved)
149{155{
150 model.swarm_name = swarm_name_changing;
151 WaitForSynchronize(model);156 WaitForSynchronize(model);
152157
153 unsigned removed = 0;158 unsigned removed = 0;
154 model.category_removed.connect([&removed] (Category const&) { ++removed; });159 model.category_removed.connect([&removed] (Category const&) { ++removed; });
155 Utils::WaitUntil([&removed] { return removed == 1; }, true, 2, "Did not detect row removal "+swarm_name_changing+".");160 Utils::WaitUntil([&removed] { return removed == 1; }, true, 2, "Did not detect row removal.");
156}161}
157162
158TEST_F(TestCategories, TestCategoryCopy)163TEST_F(TestCategoriesChanging, TestCategoryCopy)
159{164{
160 model.swarm_name = swarm_name_changing;
161 WaitForSynchronize(model);165 WaitForSynchronize(model);
162 166
163 Category category = model.RowAtIndex(0);167 Category category = model.RowAtIndex(0);
@@ -170,9 +174,8 @@
170 EXPECT_EQ(category.index(), category_2.index());174 EXPECT_EQ(category.index(), category_2.index());
171}175}
172176
173TEST_F(TestCategories, TestCategoryEqual)177TEST_F(TestCategoriesChanging, TestCategoryEqual)
174{178{
175 model.swarm_name = swarm_name_changing;
176 WaitForSynchronize(model);179 WaitForSynchronize(model);
177180
178 Category category = model.RowAtIndex(0);181 Category category = model.RowAtIndex(0);
179182
=== modified file 'tests/test_scope_impl.c'
--- tests/test_scope_impl.c 2013-03-27 17:26:54 +0000
+++ tests/test_scope_impl.c 2013-07-19 11:30:33 +0000
@@ -24,195 +24,7 @@
2424
25#define TEST_DBUS_NAME "com.canonical.Unity.Test.Scope"25#define TEST_DBUS_NAME "com.canonical.Unity.Test.Scope"
2626
27#define _g_object_unref_safe(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))27static UnityAbstractPreview* test_scope_preview(UnityResultPreviewer* self, gpointer user_data)
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 (UnityScopeSearchBase* base);
68static TestScope* test_searcher_get_owner (TestSearcher* self);
69static void test_searcher_set_owner (TestSearcher* self, TestScope* value);
70static void test_searcher_finalize (GObject* obj);
71static void test_searcher_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
72static void test_searcher_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
73
74static TestSearcher* test_searcher_new (TestScope* scope)
75{
76 return (TestSearcher*) g_object_new (TEST_TYPE_SEARCHER, "owner", scope, NULL);
77}
78
79static TestScope* test_searcher_get_owner (TestSearcher* self)
80{
81 g_return_val_if_fail (self != NULL, NULL);
82 return self->priv->_owner;
83}
84
85static void test_searcher_set_owner (TestSearcher* self, TestScope* value)
86{
87 g_return_if_fail (self != NULL);
88 self->priv->_owner = value;
89 g_object_notify ((GObject *) self, "owner");
90}
91
92static void test_searcher_class_init (TestSearcherClass * klass)
93{
94 g_type_class_add_private (klass, sizeof (TestSearcherPrivate));
95 UNITY_SCOPE_SEARCH_BASE_CLASS (klass)->run = test_searcher_run;
96 G_OBJECT_CLASS (klass)->get_property = test_searcher_get_property;
97 G_OBJECT_CLASS (klass)->set_property = test_searcher_set_property;
98 G_OBJECT_CLASS (klass)->finalize = test_searcher_finalize;
99 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));
100}
101
102static void test_searcher_init(TestSearcher* self)
103{
104 self->priv = TEST_SEARCHER_GET_PRIVATE (self);
105}
106
107static void test_searcher_finalize (GObject* obj)
108{
109 TestSearcher * self;
110 self = TEST_SCOPE_SEARCHER (obj);
111 G_OBJECT_CLASS (test_searcher_parent_class)->finalize (obj);
112}
113
114static void test_searcher_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
115{
116 TestSearcher * self;
117 self = TEST_SCOPE_SEARCHER (object);
118 switch (property_id) {
119 case TEST_SEARCHER_OWNER:
120 g_value_set_object (value, test_searcher_get_owner (self));
121 break;
122 default:
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
124 break;
125 }
126}
127
128static void test_searcher_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
129{
130 TestSearcher * self;
131 self = TEST_SCOPE_SEARCHER (object);
132 switch (property_id) {
133 case TEST_SEARCHER_OWNER:
134 test_searcher_set_owner (self, g_value_get_object (value));
135 break;
136 default:
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
138 break;
139 }
140}
141
142struct _SearcherRunData
143{
144 int _ref_count_;
145 TestSearcher * self;
146 GMainLoop* ml;
147 UnityScopeSearchBaseCallback async_callback;
148 void* async_callback_target;
149};
150
151static SearcherRunData* run_data_ref (SearcherRunData* data)
152{
153 g_atomic_int_inc (&data->_ref_count_);
154 return data;
155}
156
157static void run_data_unref (void * _userdata_)
158{
159 SearcherRunData* data;
160 data = (SearcherRunData*) _userdata_;
161 if (g_atomic_int_dec_and_test (&data->_ref_count_))
162 {
163 TestSearcher* self;
164 self = data->self;
165 g_main_loop_unref (data->ml);
166 g_object_unref (self);
167 g_slice_free (SearcherRunData, data);
168 }
169}
170
171static gboolean test_searcher_main_loop_func (gpointer data)
172{
173 SearcherRunData* search_data;
174 search_data = (SearcherRunData*) data;
175
176 TestSearcher* self;
177 self = search_data->self;
178 UNITY_SCOPE_SEARCH_BASE_GET_CLASS (self)->run(UNITY_SCOPE_SEARCH_BASE (self));
179
180 search_data->async_callback (UNITY_SCOPE_SEARCH_BASE (self), search_data->async_callback_target);
181 g_main_loop_quit (search_data->ml);
182 return FALSE;
183}
184
185static void test_searcher_run (UnityScopeSearchBase* base)
186{
187 TestSearcher* self;
188 self = TEST_SCOPE_SEARCHER (base);
189
190 g_signal_emit_by_name (self->priv->_owner, "search", base);
191}
192
193/* ------------------ Test Result Previewer ---------------------- */
194
195#define TEST_TYPE_RESULT_PREVIEWER (test_result_previewer_get_type ())
196#define TEST_RESULT_PREVIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewer))
197#define TEST_RESULT_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewerClass))
198#define TEST_IS_RESULT_PREVIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_RESULT_PREVIEWER))
199#define TEST_IS_RESULT_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_RESULT_PREVIEWER))
200#define TEST_RESULT_PREVIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_RESULT_PREVIEWER, TestResultPreviewerClass))
201
202typedef struct _TestResultPreviewer TestResultPreviewer;
203typedef struct _TestResultPreviewerClass TestResultPreviewerClass;
204
205struct _TestResultPreviewer {
206 UnityResultPreviewer parent_instance;
207};
208
209struct _TestResultPreviewerClass {
210 UnityResultPreviewerClass parent_class;
211};
212
213G_DEFINE_TYPE(TestResultPreviewer, test_result_previewer, UNITY_TYPE_RESULT_PREVIEWER);
214
215static UnityAbstractPreview* test_result_previewer_run(UnityResultPreviewer* self)
216{28{
217 UnityAbstractPreview* preview;29 UnityAbstractPreview* preview;
218 UnityPreviewAction* action;30 UnityPreviewAction* action;
@@ -222,172 +34,17 @@
222 unity_preview_add_action(UNITY_PREVIEW (preview), action);34 unity_preview_add_action(UNITY_PREVIEW (preview), action);
22335
224 action = unity_preview_action_new ("action2", "Action 2", NULL);36 action = unity_preview_action_new ("action2", "Action 2", NULL);
225 // GHashTable* hints = unity_preview_action_get_hints(action);
226
227 unity_preview_add_action(UNITY_PREVIEW (preview), action);37 unity_preview_add_action(UNITY_PREVIEW (preview), action);
22838
229 return preview;39 return preview;
230}40}
23141
232static void test_result_previewer_class_init(TestResultPreviewerClass* klass)42static UnityActivationResponse* test_scope_activate(UnityScopeResult* result, UnitySearchMetadata* metadata, const gchar* action_id, gpointer data)
233{43{
234 UNITY_RESULT_PREVIEWER_CLASS (klass)->run = test_result_previewer_run;44 return unity_activation_response_new (UNITY_HANDLED_TYPE_HIDE_DASH, "");
235}45}
23646
237static void test_result_previewer_init(TestResultPreviewer* self)47static UnitySchema* test_scope_get_schema(void)
238{
239}
240
241TestResultPreviewer* test_result_previewer_new ()
242{
243 return (TestResultPreviewer*) g_object_new (TEST_TYPE_RESULT_PREVIEWER, NULL);
244}
245
246/* ------------------ Test Scope ---------------------- */
247
248#define TEST_SCOPE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_SCOPE, TestScopePrivate))
249
250G_DEFINE_TYPE(TestScope, test_scope, UNITY_TYPE_ABSTRACT_SCOPE);
251
252struct _TestScopePrivate
253{
254 gchar* _dbus_path;
255 UnityScopeDBusConnector* _connector;
256 UnityCategorySet* _categories;
257 UnityFilterSet* _filters;
258};
259
260enum {
261 TEST_SCOPE_DUMMY_PROPERTY,
262 TEST_SCOPE_DBUS_PATH
263};
264
265static UnityScopeSearchBase* test_scope_create_search_for_query(UnityAbstractScope* self, UnitySearchContext* search_context);
266static UnityResultPreviewer* test_scope_create_previewer(UnityAbstractScope* self, UnityScopeResult* _result_, UnitySearchMetadata* metadata);
267static UnityCategorySet* test_scope_get_categories(UnityAbstractScope* self);
268static UnityFilterSet* test_scope_get_filters(UnityAbstractScope* self);
269static UnitySchema* test_scope_get_schema(UnityAbstractScope* self);
270static gchar* test_scope_get_search_hint(UnityAbstractScope* self);
271static gchar* test_scope_get_group_name(UnityAbstractScope* self);
272static gchar* test_scope_get_unique_name(UnityAbstractScope* self);
273static UnityActivationResponse* test_scope_activate(UnityAbstractScope* self, UnityScopeResult* _result_, UnitySearchMetadata* metadata, const gchar* action_id);
274static void test_scope_set_dbus_path (TestScope* self, const gchar* value);
275static const gchar* test_scope_get_dbus_path (TestScope* self);
276
277static void test_scope_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
278static void test_scope_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
279static 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);
280
281static void test_scope_class_init(TestScopeClass* klass)
282{
283 g_type_class_add_private (klass, sizeof (TestScopePrivate));
284
285 UNITY_ABSTRACT_SCOPE_CLASS (klass)->create_search_for_query = test_scope_create_search_for_query;
286 UNITY_ABSTRACT_SCOPE_CLASS (klass)->create_previewer = test_scope_create_previewer;
287 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_categories = test_scope_get_categories;
288 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_filters = test_scope_get_filters;
289 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_schema = test_scope_get_schema;
290 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_search_hint = test_scope_get_search_hint;
291 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_group_name = test_scope_get_group_name;
292 UNITY_ABSTRACT_SCOPE_CLASS (klass)->get_unique_name = test_scope_get_unique_name;
293 UNITY_ABSTRACT_SCOPE_CLASS (klass)->activate = test_scope_activate;
294 G_OBJECT_CLASS (klass)->get_property = test_scope_get_property;
295 G_OBJECT_CLASS (klass)->set_property = test_scope_set_property;
296
297 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));
298 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);
299 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);
300}
301
302static void test_scope_init(TestScope* self)
303{
304 self->priv = TEST_SCOPE_GET_PRIVATE (self);
305
306 self->priv->_dbus_path = NULL;
307 self->priv->_connector = NULL;
308 self->priv->_categories = NULL;
309 self->priv->_filters = NULL;
310}
311
312static void test_scope_finalize (GObject* obj)
313{
314 TestScope * self;
315 self = G_TYPE_CHECK_INSTANCE_CAST (obj, TEST_TYPE_SCOPE, TestScope);
316 _g_free_safe (self->priv->_dbus_path);
317 _g_object_unref_safe (self->priv->_connector);
318 _g_object_unref_safe (self->priv->_categories);
319 G_OBJECT_CLASS (test_scope_parent_class)->finalize (obj);
320}
321
322static void test_scope_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
323{
324 TestScope * self;
325 self = G_TYPE_CHECK_INSTANCE_CAST (object, TEST_TYPE_SCOPE, TestScope);
326 switch (property_id)
327 {
328 case TEST_SCOPE_DBUS_PATH:
329 g_value_set_string (value, test_scope_get_dbus_path (self));
330 break;
331 default:
332 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
333 break;
334 }
335}
336
337static void test_scope_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
338{
339 TestScope * self;
340 self = G_TYPE_CHECK_INSTANCE_CAST (object, TEST_TYPE_SCOPE, TestScope);
341 switch (property_id) {
342 case TEST_SCOPE_DBUS_PATH:
343 test_scope_set_dbus_path (self, g_value_get_string (value));
344 break;
345 default:
346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
347 break;
348 }
349}
350
351static UnityScopeSearchBase* test_scope_create_search_for_query(UnityAbstractScope* base, UnitySearchContext* search_context)
352{
353 UnityScopeSearchBase* searcher;
354 TestScope* scope;
355 scope = (TestScope*) base;
356 searcher = (UnityScopeSearchBase*) test_searcher_new (scope);
357
358 UnitySearchContext ctx;
359 ctx = *search_context;
360 unity_scope_search_base_set_search_context (searcher, &ctx);
361 return searcher;
362}
363
364static UnityResultPreviewer* test_scope_create_previewer(UnityAbstractScope* self, UnityScopeResult* result, UnitySearchMetadata* metadata)
365{
366 UnityResultPreviewer* previewer;
367 previewer = UNITY_RESULT_PREVIEWER (test_result_previewer_new());
368 unity_scope_result_copy(result, &previewer->result);
369 return previewer;
370}
371
372static UnityCategorySet* test_scope_get_categories(UnityAbstractScope* base)
373{
374 TestScope* self;
375 self = G_TYPE_CHECK_INSTANCE_CAST (base, TEST_TYPE_SCOPE, TestScope);
376 g_return_if_fail (self != NULL);
377
378 return self->priv->_categories;
379}
380
381static UnityFilterSet* test_scope_get_filters(UnityAbstractScope* base)
382{
383 TestScope* self;
384 self = G_TYPE_CHECK_INSTANCE_CAST (base, TEST_TYPE_SCOPE, TestScope);
385 g_return_if_fail (self != NULL);
386
387 return self->priv->_filters;
388}
389
390static UnitySchema* test_scope_get_schema(UnityAbstractScope* self)
391{48{
392 UnitySchema* schema = unity_schema_new ();49 UnitySchema* schema = unity_schema_new ();
393 unity_schema_add_field (schema, "required_string", "s", UNITY_SCHEMA_FIELD_TYPE_REQUIRED);50 unity_schema_add_field (schema, "required_string", "s", UNITY_SCHEMA_FIELD_TYPE_REQUIRED);
@@ -396,102 +53,26 @@
396 return schema;53 return schema;
397}54}
39855
399static gchar* test_scope_get_search_hint(UnityAbstractScope* self)
400{
401 return g_strdup ("Search hint");
402}
403
404static gchar* test_scope_get_group_name(UnityAbstractScope* self)
405{
406 return g_strdup (TEST_DBUS_NAME);
407}
408
409static gchar* test_scope_get_unique_name(UnityAbstractScope* base)
410{
411 TestScope * self;
412 self = (TestScope*) base;
413 return g_strdup (self->priv->_dbus_path);
414}
415
416static UnityActivationResponse* test_scope_activate(UnityAbstractScope* self, UnityScopeResult* result, UnitySearchMetadata* metadata, const gchar* action_id)
417{
418 UnityActivationResponse* response = NULL;
419 g_signal_emit_by_name (self, "activate-uri", result->uri, &response);
420 return response;
421}
422
423static const gchar* test_scope_get_dbus_path (TestScope* self)
424{
425 g_return_val_if_fail (self != NULL, NULL);
426 return self->priv->_dbus_path;
427}
428
429static void test_scope_set_dbus_path (TestScope* self, const gchar* value)
430{
431 g_return_if_fail (self != NULL);
432 _g_free_safe (self->priv->_dbus_path);
433 self->priv->_dbus_path = g_strdup (value);;
434 g_object_notify ((GObject *) self, "dbus-path");
435}
436
437static 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)
438{
439 typedef gpointer (*GMarshalFunc_OBJECT__STRING) (gpointer data1, const char* arg_1, gpointer data2);
440 register GMarshalFunc_OBJECT__STRING callback;
441 register GCClosure * cc;
442 register gpointer data1;
443 register gpointer data2;
444 gpointer v_return;
445 cc = (GCClosure *) closure;
446 g_return_if_fail (return_value != NULL);
447 g_return_if_fail (n_param_values == 2);
448 if (G_CCLOSURE_SWAP_DATA (closure)) {
449 data1 = closure->data;
450 data2 = param_values->data[0].v_pointer;
451 } else {
452 data1 = param_values->data[0].v_pointer;
453 data2 = closure->data;
454 }
455 callback = (GMarshalFunc_OBJECT__STRING) (marshal_data ? marshal_data : cc->callback);
456 v_return = callback (data1, g_value_get_string (param_values + 1), data2);
457 g_value_take_object (return_value, v_return);
458}
459
460TestScope* test_scope_new (const gchar* dbus_path)
461{
462 return (TestScope*) g_object_new (TEST_TYPE_SCOPE, "dbus-path", dbus_path, NULL);
463}
464
465void test_scope_set_categories(TestScope* self, UnityCategorySet* categories)
466{
467 g_return_if_fail (self != NULL);
468
469 g_object_ref(categories);
470 self->priv->_categories = categories;
471}
472
473void test_scope_set_filters(TestScope* self, UnityFilterSet* filters)
474{
475 g_return_if_fail (self != NULL);
476
477 g_object_ref(filters);
478 self->priv->_filters = filters;
479}
480
481void test_scope_export (TestScope* self, GError** error)
482{
483 UnityScopeDBusConnector* connector;
484 g_return_if_fail (self != NULL);
485
486 connector = unity_scope_dbus_connector_new ((UnityAbstractScope*) self);
487 _g_object_unref_safe (self->priv->_connector);
488 self->priv->_connector = connector;
489 unity_scope_dbus_connector_export (connector, error);
490}
491
492void test_scope_unexport (TestScope* self)
493{
494 g_return_if_fail (self != NULL);
495 g_return_if_fail (self->priv->_connector != NULL);
496 unity_scope_dbus_connector_unexport (self->priv->_connector);
497}
498\ No newline at end of file56\ No newline at end of file
57UnityAbstractScope* test_scope_new (const gchar* dbus_path,
58 UnityCategorySet* category_set,
59 UnityFilterSet* filter_set,
60 UnitySimpleScopeSearchRunFunc search_func,
61 gpointer data)
62{
63 UnitySimpleScope *scope = unity_simple_scope_new ();
64
65 unity_simple_scope_set_unique_name (scope, dbus_path);
66 unity_simple_scope_set_group_name (scope, TEST_DBUS_NAME);
67 unity_simple_scope_set_search_hint (scope, "Search hint");
68
69 unity_simple_scope_set_category_set (scope, category_set);
70 unity_simple_scope_set_filter_set (scope, filter_set);
71 unity_simple_scope_set_schema (scope, test_scope_get_schema ());
72
73 unity_simple_scope_set_search_func (scope, search_func, data, NULL);
74 unity_simple_scope_set_preview_func (scope, test_scope_preview, NULL, NULL);
75 unity_simple_scope_set_activate_func (scope, test_scope_activate, NULL, NULL);
76
77 return UNITY_ABSTRACT_SCOPE (scope);
78}
79
49980
=== modified file 'tests/test_scope_impl.h'
--- tests/test_scope_impl.h 2013-03-13 10:31:19 +0000
+++ tests/test_scope_impl.h 2013-07-19 11:30:33 +0000
@@ -25,42 +25,12 @@
2525
26G_BEGIN_DECLS26G_BEGIN_DECLS
2727
28#define TEST_TYPE_SCOPE (test_scope_get_type ())28UnityAbstractScope* test_scope_new (const gchar* dbus_path,
29#define TEST_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_SCOPE, TestScope))29 UnityCategorySet* category_set,
30#define TEST_IS_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_SCOPE))30 UnityFilterSet* filter_set,
31#define TEST_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_SCOPE, TestScopeClass))31 UnitySimpleScopeSearchRunFunc search_func,
32#define TEST_IS_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_TYPE_SCOPE))32 gpointer user_data);
33#define TEST_SCOPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_SCOPE, TestScopeClass))
34
35typedef struct _TestScope TestScope;
36typedef struct _TestScopeClass TestScopeClass;
37typedef struct _TestScopePrivate TestScopePrivate;
38
39struct _TestScope
40{
41 UnityAbstractScope parent_instance;
42
43 /* instance members */
44 TestScopePrivate * priv;
45};
46
47struct _TestScopeClass
48{
49 UnityAbstractScopeClass parent_class;
50
51 /* class members */
52};
53
54/* used by TEST_TYPE_SCOPE */
55GType test_scope_get_type (void);
56
57TestScope* test_scope_new (const gchar* dbus_path);
58
59void test_scope_set_categories(TestScope* self, UnityCategorySet* categories);
60void test_scope_set_filters(TestScope* self, UnityFilterSet* filters);
61void test_scope_export (TestScope* self, GError** error);
62void test_scope_unexport (TestScope* self);
6333
64G_END_DECLS34G_END_DECLS
6535
66#endif /* _TEST_SCOPE_IMPL_H_ */
67\ No newline at end of file36\ No newline at end of file
37#endif /* _TEST_SCOPE_IMPL_H_ */
6838
=== modified file 'tests/test_scope_proxy.cpp'
--- tests/test_scope_proxy.cpp 2013-07-09 18:56:00 +0000
+++ tests/test_scope_proxy.cpp 2013-07-19 11:30:33 +0000
@@ -59,7 +59,7 @@
5959
60TEST(TestScopeProxy, ConnectionFail)60TEST(TestScopeProxy, ConnectionFail)
61{61{
62 ScopeProxyInterface::Ptr scope_proxy(new ScopeProxy(ScopeData::Ptr(new MockScopeData("fail", "this.is.a.fail.test", "this/is/a/fail/test"))));62 ScopeProxyInterface::Ptr scope_proxy(new ScopeProxy(ScopeData::Ptr(new MockScopeData("fail", "this.is.a.fail.test", "/this/is/a/fail/test"))));
63 scope_proxy->ConnectProxy();63 scope_proxy->ConnectProxy();
6464
65 Utils::WaitForTimeoutMSec(1000);65 Utils::WaitForTimeoutMSec(1000);
@@ -180,7 +180,7 @@
180180
181TEST(TestScopeProxy, SearchFail)181TEST(TestScopeProxy, SearchFail)
182{182{
183 ScopeProxyInterface::Ptr scope_proxy(new ScopeProxy(ScopeData::Ptr(new MockScopeData("fail", "this.is.a.fail.test", "this/is/a/fail/test"))));183 ScopeProxyInterface::Ptr scope_proxy(new ScopeProxy(ScopeData::Ptr(new MockScopeData("fail", "this.is.a.fail.test", "/this/is/a/fail/test"))));
184 // Auto-connect on search184 // Auto-connect on search
185185
186 bool search_ok = false;186 bool search_ok = false;
@@ -262,7 +262,7 @@
262 activate_callback,262 activate_callback,
263 nullptr);263 nullptr);
264264
265 Utils::WaitUntilMSec(activated_return, 3, "Failed to activate");265 Utils::WaitUntil(activated_return, 3, "Failed to activate");
266}266}
267267
268TEST(TestScopeProxy, Preview)268TEST(TestScopeProxy, Preview)
269269
=== modified file 'tests/test_service_main.cpp'
--- tests/test_service_main.cpp 2013-07-17 18:03:19 +0000
+++ tests/test_service_main.cpp 2013-07-19 11:30:33 +0000
@@ -1,5 +1,6 @@
1#include <Nux/Nux.h>1#include <Nux/Nux.h>
2#include <NuxCore/Logger.h>2#include <NuxCore/Logger.h>
3#include <unity.h>
34
4#include "test_service_scope.h"5#include "test_service_scope.h"
5#include "test_service_model.h"6#include "test_service_model.h"
@@ -44,8 +45,6 @@
44 return 1;45 return 1;
45 }46 }
4647
47 auto loop = g_main_loop_new(NULL, FALSE);
48
49 nux::NuxInitialize(0);48 nux::NuxInitialize(0);
50 // Slightly higher as we're more likely to test things we know will fail49 // Slightly higher as we're more likely to test things we know will fail
51 nux::logging::configure_logging("<root>=error");50 nux::logging::configure_logging("<root>=error");
@@ -53,24 +52,29 @@
53 // but you can still change it if you're debugging ;)52 // but you can still change it if you're debugging ;)
54 nux::logging::configure_logging(::getenv("UNITY_TEST_LOG_SEVERITY"));53 nux::logging::configure_logging(::getenv("UNITY_TEST_LOG_SEVERITY"));
5554
55 service::Hud hud;
56 service::GDBus gdbus;
57 service::Panel panel;
58 service::Model model;
59 service::Scope scope(scope_id ? scope_id: "testscope1");
60
61 // all the services might have requested dbus names, let's consider
62 // the controller name a "primary" name and we'll wait for it before running
63 // the actual dbus tests (since the other names were requested before this
64 // one they should be acquired before this one)
56 glib::DBusServer controller("com.canonical.Unity.Test");65 glib::DBusServer controller("com.canonical.Unity.Test");
57 controller.AddObjects(introspection_xml, "/com/canonical/unity/test/controller");66 controller.AddObjects(introspection_xml, "/com/canonical/unity/test/controller");
58 auto obj = controller.GetObjects().front();67 auto obj = controller.GetObjects().front();
59 obj->SetMethodsCallsHandler([loop] (std::string const& method, GVariant*) {68 obj->SetMethodsCallsHandler([] (std::string const& method, GVariant*) {
60 if (method == "Exit")69 if (method == "Exit")
61 g_main_loop_quit(loop);70 unity_scope_dbus_connector_quit();
6271
63 return static_cast<GVariant*>(nullptr);72 return static_cast<GVariant*>(nullptr);
64 });73 });
6574
66 service::Hud hud;75 // scope equivalent of running the main loop, needed as this also requests
67 service::GDBus gdbus;76 // a dbus name the scope uses
68 service::Panel panel;77 unity_scope_dbus_connector_run();
69 service::Model model;
70 service::Scope scope(scope_id ? scope_id: "testscope1");
71
72 g_main_loop_run(loop);
73 g_main_loop_unref(loop);
7478
75 if (scope_id) g_free(scope_id);79 if (scope_id) g_free(scope_id);
7680
7781
=== modified file 'tests/test_service_model.cpp'
--- tests/test_service_model.cpp 2013-07-10 18:22:32 +0000
+++ tests/test_service_model.cpp 2013-07-19 11:30:33 +0000
@@ -8,12 +8,26 @@
8namespace service8namespace service
9{9{
1010
11static DeeModel* create_read_only_model(const char* name)
12{
13 // A shared model with the LEADER_WRITABLE flag will ignore any change
14 // requests from the peers
15 glib::Object<DeePeer> peer(dee_peer_new(name));
16 glib::Object<DeeModel> backend(dee_sequence_model_new());
17 auto access_mode = DEE_SHARED_MODEL_ACCESS_MODE_LEADER_WRITABLE;
18 return DEE_MODEL (g_object_new (DEE_TYPE_SHARED_MODEL,
19 "peer", peer.RawPtr(),
20 "back-end", backend.RawPtr(),
21 "access-mode", access_mode,
22 NULL));
23}
24
11Model::Model()25Model::Model()
12 : model_(dee_shared_model_new("com.canonical.test.model"))26 : model_(create_read_only_model("com.canonical.test.model"))
13 , results_model_(dee_shared_model_new("com.canonical.test.resultsmodel"))27 , results_model_(create_read_only_model("com.canonical.test.resultsmodel"))
14 , categories_model_(dee_shared_model_new("com.canonical.test.categoriesmodel"))28 , categories_model_(create_read_only_model("com.canonical.test.categoriesmodel"))
15 , categories_changing_model_(dee_shared_model_new("com.canonical.test.categoriesmodel_changing"))29 , categories_changing_model_(create_read_only_model("com.canonical.test.categoriesmodel_changing"))
16 , tracks_model_(dee_shared_model_new("com.canonical.test.tracks"))30 , tracks_model_(create_read_only_model("com.canonical.test.tracks"))
17{31{
18 PopulateTestModel();32 PopulateTestModel();
19 PopulateResultsModel();33 PopulateResultsModel();
2034
=== modified file 'tests/test_service_scope.cpp'
--- tests/test_service_scope.cpp 2013-03-13 10:31:19 +0000
+++ tests/test_service_scope.cpp 2013-07-19 11:30:33 +0000
@@ -43,21 +43,20 @@
43 "cat1",43 "cat1",
44 "cat2" };44 "cat2" };
4545
46static UnityActivationResponse* on_activate_uri(TestScope* scope, const char* uri, Scope* self);46static void on_scope_search (UnityScopeSearchBase* search_ctx, gpointer user_data);
47static void on_scope_search (TestScope* scope, UnityScopeSearchBase* search_ctx, Scope* self);
4847
49Scope::Scope(std::string const& scope_id)48Scope::Scope(std::string const& scope_id)
50: scope_(test_scope_new (("/com/canonical/unity/scope/"+scope_id).c_str()))
51{49{
52 AddCategories();50 scope_ = test_scope_new (("/com/canonical/unity/scope/"+scope_id).c_str(),
53 AddFilters();51 CreateCategories(),
5452 CreateFilters(),
55 g_signal_connect(scope_, "activate-uri", G_CALLBACK(on_activate_uri), this);53 on_scope_search,
56 g_signal_connect(scope_, "search", G_CALLBACK(on_scope_search), this);54 NULL);
5755
58 /* Export */56 /* Export */
59 GError* error = NULL;57 GError* error = NULL;
60 test_scope_export(scope_, &error);58 connector_ = unity_scope_dbus_connector_new (scope_);
59 unity_scope_dbus_connector_export (connector_, &error);
61 if (error)60 if (error)
62 {61 {
63 g_error ("Unable to export Scope: %s", error->message);62 g_error ("Unable to export Scope: %s", error->message);
@@ -70,7 +69,7 @@
70 g_signal_handlers_disconnect_by_data(scope_, this);69 g_signal_handlers_disconnect_by_data(scope_, this);
71}70}
7271
73void Scope::AddCategories()72UnityCategorySet* Scope::CreateCategories()
74{73{
75 UnityCategorySet* categories;74 UnityCategorySet* categories;
76 GIcon *icon;75 GIcon *icon;
@@ -96,11 +95,10 @@
96 g_free(title);95 g_free(title);
97 }96 }
9897
99 test_scope_set_categories(scope_, categories);98 return categories;
100 g_object_unref (categories);
101}99}
102100
103void Scope::AddFilters()101UnityFilterSet* Scope::CreateFilters()
104{102{
105 UnityFilterSet *filters = NULL;103 UnityFilterSet *filters = NULL;
106 UnityFilter *filter;104 UnityFilter *filter;
@@ -159,20 +157,14 @@
159 unity_filter_set_add (filters, filter);157 unity_filter_set_add (filters, filter);
160 g_object_unref(filter); 158 g_object_unref(filter);
161159
162 test_scope_set_filters(scope_, filters);160 return filters;
163 g_object_unref (filters);
164}
165
166static UnityActivationResponse* on_activate_uri(TestScope* scope, const char* uri, Scope* self)
167{
168 return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, "");
169}161}
170162
171static void _g_variant_unref0_ (gpointer var) {163static void _g_variant_unref0_ (gpointer var) {
172 if (var) g_variant_unref ((GVariant*)var);164 if (var) g_variant_unref ((GVariant*)var);
173}165}
174166
175static void on_scope_search (TestScope* scope, UnityScopeSearchBase* search_base, Scope* self)167static void on_scope_search (UnityScopeSearchBase* search_base, gpointer self)
176{168{
177 UnitySearchContext* search_ctx;169 UnitySearchContext* search_ctx;
178 search_ctx = search_base->search_context;170 search_ctx = search_base->search_context;
179171
=== modified file 'tests/test_service_scope.h'
--- tests/test_service_scope.h 2013-03-13 10:31:19 +0000
+++ tests/test_service_scope.h 2013-07-19 11:30:33 +0000
@@ -35,11 +35,12 @@
35 ~Scope();35 ~Scope();
3636
37private:37private:
38 void AddCategories();38 UnityCategorySet* CreateCategories();
39 void AddFilters();39 UnityFilterSet* CreateFilters();
4040
41private:41private:
42 glib::Object<TestScope> scope_;42 glib::Object<UnityAbstractScope> scope_;
43 glib::Object<UnityScopeDBusConnector> connector_;
43};44};
4445
45}46}