Merge lp:~aacid/unity/do_not_reuse_menus_on_order_change_for_5 into lp:unity/5.0

Proposed by Albert Astals Cid on 2012-10-09
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2012-10-09
Approved revision: 2408
Merged at revision: 2408
Proposed branch: lp:~aacid/unity/do_not_reuse_menus_on_order_change_for_5
Merge into: lp:unity/5.0
Diff against target: 664 lines (+470/-6)
11 files modified
UnityCore/DBusIndicators.cpp (+28/-5)
UnityCore/DBusIndicators.h (+4/-0)
UnityCore/Indicator.cpp (+15/-0)
UnityCore/Indicator.h (+1/-0)
tests/CMakeLists.txt (+4/-1)
tests/test_dbus_indicators.cpp (+98/-0)
tests/test_indicator.cpp (+3/-0)
tests/test_service_main.c (+4/-0)
tests/test_service_panel.c (+253/-0)
tests/test_service_panel.h (+46/-0)
tests/test_utils.h (+14/-0)
To merge this branch: bzr merge lp:~aacid/unity/do_not_reuse_menus_on_order_change_for_5
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) 2012-10-09 Approve on 2012-10-09
Review via email: mp+128692@code.launchpad.net

Commit message

Do not reuse the menu entries if their order changes

Since the indicators api only have "add" and "remove" signals, if we reuse an entry that is not in the correct order it will case the menus or whatever this indicator represents to be in the wrong order

Description of the change

Do not reuse the menu entries if their order changes

Since the indicators api only have "add" and "remove" signals, if we reuse an entry that is not in the correct order it will case the menus or whatever this indicator represents to be in the wrong order

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

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/DBusIndicators.cpp'
2--- UnityCore/DBusIndicators.cpp 2012-03-21 12:31:11 +0000
3+++ UnityCore/DBusIndicators.cpp 2012-10-09 11:53:25 +0000
4@@ -43,7 +43,7 @@
5 class DBusIndicators::Impl
6 {
7 public:
8- Impl(DBusIndicators* owner);
9+ Impl(std::string const& dbus_name, DBusIndicators* owner);
10 ~Impl();
11
12 void CheckLocalService();
13@@ -85,12 +85,12 @@
14
15
16 // Public Methods
17-DBusIndicators::Impl::Impl(DBusIndicators* owner)
18+DBusIndicators::Impl::Impl(std::string const& dbus_name, DBusIndicators* owner)
19 : owner_(owner)
20 , reconnect_timeout_id_(0)
21 , show_entry_idle_id_(0)
22 , show_appmenu_idle_id_(0)
23- , gproxy_(SERVICE_NAME, SERVICE_PATH, SERVICE_IFACE,
24+ , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE,
25 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
26 {
27 gproxy_.Connect("ReSync", sigc::mem_fun(this, &DBusIndicators::Impl::OnReSync));
28@@ -313,6 +313,8 @@
29 return;
30
31 std::map<Indicator::Ptr, Indicator::Entries> indicators;
32+ int wantedIndex = 0;
33+ bool anyIndexDifferent = false;
34
35 g_variant_get(args, "(a(ssssbbusbbi))", &iter);
36 while (g_variant_iter_loop(iter, "(ssssbbusbbi)",
37@@ -342,7 +344,18 @@
38 // Null entries (entry_id == "") are empty indicators.
39 if (entry != "")
40 {
41- Entry::Ptr e = indicator->GetEntry(entry_id);
42+ Entry::Ptr e;
43+ if (!anyIndexDifferent)
44+ {
45+ // Indicators can only add or remove entries, so if
46+ // there is a index change we can't reuse the existing ones
47+ // after that index
48+ int existingEntryIndex = indicator->EntryIndex(entry_id);
49+ if (wantedIndex == existingEntryIndex)
50+ e = indicator->GetEntry(entry_id);
51+ else
52+ anyIndexDifferent = true;
53+ }
54
55 if (!e)
56 {
57@@ -365,6 +378,7 @@
58 }
59
60 entries.push_back(e);
61+ wantedIndex++;
62 }
63 }
64 g_variant_iter_free(iter);
65@@ -437,12 +451,21 @@
66 }
67
68 DBusIndicators::DBusIndicators()
69- : pimpl(new Impl(this))
70+ : pimpl(new Impl(SERVICE_NAME, this))
71+{}
72+
73+DBusIndicators::DBusIndicators(std::string const& dbus_name)
74+ : pimpl(new Impl(dbus_name, this))
75 {}
76
77 DBusIndicators::~DBusIndicators()
78 {}
79
80+bool DBusIndicators::IsConnected() const
81+{
82+ return pimpl->gproxy_.IsConnected();
83+}
84+
85 void DBusIndicators::SyncGeometries(std::string const& name,
86 EntryLocationMap const& locations)
87 {
88
89=== modified file 'UnityCore/DBusIndicators.h'
90--- UnityCore/DBusIndicators.h 2012-03-14 00:27:01 +0000
91+++ UnityCore/DBusIndicators.h 2012-10-09 11:53:25 +0000
92@@ -50,6 +50,10 @@
93 virtual void OnShowAppMenu(unsigned int xid, int x, int y,
94 unsigned int timestamp);
95
96+protected:
97+ DBusIndicators(std::string const& dbus_name);
98+ bool IsConnected() const;
99+
100 private:
101 class Impl;
102 std::unique_ptr<Impl> pimpl;
103
104=== modified file 'UnityCore/Indicator.cpp'
105--- UnityCore/Indicator.cpp 2012-02-01 01:41:18 +0000
106+++ UnityCore/Indicator.cpp 2012-10-09 11:53:25 +0000
107@@ -120,6 +120,21 @@
108 return Entry::Ptr();
109 }
110
111+int Indicator::EntryIndex(std::string const& entry_id) const
112+{
113+ int i = 0;
114+ for (auto entry : entries_)
115+ {
116+ if (entry->id() == entry_id)
117+ {
118+ return i;
119+ }
120+ ++i;
121+ }
122+
123+ return -1;
124+}
125+
126 void Indicator::OnEntryShowMenu(std::string const& entry_id, unsigned int xid,
127 int x, int y, unsigned int button, unsigned int timestamp)
128 {
129
130=== modified file 'UnityCore/Indicator.h'
131--- UnityCore/Indicator.h 2012-02-01 01:41:18 +0000
132+++ UnityCore/Indicator.h 2012-10-09 11:53:25 +0000
133@@ -48,6 +48,7 @@
134
135 void Sync(Entries const& new_entries);
136 Entry::Ptr GetEntry(std::string const& entry_id) const;
137+ int EntryIndex(std::string const& entry_id) const;
138 Entries GetEntries() const;
139
140 // Signals
141
142=== modified file 'tests/CMakeLists.txt'
143--- tests/CMakeLists.txt 2012-07-26 13:12:26 +0000
144+++ tests/CMakeLists.txt 2012-10-09 11:53:25 +0000
145@@ -110,7 +110,9 @@
146 test_service_lens.h
147 test_service_main.c
148 test_service_model.c
149- test_service_model.h)
150+ test_service_model.h
151+ test_service_panel.c
152+ test_service_panel.c)
153 target_link_libraries(test-gtest-service ${LIBS})
154 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION} gtest)
155
156@@ -189,6 +191,7 @@
157 test_utils.h
158 test_ratings_filter.cpp
159 test_results.cpp
160+ test_dbus_indicators.cpp
161 )
162 target_link_libraries(test-gtest-dbus gtest ${LIBS})
163 add_test(UnityGTestDBus test-gtest-dbus)
164
165=== added file 'tests/test_dbus_indicators.cpp'
166--- tests/test_dbus_indicators.cpp 1970-01-01 00:00:00 +0000
167+++ tests/test_dbus_indicators.cpp 2012-10-09 11:53:25 +0000
168@@ -0,0 +1,98 @@
169+#include <gtest/gtest.h>
170+
171+#include <UnityCore/GLibDBusProxy.h>
172+#include <UnityCore/GLibWrapper.h>
173+#include <UnityCore/DBusIndicators.h>
174+
175+#include "test_utils.h"
176+
177+using namespace unity;
178+using namespace unity::indicator;
179+
180+namespace
181+{
182+
183+class DBusIndicatorsTest : public DBusIndicators
184+{
185+public:
186+ DBusIndicatorsTest() : DBusIndicators("com.canonical.Unity.Test")
187+ {
188+ }
189+
190+ bool HasIndicators() const
191+ {
192+ return !GetIndicators().empty();
193+ }
194+
195+ using DBusIndicators::IsConnected;
196+};
197+
198+class TestDBusIndicators : public ::testing::Test
199+{
200+public:
201+ void SetUp()
202+ {
203+ session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
204+ g_dbus_connection_set_exit_on_close(session, FALSE);
205+
206+ dbus_indicators.reset(new DBusIndicatorsTest ());
207+
208+ // wait until the dbus indicator has connected to the panel service
209+ Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::IsConnected));
210+ }
211+
212+ bool TriggerResync1Sent() const
213+ {
214+ GVariant *ret = CallPanelMethod("TriggerResync1Sent");
215+ return g_variant_get_boolean(g_variant_get_child_value(ret, 0));
216+ }
217+
218+ GVariant* CallPanelMethod(std::string const& name) const
219+ {
220+ return g_dbus_connection_call_sync(session,
221+ "com.canonical.Unity.Test",
222+ "/com/canonical/Unity/Panel/Service",
223+ "com.canonical.Unity.Panel.Service",
224+ name.c_str(),
225+ NULL,
226+ NULL,
227+ G_DBUS_CALL_FLAGS_NONE,
228+ -1,
229+ NULL,
230+ NULL);
231+ }
232+
233+ glib::Object<GDBusConnection> session;
234+ std::shared_ptr<DBusIndicatorsTest> dbus_indicators;
235+};
236+
237+TEST_F(TestDBusIndicators, TestConstruction)
238+{
239+ EXPECT_EQ(dbus_indicators->IsConnected(), true);
240+}
241+
242+TEST_F(TestDBusIndicators, TestSync)
243+{
244+ // wait until the dbus indicator gets any indicator from the panel service
245+ Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::HasIndicators));
246+
247+ EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
248+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
249+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().front()->id(), "test_entry_id");
250+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().back()->id(), "test_entry_id2");
251+
252+ // Tell the service to trigger a resync and to send the entries in the reverse order
253+ CallPanelMethod("TriggerResync1");
254+
255+ Utils::WaitUntil(sigc::mem_fun(this, &TestDBusIndicators::TriggerResync1Sent));
256+ // We know the resync has been sent, but it may have not been processed
257+ // so do one interation of the main loop more
258+ g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
259+
260+ EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
261+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
262+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().front()->id(), "test_entry_id2");
263+ EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().back()->id(), "test_entry_id");
264+}
265+
266+}
267
268=== modified file 'tests/test_indicator.cpp'
269--- tests/test_indicator.cpp 2012-02-01 01:55:05 +0000
270+++ tests/test_indicator.cpp 2012-10-09 11:53:25 +0000
271@@ -35,6 +35,7 @@
272 EXPECT_EQ(indicator.name(), "indicator-test");
273 EXPECT_FALSE(indicator.IsAppmenu());
274 EXPECT_EQ(indicator.GetEntry("test-entry"), nullptr);
275+ EXPECT_EQ(indicator.EntryIndex("test-entry"), -1);
276 EXPECT_TRUE(indicator.GetEntries().empty());
277 }
278
279@@ -76,6 +77,7 @@
280 indicator.Sync(sync_data);
281 EXPECT_EQ(indicator.GetEntries().size(), 3);
282 EXPECT_EQ(indicator.GetEntry("test-entry-2"), entry2);
283+ EXPECT_EQ(indicator.EntryIndex("test-entry-2"), 1);
284 EXPECT_EQ(added.size(), 3);
285 EXPECT_EQ(added.front()->id(), "test-entry-1");
286 EXPECT_EQ(added.back()->id(), "test-entry-3");
287@@ -91,6 +93,7 @@
288 indicator.Sync(sync_data);
289 EXPECT_EQ(indicator.GetEntries().size(), 2);
290 EXPECT_EQ(indicator.GetEntry("test-entry-2"), nullptr);
291+ EXPECT_EQ(indicator.EntryIndex("test-entry-2"), -1);
292 EXPECT_EQ(added.size(), 0);
293 EXPECT_EQ(removed.size(), 1);
294 EXPECT_EQ(removed.front(), entry2->id());
295
296=== modified file 'tests/test_service_main.c'
297--- tests/test_service_main.c 2012-03-14 06:24:18 +0000
298+++ tests/test_service_main.c 2012-10-09 11:53:25 +0000
299@@ -3,6 +3,7 @@
300 #include "test_service_lens.h"
301 #include "test_service_model.h"
302 #include "test_service_hud.h"
303+#include "test_service_panel.h"
304 #include "test_service_gdbus_wrapper.h"
305
306 static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);
307@@ -37,6 +38,7 @@
308 static ServiceLens* lens_ = NULL;
309 static ServiceModel* model_ = NULL;
310 static ServiceHud* hud_ = NULL;
311+static ServicePanel* panel_ = NULL;
312 static ServiceGDBusWrapper* gdbus_wrapper_ = NULL;
313 gint
314 main(gint argc, gchar** argv)
315@@ -48,6 +50,7 @@
316 lens_ = service_lens_new();
317 model_ = service_model_new();
318 hud_ = service_hud_new();
319+ panel_ = service_panel_new();
320 gdbus_wrapper_ = service_gdbus_wrapper_new();
321
322 g_bus_own_name(G_BUS_TYPE_SESSION,
323@@ -65,6 +68,7 @@
324 //g_object_unref(lens_);
325 //g_object_unref(model_);
326 g_object_unref(hud_);
327+ g_object_unref(panel_);
328 g_dbus_node_info_unref(introspection_data);
329
330 return 0;
331
332=== added file 'tests/test_service_panel.c'
333--- tests/test_service_panel.c 1970-01-01 00:00:00 +0000
334+++ tests/test_service_panel.c 2012-10-09 11:53:25 +0000
335@@ -0,0 +1,253 @@
336+#include "test_service_panel.h"
337+#include <unity.h>
338+#include <gio/gio.h>
339+
340+static const char * panel_interface =
341+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
342+"<node name=\"/\">\n"
343+" <interface name=\"com.canonical.Unity.Panel.Service\">\n"
344+"\n"
345+"<!-- Begin of real methods/signals -->\n"
346+" <method name='Sync'>"
347+" <arg type='a(ssssbbusbbi)' name='state' direction='out'/>"
348+" </method>"
349+"\n"
350+" <signal name='ReSync'>"
351+" <arg type='s' name='indicator_id' />"
352+" </signal>"
353+"\n"
354+"<!-- Begin of test only methods/signals -->\n"
355+"\n"
356+" <method name='TriggerResync1' />"
357+"\n"
358+" <method name='TriggerResync1Sent'>"
359+" <arg type='b' name='sent' direction='out'/>"
360+" </method>"
361+"\n"
362+" </interface>\n"
363+"</node>\n"
364+;
365+static void bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data);
366+static void bus_method (GDBusConnection *connection,
367+ const gchar *sender,
368+ const gchar *object_path,
369+ const gchar *interface_name,
370+ const gchar *method_name,
371+ GVariant *parameters,
372+ GDBusMethodInvocation *invocation,
373+ gpointer user_data);
374+
375+G_DEFINE_TYPE(ServicePanel, service_panel, G_TYPE_OBJECT);
376+static GDBusNodeInfo * node_info = NULL;
377+static GDBusInterfaceInfo * iface_info = NULL;
378+static GDBusInterfaceVTable bus_vtable = {
379+ method_call: bus_method,
380+ get_property: NULL,
381+ set_property: NULL,
382+};
383+
384+struct _ServicePanelPrivate
385+{
386+ GDBusConnection * bus;
387+ GCancellable * bus_lookup;
388+ guint bus_registration;
389+ guint sig_emission_handle;
390+};
391+
392+static void
393+service_panel_dispose(GObject* object)
394+{
395+ ServicePanel* self = SERVICE_PANEL(object);
396+ if (self->priv->bus_lookup != NULL) {
397+ g_cancellable_cancel(self->priv->bus_lookup);
398+ g_object_unref(self->priv->bus_lookup);
399+ self->priv->bus_lookup = NULL;
400+ }
401+
402+ if (self->priv->bus_registration != 0) {
403+ g_dbus_connection_unregister_object(self->priv->bus, self->priv->bus_registration);
404+ self->priv->bus_registration = 0;
405+ }
406+
407+ if (self->priv->bus != NULL) {
408+ g_object_unref(self->priv->bus);
409+ self->priv->bus = NULL;
410+ }
411+
412+ if (self->priv->sig_emission_handle) {
413+ g_source_remove(self->priv->sig_emission_handle);
414+ self->priv->sig_emission_handle = 0;
415+ }
416+
417+}
418+
419+static void
420+service_panel_class_init(ServicePanelClass* klass)
421+{
422+ G_OBJECT_CLASS(klass)->dispose = service_panel_dispose;
423+ g_type_class_add_private (klass, sizeof (ServicePanelPrivate));
424+
425+ if (node_info == NULL)
426+ {
427+ GError * error = NULL;
428+
429+ node_info = g_dbus_node_info_new_for_xml(panel_interface, &error);
430+ if (error != NULL)
431+ {
432+ g_error("Unable to parse Panel interface: %s", error->message);
433+ g_error_free(error);
434+ }
435+ }
436+
437+ if (node_info != NULL && iface_info == NULL)
438+ {
439+ iface_info = g_dbus_node_info_lookup_interface(node_info,"com.canonical.Unity.Panel.Service");
440+ if (iface_info == NULL)
441+ {
442+ g_error("Unable to find interface 'com.canonical.Unity.Panel.Service'");
443+ }
444+ }
445+
446+}
447+
448+static void
449+service_panel_init(ServicePanel* self)
450+{
451+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SERVICE_TYPE_PANEL, ServicePanelPrivate);
452+ self->priv->bus = NULL;
453+ self->priv->bus_lookup = NULL;
454+ self->priv->bus_registration = 0;
455+
456+ self->priv->bus_lookup = g_cancellable_new();
457+ g_bus_get(G_BUS_TYPE_SESSION, self->priv->bus_lookup, bus_got_cb, self);
458+}
459+
460+ServicePanel*
461+service_panel_new()
462+{
463+ return g_object_new(SERVICE_TYPE_PANEL, NULL);
464+}
465+
466+static void
467+bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data)
468+{
469+ GError * error = NULL;
470+ ServicePanel * self = SERVICE_PANEL(user_data);
471+ GDBusConnection * bus;
472+
473+ bus = g_bus_get_finish(res, &error);
474+ if (error != NULL) {
475+ g_critical("Unable to get bus: %s", error->message);
476+ g_error_free(error);
477+ return;
478+ }
479+
480+ self->priv->bus = bus;
481+
482+ /* Register object */
483+ self->priv->bus_registration = g_dbus_connection_register_object(bus,
484+ /* path */ "/com/canonical/Unity/Panel/Service",
485+ /* interface */ iface_info,
486+ /* vtable */ &bus_vtable,
487+ /* userdata */ self,
488+ /* destroy */ NULL,
489+ /* error */ &error);
490+
491+ if (error != NULL) {
492+ g_critical ("Unable to create bus connection object, %s", error->message);
493+ g_error_free(error);
494+ return;
495+ }
496+
497+ return;
498+}
499+
500+static void
501+add_entry_id(GVariantBuilder *b)
502+{
503+ g_variant_builder_add (b, "(ssssbbusbbi)",
504+ "test_indicator_id",
505+ "test_entry_id",
506+ "test_entry_name_hint",
507+ "test_entry_label",
508+ TRUE, /* label sensitive */
509+ TRUE, /* label visible */
510+ 0, /* image type */
511+ "", /* image_data */
512+ TRUE, /* image sensitive */
513+ TRUE, /* image visible */
514+ 1 /* priority */);
515+}
516+
517+static void
518+add_entry_id_2(GVariantBuilder *b)
519+{
520+ g_variant_builder_add (b, "(ssssbbusbbi)",
521+ "test_indicator_id",
522+ "test_entry_id2",
523+ "test_entry_name_hint2",
524+ "test_entry_label2",
525+ TRUE, /* label sensitive */
526+ TRUE, /* label visible */
527+ 0, /* image type */
528+ "", /* image_data */
529+ TRUE, /* image sensitive */
530+ TRUE, /* image visible */
531+ 1 /* priority */);
532+}
533+
534+static int sync_return_mode = 0;
535+static int trigger_resync1_sent = FALSE;
536+
537+static void
538+bus_method (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
539+{
540+ if (g_strcmp0(method_name, "Sync") == 0)
541+ {
542+ GVariantBuilder b;
543+
544+ g_variant_builder_init (&b, G_VARIANT_TYPE ("(a(ssssbbusbbi))"));
545+ g_variant_builder_open (&b, G_VARIANT_TYPE ("a(ssssbbusbbi)"));
546+
547+ if (sync_return_mode == 0)
548+ {
549+ add_entry_id(&b);
550+ add_entry_id_2(&b);
551+ }
552+ else if (sync_return_mode == 1)
553+ {
554+ add_entry_id_2(&b);
555+ add_entry_id(&b);
556+ }
557+
558+ g_variant_builder_close (&b);
559+
560+ g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&b));
561+
562+ if (sync_return_mode == 1)
563+ {
564+ trigger_resync1_sent = TRUE;
565+ }
566+ }
567+ else if (g_strcmp0(method_name, "TriggerResync1") == 0)
568+ {
569+ sync_return_mode = 1;
570+ trigger_resync1_sent = FALSE;
571+
572+ g_dbus_method_invocation_return_value(invocation, NULL);
573+ GVariantBuilder ret_builder;
574+ g_variant_builder_init(&ret_builder, G_VARIANT_TYPE_TUPLE);
575+ g_variant_builder_add_value(&ret_builder, g_variant_new_string(""));
576+ g_dbus_connection_emit_signal (connection, NULL, "/com/canonical/Unity/Panel/Service", "com.canonical.Unity.Panel.Service", "ReSync", g_variant_builder_end(&ret_builder), NULL);
577+ }
578+ else if (g_strcmp0(method_name, "TriggerResync1Sent") == 0)
579+ {
580+ GVariantBuilder ret_builder;
581+ g_variant_builder_init(&ret_builder, G_VARIANT_TYPE ("(b)"));
582+ g_variant_builder_add_value (&ret_builder, g_variant_new_boolean(trigger_resync1_sent));
583+ g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&ret_builder));
584+ }
585+
586+ return;
587+}
588+
589
590=== added file 'tests/test_service_panel.h'
591--- tests/test_service_panel.h 1970-01-01 00:00:00 +0000
592+++ tests/test_service_panel.h 2012-10-09 11:53:25 +0000
593@@ -0,0 +1,46 @@
594+#ifndef _SERVICE_PANEL_H_
595+#define _SERVICE_PANEL_H_
596+
597+#include <glib-object.h>
598+G_BEGIN_DECLS
599+
600+#define SERVICE_TYPE_PANEL (service_panel_get_type ())
601+
602+#define SERVICE_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
603+ SERVICE_TYPE_PANEL, ServicePanel))
604+
605+#define SERVICE_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
606+ SERVICE_TYPE_PANEL, ServicePanelClass))
607+
608+#define SERVICE_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
609+ SERVICE_TYPE_PANEL))
610+
611+#define SERVICE_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
612+ SERVICE_TYPE_PANEL))
613+
614+#define ServicePanel_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
615+ SERVICE_TYPE_PANEL, ServicePanelClass))
616+
617+typedef struct _ServicePanel ServicePanel;
618+typedef struct _ServicePanelClass ServicePanelClass;
619+typedef struct _ServicePanelPrivate ServicePanelPrivate;
620+
621+struct _ServicePanel
622+{
623+ GObject parent;
624+
625+ ServicePanelPrivate *priv;
626+};
627+
628+struct _ServicePanelClass
629+{
630+ GObjectClass parent_class;
631+};
632+
633+GType service_panel_get_type(void) G_GNUC_CONST;
634+
635+ServicePanel* service_panel_new(void);
636+
637+G_END_DECLS
638+
639+#endif /* _SERVICE_PANEL_H_ */
640
641=== modified file 'tests/test_utils.h'
642--- tests/test_utils.h 2012-03-14 06:24:18 +0000
643+++ tests/test_utils.h 2012-10-09 11:53:25 +0000
644@@ -46,6 +46,20 @@
645 EXPECT_TRUE(success);
646 }
647
648+ static void WaitUntil(std::function<bool()> check_function, bool result = true, unsigned int max_wait = 10)
649+ {
650+ bool timeout_reached = false;
651+ guint32 timeout_id = ScheduleTimeout(&timeout_reached, max_wait * 1000);
652+
653+ while (!check_function() && !timeout_reached)
654+ g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
655+
656+ if (check_function())
657+ g_source_remove(timeout_id);
658+
659+ EXPECT_EQ(check_function(), result);
660+ }
661+
662 static guint32 ScheduleTimeout(bool* timeout_reached, unsigned int timeout_duration = 10)
663 {
664 return g_timeout_add(timeout_duration*1000, TimeoutCallback, timeout_reached);

Subscribers

People subscribed via source and target branches

to all changes: