4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
34 #include "email-api.h"
35 #include "email-api-account.h"
36 #include "email-api-network.h"
40 #include "testapp-utility.h"
41 #include "testapp-others.h"
42 #include "email-ipc.h"
43 #include "email-core-utils.h"
45 static gboolean testapp_test_get_network_status()
49 email_get_network_status(&on_sending, &on_receiving);
50 testapp_print("\tNetwork status : \n On sending - %d \n On Receiving - %d \n", on_sending, on_receiving);
54 static gboolean testapp_test_get_pending_job()
59 int result_from_scanf = 0;
60 email_event_status_type_t status = -1;
61 testapp_print( " Enter Action \n SEND_MAIL = 0 \n SYNC_HEADER = 1 \n" \
62 " DOWNLOAD_BODY,= 2 \n DOWNLOAD_ATTACHMENT = 3 \n" \
63 " DELETE_MAIL = 4 \n SEARCH_MAIL = 5 \n SAVE_MAIL = 6 \n" \
65 result_from_scanf = scanf("%d",&action);
67 testapp_print("\n > Enter account_id: ");
68 result_from_scanf = scanf("%d", &account_id);
70 testapp_print("\n > Enter Mail Id: ");
71 result_from_scanf = scanf("%d", &mail_id);
73 if( email_get_pending_job( action, account_id, mail_id, &status) >= 0)
74 testapp_print("\t status - %d \n",status);
79 static gboolean testapp_test_cancel_job ()
83 int result_from_scanf = 0;
85 testapp_print("\n > Enter account_id (0: all account): ");
86 result_from_scanf = scanf("%d", &account_id);
88 testapp_print("\n > Enter handle: ");
89 result_from_scanf = scanf("%d", &handle);
91 if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
92 testapp_print("email_cancel_job failed..!");
96 static gboolean testapp_test_set_dnet_proper_profile_type()
98 testapp_print("NOT Support\n");
103 static gboolean testapp_test_get_dnet_proper_profile_type()
105 testapp_print("NOT Support\n");
110 static gboolean testapp_test_get_preview_text_from_file()
112 int result_from_scanf;
113 char *preview_buffer = NULL;
114 char html_file_path[1024] = { 0, };
116 testapp_print("\n > Enter file path : ");
117 result_from_scanf = scanf("%s", html_file_path);
119 emcore_get_preview_text_from_file(NULL, html_file_path, 1024, &preview_buffer);
121 testapp_print("\n result :\n %s ", preview_buffer);
126 static gboolean testapp_test_print_receving_queue_via_debug_msg()
129 void* hAPI = (void*)emipc_create_email_api(_EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE);
132 return EMAIL_ERROR_NULL_VALUE;
134 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
135 testapp_print("testapp_test_print_receving_queue_via_debug_msg - emipc_execute_proxy_api failed \n ");
137 return EMAIL_ERROR_NULL_VALUE;
140 emipc_get_parameter(hAPI, 1, 0, sizeof(int), &err);
142 testapp_print(" >>>> RETURN VALUE : %d \n", err);
144 emipc_destroy_email_api(hAPI);
147 testapp_print("testapp_test_print_receving_queue_via_debug_msg ..........End\n");
151 static gboolean testapp_test_create_db_full()
155 err = email_create_db_full();
157 testapp_print("testapp_test_create_db_full returns [%d]", err);
162 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
164 unsigned char *content = NULL;
166 int err = EMAIL_ERROR_NONE;
168 if (err_code != NULL) {
169 *err_code = EMAIL_ERROR_NONE;
172 content = rfc822_binary(src, src_len, enc_len);
175 *enc = (char *)content;
177 err = EMAIL_ERROR_UNKNOWN;
188 static gboolean testapp_test_encoding_test()
190 int error = EMAIL_ERROR_NONE;
191 int has_special_character = 0, base64_file_name_length = 0, i;
192 gsize bytes_read, bytes_written;
193 char *encoded_file_name = NULL, *base64_file_name = NULL;
194 SIZEDTEXT source_text;
195 GError *glib_error = NULL;
196 CHARSET *result_charset = NULL;
197 char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
199 source_text.data = (unsigned char*)filename;
200 source_text.size = strlen(filename);
202 result_charset = (CHARSET*)utf8_infercharset(&source_text);
205 testapp_print("return_charset->name [%s]", result_charset->name);
206 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
210 while(filename[i++] & 0x80)
211 has_special_character = 1;
212 testapp_print("has_special_character [%d]", has_special_character);
213 if(has_special_character)
214 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
217 if(encoded_file_name == NULL)
218 encoded_file_name = strdup(filename);
220 testapp_print("encoded_file_name [%s]", encoded_file_name);
222 if(!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
223 testapp_print("encode_base64 failed. error [%d]", error);
227 testapp_print("base64_file_name [%s]", base64_file_name);
229 if(base64_file_name) {
230 free(encoded_file_name);
231 encoded_file_name = malloc(strlen(base64_file_name) + 15);
232 if(!encoded_file_name) {
233 testapp_print("em_malloc failed.");
236 snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
237 testapp_print("encoded_file_name [%s]", encoded_file_name);
241 if (encoded_file_name)
242 free(encoded_file_name);
244 if (base64_file_name)
245 free(base64_file_name);
250 #define LIB_EMAIL_SERVICE_PATH "/usr/lib/libemail-api.so"
252 int (*Datastore_FI_EMTB)(char **);
253 int (*Datastore_FI_EMSB)(char **);
254 int (*Datastore_FI_EMOB)(char **);
255 int (*Datastore_FI_EMDR)(char **);
256 int (*Datastore_FI_EMMF)(char **);
257 int (*Datastore_FI_EMTR)(char **);
258 int (*Datastore_FI_EMSP)(char **);
260 static gboolean email_test_dtt_Datastore_FI()
263 char *dl_error = NULL, *output_str = NULL;
265 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
267 dl_error = dlerror();
269 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
273 Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
274 Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
275 Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
276 Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
277 Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
278 Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
279 Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
281 Datastore_FI_EMTB(&output_str);
283 testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
290 dl_error = dlerror();
292 testapp_print("\t Close handle return : %s\n", dl_error);
298 int (*Datastore_R_EMTB)(char **);
299 int (*Datastore_R_EMSB)(char **);
300 int (*Datastore_R_EMOB)(char **);
301 int (*Datastore_R_EMDR)(char **);
302 int (*Datastore_R_EMMF)(char **);
303 int (*Datastore_R_EMTR)(char **);
304 int (*Datastore_R_EMSP)(char **);
307 static gboolean email_test_dtt_Datastore_R()
310 char *dl_error = NULL, *output_str = NULL;
312 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
314 dl_error = dlerror();
316 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
320 Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
321 Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
322 Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
323 Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
324 Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
325 Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
326 Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
328 Datastore_R_EMTB(&output_str);
330 testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
337 dl_error = dlerror();
339 testapp_print("\t Close handle return : %s\n", dl_error);
345 int (*Datastore_C_EMTB)(char **);
346 int (*Datastore_C_EMSB)(char **);
347 int (*Datastore_C_EMOB)(char **);
348 int (*Datastore_C_EMDR)(char **);
349 int (*Datastore_C_EMMF)(char **);
350 int (*Datastore_C_EMTR)(char **);
351 int (*Datastore_C_EMSP)(char **);
353 static gboolean email_test_dtt_Datastore_C()
356 char *dl_error = NULL, *output_str = NULL;
358 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
360 dl_error = dlerror();
362 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
366 Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
367 Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
368 Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
369 Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
370 Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
371 Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
372 Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
374 Datastore_C_EMTB(&output_str);
377 testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
384 dl_error = dlerror();
386 testapp_print("\t Close handle return : %s\n", dl_error);
392 static gboolean testapp_test_show_user_message()
395 int result_from_scanf = 0;
397 testapp_print("\n > Enter mail id : ");
398 result_from_scanf = scanf("%d", &mail_id);
400 email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
404 static gboolean testapp_test_get_mime_entity()
406 char mime_path[512] = {0, };
407 int result_from_scanf = 0;
408 char *mime_entity = NULL;
410 testapp_print("\n > Enter mime path for parsing : ");
411 result_from_scanf = scanf("%s", mime_path);
413 email_get_mime_entity(mime_path, &mime_entity);
415 testapp_print("\nmime_entity = %s\n", mime_entity);
419 static gboolean testapp_test_interpret_command (int menu_number)
421 gboolean go_to_loop = TRUE;
423 switch (menu_number) {
425 testapp_test_get_network_status();
428 testapp_test_get_pending_job ();
431 testapp_test_cancel_job ();
434 testapp_test_set_dnet_proper_profile_type();
437 testapp_test_get_dnet_proper_profile_type();
440 testapp_test_get_preview_text_from_file();
443 testapp_test_print_receving_queue_via_debug_msg();
446 testapp_test_create_db_full();
449 testapp_test_encoding_test();
452 email_test_dtt_Datastore_FI();
453 email_test_dtt_Datastore_C();
454 email_test_dtt_Datastore_R();
457 testapp_test_show_user_message();
460 testapp_test_get_mime_entity();
472 void testapp_others_main()
474 gboolean go_to_loop = TRUE;
476 int result_from_scanf = 0;
479 testapp_show_menu (EMAIL_OTHERS_MENU);
480 testapp_show_prompt (EMAIL_OTHERS_MENU);
482 result_from_scanf = scanf ("%d", &menu_number);
484 go_to_loop = testapp_test_interpret_command (menu_number);