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_ping_service()
47 if (email_ping_service() < 0)
48 testapp_print("email_ping_service failed..!");
53 static gboolean testapp_test_cancel_job()
58 testapp_print("\n > Enter account_id(0: all account): ");
59 if (0 >= scanf("%d", &account_id))
60 testapp_print("Invalid input. ");
62 testapp_print("\n > Enter handle: ");
63 if (0 >= scanf("%d", &handle))
64 testapp_print("Invalid input. ");
66 if (email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
67 testapp_print("email_cancel_job failed..!");
71 static gboolean testapp_test_init_storage()
73 if (email_init_storage() < 0)
74 testapp_print("email_init_storaege failed..!");
79 static gboolean testapp_test_set_dnet_proper_profile_type()
81 testapp_print("NOT Support\n");
86 static gboolean testapp_test_get_dnet_proper_profile_type()
88 testapp_print("NOT Support\n");
93 static gboolean testapp_test_get_preview_text_from_file()
95 char *preview_buffer = NULL;
96 char html_file_path[1024] = { 0, };
98 testapp_print("\n > Enter file path : ");
99 if (0 >= scanf("%s", html_file_path))
100 testapp_print("Invalid input. ");
102 emcore_get_preview_text_from_file(NULL, NULL, html_file_path, 1024, &preview_buffer);
104 testapp_print("\n result :\n %s ", preview_buffer);
109 static gboolean testapp_test_get_task_information()
112 int err = EMAIL_ERROR_NONE;
113 int task_information_count = 0;
114 email_task_information_t *task_information_array = NULL;
117 err = email_get_task_information(&task_information_array, &task_information_count);
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");
124 testapp_print("testapp_test_get_task_information ..........End\n");
129 static gboolean testapp_test_create_db_full()
133 err = email_create_db_full();
135 testapp_print("testapp_test_create_db_full returns [%d]", err);
140 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
142 unsigned char *content = NULL;
144 int err = EMAIL_ERROR_NONE;
146 if (err_code != NULL) {
147 *err_code = EMAIL_ERROR_NONE;
150 content = rfc822_binary(src, src_len, enc_len);
153 *enc = (char *)content;
155 err = EMAIL_ERROR_UNKNOWN;
166 static gboolean testapp_test_encoding_test()
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 */
177 source_text.data = (unsigned char*)filename;
178 source_text.size = strlen(filename);
180 result_charset = (CHARSET*)utf8_infercharset(&source_text);
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);
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);
194 if (encoded_file_name == NULL)
195 encoded_file_name = strdup(filename);
197 testapp_print("encoded_file_name [%s]", encoded_file_name);
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);
204 testapp_print("base64_file_name [%s]", base64_file_name);
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.");
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);
218 if (encoded_file_name)
219 free(encoded_file_name);
221 if (base64_file_name)
222 free(base64_file_name);
228 #define LIB_EMAIL_SERVICE_PATH "/usr/lib/libemail-api.so"
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 **);
238 static gboolean email_test_dtt_Datastore_FI()
241 char *dl_error = NULL, *output_str = NULL;
243 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
245 dl_error = dlerror();
247 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
259 Datastore_FI_EMTB(&output_str);
261 testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
268 dl_error = dlerror();
270 testapp_print("\t Close handle return : %s\n", dl_error);
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 **);
285 static gboolean email_test_dtt_Datastore_R()
288 char *dl_error = NULL, *output_str = NULL;
290 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
292 dl_error = dlerror();
294 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
306 Datastore_R_EMTB(&output_str);
308 testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
315 dl_error = dlerror();
317 testapp_print("\t Close handle return : %s\n", dl_error);
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 **);
331 static gboolean email_test_dtt_Datastore_C()
334 char *dl_error = NULL, *output_str = NULL;
336 handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
338 dl_error = dlerror();
340 testapp_print("\t dlopen error : Open Library with absolute path return : %s\n", dl_error);
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");
352 Datastore_C_EMTB(&output_str);
355 testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
362 dl_error = dlerror();
364 testapp_print("\t Close handle return : %s\n", dl_error);
370 static gboolean testapp_test_show_user_message()
374 testapp_print("\n > Enter mail id : ");
375 if (0 >= scanf("%d", &mail_id))
376 testapp_print("Invalid input. ");
378 email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
382 static gboolean testapp_test_get_mime_entity()
384 char mime_path[512] = {0, };
385 char *mime_entity = NULL;
387 testapp_print("\n > Enter mime path for parsing : ");
388 if (0 >= scanf("%s", mime_path))
389 testapp_print("Invalid input. ");
391 email_get_mime_entity(mime_path, &mime_entity);
393 testapp_print("\nmime_entity = %s\n", mime_entity);
397 static gboolean testapp_test_query_smtp_mail_size_limit()
400 testapp_print("\n > Enter account id : ");
401 if (0 >= scanf("%d", &account_id))
402 testapp_print("Invalid input. ");
404 email_query_smtp_mail_size_limit(account_id, NULL);
408 static gboolean testapp_test_verify_email_address()
410 int err = EMAIL_ERROR_NONE;
411 char email_address[512] = {0, };
413 testapp_print("\n > Enter mime path for parsing : ");
414 if (0 >= scanf("%s", email_address))
415 testapp_print("Invalid input. ");
417 err = email_verify_email_address(email_address);
419 testapp_print("\nemail_verify_email_address returns [%d]\n", err);
425 static gboolean testapp_test_interpret_command(int menu_number)
427 gboolean go_to_loop = TRUE;
429 switch (menu_number) {
431 testapp_test_ping_service();
434 testapp_test_init_storage();
437 testapp_test_cancel_job();
440 testapp_test_set_dnet_proper_profile_type();
443 testapp_test_get_dnet_proper_profile_type();
446 testapp_test_get_preview_text_from_file();
449 testapp_test_get_task_information();
452 testapp_test_create_db_full();
455 testapp_test_encoding_test();
458 email_test_dtt_Datastore_FI();
459 email_test_dtt_Datastore_C();
460 email_test_dtt_Datastore_R();
463 testapp_test_show_user_message();
466 testapp_test_get_mime_entity();
469 testapp_test_query_smtp_mail_size_limit();
472 testapp_test_verify_email_address();
484 void testapp_others_main()
486 gboolean go_to_loop = TRUE;
490 testapp_show_menu(EMAIL_OTHERS_MENU);
491 testapp_show_prompt(EMAIL_OTHERS_MENU);
493 if (0 >= scanf("%d", &menu_number))
494 testapp_print("Invalid input. ");
496 go_to_loop = testapp_test_interpret_command(menu_number);