summaryrefslogtreecommitdiff
path: root/test/calendar_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/calendar_test.c')
-rwxr-xr-xtest/calendar_test.c464
1 files changed, 464 insertions, 0 deletions
diff --git a/test/calendar_test.c b/test/calendar_test.c
new file mode 100755
index 0000000..aae2235
--- /dev/null
+++ b/test/calendar_test.c
@@ -0,0 +1,464 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <tizen.h>
+#include <calendar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <calendar-svc-provider.h>
+
+static char* calendar_error_e_2_string(int error)
+{
+ switch(error)
+ {
+ case CALENDAR_ERROR_OUT_OF_MEMORY: return "CALENDAR_ERROR_OUT_OF_MEMORY";
+ case CALENDAR_ERROR_ITERATOR_END: return "CALENDAR_ERROR_ITERATOR_END";
+ case CALENDAR_ERROR_INVALID_PARAMETER: return "CALENDAR_ERROR_INVALID_PARAMETER";
+ case CALENDAR_ERROR_DB_FAILED: return "CALENDAR_ERROR_DB_FAILED";
+ case CALENDAR_ERROR_NONE: return "CALENDAR_ERROR_NONE";
+ case CALENDAR_ERROR_NO_DATA: return "CALENDAR_ERROR_NO_DATA";
+ }
+ return "UNKNOWN-CALENDAR-ERROR";
+}
+
+void print_detail_event(calendar_event_h event)
+{
+ char *subject = NULL;
+ char *name = NULL;
+ char *description = NULL;
+ calendar_attendee_iterator_h iterator = NULL;
+ calendar_attendee_h attendee = NULL;
+
+ printf("\t # ---------------------------------- #\n");
+ calendar_event_get_subject(event, &subject);
+ printf("\t # subject : %s\n", subject);
+ if(subject != NULL)
+ free(subject);
+ calendar_event_get_description(event, &description);
+ printf("\t # description : %s\n", description);
+ if(description != NULL)
+ free(description);
+ bool is_all_day_event = false;
+ calendar_event_get_is_all_day_event(event, &is_all_day_event);
+ if(is_all_day_event == true) {
+ struct tm start_time;
+ calendar_event_get_start_time(event, &start_time);
+ printf("# %d-%d-%d, all day\n", start_time.tm_year + 1900, start_time.tm_mon + 1, start_time.tm_mday);
+ } else {
+ struct tm start_time;
+ struct tm end_time;
+ calendar_event_get_start_time(event, &start_time);
+ calendar_event_get_end_time(event, &end_time);
+ printf("\t # start %d-%d-%d %d:%d:%d\n", start_time.tm_year + 1900, start_time.tm_mon + 1, start_time.tm_mday,
+ start_time.tm_hour, start_time.tm_min, start_time.tm_sec);
+ printf("\t # end %d-%d-%d %d:%d:%d\n", end_time.tm_year + 1900, end_time.tm_mon + 1, end_time.tm_mday,
+ end_time.tm_hour, end_time.tm_min, end_time.tm_sec);
+ }
+
+ calendar_event_get_attendee_iterator(event, &iterator);
+ if(iterator == NULL) {
+ return;
+ }
+ while(calendar_attendee_iterator_has_next(iterator)) {
+ calendar_attendee_iterator_next(&iterator, &attendee);
+ calendar_attendee_get_name(attendee, &name);
+ printf("\t # attendee : %s\n", name);
+ if(name != NULL)
+ free(name);
+ }
+}
+
+void print_detail_timezone_event(calendar_event_h event)
+{
+ char* timezone_name = NULL;
+ calendar_event_get_timezone(event, &timezone_name);
+ printf("\t\t timezone_name = %s\n", timezone_name);
+ if(timezone_name != NULL)
+ free(timezone_name);
+}
+
+bool get_all_event_callback(calendar_event_h event, void *user_data)
+{
+ printf("\t #get_all_event_callback()\n");
+// print_detail_event(event);
+ print_detail_timezone_event(event);
+ printf("\t #get_all_event_callback() end\n");
+ return true;
+}
+
+#include <calendar_private.h>
+void test_insert()
+{
+ calendar_event_h event = NULL;
+ calendar_attendee_h attendee1 = NULL;
+ calendar_attendee_h attendee2 = NULL;
+
+ int id = 0;
+ struct tm tm_now = {0,};
+ int ret = 0;
+
+ ret = calendar_event_create(&event);
+ printf("\tcalendar_event_create() ret = %d\n", ret);
+
+ ret = calendar_event_set_subject(event, "test subject");
+ printf("\tcalendar_event_set_subject() ret = %d\n", ret);
+
+ ret = calendar_event_set_description(event, "test description");
+ printf("\tcalendar_event_set_description() ret = %d\n", ret);
+
+ ret = calendar_event_set_location(event, "Suwon");
+ printf("\tcalendar_event_set_location() ret = %d\n", ret);
+
+ tm_now.tm_year = 112; // 2011
+ tm_now.tm_mon = 0; // Aug
+ tm_now.tm_mday = 26; // 27th
+ tm_now.tm_hour = 10; // 10am
+ ret = calendar_event_set_start_time(event, tm_now);
+ printf("\tcalendar_event_set_start_time() ret = %d\n", ret);
+ tm_now.tm_hour = 12; // 12am
+ ret = calendar_event_set_end_time(event, tm_now);
+ printf("\tcalendar_event_set_end_time() ret = %d\n", ret);
+// ret = calendar_event_set_is_all_day_event(event, true);
+// printf("\tcalendar_event_set_is_all_day_event() ret = %d\n", ret);
+
+ ret = calendar_event_set_timezone(event, "Asia/Shanghai");
+ printf("\tcalendar_set_timezone() ret = %d\n", ret);
+
+
+ ret = calendar_event_add_attendee(event, &attendee1);
+ printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+ ret = calendar_attendee_set_name(attendee1, "sora lee");
+ printf("\tcalendar_attendee_set_name() ret = %d\n", ret);
+ ret = calendar_attendee_set_email(attendee1, "sl@sl.com");
+ printf("\tcalendar_attendee_set_email() ret = %d\n", ret);
+// ret = calendar_event_add_attendee(event, attendee1);
+// printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+
+
+ ret = calendar_event_add_attendee(event, &attendee2);
+ printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+ ret = calendar_attendee_set_name(attendee2, "dohyun yoon");
+ printf("\tcalendar_attendee_set_name() ret = %d\n", ret);
+ ret = calendar_attendee_set_email(attendee2, "dy@dy.com");
+ printf("\tcalendar_attendee_set_email() ret = %d\n", ret);
+// ret = calendar_event_add_attendee(event, attendee2);
+// printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_CALENDAR_ID, 2);
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_ACCOUNT_ID, 1);
+ ret = calendar_event_insert_to_db(event, 1, &id);
+ printf("\tcalendar_event_insert_to_db() ret = %d, id = %d\n", ret, id);
+
+ ret = calendar_event_destroy(event);
+ printf("\tcalendar_event_destroy() ret = %d\n", ret);
+}
+
+int g_recurrence_event_id = 0;
+
+void test_insert2()
+{
+ calendar_event_h event = NULL;
+ calendar_attendee_h attendee1 = NULL;
+ calendar_attendee_h attendee2 = NULL;
+
+ int id = 0;
+ struct tm tm_start = {0};
+ struct tm tm_end = {0};
+ struct tm tm_recurrence = {0};
+ int ret = 0;
+
+ ret = calendar_event_create(&event);
+ printf("\tcalendar_event_create() ret = %d\n", ret);
+
+ ret = calendar_event_set_subject(event, "Hospital");
+ printf("\tcalendar_event_set_subject() ret = %d\n", ret);
+
+ ret = calendar_event_set_description(event, "I have to");
+ printf("\tcalendar_event_set_description() ret = %d\n", ret);
+
+ ret = calendar_event_set_location(event, "Seoul");
+ printf("\tcalendar_event_set_location() ret = %d\n", ret);
+
+ tm_start.tm_year = 112; // 2011
+ tm_start.tm_mon = 0; // may
+ tm_start.tm_mday = 23; // 23th
+ tm_start.tm_hour = 10; // 10am
+
+ tm_end.tm_year = 112; // 2011
+ tm_end.tm_mon = 0; // may
+ tm_end.tm_mday = 23; // 23th
+ tm_end.tm_hour = 11; // 11am
+ ret = calendar_event_set_start_time(event, tm_start);
+ printf("\tcalendar_event_set_start_time() ret = %d\n", ret);
+ ret = calendar_event_set_end_time(event, tm_end);
+ printf("\tcalendar_event_set_end_time() ret = %d\n", ret);
+
+ memcpy(&tm_recurrence, &tm_end, sizeof(tm_recurrence)); // proper memcpy
+ tm_recurrence.tm_mon = 9; // Oct
+ ret = calendar_event_set_recurrence_until_date(event, tm_recurrence);
+ printf("\tcalendar_event_set_recurrence_until_date() ret = %d\n", ret);
+ ret = calendar_event_set_recurrence_frequency(event, CALENDAR_RECURRENCE_WEEKLY);
+ printf("\tcalendar_event_set_recurrence_frequency() ret = %d\n", ret);
+ ret = calendar_event_set_recurrence_week_flag(event, CALENDAR_WEEK_FLAG_MON | CALENDAR_WEEK_FLAG_WED);
+ printf("\tcalendar_event_set_recurrence_week_flag() ret = %d\n", ret);
+ int week_flag = 0;
+ ret = calendar_event_get_recurrence_week_flag(event, &week_flag);
+ printf("\tcalendar_event_set_recurrence_week_flag() ret = %d, week_flag=%d\n", ret, week_flag);
+
+ ret = calendar_event_add_attendee(event, &attendee1);
+ printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+ ret = calendar_attendee_set_name(attendee1, "Andrew Lim");
+ printf("\tcalendar_attendee_set_name() ret = %d\n", ret);
+ ret = calendar_attendee_set_email(attendee1, "al@al.com");
+ printf("\tcalendar_attendee_set_email() ret = %d\n", ret);
+// ret = calendar_event_add_attendee(event, attendee1);
+// printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+
+
+ ret = calendar_event_add_attendee(event, &attendee2);
+ printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+ ret = calendar_attendee_set_name(attendee2, "Big joe");
+ printf("\tcalendar_attendee_set_name() ret = %d\n", ret);
+ ret = calendar_attendee_set_email(attendee2, "bj@bj.com");
+ printf("\tcalendar_attendee_set_email() ret = %d\n", ret);
+// ret = calendar_event_add_attendee(event, attendee2);
+// printf("\tcalendar_event_add_attendee() ret = %d\n", ret);
+
+ print_detail_event(event);
+
+ ret = calendar_event_insert_to_db(event, 1, &id);
+ printf("\tcalendar_event_insert_to_db() ret = %d, id = %d\n", ret, id);
+ g_recurrence_event_id = id;
+
+// ret = calendar_event_delete_from_db(id);
+// printf("\tcalendar_event_delete_from_db() ret = %d, id = %d\n", ret, id);
+
+// ret = calendar_event_set_subject(event, "G. Hospital");
+// printf("\tcalendar_event_set_subject() ret = %d\n", ret);
+
+// ret = calendar_event_update_to_db(event);
+// printf("\tcalendar_event_update_to_db() ret = %d, id = %d\n", ret, id);
+
+ ret = calendar_event_destroy(event);
+ printf("\tcalendar_event_destroy() ret = %d\n", ret);
+}
+
+bool delete_all_event_callback(calendar_event_h event, void *user_data)
+{
+ int id = -1;
+ int ret = 0;
+ ret = calendar_event_get_db_id(event, &id);
+ printf("\tcalendar_event_get_db_id() ret = %d\n", ret);
+ ret = calendar_event_delete_from_db(id);
+ printf("\tcalendar_event_delete_from_db() ret = %d\n", ret);
+ return true;
+}
+
+void test_delete_all()
+{
+ printf("-------- test_delete_all ------------\n");
+ calendar_foreach_event_from_db(delete_all_event_callback, NULL);
+ printf("-------- test_delete_all END --------\n");
+}
+
+void subscribing(void* data)
+{
+
+}
+
+void vcalendar_test()
+{
+ calendar_event_h event = NULL;
+ calendar_attendee_h attendee1 = NULL;
+ calendar_attendee_h attendee2 = NULL;
+ char* vcalendar_stream = NULL;
+
+ struct tm tm_now = {0,};
+ int ret = 0;
+
+ ret = calendar_event_create(&event);
+
+ ret = calendar_event_set_subject(event, "test subject");
+
+ ret = calendar_event_set_description(event, "test description");
+
+ ret = calendar_event_set_location(event, "Suwon");
+
+ tm_now.tm_year = 111; // 2011
+ tm_now.tm_mon = 7; // Aug
+ tm_now.tm_mday = 26; // 27th
+ tm_now.tm_hour = 10; // 10am
+ ret = calendar_event_set_start_time(event, tm_now);
+ tm_now.tm_hour = 12; // 12am
+ ret = calendar_event_set_end_time(event, tm_now);
+
+ ret = calendar_event_set_timezone(event, "Asia/Shanghai");
+
+
+ ret = calendar_event_add_attendee(event, &attendee1);
+ ret = calendar_attendee_set_name(attendee1, "sora lee");
+ ret = calendar_attendee_set_email(attendee1, "sl@sl.com");
+
+
+ ret = calendar_event_add_attendee(event, &attendee2);
+ ret = calendar_attendee_set_name(attendee2, "dohyun yoon");
+ ret = calendar_attendee_set_email(attendee2, "dy@dy.com");
+
+ ret = calendar_event_get_vcalendar_from_event(event, &vcalendar_stream);
+ printf("calendar_event_get_vcalendar_from_event, ret = %d\n", ret);
+ printf("vcalendar_stream = %s\n", vcalendar_stream);
+ calendar_event_destroy(event);
+
+ ret = calendar_event_get_from_vcalendar(vcalendar_stream, &event);
+ printf("calendar_event_get_from_vcalendar, ret = %d\n", ret);
+ char* subject = NULL;
+ ret = calendar_event_get_subject(event, &subject);
+ printf("calendar_event_get_subject, ret = %d, subject = %s\n", ret, subject);
+ free(subject);
+
+ free(vcalendar_stream);
+ calendar_event_destroy(event);
+}
+/*
+void print_recurrence_event_date()
+{
+ int ret = 0;
+ calendar_event_h event = NULL;
+ ret = calendar_event_get_from_db(g_recurrence_event_id, &event);
+ printf("calendar_event_get_from_db, ret = %d\n", ret);
+ struct tm start = {0};
+ struct tm end = {0};
+ struct tm next_start = {0};
+ struct tm next_end = {0};
+ calendar_event_get_start_time(event, &start);
+ calendar_event_get_end_time(event, &end);
+ printf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d ~ %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
+ start.tm_year + 1900, start.tm_mon + 1, start.tm_mday + 1, start.tm_hour, start.tm_min, start.tm_sec,
+ end.tm_year + 1900, end.tm_mon + 1, end.tm_mday + 1, end.tm_hour, end.tm_min, end.tm_sec
+ );
+ while(calendar_event_get_next_recurrence_time(event, start, end, &next_start, &next_end) == CALENDAR_ERROR_NONE) {
+ memcpy(&start, &next_start, sizeof(struct tm));
+ memcpy(&end, &next_end, sizeof(struct tm));
+
+ printf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d ~ %.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
+ start.tm_year + 1900, start.tm_mon + 1, start.tm_mday + 1, start.tm_hour, start.tm_min, start.tm_sec,
+ end.tm_year + 1900, end.tm_mon + 1, end.tm_mday + 1, end.tm_hour, end.tm_min, end.tm_sec
+ );
+
+ }
+}
+*/
+
+int main(int argc, char *argv[])
+{
+ printf("test 20110711 1\n");
+
+// vcalendar_test();
+#if 0
+ int ret = 0;
+ ret = calendar_connect();
+ printf("calendar_connect() ret = %d\n", ret);
+
+ cal_iter* iter = NULL;
+ ret = calendar_svc_get_all(ALL_ACCOUNT_ID, 0, CAL_STRUCT_CALENDAR, &iter);
+ printf("calendar_svc_get_all() ret = %d\n", ret);
+ if (iter == NULL) {
+ printf("iter == NULL\n");
+ } else {
+ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
+ cal_struct *calendar = NULL;
+ if(calendar_svc_iter_get_info(iter, &calendar) != CAL_SUCCESS) {
+ calendar_svc_iter_remove(&iter);
+ printf("calendar_svc_iter_get_info(iter, (cal_struct**)&calendar) != CAL_SUCCESS\n");
+ }
+
+ int index = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_INDEX);
+ int account_id = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID);
+ char* calendar_id = calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_CALENDAR_ID);
+ char* calendar_name = calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_NAME);
+ int visibility = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_VISIBILITY);
+ printf("index = %d, account_id = %d, calendar_id = %s, calendar_name = %s, visibility = %d\n", index, account_id, calendar_id, calendar_name, visibility);
+
+ calendar_svc_struct_free(&calendar);
+ }
+ calendar_svc_iter_remove(&iter);
+ }
+
+ printf("-------------------------------------\n");
+ iter = NULL;
+ ret = calendar_svc_get_all(LOCAL_ACCOUNT_ID, DEFAULT_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter);
+ printf("calendar_svc_get_all() ret = %d\n", ret);
+ if (iter == NULL) {
+ printf("iter == NULL\n");
+ } else {
+ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
+ cal_struct *calendar = NULL;
+ if(calendar_svc_iter_get_info(iter, &calendar) != CAL_SUCCESS) {
+ calendar_svc_iter_remove(&iter);
+ printf("calendar_svc_iter_get_info(iter, (cal_struct**)&calendar) != CAL_SUCCESS\n");
+ }
+
+ int index = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_INDEX);
+ int account_id = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID);
+ char* calendar_id = calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_CALENDAR_ID);
+ char* calendar_name = calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_NAME);
+ int visibility = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_VISIBILITY);
+ printf("index = %d, account_id = %d, calendar_id = %s, calendar_name = %s, visibility = %d\n", index, account_id, calendar_id, calendar_name, visibility);
+
+ calendar_svc_struct_free(&calendar);
+ }
+ calendar_svc_iter_remove(&iter);
+ }
+
+ ret = calendar_disconnect();
+ printf("calendar_disconnect() ret = %d\n", ret);
+#endif
+
+
+#if 1
+ int ret = 0;
+ ret = calendar_connect();
+ printf("calendar_connect() ret = %d\n", ret);
+
+
+ test_delete_all();
+// calendar_event_api_test();
+
+ test_insert();
+ test_insert2();
+// print_recurrence_event_date(g_recurrence_event_id);
+
+ printf("-------- calendar_foreach_event_from_db ------------\n");
+ ret = calendar_foreach_event_from_db(get_all_event_callback, NULL);
+ printf("-------- calendar_foreach_event_from_db END --------\n");
+
+// printf("------------- find description -------------\n");
+// ret = calendar_query_event_by_description(get_all_event_callback, "test", NULL);
+// printf("------------- find description END ---------\n");
+// printf("\tcalendar_foreach_calendar_event_from_db() ret = %d\n", ret);
+
+// printf("-------- calendar_foreach_timezone ------------\n");
+// ret = calendar_foreach_timezone(get_all_timezone_cb, NULL);
+// printf("-------- calendar_foreach_timezone END --------\n");
+
+ ret = calendar_disconnect();
+ printf("calendar_disconnect() ret = %d\n", ret);
+#endif
+ calendar_error_e_2_string(0);
+ return 0;
+}
+