/*
- * 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.
#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__ */
/*
- * 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.
#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;
}
+/*
+ * 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 <stdio.h>
#include <stdlib.h>
#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;
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;
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);
}
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;
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;
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);
}
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;
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;
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);
}
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;
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;
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);
}
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;
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;
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);
}
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;
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;
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);
}
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;
+}
+