static void test_syntax (Fixture *f, gconstpointer arg) { const Test *test = arg; int i; g_assert (test != NULL); g_assert (test->function != NULL); g_assert (test->valid != NULL); g_assert (test->invalid != NULL); for (i = 0; test->valid[i] != NULL; i++) { dbus_bool_t ok = test->function (test->valid[i], &f->e); if (dbus_error_is_set (&f->e)) g_error ("%s was considered invalid: %s: %s", test->valid[i], f->e.name, f->e.message); if (!ok) g_error ("%s was considered invalid without an error", test->valid[i]); } for (i = 0; test->invalid[i] != NULL; i++) { dbus_bool_t ok = test->function (test->invalid[i], &f->e); if (ok) g_error ("%s should have been considered invalid", test->invalid[i]); if (!dbus_error_is_set (&f->e)) g_error ("%s should have an error set", test->invalid[i]); if (!dbus_validate_error_name (f->e.name, NULL)) g_error ("%s produced an invalid error name: %s", test->invalid[i], f->e.name); if (!dbus_validate_utf8 (f->e.message, NULL)) g_error ("%s produced an invalid error message: %s", test->invalid[i], f->e.message); dbus_error_free (&f->e); } }
int is_utf8_string(const char *string) { return !!dbus_validate_utf8(string, NULL); }