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
/* We are going to test the camel implementation */
23
#include <tny-camel-mime-part.h>
24
#include <tny-stream.h>
25
#include <tny-test-stream.h>
26
#include <tny-stream-camel.h>
27
#include <tny-camel-stream.h>
28
29
#include <camel/camel-folder.h>
30
#include <camel/camel.h>
31
#include <camel/camel-folder-summary.h>
32
33
34
static TnyMimePart *iface = NULL;
35
static gchar *str;
36
37
static void
38
tny_mime_part_test_setup (void)
39
{
40
	/* Don't ask me why, I think this is a Camel bug */
41
	CamelInternetAddress *addr = camel_internet_address_new ();
42
	camel_object_unref (CAMEL_OBJECT (addr));
43
44
	iface = tny_camel_mime_part_new ();
45
46
	return;
47
}
48
49
static void 
50
tny_mime_part_test_teardown (void)
51
{
52
	g_object_unref (G_OBJECT (iface));
53
54
	return;
55
}
56
57
START_TEST (tny_mime_part_test_set_content_location)
58
{
59
	const gchar *str_in = "testcontentlocation", *str_out;
60
	
61
	tny_mime_part_set_content_location (iface, str_in);
62
	str_out = tny_mime_part_get_content_location (iface);
63
64
	str = g_strdup_printf ("Unable to set content location! (%s) vs. (%s)\n",
65
		str_in, str_out);
66
67
	fail_unless(!strcmp (str_in, str_out), str);
68
69
	g_free (str);
70
71
	return;
72
}
73
END_TEST
74
75
76
START_TEST (tny_mime_part_test_set_description)
77
{
78
	const gchar *str_in = "test description", *str_out;
79
	
80
	tny_mime_part_set_description (iface, str_in);
81
	str_out = tny_mime_part_get_description (iface);
82
83
	fail_unless(!strcmp (str_in, str_out), "Unable to set description!\n");
84
85
	return;
86
}
87
END_TEST
88
89
START_TEST (tny_mime_part_test_set_content_id)
90
{
91
	const gchar *str_in = "testcontentid", *str_out;
92
	
93
	tny_mime_part_set_content_id (iface, str_in);
94
	str_out = tny_mime_part_get_content_id (iface);
95
96
	fail_unless(!strcmp (str_in, str_out), "Unable to set content id!\n");
97
98
	return;
99
}
100
END_TEST
101
    
102
START_TEST (tny_mime_part_test_set_filename)
103
{
104
	const gchar *str_in = "test_filename.txt", *str_out;
105
	
106
	tny_mime_part_set_filename (iface, str_in);
107
	str_out = tny_mime_part_get_filename (iface);
108
109
	fail_unless(!strcmp (str_in, str_out), "Unable to set filename!\n");
110
111
	return;
112
}
113
END_TEST
114
       
115
START_TEST (tny_mime_part_test_set_content_type)
116
{
117
	const gchar *str_in = "text/html", *str_out;
118
	
119
	tny_mime_part_set_content_type (iface, str_in);
120
	str_out = tny_mime_part_get_content_type (iface);
121
122
	fail_unless(!strcmp (str_in, str_out), "Unable to content type!\n");
123
124
	return;
125
}
126
END_TEST
127
128
START_TEST (tny_mime_part_test_stream)
129
{
130
	CamelStream *real_to = camel_stream_mem_new ();
131
	TnyStream *to = TNY_STREAM (tny_camel_stream_new (real_to));
132
133
/* TODO (this one crashes)
134
135
	tny_mime_part_construct (iface, from, "text/plain");
136
	tny_mime_part_write_to_stream (iface, to, NULL);
137
138
	while (!tny_stream_is_eos (to) && n < 1)
139
	{
140
		gchar buf[2];
141
		tny_stream_read (to, buf, sizeof (buf));
142
143
		buf[2] = '\0';
144
145
		fail_unless(!strcmp (buf, "42"), "Unable to stream!\n");
146
147
		n++;
148
	}
149
*/
150
	g_object_unref (G_OBJECT (to));
151
	camel_object_unref (CAMEL_OBJECT (real_to));
152
153
	return;
154
}
155
END_TEST
156
157
Suite *
158
create_tny_mime_part_suite (void)
159
{
160
     Suite *s = suite_create ("MIME Part");
161
     TCase *tc = NULL;
162
163
     tc = tcase_create ("Set Content Location");
164
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
165
     tcase_add_test (tc, tny_mime_part_test_set_content_location);
166
     suite_add_tcase (s, tc);
167
168
     tc = tcase_create ("Set Description");
169
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
170
     tcase_add_test (tc, tny_mime_part_test_set_description);
171
     suite_add_tcase (s, tc);
172
173
     tc = tcase_create ("Set Content ID");
174
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
175
     tcase_add_test (tc, tny_mime_part_test_set_content_id);
176
     suite_add_tcase (s, tc);
177
178
     tc = tcase_create ("Set Content Type");
179
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
180
     tcase_add_test (tc, tny_mime_part_test_set_content_type);
181
     suite_add_tcase (s, tc);
182
183
     tc = tcase_create ("Set Filename");
184
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
185
     tcase_add_test (tc, tny_mime_part_test_set_filename);
186
     suite_add_tcase (s, tc);
187
188
     tc = tcase_create ("Stream");
189
     tcase_add_checked_fixture (tc, tny_mime_part_test_setup, tny_mime_part_test_teardown);
190
     tcase_add_test (tc, tny_mime_part_test_stream);
191
     suite_add_tcase (s, tc);
192
193
     return s;
194
}