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-msg.h>
23
#include <tny-header.h>
24
25
#include <tny-camel-msg.h>
26
27
#include <camel/camel-folder.h>
28
#include <camel/camel.h>
29
#include <camel/camel-folder-summary.h>
30
31
/* We are going to test the camel implementation */
32
#include <tny-camel-header.h>
33
34
static TnyHeader *iface = NULL;
35
static TnyMsg *msg = NULL;
36
37
/* TODO: Check wether we are missing testing properties here */
38
39
static void
40
tny_header_test_setup (void)
41
{
42
	/* Don't ask me why, I think this is a Camel bug */
43
	CamelInternetAddress *addr = camel_internet_address_new ();
44
	camel_object_unref (CAMEL_OBJECT (addr));
45
46
	msg = TNY_MSG (tny_camel_msg_new ());
47
	iface = tny_msg_get_header (msg);
48
49
	return;
50
}
51
52
static void
53
tny_header_test_teardown (void)
54
{
55
	g_object_unref (G_OBJECT (iface));
56
	g_object_unref (G_OBJECT (msg));
57
58
59
	return;
60
}
61
62
START_TEST (tny_header_test_set_from)
63
{
64
	const gchar *str_in = "Me myself and I <me.myself@and.i.com>", *str_out;
65
	
66
	tny_header_set_from (iface, str_in);
67
	str_out = tny_header_dup_from (iface);
68
69
	fail_unless(!strcmp (str_in, str_out), "Unable to set from!\n");
70
71
        if (NULL != str_out)
72
        {
73
            g_free (str_out);
74
        }
75
76
	return;
77
}
78
END_TEST
79
80
START_TEST (tny_header_test_set_to)
81
{
82
	gchar *str_in = g_strdup ("Myself <this@is.me>, You Do Die Daa <you.doe.die@daa.com>; patrick@test.com");
83
	const gchar *str_out;
84
	int i=0;
85
	
86
	tny_header_set_to (iface, (const gchar*)str_in);
87
	str_out = tny_header_dup_to (iface);
88
89
	/* The implementation will always return a comma separated list
90
	 * but should also accept ; separated lists. Even mixed (both
91
	 * characters have the same meaning). */
92
93
	for (i=0; i < strlen(str_in); i++)
94
		if (str_in[i] == ';')
95
			str_in[i] = ',';
96
97
	fail_unless(!strcmp (str_in, str_out), "Unable to set to!\n");
98
99
	g_free (str_in);
100
101
        if (NULL != str_out)
102
        {
103
             g_free (str_out);
104
        }
105
106
	return;
107
}
108
END_TEST
109
110
START_TEST (tny_header_test_set_cc)
111
{
112
	const gchar *str_in = "First user <first@user.be>, Second user <second@user.com>", *str_out;
113
114
	tny_header_set_cc (iface, str_in);
115
	str_out = tny_header_dup_cc (iface);
116
117
	fail_unless(!strcmp (str_in, str_out), "Unable to set cc!\n");
118
119
        if (NULL != str_out)
120
        {
121
             g_free (str_out);
122
        }
123
124
	return;
125
}
126
END_TEST
127
128
START_TEST (tny_header_test_set_bcc)
129
{
130
	const gchar *str_in = "The Invisible man <the.invisible@man.com>, mark@here.there.com", *str_out;
131
132
	tny_header_set_bcc (iface, str_in);
133
	str_out = tny_header_dup_bcc (iface);
134
135
	fail_unless(!strcmp (str_in, str_out), "Unable to set bcc!\n");
136
137
        if (NULL != str_out)
138
        {
139
             g_free (str_out);
140
        }
141
142
	return;
143
}
144
END_TEST
145
146
START_TEST (tny_header_test_set_subject)
147
{
148
	const gchar *str_in = "I'm the nice subject", *str_out;
149
	
150
	tny_header_set_subject (iface, str_in);
151
	str_out = tny_header_dup_subject (iface);
152
153
	fail_unless(!strcmp (str_in, str_out), "Unable to set subject!\n");
154
155
        if (NULL != str_out)
156
        {
157
             g_free (str_out);
158
        }
159
160
        return;
161
        
162
}
163
END_TEST
164
165
START_TEST (tny_header_test_set_replyto)
166
{
167
168
	/* g_warning ("TODO"); */
169
170
	return;
171
}
172
END_TEST
173
174
START_TEST (tny_header_test_set_priority_flags)
175
{
176
	TnyHeaderFlags flags;
177
178
	tny_header_set_priority (iface, TNY_HEADER_FLAG_HIGH_PRIORITY);
179
	flags = tny_header_get_priority (iface);
180
	fail_unless (flags == TNY_HEADER_FLAG_HIGH_PRIORITY, "Unable to set high priority.\n");
181
182
	tny_header_set_priority (iface, TNY_HEADER_FLAG_NORMAL_PRIORITY);
183
	flags = tny_header_get_priority (iface);
184
	fail_unless (flags == TNY_HEADER_FLAG_NORMAL_PRIORITY, "Unable to set normal priority.\n");
185
186
	tny_header_set_priority (iface, TNY_HEADER_FLAG_LOW_PRIORITY);
187
	flags = tny_header_get_priority (iface);
188
	fail_unless (flags == TNY_HEADER_FLAG_LOW_PRIORITY, "Unable to set low priority.\n");
189
190
	return;
191
}
192
END_TEST
193
194
Suite *
195
create_tny_header_suite (void)
196
{
197
     Suite *s = suite_create ("Header");
198
     TCase *tc = NULL;
199
200
     tc = tcase_create ("Set Bcc");
201
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
202
     tcase_add_test (tc, tny_header_test_set_bcc);
203
     suite_add_tcase (s, tc);
204
205
     tc = tcase_create ("Set Cc");
206
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
207
     tcase_add_test (tc, tny_header_test_set_cc);
208
     suite_add_tcase (s, tc);
209
210
     tc = tcase_create ("Set To");
211
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
212
     tcase_add_test (tc, tny_header_test_set_to);
213
     suite_add_tcase (s, tc);
214
215
     tc = tcase_create ("Set From");
216
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
217
     tcase_add_test (tc, tny_header_test_set_from);
218
     suite_add_tcase (s, tc);
219
220
     tc = tcase_create ("Set Replyto");
221
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
222
     tcase_add_test (tc, tny_header_test_set_replyto);
223
     suite_add_tcase (s, tc);
224
225
     tc = tcase_create ("Set Subject");
226
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
227
     tcase_add_test (tc, tny_header_test_set_subject);
228
     suite_add_tcase (s, tc);
229
230
     tc = tcase_create ("Set priority flags");
231
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
232
     tcase_add_test (tc, tny_header_test_set_priority_flags);
233
     suite_add_tcase (s, tc);
234
235
     return s;
236
}