message service dependency removed
[platform/core/messaging/email-service.git] / test / testapp-others.c
1 /*
2 *  email-service
3 *
4 * Copyright(c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7 *
8 * Licensed under the Apache License, Version 2.0(the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23 /* common header */
24 #include <stdio.h>
25 #include <string.h>
26
27 /* open header */
28 #include <glib.h>
29 #include <dlfcn.h>
30 #include <vconf.h>
31 #include "c-client.h"
32
33
34 #include "email-api.h"
35 #include "email-api-account.h"
36 #include "email-api-network.h"
37
38
39 /* internal header */
40 #include "testapp-utility.h"
41 #include "testapp-others.h"
42 #include "email-ipc.h"
43 #include "email-core-utils.h"
44
45 static gboolean testapp_test_ping_service()
46 {
47         if (email_ping_service() < 0)
48                 testapp_print("email_ping_service failed..!");
49
50         return FALSE;
51 }
52
53 static gboolean testapp_test_cancel_job()
54 {
55         int account_id = 0;
56         int handle = 0;
57
58         testapp_print("\n > Enter account_id(0: all account): ");
59         if (0 >= scanf("%d", &account_id))
60                 testapp_print("Invalid input. ");
61
62         testapp_print("\n > Enter handle: ");
63         if (0 >= scanf("%d", &handle))
64                 testapp_print("Invalid input. ");
65
66         if (email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
67                 testapp_print("email_cancel_job failed..!");
68         return FALSE;
69 }
70
71 static gboolean testapp_test_init_storage()
72 {
73         if (email_init_storage() < 0)
74                 testapp_print("email_init_storaege failed..!");
75
76         return FALSE;
77 }
78
79 static gboolean testapp_test_set_dnet_proper_profile_type()
80 {
81         testapp_print("NOT Support\n");
82
83         return TRUE;
84 }
85
86 static gboolean testapp_test_get_dnet_proper_profile_type()
87 {
88         testapp_print("NOT Support\n");
89
90         return TRUE;
91 }
92
93 static gboolean testapp_test_get_preview_text_from_file()
94 {
95         char *preview_buffer = NULL;
96         char  html_file_path[1024] = { 0, };
97
98         testapp_print("\n > Enter file path : ");
99         if (0 >= scanf("%s", html_file_path))
100                 testapp_print("Invalid input. ");
101
102         emcore_get_preview_text_from_file(NULL, NULL, html_file_path, 1024, &preview_buffer);
103
104         testapp_print("\n result :\n %s ", preview_buffer);
105
106         return TRUE;
107 }
108
109 static gboolean testapp_test_get_task_information()
110 {
111         int i = 0;
112         int err = EMAIL_ERROR_NONE;
113         int task_information_count = 0;
114         email_task_information_t *task_information_array = NULL;
115
116
117         err = email_get_task_information(&task_information_array, &task_information_count);
118
119         testapp_print("\n======================================================================\n");
120         for (i = 0; i < task_information_count; i++)
121                 testapp_print("type[%d], account_id[%d], handle[%d], status[%d] nth[%d] progress[%d] mail_id[%d]", task_information_array[i].type, task_information_array[i].account_id, task_information_array[i].handle, task_information_array[i].status,(int)task_information_array[i].task_data2, (int)task_information_array[i].task_data3, task_information_array[i].task_data1 );
122         testapp_print("\n======================================================================\n");
123
124         testapp_print("testapp_test_get_task_information  ..........End\n");
125
126         return err;
127 }
128
129 static gboolean testapp_test_create_db_full()
130 {
131         int err;
132
133         err = email_create_db_full();
134
135         testapp_print("testapp_test_create_db_full returns [%d]", err);
136
137         return err;
138 }
139
140 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
141 {
142         unsigned char *content = NULL;
143         int ret = true;
144         int err = EMAIL_ERROR_NONE;
145
146         if (err_code != NULL) {
147                 *err_code = EMAIL_ERROR_NONE;
148         }
149
150         content = rfc822_binary(src, src_len, enc_len);
151
152         if (content)
153                 *enc = (char *)content;
154         else {
155                 err = EMAIL_ERROR_UNKNOWN;
156                 ret = false;
157         }
158
159         if (err_code)
160             *err_code = err;
161
162         return ret;
163 }
164
165
166 static gboolean testapp_test_encoding_test()
167 {
168         int error = EMAIL_ERROR_NONE;
169         int has_special_character = 0, base64_file_name_length = 0, i;
170         gsize bytes_read, bytes_written;
171         char *encoded_file_name = NULL, *base64_file_name = NULL;
172         SIZEDTEXT source_text;
173         GError *glib_error = NULL;
174         CHARSET *result_charset = NULL;
175         char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
176
177         source_text.data = (unsigned char*)filename;
178         source_text.size = strlen(filename);
179
180         result_charset = (CHARSET*)utf8_infercharset(&source_text);
181
182         if (result_charset) {
183                 testapp_print("return_charset->name [%s]", result_charset->name);
184                 encoded_file_name = (char*)g_convert(filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
185         } else {
186                 i = 0;
187                 while (filename[i++] & 0x80)
188                         has_special_character = 1;
189                 testapp_print("has_special_character [%d]", has_special_character);
190                 if (has_special_character)
191                         encoded_file_name = (char*)g_convert(filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
192         }
193
194         if (encoded_file_name == NULL)
195                 encoded_file_name = strdup(filename);
196
197         testapp_print("encoded_file_name [%s]", encoded_file_name);
198
199         if (!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
200                 testapp_print("encode_base64 failed. error [%d]", error);
201                 goto FINISH_OFF;
202         }
203
204         testapp_print("base64_file_name [%s]", base64_file_name);
205
206         if (base64_file_name) {
207                 free(encoded_file_name);
208                 encoded_file_name = malloc(strlen(base64_file_name) + 15);
209                 if (!encoded_file_name) {
210                         testapp_print("em_malloc failed.");
211                         goto FINISH_OFF;
212                 }
213                 snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
214                 testapp_print("encoded_file_name [%s]", encoded_file_name);
215         }
216 FINISH_OFF:
217
218         if (encoded_file_name)
219                 free(encoded_file_name);
220
221         if (base64_file_name)
222                 free(base64_file_name);
223         free(glib_error);
224
225         return error;
226 }
227
228 #define LIB_EMAIL_SERVICE_PATH  "/usr/lib/libemail-api.so"
229
230 int(*Datastore_FI_EMTB)(char **);
231 int(*Datastore_FI_EMSB)(char **);
232 int(*Datastore_FI_EMOB)(char **);
233 int(*Datastore_FI_EMDR)(char **);
234 int(*Datastore_FI_EMMF)(char **);
235 int(*Datastore_FI_EMTR)(char **);
236 int(*Datastore_FI_EMSP)(char **);
237
238 static gboolean email_test_dtt_Datastore_FI()
239 {
240         void *handle = NULL;
241         char *dl_error = NULL, *output_str = NULL;
242
243         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
244         if (!handle) {
245                 dl_error = dlerror();
246                 if (dl_error)
247                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
248                 return false;
249         }
250
251         Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
252         Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
253         Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
254         Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
255         Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
256         Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
257         Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
258
259         Datastore_FI_EMTB(&output_str);
260
261         testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
262
263         if (output_str)
264                 free(output_str);
265
266         if (handle) {
267                 dlclose(handle);
268                 dl_error = dlerror();
269                 if (dl_error)
270                         testapp_print("\t Close handle return  :  %s\n", dl_error);
271         }
272
273         return true;
274 }
275
276 int(*Datastore_R_EMTB)(char **);
277 int(*Datastore_R_EMSB)(char **);
278 int(*Datastore_R_EMOB)(char **);
279 int(*Datastore_R_EMDR)(char **);
280 int(*Datastore_R_EMMF)(char **);
281 int(*Datastore_R_EMTR)(char **);
282 int(*Datastore_R_EMSP)(char **);
283
284
285 static gboolean email_test_dtt_Datastore_R()
286 {
287         void *handle = NULL;
288         char *dl_error = NULL, *output_str = NULL;
289
290         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
291         if (!handle) {
292                 dl_error = dlerror();
293                 if (dl_error)
294                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
295                 return false;
296         }
297
298         Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
299         Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
300         Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
301         Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
302         Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
303         Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
304         Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
305
306         Datastore_R_EMTB(&output_str);
307
308         testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
309
310         if (output_str)
311                 free(output_str);
312
313         if (handle) {
314                 dlclose(handle);
315                 dl_error = dlerror();
316                 if (dl_error)
317                         testapp_print("\t Close handle return  :  %s\n", dl_error);
318         }
319
320         return true;
321 }
322
323 int(*Datastore_C_EMTB)(char **);
324 int(*Datastore_C_EMSB)(char **);
325 int(*Datastore_C_EMOB)(char **);
326 int(*Datastore_C_EMDR)(char **);
327 int(*Datastore_C_EMMF)(char **);
328 int(*Datastore_C_EMTR)(char **);
329 int(*Datastore_C_EMSP)(char **);
330
331 static gboolean email_test_dtt_Datastore_C()
332 {
333         void *handle = NULL;
334         char *dl_error = NULL, *output_str = NULL;
335
336         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
337         if (!handle) {
338                 dl_error = dlerror();
339                 if (dl_error)
340                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
341                 return false;
342         }
343
344         Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
345         Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
346         Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
347         Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
348         Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
349         Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
350         Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
351
352         Datastore_C_EMTB(&output_str);
353
354
355         testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
356
357         if (output_str)
358                 free(output_str);
359
360         if (handle) {
361                 dlclose(handle);
362                 dl_error = dlerror();
363                 if (dl_error)
364                         testapp_print("\t Close handle return  :  %s\n", dl_error);
365         }
366
367         return true;
368 }
369
370 static gboolean testapp_test_show_user_message()
371 {
372         int mail_id;
373
374         testapp_print("\n > Enter mail id : ");
375         if (0 >= scanf("%d", &mail_id))
376                 testapp_print("Invalid input. ");
377
378         email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
379         return FALSE;
380 }
381
382 static gboolean testapp_test_get_mime_entity()
383 {
384         char mime_path[512] = {0, };
385         char *mime_entity = NULL;
386
387         testapp_print("\n > Enter mime path for parsing : ");
388         if (0 >= scanf("%s", mime_path))
389                 testapp_print("Invalid input. ");
390
391         email_get_mime_entity(mime_path, &mime_entity);
392
393         testapp_print("\nmime_entity = %s\n", mime_entity);
394         return true;
395 }
396
397 static gboolean testapp_test_query_smtp_mail_size_limit()
398 {
399         int account_id = 0;
400         testapp_print("\n > Enter account id : ");
401         if (0 >= scanf("%d", &account_id))
402                 testapp_print("Invalid input. ");
403
404         email_query_smtp_mail_size_limit(account_id, NULL);
405         return true;
406 }
407
408 static gboolean testapp_test_verify_email_address()
409 {
410         int err = EMAIL_ERROR_NONE;
411         char email_address[512] = {0, };
412
413         testapp_print("\n > Enter mime path for parsing : ");
414         if (0 >= scanf("%s", email_address))
415                 testapp_print("Invalid input. ");
416
417         err = email_verify_email_address(email_address);
418
419         testapp_print("\nemail_verify_email_address returns [%d]\n", err);
420         return true;
421 }
422
423
424
425 static gboolean testapp_test_interpret_command(int menu_number)
426 {
427         gboolean go_to_loop = TRUE;
428
429         switch (menu_number) {
430                 case 1:
431                         testapp_test_ping_service();
432                         break;
433                 case 2:
434                         testapp_test_init_storage();
435                         break;
436                 case 3:
437                         testapp_test_cancel_job();
438                         break;
439                 case 5:
440                         testapp_test_set_dnet_proper_profile_type();
441                         break;
442                 case 6:
443                         testapp_test_get_dnet_proper_profile_type();
444                         break;
445                 case 7:
446                         testapp_test_get_preview_text_from_file();
447                         break;
448                 case 11:
449                         testapp_test_get_task_information();
450                         break;
451                 case 12:
452                         testapp_test_create_db_full();
453                         break;
454                 case 13:
455                         testapp_test_encoding_test();
456                         break;
457                 case 14:
458                         email_test_dtt_Datastore_FI();
459                         email_test_dtt_Datastore_C();
460                         email_test_dtt_Datastore_R();
461                         break;
462                 case 15:
463                         testapp_test_show_user_message();
464                         break;
465                 case 16:
466                         testapp_test_get_mime_entity();
467                         break;
468                 case 17:
469                         testapp_test_query_smtp_mail_size_limit();
470                         break;
471                 case 18:
472                         testapp_test_verify_email_address();
473                         break;
474                 case 0:
475                         go_to_loop = FALSE;
476                         break;
477                 default:
478                         break;
479         }
480
481         return go_to_loop;
482 }
483
484 void testapp_others_main()
485 {
486         gboolean go_to_loop = TRUE;
487         int menu_number = 0;
488
489         while (go_to_loop) {
490                 testapp_show_menu(EMAIL_OTHERS_MENU);
491                 testapp_show_prompt(EMAIL_OTHERS_MENU);
492
493                 if (0 >= scanf("%d", &menu_number))
494                         testapp_print("Invalid input. ");
495
496                 go_to_loop = testapp_test_interpret_command(menu_number);
497         }
498 }
499