static void
test_get_view_sync (ETestServerFixture *fixture,
                    gconstpointer user_data)
{
	EBookClient *book_client;
	EBookQuery *query;
	EBookClientView *view;
	gchar *sexp;
	GError *error = NULL;
	UIDOnlyClosure *closure = (UIDOnlyClosure *) user_data;

	uids_only = closure->uids_only;

	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);

	setup_book (book_client);

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
		g_error ("get book view sync: %s", error->message);
		g_free (sexp);
		g_object_unref (book_client);
	}

	g_free (sexp);

	setup_and_start_view (view, fixture->loop);
	g_main_loop_run (fixture->loop);
}
gint
main (gint argc,
      gchar **argv)
{
	EBook *book;
	EBookQuery *query;
	EBookView *view;

	g_type_init ();

	/*
	 * Sync version
	 */
	setup_book (&book);
	query = e_book_query_any_field_contains ("");
	ebook_test_utils_book_get_book_view (book, query, &view);
	setup_and_start_view (view);

	test_print ("successfully set up the book view\n");

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);

	e_book_query_unref (query);
	ebook_test_utils_book_remove (book);

	/*
	 * Async version
	 */
	setup_book (&book);
	query = e_book_query_any_field_contains ("");

	loop = g_main_loop_new (NULL, TRUE);
	ebook_test_utils_book_async_get_book_view (book, query,
			(GSourceFunc) get_book_view_cb, loop);

	g_main_loop_run (loop);

	e_book_query_unref (query);
	ebook_test_utils_book_remove (book);

	return 0;
}
gint
main (gint argc,
      gchar **argv)
{
	EBookClient *book;
	EBookClientView *view;
	EBookQuery *query;
	GError     *error = NULL;
	gchar      *sexp;

	g_type_init ();

	setup_book (&book);

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book, sexp, &view, NULL, &error)) {
		report_error ("get book view sync", &error);
		g_free (sexp);
		g_object_unref (book);

		return 1;
	}

	g_free (sexp);

	setup_and_start_view (view);

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);

	if (!e_client_remove_sync (E_CLIENT (book), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book);

		return 1;
	}

	g_object_unref (book);

	return 0;
}
static void
test_get_book_view_async (ETestServerFixture *fixture,
                          gconstpointer user_data)
{
	EBook *book;
	EBookQuery *query;

	book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBook);
	setup_book (book);

	query = e_book_query_any_field_contains ("");

	ebook_test_utils_book_async_get_book_view (
		book, query,
			(GSourceFunc) get_book_view_cb, fixture->loop);

	g_timeout_add_seconds (5, (GSourceFunc) main_loop_fail_timeout, NULL);
	g_main_loop_run (fixture->loop);
	e_book_query_unref (query);
}
static void
test_get_view_async (ETestServerFixture *fixture,
                     gconstpointer user_data)
{
	EBookClient *book_client;
	EBookQuery *query;
	gchar *sexp;

	book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);

	setup_book (book_client);
	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);

	e_book_client_get_view (book_client, sexp, NULL, get_view_cb, fixture->loop);

	g_free (sexp);
	g_main_loop_run (fixture->loop);
}
static void
test_get_book_view_sync (ETestServerFixture *fixture,
                         gconstpointer user_data)
{
	EBook *book;
	EBookQuery *query;
	EBookView *view;

	book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBook);
	setup_book (book);

	query = e_book_query_any_field_contains ("");
	ebook_test_utils_book_get_book_view (book, query, &view);
	setup_and_start_view (view, fixture->loop);

	test_print ("successfully set up the book view\n");

	g_main_loop_run (fixture->loop);

	e_book_query_unref (query);
}
gint
main (gint argc,
      gchar **argv)
{
	EBookClient *book_client;
	EBookQuery *query;
	EBookClientView *view;
	gchar *sexp;
	GError *error = NULL;

	main_initialize ();

	/*
	 * Sync version
	 */
	if (!setup_book (&book_client))
		return 1;

	query = e_book_query_any_field_contains ("");
	sexp = e_book_query_to_string (query);
	e_book_query_unref (query);
	if (!e_book_client_get_view_sync (book_client, sexp, &view, NULL, &error)) {
		report_error ("get book view sync", &error);
		g_free (sexp);
		g_object_unref (book_client);

		return 1;
	}

	g_free (sexp);

	setup_and_start_view (view);
	start_main_loop (NULL, NULL);

	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book_client);

		return 1;
	}
	g_object_unref (book_client);

	/*
	 * Async version uids only
	 */
	if (!setup_book (&book_client))
		return 1;

	start_in_idle_with_main_loop (call_get_view, book_client);

	if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) {
		report_error ("client remove sync", &error);
		g_object_unref (book_client);

		return 1;
	}

	g_object_unref (book_client);

	return get_main_loop_stop_result ();
}