* bounce back an error message.
*/
- if (!_dbus_string_init (&error_message, _DBUS_INT_MAX))
+ if (!_dbus_string_init (&error_message))
{
BUS_SET_OOM (error);
return FALSE;
return FALSE;
}
- _dbus_string_get_const_data (&error_message, &error_str);
+ error_str = _dbus_string_get_const_data (&error_message);
error_reply = dbus_message_new_error_reply (in_reply_to,
DBUS_ERROR_SERVICE_DOES_NOT_EXIST,
error_str);
return TRUE;
}
-static void
-check1_try_iterations (BusContext *context,
- const char *description,
- Check1Func func)
+typedef struct
{
- int approx_mallocs;
-
- /* Run once to see about how many mallocs are involved */
-
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
-
- if (! (*func) (context))
- _dbus_assert_not_reached ("test failed");
+ Check1Func func;
+ BusContext *context;
+} Check1Data;
- approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
+static dbus_bool_t
+check_oom_check1_func (void *data)
+{
+ Check1Data *d = data;
- _dbus_verbose ("=================\n%s: about %d mallocs total\n=================\n",
- description, approx_mallocs);
-
- approx_mallocs += 10; /* fudge factor */
-
- /* Now run failing each malloc */
+ if (! (* d->func) (d->context))
+ return FALSE;
- while (approx_mallocs >= 0)
+ if (!check_no_leftovers (d->context))
{
- _dbus_set_fail_alloc_counter (approx_mallocs);
-
- _dbus_verbose ("\n===\n %s: (will fail malloc %d)\n===\n",
- description, approx_mallocs);
+ _dbus_warn ("Messages were left over, should be covered by test suite");
+ return FALSE;
+ }
- if (! (*func) (context))
- _dbus_assert_not_reached ("test failed");
+ return TRUE;
+}
- if (!check_no_leftovers (context))
- _dbus_assert_not_reached ("Messages were left over, should be covered by test suite");
-
- approx_mallocs -= 1;
- }
+static void
+check1_try_iterations (BusContext *context,
+ const char *description,
+ Check1Func func)
+{
+ Check1Data d;
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
+ d.func = func;
+ d.context = context;
- _dbus_verbose ("=================\n%s: all iterations passed\n=================\n",
- description);
+ if (!_dbus_test_oom_handling (description, check_oom_check1_func,
+ &d))
+ _dbus_assert_not_reached ("test failed");
}
dbus_bool_t
bus_dispatch_test (const DBusString *test_data_dir)
{
BusContext *context;
- DBusError error;
- const char *activation_dirs[] = { NULL, NULL };
DBusConnection *foo;
DBusConnection *bar;
DBusConnection *baz;
+ DBusError error;
+
+ context = bus_context_new_test (test_data_dir,
+ "valid-config-files/debug-allow-all.conf");
+ if (context == NULL)
+ return FALSE;
dbus_error_init (&error);
- context = bus_context_new ("debug-pipe:name=test-server",
- activation_dirs,
- &error);
- if (context == NULL)
- _dbus_assert_not_reached ("could not alloc context");
foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
if (foo == NULL)