From: Jeesun Kim Date: Sun, 21 Feb 2016 23:43:02 +0000 (+0900) Subject: modified test X-Git-Tag: accepted/tizen/common/20160304.195728~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F59962%2F1;p=platform%2Fcore%2Fpim%2Fcontacts-service.git modified test Change-Id: I40d0133402d5e71f601505ef55738c451791294d --- diff --git a/test/test_debug.h b/test/test_debug.h index 3b38fad..9f734a5 100644 --- a/test/test_debug.h +++ b/test/test_debug.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -34,13 +34,13 @@ #define COLOR_PURPLE "\033[0;35m" #define COLOR_CYAN "\033[0;36m" #define COLOR_LIGHTBLUE "\033[0;37m" -#define COLOR_END "\033[0;m" +#define COLOR_END "\033[0;m" -#define DEBUG(fmt, args...) LOGD(COLOR_CYAN fmt COLOR_END, ##args) -#define VERBOSE(fmt, args...) LOGD(COLOR_BROWN fmt COLOR_END, ##args) -#define WARNING(fmt, args...) LOGD(COLOR_PURPLE fmt COLOR_END, ##args) -#define ERROR(fmt, args...) LOGE(COLOR_RED" * Critical * " fmt COLOR_END, ##args) -#define ENTER() LOGD(COLOR_GREEN" BEGIN >>>> "COLOR_END) -#define LEAVE() LOGD(COLOR_GREEN" END <<<< "COLOR_END) +#define DBG(fmt, args...) LOGD(COLOR_CYAN" [TEST] "COLOR_END fmt, ##args) +#define VERB(fmt, args...) LOGD(COLOR_BROWN" [TEST] "COLOR_END fmt, ##args) +#define WARN(fmt, args...) LOGD(COLOR_PURPLE fmt COLOR_END, ##args) +#define ERR(fmt, args...) LOGE(COLOR_RED" [TEST] "COLOR_END fmt, ##args) +#define ENTER() LOGD(COLOR_GREEN" BEGIN >>>> "COLOR_END) +#define LEAVE() LOGD(COLOR_GREEN" END <<<< "COLOR_END) #endif /* __TEST_DEBUG_H__ */ diff --git a/test/test_main.c b/test/test_main.c index b58274b..4c1f4e8 100644 --- a/test/test_main.c +++ b/test/test_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -21,30 +21,65 @@ #include "test_main.h" #include "test_debug.h" -#include "test_query.h" -void _print_errors(void) +void _print_errors(int argc, char **argv) { - DEBUG("CONTACTS_ERROR_NONE (%d)", CONTACTS_ERROR_NONE ); - DEBUG("CONTACTS_ERROR_OUT_OF_MEMORY (%d)", CONTACTS_ERROR_OUT_OF_MEMORY ); - DEBUG("CONTACTS_ERROR_INVALID_PARAMETER (%d)", CONTACTS_ERROR_INVALID_PARAMETER ); - DEBUG("CONTACTS_ERROR_FILE_NO_SPACE (%d)", CONTACTS_ERROR_FILE_NO_SPACE ); - DEBUG("CONTACTS_ERROR_PERMISSION_DENIED (%d)", CONTACTS_ERROR_PERMISSION_DENIED ); - DEBUG("CONTACTS_ERROR_NOT_SUPPORTED (%d)", CONTACTS_ERROR_NOT_SUPPORTED ); - DEBUG("CONTACTS_ERROR_NO_DATA (%d)", CONTACTS_ERROR_NO_DATA ); - DEBUG("CONTACTS_ERROR_DB_LOCKED (%d)", CONTACTS_ERROR_DB_LOCKED ); - DEBUG("CONTACTS_ERROR_DB (%d)", CONTACTS_ERROR_DB ); - DEBUG("CONTACTS_ERROR_IPC_NOT_AVALIABLE (%d)", CONTACTS_ERROR_IPC_NOT_AVALIABLE ); - DEBUG("CONTACTS_ERROR_IPC (%d)", CONTACTS_ERROR_IPC ); - DEBUG("CONTACTS_ERROR_SYSTEM (%d)", CONTACTS_ERROR_SYSTEM ); - DEBUG("CONTACTS_ERROR_INTERNAL (%d)", CONTACTS_ERROR_INTERNAL ); + DBG("CONTACTS_ERROR_NONE (%d)", CONTACTS_ERROR_NONE ); + DBG("CONTACTS_ERROR_OUT_OF_MEMORY (%d)", CONTACTS_ERROR_OUT_OF_MEMORY ); + DBG("CONTACTS_ERROR_INVALID_PARAMETER (%d)", CONTACTS_ERROR_INVALID_PARAMETER ); + DBG("CONTACTS_ERROR_FILE_NO_SPACE (%d)", CONTACTS_ERROR_FILE_NO_SPACE ); + DBG("CONTACTS_ERROR_PERMISSION_DENIED (%d)", CONTACTS_ERROR_PERMISSION_DENIED ); + DBG("CONTACTS_ERROR_NOT_SUPPORTED (%d)", CONTACTS_ERROR_NOT_SUPPORTED ); + DBG("CONTACTS_ERROR_NO_DATA (%d)", CONTACTS_ERROR_NO_DATA ); + DBG("CONTACTS_ERROR_DB_LOCKED (%d)", CONTACTS_ERROR_DB_LOCKED ); + DBG("CONTACTS_ERROR_DB (%d)", CONTACTS_ERROR_DB ); + DBG("CONTACTS_ERROR_IPC_NOT_AVALIABLE (%d)", CONTACTS_ERROR_IPC_NOT_AVALIABLE ); + DBG("CONTACTS_ERROR_IPC (%d)", CONTACTS_ERROR_IPC ); + DBG("CONTACTS_ERROR_SYSTEM (%d)", CONTACTS_ERROR_SYSTEM ); + DBG("CONTACTS_ERROR_INTERNAL (%d)", CONTACTS_ERROR_INTERNAL ); } +static const func _func[] = { + _print_errors, +}; + +bool test_main_is_selected(int argc, char **argv, int depth, const func _func[]) +{ + if (argc <= depth) { + return false; + } + + int select = atoi(argv[depth]); + _func[select](argc, argv); + + return true; +} + +/* + * With no argument, all cases are tested. + * If argument, specific case could be tested. + * ex> to test all cases, + * # /usr/bin/calendar-service-test + * to test 4th case, + * # /usr/bin/calendar-service-test 4 + * + * NOTICE: each case could be tested independently. + * create resource -> test -> delete resource. + */ + int main(int argc, char **argv) { ENTER(); - _print_errors(); - test_query_person_contact(argv +1); + DBG("argc(%d)", argc); + if (true == test_main_is_selected(argc, argv, 1, _func)) + return 0; + + int i = 0; + int count = sizeof(_func) / sizeof(func); + for (i = 0; i < count; i++) { + if (_func[i](argc, argv) < 0) + break; + } return 0; } diff --git a/test/test_main.h b/test/test_main.h index 0af63e0..9ac380b 100644 --- a/test/test_main.h +++ b/test/test_main.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ #ifndef __TEST_MAIN_H__ #define __TEST_MAIN_H__ -#define IF_CONDITION if (input == 0 || input == index++) -#define COND_PARAM(x) (input && param) ? param : x +typedef int (*func)(int argc, char **argv); +bool test_main_is_selected(int argc, char **argv, int step, const func _func[]); #endif /* __TEST_MAIN_H__ */ diff --git a/test/test_query.c b/test/test_query.c index 0e91088..fdcc0cc 100644 --- a/test/test_query.c +++ b/test/test_query.c @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include #include @@ -7,11 +22,11 @@ #include "test_main.h" #include "test_debug.h" -int test_query_person_contact(char **argv) +int test_query_person_contact(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -23,7 +38,7 @@ int test_query_person_contact(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -35,8 +50,8 @@ int test_query_person_contact(char **argv) contacts_record_get_str_p(record, _contacts_person_contact.display_name_index, &name_index); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s]", name_index, name); + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s]", name_index, name); contacts_list_next(list); } @@ -45,11 +60,11 @@ int test_query_person_contact(char **argv) return 0; } -int test_query_with_query_person_contact(char **argv) +int test_query_with_query_person_contact(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -74,7 +89,7 @@ int test_query_with_query_person_contact(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -86,8 +101,8 @@ int test_query_with_query_person_contact(char **argv) contacts_record_get_str_p(record, _contacts_person_contact.display_name_index, &name_index); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s]", name_index, name); + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s]", name_index, name); contacts_list_next(list); } @@ -96,11 +111,11 @@ int test_query_with_query_person_contact(char **argv) return 0; } -int test_query_person_number(char **argv) +int test_query_person_number(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -112,7 +127,7 @@ int test_query_person_number(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -130,8 +145,8 @@ int test_query_person_number(char **argv) contacts_record_get_str_p(record, _contacts_person_number.normalized_number, &normalized_number); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s] number[%s] normalized_number[%s]", + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s] number[%s] normalized_number[%s]", name_index, name, number, normalized_number); contacts_list_next(list); } @@ -141,11 +156,11 @@ int test_query_person_number(char **argv) return 0; } -int test_query_with_query_person_number(char **argv) +int test_query_with_query_person_number(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -170,7 +185,7 @@ int test_query_with_query_person_number(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -188,8 +203,8 @@ int test_query_with_query_person_number(char **argv) contacts_record_get_str_p(record, _contacts_person_number.normalized_number, &normalized_number); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s] number[%s] normalized_number[%s]", + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s] number[%s] normalized_number[%s]", name_index, name, number, normalized_number); contacts_list_next(list); } @@ -199,11 +214,11 @@ int test_query_with_query_person_number(char **argv) return 0; } -int test_query_person_email(char **argv) +int test_query_person_email(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -215,7 +230,7 @@ int test_query_person_email(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -230,8 +245,8 @@ int test_query_person_email(char **argv) contacts_record_get_str_p(record, _contacts_person_email.email, &email); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s] email[%s]", name_index, name, email); + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s] email[%s]", name_index, name, email); contacts_list_next(list); } @@ -239,11 +254,12 @@ int test_query_person_email(char **argv) return 0; } -int test_query_with_query_person_email(char **argv) + +int test_query_with_query_person_email(int argc, char **argv) { char *keyword = NULL; keyword = argv[0]; - DEBUG("keyword[%s]", keyword); + DBG("keyword[%s]", keyword); int limit = -1; int offset = -1; @@ -268,7 +284,7 @@ int test_query_with_query_person_email(char **argv) int count = 0; contacts_list_get_count(list, &count); - DEBUG("count(%d)", count); + DBG("count(%d)", count); contacts_list_first(list); contacts_record_h record = NULL; @@ -283,8 +299,8 @@ int test_query_with_query_person_email(char **argv) contacts_record_get_str_p(record, _contacts_person_email.email, &email); - DEBUG("-------------------------------------------"); - DEBUG("name_index[%s] name[%s] email[%s]", name_index, name, email); + DBG("-------------------------------------------"); + DBG("name_index[%s] name[%s] email[%s]", name_index, name, email); contacts_list_next(list); } @@ -292,3 +308,29 @@ int test_query_with_query_person_email(char **argv) return 0; } + +static const func _func[] = { + test_query_person_contact, + test_query_with_query_person_contact, + test_query_person_number, + test_query_with_query_person_number, + test_query_person_email, + test_query_with_query_person_email, +}; + +int test_query(int argc, char **argv) +{ + ENTER(); + + if (true == test_main_is_selected(argc, argv, 2, _func)) + return 0; + + int i = 0; + int count = sizeof(_func) / sizeof(func); + for (i = 0; i < count; i++) { + if (_func[i](argc, argv) < 0) + break; + } + return 0; +} +