1
/* tinymail - Tiny Mail unit test
2
 * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with self library; if not, write to the
16
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "check_libtinymail.h"
21
22
#include <tny-account.h>
23
#include <tny-folder-store.h>
24
25
#include <tny-camel-store-account.h>
26
#include <tny-list.h>
27
#include <tny-iterator.h>
28
#include <tny-simple-list.h>
29
#include <tny-account-store.h>
30
#include <tny-store-account.h>
31
#include <tny-folder.h>
32
#include <tny-camel-header.h>
33
34
#include <account-store.h>
35
36
static TnyAccount *iface = NULL;
37
static TnyAccountStore *account_store;
38
static gboolean online_tests=FALSE;
39
static gchar *str;
40
41
static void
42
tny_account_test_setup (void)
43
{
44
    TnyList *accounts;
45
    TnyIterator *aiter;
46
    iface = NULL;
47
    
48
    if (online_tests)
49
    {
50
	accounts = tny_simple_list_new ();
51
	account_store = tny_test_account_store_new (TRUE, NULL);
52
	tny_account_store_get_accounts (account_store, accounts, 
53
			TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
54
55
	aiter = tny_list_create_iterator (accounts);
56
	iface = TNY_ACCOUNT (tny_iterator_get_current (aiter));
57
    
58
    	if (!iface)
59
		online_tests = FALSE;
60
	
61
    }
62
    
63
    if (!iface)
64
	    iface = TNY_ACCOUNT (tny_camel_store_account_new ());
65
    
66
   return;
67
}
68
69
static void 
70
tny_account_test_teardown (void)
71
{
72
     /* TODO: Find out why tests fail when objects are unref'ed */
73
/*     	g_object_unref (G_OBJECT (iface)); */
74
/* 	g_object_unref (G_OBJECT (aiter)); */
75
/* 	g_object_unref (G_OBJECT (accounts)); */
76
    
77
	return;
78
}
79
80
START_TEST (tny_store_account_test_get_folders)
81
{
82
    	TnyList *folders = NULL;
83
    
84
      	if (!online_tests)
85
	    	return;
86
    
87
    	folders = tny_simple_list_new ();
88
    
89
    	tny_folder_store_get_folders (TNY_FOLDER_STORE (iface),
90
			folders, NULL, TRUE, NULL);
91
        
92
    	fail_unless (tny_list_get_length (folders) == 1, 
93
		"Account should have at least an inbox folder\n");
94
    
95
    	g_object_unref (G_OBJECT (folders));
96
    
97
    	return;
98
}
99
END_TEST
100
101
START_TEST (tny_account_test_get_account_type)
102
{
103
	fail_unless (tny_account_get_account_type (iface) == TNY_ACCOUNT_TYPE_STORE,
104
		"Account type should be store\n");
105
}
106
END_TEST
107
108
START_TEST (tny_account_test_set_hostname)
109
{
110
	const gchar *str_in = "imap.imapserver.com", *str_out;
111
112
	tny_account_set_hostname (iface, str_in);
113
	str_out = tny_account_get_hostname (iface);
114
115
	str = g_strdup_printf ("Unable to set hostname to %s, it became %s\n", str_in, str_out);
116
	fail_unless (!strcmp (str_in, str_out), str);
117
	g_free (str);
118
}
119
END_TEST
120
121
START_TEST (tny_account_test_set_user)
122
{
123
	const gchar *str_in = "myusername", *str_out;
124
125
	tny_account_set_user (iface, str_in);
126
	str_out = tny_account_get_user (iface);
127
128
	str = g_strdup_printf ("Unable to set user to %s, it became %s\n", str_in, str_out);
129
	fail_unless (!strcmp (str_in, str_out), str);
130
	g_free (str);
131
}
132
END_TEST
133
134
START_TEST (tny_account_test_set_id)
135
{
136
	const gchar *str_in = "THE_ID", *str_out;
137
138
	tny_account_set_id (iface, str_in);
139
	str_out = tny_account_get_id (iface);
140
141
	str = g_strdup_printf ("Unable to set id to %s, it became %s\n", str_in, str_out);
142
	fail_unless (!strcmp (str_in, str_out), str);
143
	g_free (str);
144
}
145
END_TEST
146
147
START_TEST (tny_account_test_set_name)
148
{
149
	const gchar *str_in = "The name of the account", *str_out;
150
151
	tny_account_set_name (iface, str_in);
152
	str_out = tny_account_get_name (iface);
153
154
	str = g_strdup_printf ("Unable to set name to %s, it became %s\n", str_in, str_out);
155
	fail_unless (!strcmp (str_in, str_out), str);
156
	g_free (str);
157
}
158
END_TEST
159
160
START_TEST (tny_account_test_set_proto)
161
{
162
	const gchar *str_in = "imap", *str_out;
163
164
	tny_account_set_proto (iface, str_in);
165
	str_out = tny_account_get_proto (iface);
166
167
	str = g_strdup_printf ("Unable to set proto to %s, it became %s\n", str_in, str_out);
168
	fail_unless (!strcmp (str_in, str_out), str);
169
	g_free (str);
170
}
171
END_TEST
172
173
Suite *
174
create_tny_account_suite (void)
175
{
176
     Suite *s = suite_create ("Account");
177
     TCase *tc = NULL;
178
179
     tc = tcase_create ("Get Account Type");
180
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
181
     tcase_add_test (tc, tny_account_test_get_account_type);
182
     suite_add_tcase (s, tc);
183
184
     tc = tcase_create ("Set Hostname");
185
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
186
     tcase_add_test (tc, tny_account_test_set_hostname);
187
     suite_add_tcase (s, tc);
188
189
     tc = tcase_create ("Set User");
190
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
191
     tcase_add_test (tc, tny_account_test_set_user);
192
     suite_add_tcase (s, tc);
193
194
     tc = tcase_create ("Set ID");
195
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
196
     tcase_add_test (tc, tny_account_test_set_id);
197
     suite_add_tcase (s, tc);
198
199
     tc = tcase_create ("Set Protocol");
200
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
201
     tcase_add_test (tc, tny_account_test_set_proto);
202
     suite_add_tcase (s, tc);
203
204
     tc = tcase_create ("Set Name");
205
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
206
     tcase_add_test (tc, tny_account_test_set_name);
207
     suite_add_tcase (s, tc);
208
209
     tc = tcase_create ("Store Account Get Folders");
210
     tcase_add_checked_fixture (tc, tny_account_test_setup, tny_account_test_teardown);
211
     tcase_add_test (tc, tny_store_account_test_get_folders);
212
     suite_add_tcase (s, tc);
213
214
     return s;
215
}