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_cancel_job ()
49 int result_from_scanf = 0;
51 testapp_print("\n > Enter account_id (0: all account): ");
52 result_from_scanf = scanf("%d", &account_id);
54 testapp_print("\n > Enter handle: ");
55 result_from_scanf = scanf("%d", &handle);
57 if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
58 testapp_print("email_cancel_job failed..!");
62 static gboolean testapp_test_set_dnet_proper_profile_type()
64 testapp_print("NOT Support\n");
69 static gboolean testapp_test_get_dnet_proper_profile_type()
71 testapp_print("NOT Support\n");
76 static gboolean testapp_test_get_preview_text_from_file()
78 int result_from_scanf;
79 char *preview_buffer = NULL;
80 char html_file_path[1024] = { 0, };
82 testapp_print("\n > Enter file path : ");
83 result_from_scanf = scanf("%s", html_file_path);
85 emcore_get_preview_text_from_file(NULL, html_file_path, 1024, &preview_buffer);
87 testapp_print("\n result :\n %s ", preview_buffer);
92 static gboolean testapp_test_get_task_information()
95 int err = EMAIL_ERROR_NONE;
96 int task_information_count = 0;
97 email_task_information_t *task_information_array = NULL;
100 err = email_get_task_information(&task_information_array, &task_information_count);
102 testapp_print("\n======================================================================\n");
103 for(i = 0; i < task_information_count; i++)
104 testapp_print("type[%d], account_id[%d], handle[%d], status[%d]", task_information_array[i].type, task_information_array[i].account_id, task_information_array[i].handle, task_information_array[i].status);
105 testapp_print("\n======================================================================\n");
107 testapp_print("testapp_test_get_task_information ..........End\n");
112 static gboolean testapp_test_create_db_full()
116 err = email_create_db_full();
118 testapp_print("testapp_test_create_db_full returns [%d]", err);
123 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
125 unsigned char *content = NULL;
127 int err = EMAIL_ERROR_NONE;
129 if (err_code != NULL) {
130 *err_code = EMAIL_ERROR_NONE;
133 content = rfc822_binary(src, src_len, enc_len);
136 *enc = (char *)content;
138 err = EMAIL_ERROR_UNKNOWN;
149 static gboolean testapp_test_encoding_test()
151 int error = EMAIL_ERROR_NONE;
152 int has_special_character = 0, base64_file_name_length = 0, i;
153 gsize bytes_read, bytes_written;
154 char *encoded_file_name = NULL, *base64_file_name = NULL;
155 SIZEDTEXT source_text;
156 GError *glib_error = NULL;
157 CHARSET *result_charset = NULL;
158 char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
160 source_text.data = (unsigned char*)filename;
161 source_text.size = strlen(filename);
163 result_charset = (CHARSET*)utf8_infercharset(&source_text);
166 testapp_print("return_charset->name [%s]", result_charset->name);
167 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
171 while(filename[i++] & 0x80)
172 has_special_character = 1;
173 testapp_print("has_special_character [%d]", has_special_character);
174 if(has_special_character)
175 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
178 if(encoded_file_name == NULL)
179 encoded_file_name = strdup(filename);
181 testapp_print("encoded_file_name [%s]", encoded_file_name);
183 if(!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
184 testapp_print("encode_base64 failed. error [%d]", error);
188 testapp_print("base64_file_name [%s]", base64_file_name);
190 if(base64_file_name) {
191 free(encoded_file_name);
192 encoded_file_name = malloc(strlen(base64_file_name) + 15);
193 if(!encoded_file_name) {
194 testapp_print("em_malloc failed.");
197 snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
198 testapp_print("encoded_file_name [%s]", encoded_file_name);
202 if (encoded_file_name)
203 free(encoded_file_name);
205 if (base64_file_name)
206 free(base64_file_name);
211 #define LIB_EMAIL_SERVICE_PATH "/usr/lib/libemail-api.so"
213 int (*Datastore_FI_EMTB)(char **);
214 int (*Datastore_FI_EMSB)(char **);
215 int (*Datastore_FI_EMOB)(char **);
216 int (*Datastore_FI_EMDR)(char **);
217 int (*Datastore_FI_EMMF)(char **);
218 int (*Datastore_FI_EMTR)(char **);
219 int (*Datastore_FI_EMSP)(char **);
221 static gboolean email_test_dtt_Datastore_FI()
224 char *dl_error = NULL, *output_str = NULL;
226 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
228 dl_error = dlerror();
230 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
234 Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
235 Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
236 Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
237 Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
238 Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
239 Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
240 Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
242 Datastore_FI_EMTB(&output_str);
244 testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
251 dl_error = dlerror();
253 testapp_print("\t Close handle return : %s\n", dl_error);
259 int (*Datastore_R_EMTB)(char **);
260 int (*Datastore_R_EMSB)(char **);
261 int (*Datastore_R_EMOB)(char **);
262 int (*Datastore_R_EMDR)(char **);
263 int (*Datastore_R_EMMF)(char **);
264 int (*Datastore_R_EMTR)(char **);
265 int (*Datastore_R_EMSP)(char **);
268 static gboolean email_test_dtt_Datastore_R()
271 char *dl_error = NULL, *output_str = NULL;
273 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
275 dl_error = dlerror();
277 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
281 Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
282 Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
283 Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
284 Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
285 Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
286 Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
287 Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
289 Datastore_R_EMTB(&output_str);
291 testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
298 dl_error = dlerror();
300 testapp_print("\t Close handle return : %s\n", dl_error);
306 int (*Datastore_C_EMTB)(char **);
307 int (*Datastore_C_EMSB)(char **);
308 int (*Datastore_C_EMOB)(char **);
309 int (*Datastore_C_EMDR)(char **);
310 int (*Datastore_C_EMMF)(char **);
311 int (*Datastore_C_EMTR)(char **);
312 int (*Datastore_C_EMSP)(char **);
314 static gboolean email_test_dtt_Datastore_C()
317 char *dl_error = NULL, *output_str = NULL;
319 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
321 dl_error = dlerror();
323 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
327 Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
328 Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
329 Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
330 Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
331 Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
332 Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
333 Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
335 Datastore_C_EMTB(&output_str);
338 testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
345 dl_error = dlerror();
347 testapp_print("\t Close handle return : %s\n", dl_error);
353 static gboolean testapp_test_show_user_message()
356 int result_from_scanf = 0;
358 testapp_print("\n > Enter mail id : ");
359 result_from_scanf = scanf("%d", &mail_id);
361 email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
365 static gboolean testapp_test_get_mime_entity()
367 char mime_path[512] = {0, };
368 int result_from_scanf = 0;
369 char *mime_entity = NULL;
371 testapp_print("\n > Enter mime path for parsing : ");
372 result_from_scanf = scanf("%s", mime_path);
374 email_get_mime_entity(mime_path, &mime_entity);
376 testapp_print("\nmime_entity = %s\n", mime_entity);
380 static gboolean testapp_test_interpret_command (int menu_number)
382 gboolean go_to_loop = TRUE;
384 switch (menu_number) {
386 testapp_test_cancel_job ();
389 testapp_test_set_dnet_proper_profile_type();
392 testapp_test_get_dnet_proper_profile_type();
395 testapp_test_get_preview_text_from_file();
398 testapp_test_get_task_information();
401 testapp_test_create_db_full();
404 testapp_test_encoding_test();
407 email_test_dtt_Datastore_FI();
408 email_test_dtt_Datastore_C();
409 email_test_dtt_Datastore_R();
412 testapp_test_show_user_message();
415 testapp_test_get_mime_entity();
427 void testapp_others_main()
429 gboolean go_to_loop = TRUE;
431 int result_from_scanf = 0;
434 testapp_show_menu (EMAIL_OTHERS_MENU);
435 testapp_show_prompt (EMAIL_OTHERS_MENU);
437 result_from_scanf = scanf ("%d", &menu_number);
439 go_to_loop = testapp_test_interpret_command (menu_number);