summaryrefslogtreecommitdiff
path: root/tests/libebook/test-ebook-get-supported-auth-methods.c
blob: 5f4e6f1c6d42d961d8af4548ab46457825ff21f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

#include <stdlib.h>
#include <libebook/e-book.h>

#include "ebook-test-utils.h"

static void
list_member_print_and_free (gchar     *member,
			    gpointer  user_data)
{
	test_print ("    %s\n", member);
	g_free (member);
}

static void
get_supported_auth_methods_cb (EBookTestClosure *closure)
{
	/* XXX: assuming an empty list is valid, we'll just print out anything
	 * we do get */
	if (closure->list) {
		EIterator *iter;
		const gchar *field;

		test_print ("supported auth methods:\n");
		iter = e_list_get_iterator (closure->list);
		while ((field = e_iterator_get (iter))) {
			test_print ("    %s\n", field);
			e_iterator_next (iter);
		}
		test_print ("----------------\n");
	}

	g_object_unref (closure->list);

	g_main_loop_quit ((GMainLoop*) (closure->user_data));
}

gint
main (gint argc, gchar **argv)
{
	EBook *book;
	GMainLoop *loop;
	GList *auth_methods;

	g_type_init ();

	/*
	 * Setup
	 */
	book = ebook_test_utils_book_new_temp (NULL);
	ebook_test_utils_book_open (book, FALSE);

	/*
	 * Sync version
	 */
	auth_methods = ebook_test_utils_book_get_supported_auth_methods (book);

	test_print ("successfully retrieved supported auth methods:\n");
	g_list_foreach (auth_methods, (GFunc) list_member_print_and_free, NULL);
	test_print ("----------------\n");
	g_list_free (auth_methods);

	/*
	 * Async version
	 */
	loop = g_main_loop_new (NULL, TRUE);
	ebook_test_utils_book_async_get_supported_auth_methods (book,
			(GSourceFunc) get_supported_auth_methods_cb, loop);

	g_main_loop_run (loop);

	ebook_test_utils_book_remove (book);

	return 0;
}