2.0_alpha release commit
[framework/messaging/email-service.git] / utilities / test-application / testapp-others.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 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
44 static gboolean testapp_test_get_network_status()
45 {
46         int on_sending = 0;
47         int on_receiving = 0;
48         email_get_network_status(&on_sending, &on_receiving);
49         testapp_print("\tNetwork status : \n On sending - %d \n On Receiving - %d \n", on_sending, on_receiving);
50         return FALSE;
51 }
52
53 static gboolean testapp_test_get_pending_job()
54 {
55         int action = -1;
56         int account_id = 0;
57         int mail_id = 0;
58         int result_from_scanf = 0;
59         email_event_status_type_t status = -1;
60         testapp_print( " Enter Action \n SEND_MAIL = 0 \n SYNC_HEADER = 1 \n" \
61                             " DOWNLOAD_BODY,= 2 \n DOWNLOAD_ATTACHMENT = 3 \n" \
62                             " DELETE_MAIL = 4 \n SEARCH_MAIL = 5 \n SAVE_MAIL = 6 \n" \
63                             " NUM = 7 \n");
64         result_from_scanf = scanf("%d",&action);
65
66         testapp_print("\n > Enter account_id: ");
67         result_from_scanf = scanf("%d", &account_id);
68
69         testapp_print("\n > Enter Mail Id: ");
70         result_from_scanf = scanf("%d", &mail_id);
71
72         if( email_get_pending_job( action, account_id, mail_id, &status) >= 0)
73                 testapp_print("\t status - %d \n",status);
74
75         return FALSE;
76 }
77
78 static gboolean testapp_test_cancel_job ()
79 {
80         int account_id = 0;
81         int handle = 0;
82         int result_from_scanf = 0;
83
84         testapp_print("\n > Enter account_id (0: all account): ");
85         result_from_scanf = scanf("%d", &account_id);
86
87         testapp_print("\n > Enter handle: ");
88         result_from_scanf = scanf("%d", &handle);
89
90         if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
91                 testapp_print("email_cancel_job failed..!");
92         return FALSE;
93 }
94
95 static gboolean testapp_test_set_dnet_proper_profile_type()
96 {
97         testapp_print("NOT Support\n");
98         
99         return TRUE;
100 }
101
102 static gboolean testapp_test_get_dnet_proper_profile_type()
103 {
104         testapp_print("NOT Support\n");
105
106         return TRUE;
107 }
108
109 static gboolean testapp_test_print_receving_queue_via_debug_msg()
110 {
111         int err;
112         void* hAPI = (void*)emipc_create_email_api(_EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE);
113
114         if(hAPI == NULL)
115                 return EMAIL_ERROR_NULL_VALUE;
116                 
117         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
118                 testapp_print("testapp_test_print_receving_queue_via_debug_msg - emipc_execute_proxy_api failed \n ");
119                 if(hAPI == NULL)
120                         return EMAIL_ERROR_NULL_VALUE;
121         }
122
123         emipc_get_parameter(hAPI, 1, 0, sizeof(int), &err);
124         
125         testapp_print(" >>>> RETURN VALUE : %d \n", err);
126
127         emipc_destroy_email_api(hAPI);
128
129         hAPI = NULL;
130         testapp_print("testapp_test_print_receving_queue_via_debug_msg  ..........End\n");
131         return err;
132 }
133
134 static gboolean testapp_test_create_db_full()
135 {
136         int err;
137
138         err = email_create_db_full();
139         
140         testapp_print("testapp_test_create_db_full returns [%d]", err);
141
142         return err;
143 }
144
145 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
146 {
147         unsigned char *content = NULL;
148         int ret = true; 
149         int err = EMAIL_ERROR_NONE;
150
151         if (err_code != NULL) {
152                 *err_code = EMAIL_ERROR_NONE;
153         }
154
155         content = rfc822_binary(src, src_len, enc_len);
156
157         if (content)
158                 *enc = (char *)content;
159         else {
160                 err = EMAIL_ERROR_UNKNOWN;
161                 ret = false;
162         }
163
164         if (err_code)
165             *err_code = err;
166
167         return ret;
168 }
169
170
171 static gboolean testapp_test_encoding_test()
172 {
173         int error = EMAIL_ERROR_NONE;
174         int has_special_character = 0, base64_file_name_length = 0, i;
175         gsize bytes_read, bytes_written;
176         char *encoded_file_name = NULL, *base64_file_name = NULL;
177         SIZEDTEXT source_text;
178         GError *glib_error = NULL;
179         CHARSET *result_charset = NULL;
180         char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
181
182         source_text.data = (unsigned char*)filename; 
183         source_text.size = strlen(filename);
184
185         result_charset = (CHARSET*)utf8_infercharset(&source_text);
186
187         if(result_charset) {
188                 testapp_print("return_charset->name [%s]", result_charset->name);
189                 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
190         }
191         else {
192                 i = 0;
193                 while(filename[i++] & 0x80)
194                         has_special_character = 1;
195                 testapp_print("has_special_character [%d]", has_special_character);
196                 if(has_special_character)
197                         encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
198         }
199         
200         if(encoded_file_name == NULL)
201                 encoded_file_name = strdup(filename);
202
203         testapp_print("encoded_file_name [%s]", encoded_file_name);
204
205         if(!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
206                 testapp_print("encode_base64 failed. error [%d]", error);
207                 goto FINISH_OFF;
208         }
209
210         testapp_print("base64_file_name [%s]", base64_file_name);
211
212         if(base64_file_name) {
213                 free(encoded_file_name);
214                 encoded_file_name = malloc(strlen(base64_file_name) + 15);
215                 if(!encoded_file_name) {
216                         testapp_print("em_malloc failed.");
217                         goto FINISH_OFF;
218                 }
219                 snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
220                 testapp_print("encoded_file_name [%s]", encoded_file_name);
221         }
222 FINISH_OFF:
223
224         return error;
225 }
226
227 #define LIB_EMAIL_SERVICE_PATH  "/usr/lib/libemail-api.so"
228
229 int (*Datastore_FI_EMTB)(char **);
230 int (*Datastore_FI_EMSB)(char **);
231 int (*Datastore_FI_EMOB)(char **);
232 int (*Datastore_FI_EMDR)(char **);
233 int (*Datastore_FI_EMMF)(char **);
234 int (*Datastore_FI_EMTR)(char **);
235 int (*Datastore_FI_EMSP)(char **);
236
237 static gboolean email_test_dtt_Datastore_FI()
238 {
239         void *handle = NULL;
240         char *dl_error = NULL, *output_str = NULL;
241
242         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
243         if (!handle) {
244                 dl_error = dlerror();
245                 if (dl_error)
246                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
247                 return false;
248         }       
249
250         Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
251         Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
252         Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
253         Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
254         Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
255         Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
256         Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
257
258         Datastore_FI_EMTB(&output_str);
259
260         testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
261         
262         if(output_str)
263                 free(output_str);
264
265         if (handle) {
266                 dlclose(handle);
267                 dl_error = dlerror();
268                 if (dl_error)
269                         testapp_print("\t Close handle return  :  %s\n", dl_error);
270         }
271
272         return true;
273 }
274
275 int (*Datastore_R_EMTB)(char **);
276 int (*Datastore_R_EMSB)(char **);
277 int (*Datastore_R_EMOB)(char **);
278 int (*Datastore_R_EMDR)(char **);
279 int (*Datastore_R_EMMF)(char **);
280 int (*Datastore_R_EMTR)(char **);
281 int (*Datastore_R_EMSP)(char **);
282
283
284 static gboolean email_test_dtt_Datastore_R()
285 {
286         void *handle = NULL;
287         char *dl_error = NULL, *output_str = NULL;
288
289         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
290         if (!handle) {
291                 dl_error = dlerror();
292                 if (dl_error)
293                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
294                 return false;
295         }       
296
297         Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
298         Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
299         Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
300         Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
301         Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
302         Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
303         Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
304
305         Datastore_R_EMTB(&output_str);
306
307         testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
308
309         if(output_str)
310                 free(output_str);
311
312         if (handle) {
313                 dlclose(handle);
314                 dl_error = dlerror();
315                 if (dl_error)
316                         testapp_print("\t Close handle return  :  %s\n", dl_error);
317         }
318
319         return true;
320 }
321
322 int (*Datastore_C_EMTB)(char **);
323 int (*Datastore_C_EMSB)(char **);
324 int (*Datastore_C_EMOB)(char **);
325 int (*Datastore_C_EMDR)(char **);
326 int (*Datastore_C_EMMF)(char **);
327 int (*Datastore_C_EMTR)(char **);
328 int (*Datastore_C_EMSP)(char **);
329
330 static gboolean email_test_dtt_Datastore_C()
331 {
332         void *handle = NULL;
333         char *dl_error = NULL, *output_str = NULL;
334
335         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
336         if (!handle) {
337                 dl_error = dlerror();
338                 if (dl_error)
339                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
340                 return false;
341         }       
342
343         Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
344         Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
345         Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
346         Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
347         Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
348         Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
349         Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
350
351         Datastore_C_EMTB(&output_str);
352
353
354         testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
355         
356         if(output_str)
357                 free(output_str);
358
359         if (handle) {
360                 dlclose(handle);
361                 dl_error = dlerror();
362                 if (dl_error)
363                         testapp_print("\t Close handle return  :  %s\n", dl_error);
364         }
365
366         return true;
367 }
368
369 static gboolean testapp_test_show_user_message()
370 {
371         int mail_id;
372         int result_from_scanf = 0;
373
374         testapp_print("\n > Enter mail id : ");
375         result_from_scanf = scanf("%d", &mail_id);
376
377         email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
378         return FALSE;
379 }
380
381 static gboolean testapp_test_get_mime_entity()
382 {
383         char mime_path[512] = {0, };
384         int result_from_scanf = 0;
385         char *mime_entity = NULL;
386
387         testapp_print("\n > Enter mime path for parsing : ");
388         result_from_scanf = scanf("%s", mime_path);
389         
390         email_get_mime_entity(mime_path, &mime_entity);
391
392         testapp_print("\nmime_entity = %s\n", mime_entity);
393         return true;
394 }
395
396 static gboolean testapp_test_interpret_command (int menu_number)
397 {
398         gboolean go_to_loop = TRUE;
399
400         switch (menu_number) {
401                 case 1:
402                         testapp_test_get_network_status();
403                         break;
404                 case 2:
405                         testapp_test_get_pending_job ();
406                         break;
407                 case 3:
408                         testapp_test_cancel_job ();
409                         break;
410                 case 5: 
411                         testapp_test_set_dnet_proper_profile_type();
412                         break;
413                 case 6:
414                         testapp_test_get_dnet_proper_profile_type();
415                         break;
416                 case 11:
417                         testapp_test_print_receving_queue_via_debug_msg();
418                         break;
419                 case 12:
420                         testapp_test_create_db_full();
421                         break;
422                 case 13:
423                         testapp_test_encoding_test();
424                         break;
425                 case 14:
426                         email_test_dtt_Datastore_FI();
427                         email_test_dtt_Datastore_C();
428                         email_test_dtt_Datastore_R();
429                         break;
430                 case 15:
431                         testapp_test_show_user_message();
432                         break;
433                 case 16:
434                         testapp_test_get_mime_entity();
435                         break;
436                 case 0:
437                         go_to_loop = FALSE;
438                         break;
439                 default:
440                         break;
441         }
442
443         return go_to_loop;
444 }
445
446 void testapp_others_main()
447 {
448         gboolean go_to_loop = TRUE;
449         int menu_number = 0;
450         int result_from_scanf = 0;
451
452         while (go_to_loop) {
453                 testapp_show_menu (EMAIL_OTHERS_MENU);
454                 testapp_show_prompt (EMAIL_OTHERS_MENU);
455
456                 result_from_scanf = scanf ("%d", &menu_number);
457
458                 go_to_loop = testapp_test_interpret_command (menu_number);
459         }
460 }
461