4 * Copyright (c) 2000 - 2011 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"
44 static gboolean testapp_test_get_network_status()
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);
53 static gboolean testapp_test_get_pending_job()
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" \
64 result_from_scanf = scanf("%d",&action);
66 testapp_print("\n > Enter account_id: ");
67 result_from_scanf = scanf("%d", &account_id);
69 testapp_print("\n > Enter Mail Id: ");
70 result_from_scanf = scanf("%d", &mail_id);
72 if( email_get_pending_job( action, account_id, mail_id, &status) >= 0)
73 testapp_print("\t status - %d \n",status);
78 static gboolean testapp_test_cancel_job ()
82 int result_from_scanf = 0;
84 testapp_print("\n > Enter account_id (0: all account): ");
85 result_from_scanf = scanf("%d", &account_id);
87 testapp_print("\n > Enter handle: ");
88 result_from_scanf = scanf("%d", &handle);
90 if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
91 testapp_print("email_cancel_job failed..!");
95 static gboolean testapp_test_set_dnet_proper_profile_type()
97 testapp_print("NOT Support\n");
102 static gboolean testapp_test_get_dnet_proper_profile_type()
104 testapp_print("NOT Support\n");
109 static gboolean testapp_test_print_receving_queue_via_debug_msg()
112 void* hAPI = (void*)emipc_create_email_api(_EMAIL_API_PRINT_RECEIVING_EVENT_QUEUE);
115 return EMAIL_ERROR_NULL_VALUE;
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 ");
120 return EMAIL_ERROR_NULL_VALUE;
123 emipc_get_parameter(hAPI, 1, 0, sizeof(int), &err);
125 testapp_print(" >>>> RETURN VALUE : %d \n", err);
127 emipc_destroy_email_api(hAPI);
130 testapp_print("testapp_test_print_receving_queue_via_debug_msg ..........End\n");
134 static gboolean testapp_test_create_db_full()
138 err = email_create_db_full();
140 testapp_print("testapp_test_create_db_full returns [%d]", err);
145 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
147 unsigned char *content = NULL;
149 int err = EMAIL_ERROR_NONE;
151 if (err_code != NULL) {
152 *err_code = EMAIL_ERROR_NONE;
155 content = rfc822_binary(src, src_len, enc_len);
158 *enc = (char *)content;
160 err = EMAIL_ERROR_UNKNOWN;
171 static gboolean testapp_test_encoding_test()
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 */
182 source_text.data = (unsigned char*)filename;
183 source_text.size = strlen(filename);
185 result_charset = (CHARSET*)utf8_infercharset(&source_text);
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);
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);
200 if(encoded_file_name == NULL)
201 encoded_file_name = strdup(filename);
203 testapp_print("encoded_file_name [%s]", encoded_file_name);
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);
210 testapp_print("base64_file_name [%s]", base64_file_name);
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.");
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);
227 #define LIB_EMAIL_SERVICE_PATH "/usr/lib/libemail-api.so"
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 **);
237 static gboolean email_test_dtt_Datastore_FI()
240 char *dl_error = NULL, *output_str = NULL;
242 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
244 dl_error = dlerror();
246 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
258 Datastore_FI_EMTB(&output_str);
260 testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
267 dl_error = dlerror();
269 testapp_print("\t Close handle return : %s\n", dl_error);
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 **);
284 static gboolean email_test_dtt_Datastore_R()
287 char *dl_error = NULL, *output_str = NULL;
289 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
291 dl_error = dlerror();
293 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
305 Datastore_R_EMTB(&output_str);
307 testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
314 dl_error = dlerror();
316 testapp_print("\t Close handle return : %s\n", dl_error);
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 **);
330 static gboolean email_test_dtt_Datastore_C()
333 char *dl_error = NULL, *output_str = NULL;
335 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
337 dl_error = dlerror();
339 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
351 Datastore_C_EMTB(&output_str);
354 testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
361 dl_error = dlerror();
363 testapp_print("\t Close handle return : %s\n", dl_error);
369 static gboolean testapp_test_show_user_message()
372 int result_from_scanf = 0;
374 testapp_print("\n > Enter mail id : ");
375 result_from_scanf = scanf("%d", &mail_id);
377 email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
381 static gboolean testapp_test_get_mime_entity()
383 char mime_path[512] = {0, };
384 int result_from_scanf = 0;
385 char *mime_entity = NULL;
387 testapp_print("\n > Enter mime path for parsing : ");
388 result_from_scanf = scanf("%s", mime_path);
390 email_get_mime_entity(mime_path, &mime_entity);
392 testapp_print("\nmime_entity = %s\n", mime_entity);
396 static gboolean testapp_test_interpret_command (int menu_number)
398 gboolean go_to_loop = TRUE;
400 switch (menu_number) {
402 testapp_test_get_network_status();
405 testapp_test_get_pending_job ();
408 testapp_test_cancel_job ();
411 testapp_test_set_dnet_proper_profile_type();
414 testapp_test_get_dnet_proper_profile_type();
417 testapp_test_print_receving_queue_via_debug_msg();
420 testapp_test_create_db_full();
423 testapp_test_encoding_test();
426 email_test_dtt_Datastore_FI();
427 email_test_dtt_Datastore_C();
428 email_test_dtt_Datastore_R();
431 testapp_test_show_user_message();
434 testapp_test_get_mime_entity();
446 void testapp_others_main()
448 gboolean go_to_loop = TRUE;
450 int result_from_scanf = 0;
453 testapp_show_menu (EMAIL_OTHERS_MENU);
454 testapp_show_prompt (EMAIL_OTHERS_MENU);
456 result_from_scanf = scanf ("%d", &menu_number);
458 go_to_loop = testapp_test_interpret_command (menu_number);