[UTC][calendar-service2][Non-ACR][add testcase for vcalendar, todo
authorJeesun Kim <iamjs.kim@samsung.com>
Mon, 11 Jul 2016 10:22:15 +0000 (19:22 +0900)
committerjeesun kim <iamjs.kim@samsung.com>
Wed, 13 Jul 2016 10:20:59 +0000 (03:20 -0700)
reminder]

Signed-off-by: Jeesun Kim <iamjs.kim@samsung.com>
Change-Id: I72f1253bcb2a77b1c15da5c23fd472118a999f13

src/utc/calendar-service2/tct-calendar-service2-core_mobile.h
src/utc/calendar-service2/tct-calendar-service2-core_tv.h
src/utc/calendar-service2/utc-calendar-contacts.c
src/utc/calendar-service2/utc-calendar-contacts.h
src/utc/calendar-service2/utc-calendar-recurrence.c [new file with mode: 0644]
src/utc/calendar-service2/utc-calendar-recurrence.h [new file with mode: 0644]
src/utc/calendar-service2/utc-calendar-reminder.c
src/utc/calendar-service2/utc-calendar-vcalendar.c

index e61d99c..eab7a89 100755 (executable)
@@ -35,6 +35,8 @@ extern void utc_calendar_vcalendar_startup(void);
 extern void utc_calendar_vcalendar_cleanup(void);
 extern void utc_calendar_contacts_startup(void);
 extern void utc_calendar_contacts_cleanup(void);
+extern void utc_calendar_recurrence_startup(void);
+extern void utc_calendar_recurrence_cleanup(void);
 
 extern int utc_calendar_connect_p(void);
 extern int utc_calendar_disconnect_p(void);
@@ -187,6 +189,8 @@ extern int utc_calendar_reminder_add_cb_localtime_weekly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_monthly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_yearly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_specific_p(void);
+extern int utc_calendar_reminder_add_cb_todo_utime_once_p(void);
+extern int utc_calendar_reminder_add_cb_todo_localtime_once_p(void);
 extern int utc_calendar_reminder_add_cb_n(void);
 extern int utc_calendar_reminder_remove_cb_p(void);
 extern int utc_calendar_reminder_remove_cb_n(void);
@@ -196,7 +200,8 @@ extern int utc_calendar_vcalendar_parse_to_calendar_p(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_n(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_foreach_p(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_foreach_n(void);
-extern int utc_calendar_contacts(void);
+extern int utc_calendar_contacts_p(void);
+extern int utc_calendar_recurrence_p(void);
 
 testcase tc_array[] = {
     {"utc_calendar_connect_p", utc_calendar_connect_p, NULL, NULL},
@@ -350,6 +355,8 @@ testcase tc_array[] = {
     {"utc_calendar_reminder_add_cb_localtime_monthly_p", utc_calendar_reminder_add_cb_localtime_monthly_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_localtime_yearly_p", utc_calendar_reminder_add_cb_localtime_yearly_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_localtime_specific_p", utc_calendar_reminder_add_cb_localtime_specific_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
+    {"utc_calendar_reminder_add_cb_todo_utime_once_p", utc_calendar_reminder_add_cb_todo_utime_once_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
+    {"utc_calendar_reminder_add_cb_todo_localtime_once_p", utc_calendar_reminder_add_cb_todo_localtime_once_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_n", utc_calendar_reminder_add_cb_n, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_remove_cb_p", utc_calendar_reminder_remove_cb_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_remove_cb_n", utc_calendar_reminder_remove_cb_n, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
@@ -359,7 +366,8 @@ testcase tc_array[] = {
     {"utc_calendar_vcalendar_parse_to_calendar_n", utc_calendar_vcalendar_parse_to_calendar_n, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
     {"utc_calendar_vcalendar_parse_to_calendar_foreach_p", utc_calendar_vcalendar_parse_to_calendar_foreach_p, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
     {"utc_calendar_vcalendar_parse_to_calendar_foreach_n", utc_calendar_vcalendar_parse_to_calendar_foreach_n, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
-    {"utc_calendar_contacts", utc_calendar_contacts, utc_calendar_contacts_startup, utc_calendar_contacts_cleanup},
+    {"utc_calendar_contacts_p", utc_calendar_contacts_p, utc_calendar_contacts_startup, utc_calendar_contacts_cleanup},
+    {"utc_calendar_recurrence_p", utc_calendar_recurrence_p, utc_calendar_recurrence_startup, utc_calendar_recurrence_cleanup},
     {NULL, NULL}
 };
 
index 63abbe4..eab7a89 100755 (executable)
@@ -33,6 +33,10 @@ extern void utc_calendar_reminder_startup(void);
 extern void utc_calendar_reminder_cleanup(void);
 extern void utc_calendar_vcalendar_startup(void);
 extern void utc_calendar_vcalendar_cleanup(void);
+extern void utc_calendar_contacts_startup(void);
+extern void utc_calendar_contacts_cleanup(void);
+extern void utc_calendar_recurrence_startup(void);
+extern void utc_calendar_recurrence_cleanup(void);
 
 extern int utc_calendar_connect_p(void);
 extern int utc_calendar_disconnect_p(void);
@@ -185,6 +189,8 @@ extern int utc_calendar_reminder_add_cb_localtime_weekly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_monthly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_yearly_p(void);
 extern int utc_calendar_reminder_add_cb_localtime_specific_p(void);
+extern int utc_calendar_reminder_add_cb_todo_utime_once_p(void);
+extern int utc_calendar_reminder_add_cb_todo_localtime_once_p(void);
 extern int utc_calendar_reminder_add_cb_n(void);
 extern int utc_calendar_reminder_remove_cb_p(void);
 extern int utc_calendar_reminder_remove_cb_n(void);
@@ -194,6 +200,8 @@ extern int utc_calendar_vcalendar_parse_to_calendar_p(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_n(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_foreach_p(void);
 extern int utc_calendar_vcalendar_parse_to_calendar_foreach_n(void);
+extern int utc_calendar_contacts_p(void);
+extern int utc_calendar_recurrence_p(void);
 
 testcase tc_array[] = {
     {"utc_calendar_connect_p", utc_calendar_connect_p, NULL, NULL},
@@ -347,6 +355,8 @@ testcase tc_array[] = {
     {"utc_calendar_reminder_add_cb_localtime_monthly_p", utc_calendar_reminder_add_cb_localtime_monthly_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_localtime_yearly_p", utc_calendar_reminder_add_cb_localtime_yearly_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_localtime_specific_p", utc_calendar_reminder_add_cb_localtime_specific_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
+    {"utc_calendar_reminder_add_cb_todo_utime_once_p", utc_calendar_reminder_add_cb_todo_utime_once_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
+    {"utc_calendar_reminder_add_cb_todo_localtime_once_p", utc_calendar_reminder_add_cb_todo_localtime_once_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_add_cb_n", utc_calendar_reminder_add_cb_n, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_remove_cb_p", utc_calendar_reminder_remove_cb_p, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
     {"utc_calendar_reminder_remove_cb_n", utc_calendar_reminder_remove_cb_n, utc_calendar_reminder_startup, utc_calendar_reminder_cleanup},
@@ -356,6 +366,8 @@ testcase tc_array[] = {
     {"utc_calendar_vcalendar_parse_to_calendar_n", utc_calendar_vcalendar_parse_to_calendar_n, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
     {"utc_calendar_vcalendar_parse_to_calendar_foreach_p", utc_calendar_vcalendar_parse_to_calendar_foreach_p, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
     {"utc_calendar_vcalendar_parse_to_calendar_foreach_n", utc_calendar_vcalendar_parse_to_calendar_foreach_n, utc_calendar_vcalendar_startup, utc_calendar_vcalendar_cleanup},
+    {"utc_calendar_contacts_p", utc_calendar_contacts_p, utc_calendar_contacts_startup, utc_calendar_contacts_cleanup},
+    {"utc_calendar_recurrence_p", utc_calendar_recurrence_p, utc_calendar_recurrence_startup, utc_calendar_recurrence_cleanup},
     {NULL, NULL}
 };
 
index 3f9b58a..457ca40 100755 (executable)
@@ -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.
@@ -40,6 +40,7 @@ void utc_calendar_contacts_startup(void)
         fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
         fprintf(stderr, "calendar_connect failed (code: %d)\n", g_startup_err);
     }
+       _clean_db();
 }
 
 /**
@@ -50,6 +51,7 @@ void utc_calendar_contacts_startup(void)
  */
 void utc_calendar_contacts_cleanup(void)
 {
+       _clean_db();
     calendar_disconnect();
 }
 
@@ -149,11 +151,11 @@ static int _check_contact(int contact_id, int month, int mday)
 }
 
 /**
- * @testcase           utc_calendar_contacts
+ * @testcase           utc_calendar_contacts_p
  * @since_tizen                3.0
  * @description                Test syncing contacts birthday
  */
-int utc_calendar_contacts(void)
+int utc_calendar_contacts_p(void)
 {
        int ret = 0;
 
index 57614ff..15c9958 100755 (executable)
@@ -17,6 +17,9 @@
 #ifndef __UTC_CALENDAR_CONTACTS_H__
 #define __UTC_CALENDAR_CONTACTS_H__
 
-int utc_calendar_contacts(void);
+void utc_calendar_contacts_startup(void);
+void utc_calendar_contacts_cleanup(void);
+
+int utc_calendar_contacts_p(void);
 
 #endif /* __UTC_CALENDAR_CONTACTS_H__ */
diff --git a/src/utc/calendar-service2/utc-calendar-recurrence.c b/src/utc/calendar-service2/utc-calendar-recurrence.c
new file mode 100644 (file)
index 0000000..a61e21e
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <calendar.h>
+#include <time.h>
+
+#include "utc-calendar-debug.h"
+#include "utc-calendar-util.h"
+#include "utc-calendar-db.h"
+
+static int g_startup_err = CALENDAR_ERROR_NONE;
+
+/**
+ * @function           utc_calendar_recurrence_startup
+ * @description                Called before each test
+ * @parameter          NA
+ * @return                     NA
+ */
+void utc_calendar_recurrence_startup(void)
+{
+       g_startup_err = calendar_connect();
+       if (g_startup_err != CALENDAR_ERROR_NONE) {
+               fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
+               fprintf(stderr, "calendar_connect failed (code: %d)\n", g_startup_err);
+       }
+       _clean_db();
+}
+
+/**
+ * @function           utc_calendar_recurrence_cleanup
+ * @description                Called after each test
+ * @parameter          NA
+ * @return                     NA
+ */
+void utc_calendar_recurrence_cleanup(void)
+{
+       _clean_db();
+       calendar_disconnect();
+}
+
+time_t __get_utime(int y, int m, int d, int h, int n, int s)
+{
+       struct tm st = {0};
+       st.tm_year = y - 1900;
+       st.tm_mon = m - 1;
+       st.tm_mday = d;
+       st.tm_hour = h;
+       st.tm_min = n;
+       st.tm_sec = s;
+       return mktime(&st);
+}
+
+void _create_event(calendar_record_h *out_event)
+{
+       calendar_record_h event = NULL;
+       calendar_record_create(_calendar_event._uri, &event);
+
+       const char *set_tzid = "Asia/Seoul";
+
+       calendar_record_set_str(event, _calendar_event.start_tzid, set_tzid);
+       calendar_time_s st = {0};
+       st.type = CALENDAR_TIME_UTIME;
+       int set_start_year = 2012;
+       int set_start_month = 9;
+       int set_start_mday = 3;
+
+       calendar_record_set_str(event, _calendar_event.end_tzid, set_tzid);
+       calendar_time_s et = {0};
+       et.type = CALENDAR_TIME_UTIME;
+       int set_end_year = 2012;
+       int set_end_month = 9;
+       int set_end_mday = 3;
+
+       st.time.utime = __get_utime(set_start_year, set_start_month, set_start_mday, 10, 0, 0);
+       et.time.utime = __get_utime(set_end_year, set_end_month, set_end_mday, 11, 0, 0);
+
+       calendar_record_set_caltime(event, _calendar_event.start_time, st);
+       calendar_record_set_caltime(event, _calendar_event.end_time, et);
+
+       const char *set_summary_origin = "test_origin";
+       calendar_record_set_str(event, _calendar_event.summary, set_summary_origin);
+       const char *set_description = "description";
+       calendar_record_set_str(event, _calendar_event.description, set_description);
+       const char *set_location = "location";
+       calendar_record_set_str(event, _calendar_event.location, set_location);
+       const char *set_categories = "categories";
+       calendar_record_set_str(event, _calendar_event.categories, set_categories);
+       int set_event_status = CALENDAR_EVENT_STATUS_CONFIRMED;
+       calendar_record_set_int(event, _calendar_event.event_status, set_event_status);
+
+       int set_priority = CALENDAR_EVENT_PRIORITY_NORMAL;
+       calendar_record_set_int(event, _calendar_event.priority, set_priority);
+       int set_busy_status = CALENDAR_EVENT_BUSY_STATUS_BUSY;
+       calendar_record_set_int(event, _calendar_event.busy_status, set_busy_status);
+       int set_sensitivity = CALENDAR_SENSITIVITY_PRIVATE;
+       calendar_record_set_int(event, _calendar_event.sensitivity, set_sensitivity);
+       const char *set_uid = "uid";
+       calendar_record_set_str(event, _calendar_event.uid, set_uid);
+       const char *set_organizer_name = "organizer_name";
+       calendar_record_set_str(event, _calendar_event.organizer_name, set_organizer_name);
+       const char *set_organizer_email = "organizer_email";
+       calendar_record_set_str(event, _calendar_event.organizer_email, set_organizer_email);
+       int set_meeting_status = CALENDAR_MEETING_STATUS_MEETING;
+       calendar_record_set_int(event, _calendar_event.meeting_status, set_meeting_status);
+       double set_latitude = 36.7;
+       calendar_record_set_double(event, _calendar_event.latitude, set_latitude);
+       double set_longitude = 139.3;
+       calendar_record_set_double(event, _calendar_event.longitude, set_longitude);
+       int set_calendar_system_type = CALENDAR_SYSTEM_GREGORIAN;
+       calendar_record_set_int(event, _calendar_event.calendar_system_type, set_calendar_system_type);
+       const char *set_sync_data1 = "sync_data1";
+       calendar_record_set_str(event, _calendar_event.sync_data1, set_sync_data1);
+       const char *set_sync_data2 = "sync_data2";
+       calendar_record_set_str(event, _calendar_event.sync_data2, set_sync_data2);
+       const char *set_sync_data3 = "sync_data3";
+       calendar_record_set_str(event, _calendar_event.sync_data3, set_sync_data3);
+       const char *set_sync_data4 = "sync_data4";
+       calendar_record_set_str(event, _calendar_event.sync_data4, set_sync_data4);
+
+       // recurrence
+       int set_freq = CALENDAR_RECURRENCE_MONTHLY;
+       calendar_record_set_int(event, _calendar_event.freq, set_freq);
+       int set_wkst = CALENDAR_MONDAY;
+       calendar_record_set_int(event, _calendar_event.wkst, set_wkst);
+       int set_interval = 1;
+       calendar_record_set_int(event, _calendar_event.interval, set_interval);
+       const char *set_bymonthday = "3,4,5";
+       calendar_record_set_str(event, _calendar_event.bymonthday, set_bymonthday);
+
+       int set_range_type = CALENDAR_RANGE_COUNT;
+       calendar_record_set_int(event, _calendar_event.range_type, set_range_type);
+       int set_count = 8;
+       calendar_record_set_int(event, _calendar_event.count, set_count);
+
+       // alarm
+       calendar_record_h alarm = NULL;
+       calendar_record_create(_calendar_alarm._uri, &alarm);
+       int set_alarm_tick = 5;
+       calendar_record_set_int(alarm, _calendar_alarm.tick, set_alarm_tick);
+       int set_alarm_unit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
+       calendar_record_set_int(alarm, _calendar_alarm.tick_unit, set_alarm_unit);
+       const char *set_alarm_description = "alarm_description";
+       calendar_record_set_str(alarm, _calendar_alarm.description, set_alarm_description);
+       const char *set_alarm_summary = "alarm_summary";
+       calendar_record_set_str(alarm, _calendar_alarm.summary, set_alarm_summary);
+       int set_alarm_action = 1;
+       calendar_record_set_int(alarm, _calendar_alarm.action, set_alarm_action);
+       const char *set_alarm_attach = "alarm_attach";
+       calendar_record_set_str(alarm, _calendar_alarm.attach, set_alarm_attach);
+
+       calendar_record_add_child_record(event, _calendar_event.calendar_alarm, alarm);
+
+       // attendee
+       calendar_record_h attendee = NULL;
+       calendar_record_create(_calendar_attendee._uri, &attendee);
+
+       const char *set_attendee_number = "010-1234-1234";
+       calendar_record_set_str(attendee, _calendar_attendee.number, set_attendee_number);
+       int set_attendee_cutype = CALENDAR_ATTENDEE_CUTYPE_GROUP;
+       calendar_record_set_int(attendee, _calendar_attendee.cutype, set_attendee_cutype);
+       int set_attendee_person_id = 4;
+       calendar_record_set_int(attendee, _calendar_attendee.person_id, set_attendee_person_id);
+       const char *set_attendee_uid = "attendee_uid";
+       calendar_record_set_str(attendee, _calendar_attendee.uid, set_attendee_uid);
+       const char *set_attendee_group = "company";
+       calendar_record_set_str(attendee, _calendar_attendee.group, set_attendee_group);
+       const char *set_attendee_email = "abc@company.com";
+       calendar_record_set_str(attendee, _calendar_attendee.email, set_attendee_email);
+       int set_attendee_role = CALENDAR_ATTENDEE_ROLE_CHAIR;
+       calendar_record_set_int(attendee, _calendar_attendee.role, set_attendee_role);
+       int set_attendee_status = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
+       calendar_record_set_int(attendee, _calendar_attendee.status, set_attendee_status);
+       int set_attendee_rsvp = 2;
+       calendar_record_set_int(attendee, _calendar_attendee.rsvp, set_attendee_rsvp);
+       const char *set_attendee_delegatee_uri = "Lee";
+       calendar_record_set_str(attendee, _calendar_attendee.delegatee_uri, set_attendee_delegatee_uri);
+       const char *set_attendee_delegator_uri = "Kim";
+       calendar_record_set_str(attendee, _calendar_attendee.delegator_uri, set_attendee_delegator_uri);
+       const char *set_attendee_name = "Mr.";
+       calendar_record_set_str(attendee, _calendar_attendee.name, set_attendee_name);
+       const char *set_attendee_member = "member";
+       calendar_record_set_str(attendee, _calendar_attendee.member, set_attendee_member);
+
+       calendar_record_add_child_record(event, _calendar_event.calendar_attendee, attendee);
+
+       if (out_event)
+               *out_event = event;
+}
+
+static int _del_instance(int event_id)
+{
+       int ret = 0;
+
+       calendar_record_h get_event = NULL;
+       ret = calendar_db_get_record(_calendar_event._uri, event_id, &get_event);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       const char *set_exdate = "20121104T010000Z";
+       ret = calendar_record_set_str(get_event, _calendar_event.exdate, set_exdate);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       ret = calendar_db_update_record(get_event);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_destroy(get_event, true);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       return ret;
+};
+
+static int _mod_instance(int event_id)
+{
+       int ret = 0;
+
+       calendar_record_h get_event = NULL;
+       ret = calendar_db_get_record(_calendar_event._uri, event_id, &get_event);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       calendar_record_h clone = NULL;
+       ret = calendar_record_clone(get_event, &clone);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_set_str(clone, _calendar_event.summary, "test_mod");
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_set_int(clone, _calendar_event.original_event_id, event_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_set_str(clone, _calendar_event.recurrence_id, "20121005T010000Z");
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       int clone_id = 0;
+       ret = calendar_db_insert_record(clone, &clone_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       ret = calendar_record_destroy(clone, true);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_destroy(get_event, true);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       return ret;
+}
+
+/**
+ * @testcase           utc_calendar_recurrence_p
+ * @since_tizen                3.0
+ * @description                Test for exception in recurrence event.
+ */
+
+int utc_calendar_recurrence_p(void)
+{
+       int ret = 0;
+       int event_id = 0;
+       calendar_record_h event = NULL;
+       _create_event(&event);
+       ret = calendar_db_insert_record(event, &event_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_destroy(event, true);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       ret = _del_instance(event_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = _mod_instance(event_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       calendar_db_delete_record(_calendar_event._uri, event_id);
+
+       return ret;
+}
+
diff --git a/src/utc/calendar-service2/utc-calendar-recurrence.h b/src/utc/calendar-service2/utc-calendar-recurrence.h
new file mode 100644 (file)
index 0000000..cb5898c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+#ifndef __UTC_CALENDAR_ETC_H__
+#define __UTC_CALENDAR_ETC_H__
+
+void utc_calendar_recurrence_startup(void);
+void utc_calendar_recurrence_cleanup(void);
+
+int utc_calendar_recurrence_p(void);
+
+#endif /* __UTC_CALENDAR_ETC_H__ */
+
index e56887d..d2eeaca 100755 (executable)
@@ -41,6 +41,7 @@ void utc_calendar_reminder_startup(void)
         fprintf(stderr, "Startup error at %s:%d", __FILE__, __LINE__);
         fprintf(stderr, "calendar_connect failed (code: %d)", g_startup_err);
     }
+       _clean_db();
 }
 
 /**
@@ -51,6 +52,7 @@ void utc_calendar_reminder_startup(void)
  */
 void utc_calendar_reminder_cleanup(void)
 {
+       _clean_db();
        calendar_disconnect();
 }
 
@@ -81,7 +83,12 @@ static int _delete_event(int event_id)
        return calendar_db_delete_record(_calendar_event._uri, event_id);
 }
 
-static int _reminder_utime(int64_t utime, int unit, int recurrence, int *out_id)
+static int _delete_todo(int todo_id)
+{
+       return calendar_db_delete_record(_calendar_todo._uri, todo_id);
+}
+
+static int _add_reminder_utime_in_event(int64_t utime, int unit, int recurrence, int *out_id)
 {
        int ret = 0;
        int event_id = 0;
@@ -159,7 +166,7 @@ static int _reminder_utime(int64_t utime, int unit, int recurrence, int *out_id)
        return 0;
 }
 
-static int _reminder_localtime(struct tm *local, int unit, int recurrence,  int *out_id)
+static int _add_reminder_localtime_in_event(struct tm *local, int unit, int recurrence,  int *out_id)
 {
        int ret = 0;
        int event_id = 0;
@@ -247,6 +254,136 @@ static int _reminder_localtime(struct tm *local, int unit, int recurrence,  int
        return 0;
 }
 
+static int _add_reminder_utime_in_todo(int64_t utime, int unit, int recurrence, int *out_id)
+{
+       int ret = 0;
+       int todo_id = 0;
+
+       struct tm now_s = {0};
+       time_t now_t = (time_t)utime;
+       localtime_r(&now_t, &now_s);
+       DBG("Alarm set (%04d/%02d/%02d %02d:%02d:%02d) and alarm (%d)secs before",
+                       now_s.tm_year + 1900, now_s.tm_mon + 1, now_s.tm_mday, now_s.tm_hour,
+                       now_s.tm_min, now_s.tm_sec, unit);
+
+       calendar_time_s due_time = {0};
+       due_time.type = CALENDAR_TIME_UTIME;
+       due_time.time.utime = utime;
+
+       calendar_record_h alarm = NULL;
+       ret = calendar_record_create(_calendar_alarm._uri, &alarm);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       switch (unit) {
+       case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
+               ret = calendar_record_set_caltime(alarm, _calendar_alarm.alarm_time, due_time);
+               break;
+       default:
+               ret = calendar_record_set_int(alarm, _calendar_alarm.tick, 1);
+       }
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       calendar_record_h todo = NULL;
+       ret = calendar_record_create(_calendar_todo._uri, &todo);
+       if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC != unit) {
+               ret = calendar_record_set_caltime(todo, _calendar_todo.due_time, due_time);
+               assert_eq(ret, CALENDAR_ERROR_NONE);
+       }
+       ret = calendar_record_add_child_record(todo, _calendar_todo.calendar_alarm, alarm);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_db_insert_record(todo, &todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       *out_id = todo_id;
+
+       int time_id = 0;
+       g_checked = false;
+       g_mainloop = g_main_loop_new(NULL, false);
+       ret = calendar_reminder_add_cb(_reminder_cb, NULL);
+       time_id = g_timeout_add(10000, _timeout_cb, g_mainloop);
+       g_main_loop_run(g_mainloop);
+
+       ret = calendar_reminder_remove_cb(_reminder_cb, NULL);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       calendar_record_destroy(todo, true);
+
+       if (false == g_checked) {
+               DBG("fail");
+               return -1;
+       }
+
+       g_source_remove(time_id);
+
+       return 0;
+}
+
+static int _add_reminder_localtime_in_todo(struct tm *local, int unit, int recurrence,  int *out_id)
+{
+       int ret = 0;
+       int todo_id = 0;
+
+       DBG("Alarm set : (%04d/%02d/%02d %02d:%02d:%02d) - (%d)secs",
+                       local->tm_year + 1900, local->tm_mon + 1, local->tm_mday, local->tm_hour,
+                       local->tm_min, local->tm_sec, unit);
+
+       calendar_time_s due_time = {0};
+       due_time.type = CALENDAR_TIME_LOCALTIME;
+       due_time.time.date.year = local->tm_year + 1900;
+       due_time.time.date.month = local->tm_mon + 1;
+       due_time.time.date.mday = local->tm_mday;
+       due_time.time.date.hour = local->tm_hour;
+       due_time.time.date.minute = local->tm_min;
+       due_time.time.date.second = local->tm_sec;
+
+       calendar_record_h alarm = NULL;
+       ret = calendar_record_create(_calendar_alarm._uri, &alarm);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       switch (unit) {
+       case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
+               ret = calendar_record_set_caltime(alarm, _calendar_alarm.alarm_time, due_time);
+               break;
+       default:
+               ret = calendar_record_set_int(alarm, _calendar_alarm.tick, 1);
+       }
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       calendar_record_h todo = NULL;
+       ret = calendar_record_create(_calendar_todo._uri, &todo);
+       if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC != unit) {
+               ret = calendar_record_set_caltime(todo, _calendar_todo.due_time, due_time);
+               assert_eq(ret, CALENDAR_ERROR_NONE);
+       }
+       ret = calendar_record_add_child_record(todo, _calendar_todo.calendar_alarm, alarm);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_db_insert_record(todo, &todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       *out_id = todo_id;
+
+       int time_id = 0;
+       g_checked = false;
+       g_mainloop = g_main_loop_new(NULL, false);
+       ret = calendar_reminder_add_cb(_reminder_cb, NULL);
+       time_id = g_timeout_add(10000, _timeout_cb, g_mainloop);
+       g_main_loop_run(g_mainloop);
+
+       ret = calendar_reminder_remove_cb(_reminder_cb, NULL);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       calendar_record_destroy(todo, true);
+
+       if (false == g_checked) {
+               DBG("fail");
+               return -1;
+       }
+
+       g_source_remove(time_id);
+
+       return 0;
+}
+
 /**
  * @testcase           utc_calendar_reminder_add_cb_p
  * @since_tizen                3.0
@@ -264,7 +401,7 @@ int utc_calendar_reminder_add_cb_utime_once_p(void)
        now_t = time(NULL);
        now_t += 5;
        now_t += 60;                                    /* add 1 min */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -273,7 +410,7 @@ int utc_calendar_reminder_add_cb_utime_once_p(void)
        now_t = time(NULL);
        now_t += 5;
        now_t += (60 * 60);                             /* add 1 hour */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -282,7 +419,7 @@ int utc_calendar_reminder_add_cb_utime_once_p(void)
        now_t = time(NULL);
        now_t += 5;
        now_t += (60 * 60 * 24);                /* add 1 day */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -291,7 +428,7 @@ int utc_calendar_reminder_add_cb_utime_once_p(void)
        now_t = time(NULL);
        now_t += 5;
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -318,7 +455,7 @@ int utc_calendar_reminder_add_cb_utime_daily_p(void)
        now_t += 5;
        now_t += 60;                                    /* add 1 min */
        now_t -= (60 * 60 * 24);                /* 1 day before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -328,7 +465,7 @@ int utc_calendar_reminder_add_cb_utime_daily_p(void)
        now_t += 5;
        now_t += (60 * 60);                             /* add 1 hour */
        now_t -= (60 * 60 * 24);                /* 1 day before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -338,7 +475,7 @@ int utc_calendar_reminder_add_cb_utime_daily_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24);                /* add 1 day */
        now_t -= (60 * 60 * 24);                /* 1 day before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -348,7 +485,7 @@ int utc_calendar_reminder_add_cb_utime_daily_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        now_t -= (60 * 60 * 24);                /* 1 day before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -375,7 +512,7 @@ int utc_calendar_reminder_add_cb_utime_weekly_p(void)
        now_t += 5;
        now_t += 60;                                    /* add 1 min */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -385,7 +522,7 @@ int utc_calendar_reminder_add_cb_utime_weekly_p(void)
        now_t += 5;
        now_t += (60 * 60);                             /* add 1 hour */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -395,7 +532,7 @@ int utc_calendar_reminder_add_cb_utime_weekly_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24);                /* add 1 day */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -405,7 +542,7 @@ int utc_calendar_reminder_add_cb_utime_weekly_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -442,7 +579,7 @@ int utc_calendar_reminder_add_cb_utime_monthly_p(void)
                now_s.tm_mon--;
        }
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -461,7 +598,7 @@ int utc_calendar_reminder_add_cb_utime_monthly_p(void)
                now_s.tm_mon--;
        }
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -480,7 +617,7 @@ int utc_calendar_reminder_add_cb_utime_monthly_p(void)
                now_s.tm_mon--;
        }
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -499,7 +636,7 @@ int utc_calendar_reminder_add_cb_utime_monthly_p(void)
                now_s.tm_mon--;
        }
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -529,7 +666,7 @@ int utc_calendar_reminder_add_cb_utime_yearly_p(void)
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -541,7 +678,7 @@ int utc_calendar_reminder_add_cb_utime_yearly_p(void)
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -553,7 +690,7 @@ int utc_calendar_reminder_add_cb_utime_yearly_p(void)
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -565,7 +702,7 @@ int utc_calendar_reminder_add_cb_utime_yearly_p(void)
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
        now_t = (int64_t)mktime(&now_s);
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -590,7 +727,7 @@ int utc_calendar_reminder_add_cb_utime_specific_p(void)
 
        now_t = time(NULL);
        now_t += 5;                                             /* add 5 secs */
-       ret = _reminder_utime((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_SPECIFIC,
+       ret = _add_reminder_utime_in_event((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_SPECIFIC,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -618,7 +755,7 @@ int utc_calendar_reminder_add_cb_localtime_once_p(void)
        now_t += 5;
        now_t += 60;                            /* add 1 hour */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -628,7 +765,7 @@ int utc_calendar_reminder_add_cb_localtime_once_p(void)
        now_t += 5;
        now_t += (60 * 60);                             /* add 1 hour */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -638,7 +775,7 @@ int utc_calendar_reminder_add_cb_localtime_once_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24);                /* add 1 day */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -648,7 +785,7 @@ int utc_calendar_reminder_add_cb_localtime_once_p(void)
        now_t += 5;
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -677,7 +814,7 @@ int utc_calendar_reminder_add_cb_localtime_daily_p(void)
        now_t += 60;                                    /* add 1 min */
        now_t -= (60 * 60 * 24);                /* 1 day before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -688,7 +825,7 @@ int utc_calendar_reminder_add_cb_localtime_daily_p(void)
        now_t += (60 * 60);                             /* add 1 hour */
        now_t -= (60 * 60 * 24);                /* 1 day before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -699,7 +836,7 @@ int utc_calendar_reminder_add_cb_localtime_daily_p(void)
        now_t += (60 * 60 * 24);                /* add 1 day */
        now_t -= (60 * 60 * 24);                /* 1 day before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -710,7 +847,7 @@ int utc_calendar_reminder_add_cb_localtime_daily_p(void)
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        now_t -= (60 * 60 * 24);                /* 1 day before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_DAILY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -740,7 +877,7 @@ int utc_calendar_reminder_add_cb_localtime_weekly_p(void)
        now_t += 60;                                    /* add 1 min */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -751,7 +888,7 @@ int utc_calendar_reminder_add_cb_localtime_weekly_p(void)
        now_t += (60 * 60);                             /* add 1 hour */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -762,7 +899,7 @@ int utc_calendar_reminder_add_cb_localtime_weekly_p(void)
        now_t += (60 * 60 * 24);                /* add 1 day */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -773,7 +910,7 @@ int utc_calendar_reminder_add_cb_localtime_weekly_p(void)
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        now_t -= (60 * 60 * 24 * 7);    /* 1 week before */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_WEEKLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -809,7 +946,7 @@ int utc_calendar_reminder_add_cb_localtime_monthly_p(void)
        } else {
                now_s.tm_mon--;
        }
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -827,7 +964,7 @@ int utc_calendar_reminder_add_cb_localtime_monthly_p(void)
        } else {
                now_s.tm_mon--;
        }
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -845,7 +982,7 @@ int utc_calendar_reminder_add_cb_localtime_monthly_p(void)
        } else {
                now_s.tm_mon--;
        }
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -863,7 +1000,7 @@ int utc_calendar_reminder_add_cb_localtime_monthly_p(void)
        } else {
                now_s.tm_mon--;
        }
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_MONTHLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -892,7 +1029,7 @@ int utc_calendar_reminder_add_cb_localtime_yearly_p(void)
        now_t += 60;                                    /* add 1 min */
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -903,7 +1040,7 @@ int utc_calendar_reminder_add_cb_localtime_yearly_p(void)
        now_t += (60 * 60);                             /* add 1 hour */
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_HOUR,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -914,7 +1051,7 @@ int utc_calendar_reminder_add_cb_localtime_yearly_p(void)
        now_t += (60 * 60 * 24);                /* add 1 day */
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_DAY,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -925,7 +1062,7 @@ int utc_calendar_reminder_add_cb_localtime_yearly_p(void)
        now_t += (60 * 60 * 24 * 7);    /* add 1 week */
        localtime_r(&now_t, &now_s);
        now_s.tm_year--;
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_WEEK,
                        CALENDAR_RECURRENCE_YEARLY, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -952,7 +1089,7 @@ int utc_calendar_reminder_add_cb_localtime_specific_p(void)
        now_t = time(NULL);
        now_t += 5;                                             /* add 5 secs */
        localtime_r(&now_t, &now_s);
-       ret = _reminder_localtime(&now_s, CALENDAR_ALARM_TIME_UNIT_SPECIFIC,
+       ret = _add_reminder_localtime_in_event(&now_s, CALENDAR_ALARM_TIME_UNIT_SPECIFIC,
                        CALENDAR_RECURRENCE_NONE, &event_id);
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _delete_event(event_id);
@@ -962,6 +1099,60 @@ int utc_calendar_reminder_add_cb_localtime_specific_p(void)
 }
 
 /**
+ * @testcase           utc_calendar_reminder_add_cb_todo_utime_once_p
+ * @since_tizen                3.0
+ * @description                Test adding a callback to get a notification when an todo alarm alerts.
+ */
+int utc_calendar_reminder_add_cb_todo_utime_once_p(void)
+{
+       DBG("[%s]", __func__);
+
+       assert_eq(g_startup_err, CALENDAR_ERROR_NONE);
+       int ret = 0;
+       int todo_id = 0;
+       time_t now_t = 0;
+
+       now_t = time(NULL);
+       now_t += 5;
+       now_t += 60;                                    /* add 1 min */
+       ret = _add_reminder_utime_in_todo((int64_t)now_t, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+                       CALENDAR_RECURRENCE_NONE, &todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = _delete_todo(todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       return 0;
+}
+
+/**
+ * @testcase           utc_calendar_reminder_add_cb_todo_localtime_once_p
+ * @since_tizen                3.0
+ * @description                Test adding a callback to get a notification when an once todo alarm alerts.
+ */
+int utc_calendar_reminder_add_cb_todo_localtime_once_p(void)
+{
+       DBG("[%s]", __func__);
+
+       assert_eq(g_startup_err, CALENDAR_ERROR_NONE);
+       int ret = 0;
+       int todo_id = 0;
+       time_t now_t = 0;
+       struct tm now_s = {0};
+
+       now_t = time(NULL);
+       now_t += 5;
+       now_t += 60;                            /* add 1 hour */
+       localtime_r(&now_t, &now_s);
+       ret = _add_reminder_localtime_in_todo(&now_s, CALENDAR_ALARM_TIME_UNIT_MINUTE,
+                       CALENDAR_RECURRENCE_NONE, &todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = _delete_todo(todo_id);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+
+       return 0;
+}
+
+/**
  * @testcase           utc_calendar_reminder_add_cb_n
  * @since_tizen                2.3
  * @description                Test fail adding a callback to get an alarm notification with invalid parameters.
index 9314ad4..47252a7 100755 (executable)
@@ -936,6 +936,38 @@ static int _parse_ver20_exdate(void)
        assert_eq(ret, CALENDAR_ERROR_NONE);
        return ret;
 }
+static int _parse_ver20_recurrence_id(void)
+{
+       DBG("[%s]", __func__);
+
+       int ret = 0;
+       int *ids = NULL;
+       int count = 0;
+       calendar_list_h list = NULL;
+
+       const char *stream = "BEGIN:VCALENDAR\r\n"
+               "VERSION:2.0\r\n"
+               "BEGIN:VEVENT\r\n"
+               "DTSTART;TZID=US-Eastern:19970902T090000\r\n"
+               "DTEND;TZID=US-Eastern:19970902T100000\r\n"
+               "RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13\r\n"
+               "RECURRENCE-ID;VALUE=DATE:19970401\r\n"
+               "RECURRENCE-ID;RANGE=THISANDFUTURE:19970120T120000Z\r\n"
+               "RECURRENCE-ID;RANGE=THISANDPRIOR:19970401T133000Z\r\n"
+               "RECURRENCE-ID;TZID=Asia/Seoul:20170106T090000\r\n"
+               "END:VEVENT\r\n"
+               "END:VCALENDAR\r\n";
+       ret = calendar_vcalendar_parse_to_calendar(stream, &list);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_db_insert_records(list, &ids, &count);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_db_delete_records(_calendar_event._uri, ids, count);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = calendar_list_destroy(list, true);
+       assert_eq(ret, CALENDAR_ERROR_NONE);
+       return ret;
+}
+
 static int _parse_ver10_once(void)
 {
        DBG("[%s]", __func__);
@@ -1626,6 +1658,8 @@ int utc_calendar_vcalendar_parse_to_calendar_p(void)
        assert_eq(ret, CALENDAR_ERROR_NONE);
        ret = _parse_ver20_exdate();
        assert_eq(ret, CALENDAR_ERROR_NONE);
+       ret = _parse_ver20_recurrence_id();
+       assert_eq(ret, CALENDAR_ERROR_NONE);
 
        ret = _parse_ver10_once();
        assert_eq(ret, CALENDAR_ERROR_NONE);