File: tny-header-test.c

package info (click to toggle)
libtinymail 0.0.9-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,148 kB
  • ctags: 19,175
  • sloc: ansic: 151,565; xml: 20,145; sh: 9,245; makefile: 2,394; cs: 243; cpp: 141; python: 93; perl: 71
file content (207 lines) | stat: -rw-r--r-- 5,792 bytes parent folder | download
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* tinymail - Tiny Mail unit test
 * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with self program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "check_libtinymail.h"

#include <tny-msg.h>
#include <tny-header.h>

#include <tny-camel-msg.h>

#include <camel/camel-folder.h>
#include <camel/camel.h>
#include <camel/camel-folder-summary.h>

/* We are going to test the camel implementation */
#include <tny-camel-header.h>

static TnyHeader *iface = NULL;
static TnyMsg *msg = NULL;

/* TODO: Check wether we are missing testing properties here */

static void
tny_header_test_setup (void)
{
	/* Don't ask me why, I think this is a Camel bug */
	CamelInternetAddress *addr = camel_internet_address_new ();
	camel_object_unref (CAMEL_OBJECT (addr));

	msg = TNY_MSG (tny_camel_msg_new ());
	iface = tny_msg_get_header (msg);

	return;
}

static void
tny_header_test_teardown (void)
{
	g_object_unref (G_OBJECT (iface));
	g_object_unref (G_OBJECT (msg));


	return;
}

START_TEST (tny_header_test_set_from)
{
	const gchar *str_in = "Me myself and I <me.myself@and.i.com>", *str_out;
	
	tny_header_set_from (iface, str_in);
	str_out = tny_header_get_from (iface);

	fail_unless(!strcmp (str_in, str_out), "Unable to set from!\n");

	return;
}
END_TEST

START_TEST (tny_header_test_set_to)
{
	gchar *str_in = g_strdup ("Myself <this@is.me>, You Do Die Daa <you.doe.die@daa.com>; patrick@test.com");
	const gchar *str_out;
	int i=0;
	
	tny_header_set_to (iface, (const gchar*)str_in);
	str_out = tny_header_get_to (iface);

	/* The implementation will always return a comma separated list
	 * but should also accept ; separated lists. Even mixed (both
	 * characters have the same meaning). */

	for (i=0; i < strlen(str_in); i++)
		if (str_in[i] == ';')
			str_in[i] = ',';

	fail_unless(!strcmp (str_in, str_out), "Unable to set to!\n");

	g_free (str_in);

	return;
}
END_TEST

START_TEST (tny_header_test_set_cc)
{
	const gchar *str_in = "First user <first@user.be>, Second user <second@user.com>", *str_out;

	tny_header_set_cc (iface, str_in);
	str_out = tny_header_get_cc (iface);

	fail_unless(!strcmp (str_in, str_out), "Unable to set cc!\n");

	return;
}
END_TEST

START_TEST (tny_header_test_set_bcc)
{
	const gchar *str_in = "The Invisible man <the.invisible@man.com>, mark@here.there.com", *str_out;

	tny_header_set_bcc (iface, str_in);
	str_out = tny_header_get_bcc (iface);

	fail_unless(!strcmp (str_in, str_out), "Unable to set bcc!\n");

	return;
}
END_TEST

START_TEST (tny_header_test_set_subject)
{
	const gchar *str_in = "I'm the nice subject", *str_out;
	
	tny_header_set_subject (iface, str_in);
	str_out = tny_header_get_subject (iface);

	fail_unless(!strcmp (str_in, str_out), "Unable to set subject!\n");
}
END_TEST

START_TEST (tny_header_test_set_replyto)
{

	/* g_warning ("TODO"); */

	return;
}
END_TEST

START_TEST (tny_header_test_set_priority_flags)
{
	TnyHeaderFlags flags;

	tny_header_set_priority (iface, TNY_HEADER_FLAG_HIGH_PRIORITY);
	flags = tny_header_get_priority (iface);
	fail_unless (flags == TNY_HEADER_FLAG_HIGH_PRIORITY, "Unable to set high priority.\n");

	tny_header_set_priority (iface, TNY_HEADER_FLAG_NORMAL_PRIORITY);
	flags = tny_header_get_priority (iface);
	fail_unless (flags == TNY_HEADER_FLAG_NORMAL_PRIORITY, "Unable to set normal priority.\n");

	tny_header_set_priority (iface, TNY_HEADER_FLAG_LOW_PRIORITY);
	flags = tny_header_get_priority (iface);
	fail_unless (flags == TNY_HEADER_FLAG_LOW_PRIORITY, "Unable to set low priority.\n");

	return;
}
END_TEST

Suite *
create_tny_header_suite (void)
{
     Suite *s = suite_create ("Header");
     TCase *tc = NULL;

     tc = tcase_create ("Set Bcc");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_bcc);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set Cc");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_cc);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set To");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_to);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set From");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_from);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set Replyto");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_replyto);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set Subject");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_subject);
     suite_add_tcase (s, tc);

     tc = tcase_create ("Set priority flags");
     tcase_add_checked_fixture (tc, tny_header_test_setup, tny_header_test_teardown);
     tcase_add_test (tc, tny_header_test_set_priority_flags);
     suite_add_tcase (s, tc);

     return s;
}