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
=== modified file 'UnityCore/DBusIndicators.cpp'
--- UnityCore/DBusIndicators.cpp 2012-03-21 12:31:11 +0000
+++ UnityCore/DBusIndicators.cpp 2012-10-09 11:53:25 +0000
@@ -43,7 +43,7 @@
43class DBusIndicators::Impl43class DBusIndicators::Impl
44{44{
45public:45public:
46 Impl(DBusIndicators* owner);46 Impl(std::string const& dbus_name, DBusIndicators* owner);
47 ~Impl();47 ~Impl();
4848
49 void CheckLocalService();49 void CheckLocalService();
@@ -85,12 +85,12 @@
8585
8686
87// Public Methods87// Public Methods
88DBusIndicators::Impl::Impl(DBusIndicators* owner)88DBusIndicators::Impl::Impl(std::string const& dbus_name, DBusIndicators* owner)
89 : owner_(owner)89 : owner_(owner)
90 , reconnect_timeout_id_(0)90 , reconnect_timeout_id_(0)
91 , show_entry_idle_id_(0)91 , show_entry_idle_id_(0)
92 , show_appmenu_idle_id_(0)92 , show_appmenu_idle_id_(0)
93 , gproxy_(SERVICE_NAME, SERVICE_PATH, SERVICE_IFACE,93 , gproxy_(dbus_name, SERVICE_PATH, SERVICE_IFACE,
94 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)94 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)
95{95{
96 gproxy_.Connect("ReSync", sigc::mem_fun(this, &DBusIndicators::Impl::OnReSync));96 gproxy_.Connect("ReSync", sigc::mem_fun(this, &DBusIndicators::Impl::OnReSync));
@@ -313,6 +313,8 @@
313 return;313 return;
314314
315 std::map<Indicator::Ptr, Indicator::Entries> indicators;315 std::map<Indicator::Ptr, Indicator::Entries> indicators;
316 int wantedIndex = 0;
317 bool anyIndexDifferent = false;
316318
317 g_variant_get(args, "(a(ssssbbusbbi))", &iter);319 g_variant_get(args, "(a(ssssbbusbbi))", &iter);
318 while (g_variant_iter_loop(iter, "(ssssbbusbbi)",320 while (g_variant_iter_loop(iter, "(ssssbbusbbi)",
@@ -342,7 +344,18 @@
342 // Null entries (entry_id == "") are empty indicators.344 // Null entries (entry_id == "") are empty indicators.
343 if (entry != "")345 if (entry != "")
344 {346 {
345 Entry::Ptr e = indicator->GetEntry(entry_id);347 Entry::Ptr e;
348 if (!anyIndexDifferent)
349 {
350 // Indicators can only add or remove entries, so if
351 // there is a index change we can't reuse the existing ones
352 // after that index
353 int existingEntryIndex = indicator->EntryIndex(entry_id);
354 if (wantedIndex == existingEntryIndex)
355 e = indicator->GetEntry(entry_id);
356 else
357 anyIndexDifferent = true;
358 }
346359
347 if (!e)360 if (!e)
348 {361 {
@@ -365,6 +378,7 @@
365 }378 }
366379
367 entries.push_back(e);380 entries.push_back(e);
381 wantedIndex++;
368 }382 }
369 }383 }
370 g_variant_iter_free(iter);384 g_variant_iter_free(iter);
@@ -437,12 +451,21 @@
437}451}
438452
439DBusIndicators::DBusIndicators()453DBusIndicators::DBusIndicators()
440 : pimpl(new Impl(this))454 : pimpl(new Impl(SERVICE_NAME, this))
455{}
456
457DBusIndicators::DBusIndicators(std::string const& dbus_name)
458 : pimpl(new Impl(dbus_name, this))
441{}459{}
442460
443DBusIndicators::~DBusIndicators()461DBusIndicators::~DBusIndicators()
444{}462{}
445463
464bool DBusIndicators::IsConnected() const
465{
466 return pimpl->gproxy_.IsConnected();
467}
468
446void DBusIndicators::SyncGeometries(std::string const& name,469void DBusIndicators::SyncGeometries(std::string const& name,
447 EntryLocationMap const& locations)470 EntryLocationMap const& locations)
448{471{
449472
=== modified file 'UnityCore/DBusIndicators.h'
--- UnityCore/DBusIndicators.h 2012-03-14 00:27:01 +0000
+++ UnityCore/DBusIndicators.h 2012-10-09 11:53:25 +0000
@@ -50,6 +50,10 @@
50 virtual void OnShowAppMenu(unsigned int xid, int x, int y,50 virtual void OnShowAppMenu(unsigned int xid, int x, int y,
51 unsigned int timestamp);51 unsigned int timestamp);
5252
53protected:
54 DBusIndicators(std::string const& dbus_name);
55 bool IsConnected() const;
56
53private:57private:
54 class Impl;58 class Impl;
55 std::unique_ptr<Impl> pimpl;59 std::unique_ptr<Impl> pimpl;
5660
=== modified file 'UnityCore/Indicator.cpp'
--- UnityCore/Indicator.cpp 2012-02-01 01:41:18 +0000
+++ UnityCore/Indicator.cpp 2012-10-09 11:53:25 +0000
@@ -120,6 +120,21 @@
120 return Entry::Ptr();120 return Entry::Ptr();
121}121}
122122
123int Indicator::EntryIndex(std::string const& entry_id) const
124{
125 int i = 0;
126 for (auto entry : entries_)
127 {
128 if (entry->id() == entry_id)
129 {
130 return i;
131 }
132 ++i;
133 }
134
135 return -1;
136}
137
123void Indicator::OnEntryShowMenu(std::string const& entry_id, unsigned int xid,138void Indicator::OnEntryShowMenu(std::string const& entry_id, unsigned int xid,
124 int x, int y, unsigned int button, unsigned int timestamp)139 int x, int y, unsigned int button, unsigned int timestamp)
125{140{
126141
=== modified file 'UnityCore/Indicator.h'
--- UnityCore/Indicator.h 2012-02-01 01:41:18 +0000
+++ UnityCore/Indicator.h 2012-10-09 11:53:25 +0000
@@ -48,6 +48,7 @@
4848
49 void Sync(Entries const& new_entries);49 void Sync(Entries const& new_entries);
50 Entry::Ptr GetEntry(std::string const& entry_id) const;50 Entry::Ptr GetEntry(std::string const& entry_id) const;
51 int EntryIndex(std::string const& entry_id) const;
51 Entries GetEntries() const;52 Entries GetEntries() const;
5253
53 // Signals54 // Signals
5455
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-07-26 13:12:26 +0000
+++ tests/CMakeLists.txt 2012-10-09 11:53:25 +0000
@@ -110,7 +110,9 @@
110 test_service_lens.h110 test_service_lens.h
111 test_service_main.c111 test_service_main.c
112 test_service_model.c112 test_service_model.c
113 test_service_model.h)113 test_service_model.h
114 test_service_panel.c
115 test_service_panel.c)
114 target_link_libraries(test-gtest-service ${LIBS})116 target_link_libraries(test-gtest-service ${LIBS})
115 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION} gtest)117 add_dependencies (test-gtest-service unity-core-${UNITY_API_VERSION} gtest)
116118
@@ -189,6 +191,7 @@
189 test_utils.h191 test_utils.h
190 test_ratings_filter.cpp192 test_ratings_filter.cpp
191 test_results.cpp193 test_results.cpp
194 test_dbus_indicators.cpp
192 )195 )
193 target_link_libraries(test-gtest-dbus gtest ${LIBS})196 target_link_libraries(test-gtest-dbus gtest ${LIBS})
194 add_test(UnityGTestDBus test-gtest-dbus)197 add_test(UnityGTestDBus test-gtest-dbus)
195198
=== added file 'tests/test_dbus_indicators.cpp'
--- tests/test_dbus_indicators.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_dbus_indicators.cpp 2012-10-09 11:53:25 +0000
@@ -0,0 +1,98 @@
1#include <gtest/gtest.h>
2
3#include <UnityCore/GLibDBusProxy.h>
4#include <UnityCore/GLibWrapper.h>
5#include <UnityCore/DBusIndicators.h>
6
7#include "test_utils.h"
8
9using namespace unity;
10using namespace unity::indicator;
11
12namespace
13{
14
15class DBusIndicatorsTest : public DBusIndicators
16{
17public:
18 DBusIndicatorsTest() : DBusIndicators("com.canonical.Unity.Test")
19 {
20 }
21
22 bool HasIndicators() const
23 {
24 return !GetIndicators().empty();
25 }
26
27 using DBusIndicators::IsConnected;
28};
29
30class TestDBusIndicators : public ::testing::Test
31{
32public:
33 void SetUp()
34 {
35 session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
36 g_dbus_connection_set_exit_on_close(session, FALSE);
37
38 dbus_indicators.reset(new DBusIndicatorsTest ());
39
40 // wait until the dbus indicator has connected to the panel service
41 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::IsConnected));
42 }
43
44 bool TriggerResync1Sent() const
45 {
46 GVariant *ret = CallPanelMethod("TriggerResync1Sent");
47 return g_variant_get_boolean(g_variant_get_child_value(ret, 0));
48 }
49
50 GVariant* CallPanelMethod(std::string const& name) const
51 {
52 return g_dbus_connection_call_sync(session,
53 "com.canonical.Unity.Test",
54 "/com/canonical/Unity/Panel/Service",
55 "com.canonical.Unity.Panel.Service",
56 name.c_str(),
57 NULL,
58 NULL,
59 G_DBUS_CALL_FLAGS_NONE,
60 -1,
61 NULL,
62 NULL);
63 }
64
65 glib::Object<GDBusConnection> session;
66 std::shared_ptr<DBusIndicatorsTest> dbus_indicators;
67};
68
69TEST_F(TestDBusIndicators, TestConstruction)
70{
71 EXPECT_EQ(dbus_indicators->IsConnected(), true);
72}
73
74TEST_F(TestDBusIndicators, TestSync)
75{
76 // wait until the dbus indicator gets any indicator from the panel service
77 Utils::WaitUntil(sigc::mem_fun(*dbus_indicators, &DBusIndicatorsTest::HasIndicators));
78
79 EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
80 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
81 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().front()->id(), "test_entry_id");
82 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().back()->id(), "test_entry_id2");
83
84 // Tell the service to trigger a resync and to send the entries in the reverse order
85 CallPanelMethod("TriggerResync1");
86
87 Utils::WaitUntil(sigc::mem_fun(this, &TestDBusIndicators::TriggerResync1Sent));
88 // We know the resync has been sent, but it may have not been processed
89 // so do one interation of the main loop more
90 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
91
92 EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
93 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
94 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().front()->id(), "test_entry_id2");
95 EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().back()->id(), "test_entry_id");
96}
97
98}
099
=== modified file 'tests/test_indicator.cpp'
--- tests/test_indicator.cpp 2012-02-01 01:55:05 +0000
+++ tests/test_indicator.cpp 2012-10-09 11:53:25 +0000
@@ -35,6 +35,7 @@
35 EXPECT_EQ(indicator.name(), "indicator-test");35 EXPECT_EQ(indicator.name(), "indicator-test");
36 EXPECT_FALSE(indicator.IsAppmenu());36 EXPECT_FALSE(indicator.IsAppmenu());
37 EXPECT_EQ(indicator.GetEntry("test-entry"), nullptr);37 EXPECT_EQ(indicator.GetEntry("test-entry"), nullptr);
38 EXPECT_EQ(indicator.EntryIndex("test-entry"), -1);
38 EXPECT_TRUE(indicator.GetEntries().empty());39 EXPECT_TRUE(indicator.GetEntries().empty());
39}40}
4041
@@ -76,6 +77,7 @@
76 indicator.Sync(sync_data);77 indicator.Sync(sync_data);
77 EXPECT_EQ(indicator.GetEntries().size(), 3);78 EXPECT_EQ(indicator.GetEntries().size(), 3);
78 EXPECT_EQ(indicator.GetEntry("test-entry-2"), entry2);79 EXPECT_EQ(indicator.GetEntry("test-entry-2"), entry2);
80 EXPECT_EQ(indicator.EntryIndex("test-entry-2"), 1);
79 EXPECT_EQ(added.size(), 3);81 EXPECT_EQ(added.size(), 3);
80 EXPECT_EQ(added.front()->id(), "test-entry-1");82 EXPECT_EQ(added.front()->id(), "test-entry-1");
81 EXPECT_EQ(added.back()->id(), "test-entry-3");83 EXPECT_EQ(added.back()->id(), "test-entry-3");
@@ -91,6 +93,7 @@
91 indicator.Sync(sync_data);93 indicator.Sync(sync_data);
92 EXPECT_EQ(indicator.GetEntries().size(), 2);94 EXPECT_EQ(indicator.GetEntries().size(), 2);
93 EXPECT_EQ(indicator.GetEntry("test-entry-2"), nullptr);95 EXPECT_EQ(indicator.GetEntry("test-entry-2"), nullptr);
96 EXPECT_EQ(indicator.EntryIndex("test-entry-2"), -1);
94 EXPECT_EQ(added.size(), 0);97 EXPECT_EQ(added.size(), 0);
95 EXPECT_EQ(removed.size(), 1);98 EXPECT_EQ(removed.size(), 1);
96 EXPECT_EQ(removed.front(), entry2->id());99 EXPECT_EQ(removed.front(), entry2->id());
97100
=== modified file 'tests/test_service_main.c'
--- tests/test_service_main.c 2012-03-14 06:24:18 +0000
+++ tests/test_service_main.c 2012-10-09 11:53:25 +0000
@@ -3,6 +3,7 @@
3#include "test_service_lens.h"3#include "test_service_lens.h"
4#include "test_service_model.h"4#include "test_service_model.h"
5#include "test_service_hud.h"5#include "test_service_hud.h"
6#include "test_service_panel.h"
6#include "test_service_gdbus_wrapper.h"7#include "test_service_gdbus_wrapper.h"
78
8static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);9static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);
@@ -37,6 +38,7 @@
37static ServiceLens* lens_ = NULL;38static ServiceLens* lens_ = NULL;
38static ServiceModel* model_ = NULL;39static ServiceModel* model_ = NULL;
39static ServiceHud* hud_ = NULL;40static ServiceHud* hud_ = NULL;
41static ServicePanel* panel_ = NULL;
40static ServiceGDBusWrapper* gdbus_wrapper_ = NULL;42static ServiceGDBusWrapper* gdbus_wrapper_ = NULL;
41gint43gint
42main(gint argc, gchar** argv)44main(gint argc, gchar** argv)
@@ -48,6 +50,7 @@
48 lens_ = service_lens_new();50 lens_ = service_lens_new();
49 model_ = service_model_new();51 model_ = service_model_new();
50 hud_ = service_hud_new();52 hud_ = service_hud_new();
53 panel_ = service_panel_new();
51 gdbus_wrapper_ = service_gdbus_wrapper_new();54 gdbus_wrapper_ = service_gdbus_wrapper_new();
5255
53 g_bus_own_name(G_BUS_TYPE_SESSION,56 g_bus_own_name(G_BUS_TYPE_SESSION,
@@ -65,6 +68,7 @@
65 //g_object_unref(lens_);68 //g_object_unref(lens_);
66 //g_object_unref(model_);69 //g_object_unref(model_);
67 g_object_unref(hud_);70 g_object_unref(hud_);
71 g_object_unref(panel_);
68 g_dbus_node_info_unref(introspection_data);72 g_dbus_node_info_unref(introspection_data);
6973
70 return 0;74 return 0;
7175
=== added file 'tests/test_service_panel.c'
--- tests/test_service_panel.c 1970-01-01 00:00:00 +0000
+++ tests/test_service_panel.c 2012-10-09 11:53:25 +0000
@@ -0,0 +1,253 @@
1#include "test_service_panel.h"
2#include <unity.h>
3#include <gio/gio.h>
4
5static const char * panel_interface =
6"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
7"<node name=\"/\">\n"
8" <interface name=\"com.canonical.Unity.Panel.Service\">\n"
9"\n"
10"<!-- Begin of real methods/signals -->\n"
11" <method name='Sync'>"
12" <arg type='a(ssssbbusbbi)' name='state' direction='out'/>"
13" </method>"
14"\n"
15" <signal name='ReSync'>"
16" <arg type='s' name='indicator_id' />"
17" </signal>"
18"\n"
19"<!-- Begin of test only methods/signals -->\n"
20"\n"
21" <method name='TriggerResync1' />"
22"\n"
23" <method name='TriggerResync1Sent'>"
24" <arg type='b' name='sent' direction='out'/>"
25" </method>"
26"\n"
27" </interface>\n"
28"</node>\n"
29;
30static void bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data);
31static void bus_method (GDBusConnection *connection,
32 const gchar *sender,
33 const gchar *object_path,
34 const gchar *interface_name,
35 const gchar *method_name,
36 GVariant *parameters,
37 GDBusMethodInvocation *invocation,
38 gpointer user_data);
39
40G_DEFINE_TYPE(ServicePanel, service_panel, G_TYPE_OBJECT);
41static GDBusNodeInfo * node_info = NULL;
42static GDBusInterfaceInfo * iface_info = NULL;
43static GDBusInterfaceVTable bus_vtable = {
44 method_call: bus_method,
45 get_property: NULL,
46 set_property: NULL,
47};
48
49struct _ServicePanelPrivate
50{
51 GDBusConnection * bus;
52 GCancellable * bus_lookup;
53 guint bus_registration;
54 guint sig_emission_handle;
55};
56
57static void
58service_panel_dispose(GObject* object)
59{
60 ServicePanel* self = SERVICE_PANEL(object);
61 if (self->priv->bus_lookup != NULL) {
62 g_cancellable_cancel(self->priv->bus_lookup);
63 g_object_unref(self->priv->bus_lookup);
64 self->priv->bus_lookup = NULL;
65 }
66
67 if (self->priv->bus_registration != 0) {
68 g_dbus_connection_unregister_object(self->priv->bus, self->priv->bus_registration);
69 self->priv->bus_registration = 0;
70 }
71
72 if (self->priv->bus != NULL) {
73 g_object_unref(self->priv->bus);
74 self->priv->bus = NULL;
75 }
76
77 if (self->priv->sig_emission_handle) {
78 g_source_remove(self->priv->sig_emission_handle);
79 self->priv->sig_emission_handle = 0;
80 }
81
82}
83
84static void
85service_panel_class_init(ServicePanelClass* klass)
86{
87 G_OBJECT_CLASS(klass)->dispose = service_panel_dispose;
88 g_type_class_add_private (klass, sizeof (ServicePanelPrivate));
89
90 if (node_info == NULL)
91 {
92 GError * error = NULL;
93
94 node_info = g_dbus_node_info_new_for_xml(panel_interface, &error);
95 if (error != NULL)
96 {
97 g_error("Unable to parse Panel interface: %s", error->message);
98 g_error_free(error);
99 }
100 }
101
102 if (node_info != NULL && iface_info == NULL)
103 {
104 iface_info = g_dbus_node_info_lookup_interface(node_info,"com.canonical.Unity.Panel.Service");
105 if (iface_info == NULL)
106 {
107 g_error("Unable to find interface 'com.canonical.Unity.Panel.Service'");
108 }
109 }
110
111}
112
113static void
114service_panel_init(ServicePanel* self)
115{
116 self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SERVICE_TYPE_PANEL, ServicePanelPrivate);
117 self->priv->bus = NULL;
118 self->priv->bus_lookup = NULL;
119 self->priv->bus_registration = 0;
120
121 self->priv->bus_lookup = g_cancellable_new();
122 g_bus_get(G_BUS_TYPE_SESSION, self->priv->bus_lookup, bus_got_cb, self);
123}
124
125ServicePanel*
126service_panel_new()
127{
128 return g_object_new(SERVICE_TYPE_PANEL, NULL);
129}
130
131static void
132bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data)
133{
134 GError * error = NULL;
135 ServicePanel * self = SERVICE_PANEL(user_data);
136 GDBusConnection * bus;
137
138 bus = g_bus_get_finish(res, &error);
139 if (error != NULL) {
140 g_critical("Unable to get bus: %s", error->message);
141 g_error_free(error);
142 return;
143 }
144
145 self->priv->bus = bus;
146
147 /* Register object */
148 self->priv->bus_registration = g_dbus_connection_register_object(bus,
149 /* path */ "/com/canonical/Unity/Panel/Service",
150 /* interface */ iface_info,
151 /* vtable */ &bus_vtable,
152 /* userdata */ self,
153 /* destroy */ NULL,
154 /* error */ &error);
155
156 if (error != NULL) {
157 g_critical ("Unable to create bus connection object, %s", error->message);
158 g_error_free(error);
159 return;
160 }
161
162 return;
163}
164
165static void
166add_entry_id(GVariantBuilder *b)
167{
168 g_variant_builder_add (b, "(ssssbbusbbi)",
169 "test_indicator_id",
170 "test_entry_id",
171 "test_entry_name_hint",
172 "test_entry_label",
173 TRUE, /* label sensitive */
174 TRUE, /* label visible */
175 0, /* image type */
176 "", /* image_data */
177 TRUE, /* image sensitive */
178 TRUE, /* image visible */
179 1 /* priority */);
180}
181
182static void
183add_entry_id_2(GVariantBuilder *b)
184{
185 g_variant_builder_add (b, "(ssssbbusbbi)",
186 "test_indicator_id",
187 "test_entry_id2",
188 "test_entry_name_hint2",
189 "test_entry_label2",
190 TRUE, /* label sensitive */
191 TRUE, /* label visible */
192 0, /* image type */
193 "", /* image_data */
194 TRUE, /* image sensitive */
195 TRUE, /* image visible */
196 1 /* priority */);
197}
198
199static int sync_return_mode = 0;
200static int trigger_resync1_sent = FALSE;
201
202static void
203bus_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)
204{
205 if (g_strcmp0(method_name, "Sync") == 0)
206 {
207 GVariantBuilder b;
208
209 g_variant_builder_init (&b, G_VARIANT_TYPE ("(a(ssssbbusbbi))"));
210 g_variant_builder_open (&b, G_VARIANT_TYPE ("a(ssssbbusbbi)"));
211
212 if (sync_return_mode == 0)
213 {
214 add_entry_id(&b);
215 add_entry_id_2(&b);
216 }
217 else if (sync_return_mode == 1)
218 {
219 add_entry_id_2(&b);
220 add_entry_id(&b);
221 }
222
223 g_variant_builder_close (&b);
224
225 g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&b));
226
227 if (sync_return_mode == 1)
228 {
229 trigger_resync1_sent = TRUE;
230 }
231 }
232 else if (g_strcmp0(method_name, "TriggerResync1") == 0)
233 {
234 sync_return_mode = 1;
235 trigger_resync1_sent = FALSE;
236
237 g_dbus_method_invocation_return_value(invocation, NULL);
238 GVariantBuilder ret_builder;
239 g_variant_builder_init(&ret_builder, G_VARIANT_TYPE_TUPLE);
240 g_variant_builder_add_value(&ret_builder, g_variant_new_string(""));
241 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);
242 }
243 else if (g_strcmp0(method_name, "TriggerResync1Sent") == 0)
244 {
245 GVariantBuilder ret_builder;
246 g_variant_builder_init(&ret_builder, G_VARIANT_TYPE ("(b)"));
247 g_variant_builder_add_value (&ret_builder, g_variant_new_boolean(trigger_resync1_sent));
248 g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&ret_builder));
249 }
250
251 return;
252}
253
0254
=== added file 'tests/test_service_panel.h'
--- tests/test_service_panel.h 1970-01-01 00:00:00 +0000
+++ tests/test_service_panel.h 2012-10-09 11:53:25 +0000
@@ -0,0 +1,46 @@
1#ifndef _SERVICE_PANEL_H_
2#define _SERVICE_PANEL_H_
3
4#include <glib-object.h>
5G_BEGIN_DECLS
6
7#define SERVICE_TYPE_PANEL (service_panel_get_type ())
8
9#define SERVICE_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
10 SERVICE_TYPE_PANEL, ServicePanel))
11
12#define SERVICE_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
13 SERVICE_TYPE_PANEL, ServicePanelClass))
14
15#define SERVICE_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
16 SERVICE_TYPE_PANEL))
17
18#define SERVICE_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
19 SERVICE_TYPE_PANEL))
20
21#define ServicePanel_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
22 SERVICE_TYPE_PANEL, ServicePanelClass))
23
24typedef struct _ServicePanel ServicePanel;
25typedef struct _ServicePanelClass ServicePanelClass;
26typedef struct _ServicePanelPrivate ServicePanelPrivate;
27
28struct _ServicePanel
29{
30 GObject parent;
31
32 ServicePanelPrivate *priv;
33};
34
35struct _ServicePanelClass
36{
37 GObjectClass parent_class;
38};
39
40GType service_panel_get_type(void) G_GNUC_CONST;
41
42ServicePanel* service_panel_new(void);
43
44G_END_DECLS
45
46#endif /* _SERVICE_PANEL_H_ */
047
=== modified file 'tests/test_utils.h'
--- tests/test_utils.h 2012-03-14 06:24:18 +0000
+++ tests/test_utils.h 2012-10-09 11:53:25 +0000
@@ -46,6 +46,20 @@
46 EXPECT_TRUE(success);46 EXPECT_TRUE(success);
47 }47 }
4848
49 static void WaitUntil(std::function<bool()> check_function, bool result = true, unsigned int max_wait = 10)
50 {
51 bool timeout_reached = false;
52 guint32 timeout_id = ScheduleTimeout(&timeout_reached, max_wait * 1000);
53
54 while (!check_function() && !timeout_reached)
55 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
56
57 if (check_function())
58 g_source_remove(timeout_id);
59
60 EXPECT_EQ(check_function(), result);
61 }
62
49 static guint32 ScheduleTimeout(bool* timeout_reached, unsigned int timeout_duration = 10)63 static guint32 ScheduleTimeout(bool* timeout_reached, unsigned int timeout_duration = 10)
50 {64 {
51 return g_timeout_add(timeout_duration*1000, TimeoutCallback, timeout_reached);65 return g_timeout_add(timeout_duration*1000, TimeoutCallback, timeout_reached);

Subscribers

People subscribed via source and target branches

to all changes: