summaryrefslogtreecommitdiff
path: root/tests/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/client.c')
-rw-r--r--tests/client.c114
1 files changed, 94 insertions, 20 deletions
diff --git a/tests/client.c b/tests/client.c
index 4727e0c..1773ed1 100644
--- a/tests/client.c
+++ b/tests/client.c
@@ -58,7 +58,7 @@ queue_up_100_writes (DConfClient *client)
gint i;
/* We send 100 writes, letting them pile up.
- * At no time should there be more than 2 writes on the wire.
+ * At no time should there be more than one write on the wire.
*/
for (i = 0; i < 100; i++)
{
@@ -71,7 +71,7 @@ queue_up_100_writes (DConfClient *client)
check_and_free (dconf_client_read_full (client, "/test/value", DCONF_READ_DEFAULT_VALUE, NULL), NULL);
}
- g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), ==, 2);
+ g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), ==, 1);
}
static void
@@ -108,7 +108,6 @@ static void
test_fast (void)
{
DConfClient *client;
- gint i;
g_log_set_writer_func (log_writer_cb, NULL, NULL);
@@ -119,30 +118,23 @@ test_fast (void)
/* Start indicating that the writes failed.
*
- * For the first failures, we should continue to see the most recently
- * written value (99).
- *
- * After we fail that last one, we should see NULL returned.
+ * Because of the pending-merge logic, we should only have had to fail two calls.
*
* Each time, we should see a change notify.
*/
- for (i = 0; g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles) > 1; i++)
- {
- changed_was_called = FALSE;
- fail_one_call ();
- g_assert (changed_was_called);
+ g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), == , 1);
- check_and_free (dconf_client_read (client, "/test/value"), g_variant_new_int32 (99));
- check_and_free (dconf_client_read_full (client, "/test/value", DCONF_READ_DEFAULT_VALUE, NULL), NULL);
- }
+ changed_was_called = FALSE;
+ fail_one_call ();
+ g_assert (changed_was_called);
- /* Because of the pending-merging logic, we should only have had to
- * fail two calls.
- */
- g_assert (i == 2);
+ /* For the first failure, we should continue to see the most recently written value (99) */
+ check_and_free (dconf_client_read (client, "/test/value"), g_variant_new_int32 (99));
+ check_and_free (dconf_client_read_full (client, "/test/value", DCONF_READ_DEFAULT_VALUE, NULL), NULL);
+
+ g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), == , 1);
- /* Fail the last call. */
changed_was_called = FALSE;
fail_one_call ();
g_assert (changed_was_called);
@@ -151,11 +143,92 @@ test_fast (void)
check_and_free (dconf_client_read (client, "/test/value"), NULL);
check_and_free (dconf_client_read_full (client, "/test/value", DCONF_READ_DEFAULT_VALUE, NULL), NULL);
+ g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), == , 0);
+
/* Cleanup */
g_signal_handlers_disconnect_by_func (client, changed, NULL);
g_object_unref (client);
}
+static gboolean changed_a, changed_b, changed_c;
+
+static void
+coalesce_changed (DConfClient *client,
+ const gchar *prefix,
+ const gchar * const *changes,
+ const gchar *tag,
+ gpointer user_data)
+{
+ changed_a = g_str_equal (prefix, "/test/a") || g_strv_contains (changes, "a");
+ changed_b = g_str_equal (prefix, "/test/b") || g_strv_contains (changes, "b");
+ changed_c = g_str_equal (prefix, "/test/c") || g_strv_contains (changes, "c");
+}
+
+static void
+test_coalesce (void)
+{
+ gint i, a, b, c;
+ gboolean should_change_a, should_change_b, should_change_c;
+ g_autoptr(DConfClient) client = NULL;
+
+ gint changes[][3] = {
+ {1, 0, 0},
+ {1, 1, 1},
+ {0, 1, 1},
+ {0, 0, 1},
+ {0, 0, 0},
+ {1, 0, 0},
+ {1, 0, 0},
+ };
+
+ client = dconf_client_new ();
+ g_signal_connect (client, "changed", G_CALLBACK (coalesce_changed), NULL);
+
+ a = b = c = 0;
+
+ for (i = 0; i != G_N_ELEMENTS (changes); ++i)
+ {
+ g_autoptr(DConfChangeset) changeset = NULL;
+
+ should_change_a = changes[i][0];
+ should_change_b = changes[i][1];
+ should_change_c = changes[i][2];
+
+ changeset = dconf_changeset_new ();
+
+ if (should_change_a)
+ dconf_changeset_set (changeset, "/test/a", g_variant_new_int32 (++a));
+ if (should_change_b)
+ dconf_changeset_set (changeset, "/test/b", g_variant_new_int32 (++b));
+ if (should_change_c)
+ dconf_changeset_set (changeset, "/test/c", g_variant_new_int32 (++c));
+
+ changed_a = changed_b = changed_c = FALSE;
+
+ g_assert_true (dconf_client_change_fast (client, changeset, NULL));
+
+ /* Notifications should be only about keys we have just written. */
+ g_assert_cmpint (should_change_a, ==, changed_a);
+ g_assert_cmpint (should_change_b, ==, changed_b);
+ g_assert_cmpint (should_change_c, ==, changed_c);
+
+ /* We should see value from the most recent write or NULL if we haven't written it yet. */
+ check_and_free (dconf_client_read (client, "/test/a"), a == 0 ? NULL : g_variant_new_int32 (a));
+ check_and_free (dconf_client_read (client, "/test/b"), b == 0 ? NULL : g_variant_new_int32 (b));
+ check_and_free (dconf_client_read (client, "/test/c"), c == 0 ? NULL : g_variant_new_int32 (c));
+ }
+
+ dconf_mock_dbus_async_reply (g_variant_new ("(s)", "1"), NULL);
+ dconf_mock_dbus_async_reply (g_variant_new ("(s)", "2"), NULL);
+
+ /* There should be no more requests since all but first have been
+ * coalesced together. */
+ dconf_mock_dbus_assert_no_async ();
+
+ /* Cleanup */
+ g_signal_handlers_disconnect_by_func (client, changed, NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -167,6 +240,7 @@ main (int argc, char **argv)
g_test_add_func ("/client/lifecycle", test_lifecycle);
g_test_add_func ("/client/basic-fast", test_fast);
+ g_test_add_func ("/client/coalesce", test_coalesce);
return g_test_run ();
}