Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / tests / message / test4.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4  *
5  *  Copyright 2003 Ximian, Inc. (www.ximian.com)
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <dirent.h>
30
31 #include "camel-test.h"
32 #include "messages.h"
33
34 #include <camel/camel-multipart.h>
35 #include <camel/camel-mime-message.h>
36 #include <camel/camel-stream-fs.h>
37 #include <camel/camel-stream-mem.h>
38
39
40 #if 0
41 static void
42 dump_mime_struct (CamelMimePart *mime_part, int depth)
43 {
44         CamelDataWrapper *content;
45         char *mime_type;
46         int i = 0;
47         
48         while (i < depth) {
49                 printf ("   ");
50                 i++;
51         }
52         
53         content = camel_medium_get_content_object ((CamelMedium *) mime_part);
54         
55         mime_type = camel_data_wrapper_get_mime_type (content);
56         printf ("Content-Type: %s\n", mime_type);
57         g_free (mime_type);
58         
59         if (CAMEL_IS_MULTIPART (content)) {
60                 guint num, index = 0;
61                 
62                 num = camel_multipart_get_number ((CamelMultipart *) content);
63                 while (index < num) {
64                         mime_part = camel_multipart_get_part ((CamelMultipart *) content, index);
65                         dump_mime_struct (mime_part, depth + 1);
66                         index++;
67                 }
68         } else if (CAMEL_IS_MIME_MESSAGE (content)) {
69                 dump_mime_struct ((CamelMimePart *) content, depth + 1);
70         }
71 }
72 #endif
73
74 int main (int argc, char **argv)
75 {
76         struct dirent *dent;
77         DIR *dir;
78         int fd;
79         
80         camel_test_init (argc, argv);
81         
82         camel_test_start ("Message Test Suite");
83         
84         if (!(dir = opendir ("../data/messages")))
85                 return 77;
86         
87         while ((dent = readdir (dir)) != NULL) {
88                 CamelMimeMessage *message;
89                 CamelStream *stream;
90                 char *filename;
91                 struct stat st;
92                 
93                 if (dent->d_name[0] == '.')
94                         continue;
95                 
96                 filename = g_strdup_printf ("../data/messages/%s", dent->d_name);
97                 if (stat (filename, &st) == -1 || !S_ISREG (st.st_mode)) {
98                         g_free (filename);
99                         continue;
100                 }
101                 
102                 if ((fd = open (filename, O_RDONLY)) == -1) {
103                         g_free (filename);
104                         continue;
105                 }
106                 
107                 push ("testing message `%s`", filename);
108                 g_free (filename);
109                 
110                 stream = camel_stream_fs_new_with_fd (fd);
111                 message = camel_mime_message_new ();
112                 camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream);
113                 camel_stream_reset (stream);
114                 
115                 /*dump_mime_struct ((CamelMimePart *) message, 0);*/
116                 test_message_compare (message);
117                 
118                 camel_object_unref (message);
119                 camel_object_unref (stream);
120                 
121                 pull ();
122         }
123         
124         closedir (dir);
125         
126         camel_test_end ();
127         
128         return 0;
129 }