From e0356204fceabcd64244745f9a671aa3711ec822 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Fri, 19 Feb 2010 16:12:56 -0600
Subject: Putting in a mock watcher so we don't fall back.

---
 tests/test-libappindicator-dbus-client.c | 32 ++++++++++++++++++++++++++++++++
 tests/test-libappindicator-dbus-server.c |  1 +
 2 files changed, 33 insertions(+)

(limited to 'tests')

diff --git a/tests/test-libappindicator-dbus-client.c b/tests/test-libappindicator-dbus-client.c
index 6125d36..f5482aa 100644
--- a/tests/test-libappindicator-dbus-client.c
+++ b/tests/test-libappindicator-dbus-client.c
@@ -23,9 +23,13 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <glib.h>
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
 #include <libappindicator/app-indicator.h>
 #include "test-defines.h"
 
+#include "../src/dbus-shared.h"
+
 static GMainLoop * mainloop = NULL;
 static gboolean passed = TRUE;
 static int propcount = 0;
@@ -184,6 +188,19 @@ kill_func (gpointer userdata)
 	return FALSE;
 }
 
+static DBusHandlerResult
+dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data)
+{
+	if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) {
+		DBusMessage * reply = dbus_message_new_method_return(message);
+		dbus_connection_send(connection, reply, NULL);
+		dbus_message_unref(reply);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 gint
 main (gint argc, gchar * argv[])
 {
@@ -198,6 +215,21 @@ main (gint argc, gchar * argv[])
 		return 1;
 	}
 
+    DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+	guint nameret = 0;
+
+	if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) {
+		g_error("Unable to call to request name");
+		return 1;
+	}   
+
+	if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_error("Unable to get name");
+		return 1;
+	}
+
+	dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL);
+
 	DBusGProxy * props = dbus_g_proxy_new_for_name_owner(session_bus,
 	                                                     ":1.0",
 	                                                     "/org/ayatana/NotificationItem/my_id",
diff --git a/tests/test-libappindicator-dbus-server.c b/tests/test-libappindicator-dbus-server.c
index 76f0e50..2d68950 100644
--- a/tests/test-libappindicator-dbus-server.c
+++ b/tests/test-libappindicator-dbus-server.c
@@ -44,6 +44,7 @@ main (gint argc, gchar * argv[])
 	g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL))));
 
 	AppIndicator * ci = app_indicator_new (TEST_ID, TEST_ICON_NAME, TEST_CATEGORY);
+
 	app_indicator_set_status (ci, TEST_STATE);
 	app_indicator_set_attention_icon (ci, TEST_ATTENTION_ICON_NAME);
 
-- 
cgit v1.2.3


From 7e683f7476324dd4490a6b6ec0dbd27fcd47c4da Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Fri, 19 Feb 2010 16:18:51 -0600
Subject: Adding a mock server here as well

---
 tests/test-libappindicator-status-client.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

(limited to 'tests')

diff --git a/tests/test-libappindicator-status-client.c b/tests/test-libappindicator-status-client.c
index 55d85a2..acf4fca 100644
--- a/tests/test-libappindicator-status-client.c
+++ b/tests/test-libappindicator-status-client.c
@@ -23,6 +23,7 @@ with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <glib.h>
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include "../src/dbus-shared.h"
 
@@ -36,6 +37,20 @@ static guint toggle_count = 0;
 #define ACTIVE_STR   "Active"
 #define ATTN_STR     "NeedsAttention"
 
+static DBusHandlerResult
+dbus_reg_filter (DBusConnection * connection, DBusMessage * message, void * user_data)
+{
+	if (dbus_message_is_method_call(message, NOTIFICATION_WATCHER_DBUS_ADDR, "RegisterStatusNotifierItem")) {
+		DBusMessage * reply = dbus_message_new_method_return(message);
+		dbus_connection_send(connection, reply, NULL);
+		dbus_message_unref(reply);
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+
 static DBusHandlerResult
 dbus_filter (DBusConnection * connection, DBusMessage * message, void * user_data)
 {
@@ -103,6 +118,21 @@ main (gint argc, gchar * argv[])
 		return 1;
 	}
 
+    DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+	guint nameret = 0;
+
+	if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) {
+		g_error("Unable to call to request name");
+		return 1;
+	}   
+
+	if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_error("Unable to get name");
+		return 1;
+	}
+
+	dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_reg_filter, NULL, NULL);
+
 	dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL);
 	dbus_bus_add_match(dbus_g_connection_get_connection(session_bus), "type='signal',interface='" NOTIFICATION_ITEM_DBUS_IFACE "',member='NewStatus'", NULL);
 
-- 
cgit v1.2.3


From a067b5b0e1da84a381eb5ca5a426b87680dcc9f7 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 22 Feb 2010 12:54:25 -0600
Subject: Trying to make the test a little more robust by waiting for the other
 process to register on the bus, and then waiting.

---
 tests/test-libappindicator-fallback-item.c    | 23 +++++++++++++++++++++++
 tests/test-libappindicator-fallback-watcher.c | 14 ++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

(limited to 'tests')

diff --git a/tests/test-libappindicator-fallback-item.c b/tests/test-libappindicator-fallback-item.c
index 2c6e044..9fd1b45 100644
--- a/tests/test-libappindicator-fallback-item.c
+++ b/tests/test-libappindicator-fallback-item.c
@@ -1,5 +1,7 @@
 #include <glib.h>
 #include <glib-object.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
 #include <libappindicator/app-indicator.h>
 
 #define TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE            (test_libappindicator_fallback_item_get_type ())
@@ -106,6 +108,27 @@ main (int argc, char ** argv)
 {
 	gtk_init(&argc, &argv);
 
+	GError * error = NULL;
+	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+	if (error != NULL) {
+		g_error("Unable to get session bus: %s", error->message);
+		return 1;
+	}
+
+    DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+	guint nameret = 0;
+
+	if (!org_freedesktop_DBus_request_name(bus_proxy, "org.test", 0, &nameret, NULL)) {
+		g_error("Unable to call to request name");
+		return 1;
+	}   
+
+	if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_error("Unable to get name");
+		return 1;
+	}
+
 	TestLibappindicatorFallbackItem * item = g_object_new(TEST_LIBAPPINDICATOR_FALLBACK_ITEM_TYPE,
 		"id", "test-id",
 		"category", "Other",
diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c
index 90c7db8..c632dff 100644
--- a/tests/test-libappindicator-fallback-watcher.c
+++ b/tests/test-libappindicator-fallback-watcher.c
@@ -56,10 +56,6 @@ main (int argv, char ** argc)
 
 	g_debug("Waiting to init.");
 
-	/* Wait 1/4 a second, which should trigger the fallback */
-	g_usleep(250000);
-
-	g_debug("Initing");
 
 	GError * error = NULL;
 	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
@@ -69,6 +65,16 @@ main (int argv, char ** argc)
 	}
 
     DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+
+	gboolean has_owner = FALSE;
+	while (!has_owner) {
+		org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL);
+	}
+
+	g_usleep(250000);
+
+	g_debug("Initing");
+
 	guint nameret = 0;
 
 	if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) {
-- 
cgit v1.2.3


From bf13c7af125d97c2067da1b365ac4f11c2f2b943 Mon Sep 17 00:00:00 2001
From: Ted Gould <ted@gould.cx>
Date: Mon, 22 Feb 2010 12:56:03 -0600
Subject: Fall out of the while, sometime, if we really think it's not
 recoverable.

---
 tests/test-libappindicator-fallback-watcher.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'tests')

diff --git a/tests/test-libappindicator-fallback-watcher.c b/tests/test-libappindicator-fallback-watcher.c
index c632dff..70e01d1 100644
--- a/tests/test-libappindicator-fallback-watcher.c
+++ b/tests/test-libappindicator-fallback-watcher.c
@@ -67,8 +67,15 @@ main (int argv, char ** argc)
     DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
 
 	gboolean has_owner = FALSE;
-	while (!has_owner) {
+	gint owner_count = 0;
+	while (!has_owner && owner_count < 10000) {
 		org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL);
+		owner_count++;
+	}
+
+	if (owner_count == 10000) {
+		g_error("Unable to get name owner after 10000 tries");
+		return 1;
 	}
 
 	g_usleep(250000);
-- 
cgit v1.2.3