File: test-book-cache-create-cursor.c

package info (click to toggle)
evolution-data-server 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,108 kB
  • sloc: ansic: 365,415; xml: 578; cpp: 482; perl: 297; sh: 62; makefile: 60; python: 35; javascript: 29
file content (128 lines) | stat: -rw-r--r-- 3,973 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <locale.h>
#include <libebook/libebook.h>

#include "e-test-server-utils.h"
#include "test-book-cache-utils.h"

static TCUClosure closure = { NULL };

static void
test_create_cursor_empty_query (TCUFixture *fixture,
				gconstpointer user_data)
{
	EBookCacheCursor *cursor;
	EContactField sort_fields[] = { E_CONTACT_FAMILY_NAME, E_CONTACT_GIVEN_NAME };
	EBookCursorSortType sort_types[] = { E_BOOK_CURSOR_SORT_ASCENDING, E_BOOK_CURSOR_SORT_ASCENDING };
	GError *error = NULL;

	cursor = e_book_cache_cursor_new (
		fixture->book_cache, NULL,
		sort_fields, sort_types, 2, &error);

	g_assert_true (cursor != NULL);
	e_book_cache_cursor_free (fixture->book_cache, cursor);
}

static void
test_create_cursor_valid_query (TCUFixture *fixture,
				gconstpointer user_data)
{
	EBookCacheCursor *cursor;
	EContactField sort_fields[] = { E_CONTACT_FAMILY_NAME, E_CONTACT_GIVEN_NAME };
	EBookCursorSortType sort_types[] = { E_BOOK_CURSOR_SORT_ASCENDING, E_BOOK_CURSOR_SORT_ASCENDING };
	EBookQuery *query;
	gchar *sexp;
	GError *error = NULL;

	query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, "James Brown");
	sexp = e_book_query_to_string (query);

	cursor = e_book_cache_cursor_new (
		fixture->book_cache, sexp,
		sort_fields, sort_types, 2, &error);

	g_assert_true (cursor != NULL);
	e_book_cache_cursor_free (fixture->book_cache, cursor);
	g_free (sexp);
	e_book_query_unref (query);
}

static void
test_create_cursor_invalid_sort (TCUFixture *fixture,
				 gconstpointer user_data)
{
	EBookCacheCursor *cursor;
	EContactField sort_fields[] = { E_CONTACT_TEL };
	EBookCursorSortType sort_types[] = { E_BOOK_CURSOR_SORT_ASCENDING };
	GError *error = NULL;

	cursor = e_book_cache_cursor_new (
		fixture->book_cache, NULL,
		sort_fields, sort_types, 1, &error);

	g_assert_true (cursor == NULL);
	g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_INVALID_QUERY);
	g_clear_error (&error);
}

static void
test_create_cursor_missing_sort (TCUFixture *fixture,
				 gconstpointer user_data)
{
	EBookCacheCursor *cursor;
	GError *error = NULL;

	cursor = e_book_cache_cursor_new (fixture->book_cache, NULL, NULL, NULL, 0, &error);

	g_assert_true (cursor == NULL);
	g_assert_error (error, E_CACHE_ERROR, E_CACHE_ERROR_INVALID_QUERY);
	g_clear_error (&error);
}

gint
main (gint argc,
      gchar **argv)
{
#if !GLIB_CHECK_VERSION (2, 35, 1)
	g_type_init ();
#endif
	g_test_init (&argc, &argv, NULL);
	g_test_bug_base ("https://gitlab.gnome.org/GNOME/evolution-data-server/");

	tcu_read_args (argc, argv);

	/* Ensure that the client and server get the same locale */
	g_assert_true (g_setenv ("LC_ALL", "en_US.UTF-8", TRUE));
	setlocale (LC_ALL, "");

	g_test_add (
		"/EBookCacheCursor/Create/EmptyQuery", TCUFixture, &closure,
		tcu_fixture_setup, test_create_cursor_empty_query, tcu_fixture_teardown);
	g_test_add (
		"/EBookCacheCursor/Create/ValidQuery", TCUFixture, &closure,
		tcu_fixture_setup, test_create_cursor_valid_query, tcu_fixture_teardown);
	g_test_add (
		"/EBookCacheCursor/Create/InvalidSort", TCUFixture, &closure,
		tcu_fixture_setup, test_create_cursor_invalid_sort, tcu_fixture_teardown);
	g_test_add (
		"/EBookCacheCursor/Create/MissingSort", TCUFixture, &closure,
		tcu_fixture_setup, test_create_cursor_missing_sort, tcu_fixture_teardown);

	return e_test_server_utils_run_full (argc, argv, 0);
}