| 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-camel-msg.h> |
| 24 |
#include <tny-camel-header.h> |
| 25 |
#include <tny-list.h> |
| 26 |
#include <tny-iterator.h> |
| 27 |
#include <tny-simple-list.h> |
| 28 |
|
| 29 |
#include <camel/camel-folder.h> |
| 30 |
#include <camel/camel.h> |
| 31 |
#include <camel/camel-folder-summary.h> |
| 32 |
|
| 33 |
static TnyMsg *iface = NULL; |
| 34 |
static gchar *str; |
| 35 |
|
| 36 |
static void |
| 37 |
tny_msg_test_setup (void) |
| 38 |
{ |
| 39 |
/* Don't ask me why, I think this is a Camel bug */ |
| 40 |
CamelInternetAddress *addr = camel_internet_address_new (); |
| 41 |
camel_object_unref (CAMEL_OBJECT (addr)); |
| 42 |
|
| 43 |
iface = tny_camel_msg_new (); |
| 44 |
|
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
static void |
| 49 |
tny_msg_test_teardown (void) |
| 50 |
{ |
| 51 |
g_object_unref (G_OBJECT (iface)); |
| 52 |
|
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
START_TEST (tny_msg_test_add_part_del_part) |
| 58 |
{ |
| 59 |
|
| 60 |
gint length = 0; |
| 61 |
TnyList *parts = tny_simple_list_new(); |
| 62 |
TnyMimePart *part = tny_camel_mime_part_new (); |
| 63 |
|
| 64 |
tny_mime_part_add_part (TNY_MIME_PART (iface), part); |
| 65 |
|
| 66 |
tny_mime_part_get_parts (TNY_MIME_PART (iface), parts); |
| 67 |
length = tny_list_get_length (parts); |
| 68 |
g_object_unref (G_OBJECT (parts)); |
| 69 |
|
| 70 |
/* TnyMsg contains one part by itself */ |
| 71 |
str = g_strdup_printf ("Length must be exactly 2, received %d parts\n", length); |
| 72 |
fail_unless (length == 2, str); |
| 73 |
g_free (str); |
| 74 |
|
| 75 |
parts = tny_simple_list_new (); |
| 76 |
tny_mime_part_del_part (TNY_MIME_PART (iface), part); |
| 77 |
tny_mime_part_get_parts (TNY_MIME_PART (iface), parts); |
| 78 |
length = tny_list_get_length (parts); |
| 79 |
g_object_unref (G_OBJECT (parts)); |
| 80 |
|
| 81 |
str = g_strdup_printf ("Length must be exactly 1, received %d parts\n", length); |
| 82 |
fail_unless (length == 1, str); |
| 83 |
g_free (str); |
| 84 |
|
| 85 |
return; |
| 86 |
} |
| 87 |
END_TEST |
| 88 |
|
| 89 |
Suite * |
| 90 |
create_tny_msg_suite (void) |
| 91 |
{ |
| 92 |
Suite *s = suite_create ("Message"); |
| 93 |
TCase *tc = NULL; |
| 94 |
|
| 95 |
tc = tcase_create ("Add Part Delete Part"); |
| 96 |
tcase_add_checked_fixture (tc, tny_msg_test_setup, tny_msg_test_teardown); |
| 97 |
tcase_add_test (tc, tny_msg_test_add_part_del_part); |
| 98 |
/* Disabled because it fails. TODO: Enable again */ |
| 99 |
/* suite_add_tcase (s, tc); */ |
| 100 |
|
| 101 |
return s; |
| 102 |
} |