[ITC][calendar-sevice2][Non-ACR][TSAM-11744,11750,fixed the failed test cases for...
authorShilpa Jindal <shilpa.j@samsung.com>
Tue, 20 Dec 2016 05:56:59 +0000 (11:26 +0530)
committerShilpa Jindal <shilpa.j@samsung.com>
Tue, 20 Dec 2016 07:00:09 +0000 (12:30 +0530)
Change-Id: I972645a7befd81215c5cf30858d79287ddd4bad0
Signed-off-by: Shilpa Jindal <shilpa.j@samsung.com>
src/itc/calendar-service2/ITs-calendar-service2-common.c
src/itc/calendar-service2/ITs-calendar-service2-common.h
src/itc/calendar-service2/ITs-calendar-service2-database.c

index a4b29c79edafd0511bbe25b0af4c08725b130c6b..676b3e04567cb6fc4a354b27e720ae1058bbf7d3 100755 (executable)
@@ -282,4 +282,16 @@ gboolean Timeout_Function(gpointer data)
        return false;
 }
 
+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);
+}
+
 /** @} */ 
index 18c657f26b744eb011397f81c9bcbe2f9b059422..f5b538925239b9612770ff203ccda805c2974519 100755 (executable)
@@ -71,6 +71,7 @@ char* CalendarFilterOperator(int nRet);
 void GetViewURIforDB(char szArr[MAX_ROW][MAX_COL]);
 void GetViewURIforDBByVersion(char szArr[MAX_ROW][MAX_COL]);
 gboolean Timeout_Function(gpointer data);
+time_t get_utime(int y, int m, int d, int h, int n, int s);
 /** @} */ 
 
 #endif  //_ITS_CALENDAR_SERVICE2_COMMON_H_
index 76306f9b23ec7d60cf848d0d2741a94ad4d96362..afd998230a6dd6cbdd14359864fdb01d8d0fe1cb 100755 (executable)
@@ -281,28 +281,39 @@ int ITc_calendar_db_get_all_records_p(void)
 {
        START_TEST;
 
-       int nRetVal = -1, nURICount = 0;
+       int nRetVal = -1, nURICount = 1;//set to 1 for  _calendar_event._uri
        calendar_list_h list = NULL;
        int nOffset = 0;
        int nLimit = 2;
-
        char szURI[MAX_ROW][MAX_COL];
        GetViewURIforDB(szURI);
-       int nTotalURICount = URI_COUNT_FOR_DB;
-
-       for ( nURICount = 0; nURICount<nTotalURICount; nURICount++ )
+       int nEventId = 0;
+       calendar_record_h record = NULL;
+       
+       // Preconditions
+       if ( CreateCalendarRecordInsertInDb(&record, &nEventId) == FAIL )
        {
-               // Target APIs
-               nRetVal = calendar_db_get_all_records(szURI[nURICount], nOffset, nLimit, &list);
-               PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_all_records", CalendarServiceGetError(nRetVal));
+               return 1;
+       }
 
-               CHECK_HANDLE(list, "calendar_db_get_all_records");
+                       // Target APIs
+       nRetVal = calendar_db_get_all_records(szURI[nURICount], nOffset, nLimit, &list);
+       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_all_records", CalendarServiceGetError(nRetVal));
 
-               //Postcondition
-               nRetVal = calendar_list_destroy(list, true);
-               PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_list_destroy", CalendarServiceGetError(nRetVal));
-               list = NULL;
-       }
+       CHECK_HANDLE(list, "calendar_db_get_all_records");
+       
+       nRetVal = calendar_record_destroy(record, true);
+       PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_destroy", CalendarServiceGetError(nRetVal));
+
+       // delete record from database
+       nRetVal = calendar_db_delete_record(_calendar_event._uri,nEventId);
+       PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_delete_record", CalendarServiceGetError(nRetVal));
+       
+       //Postcondition
+       nRetVal = calendar_list_destroy(list, true);
+       PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_list_destroy", CalendarServiceGetError(nRetVal));
+       list = NULL;
+       
        return 0;
 }
 
@@ -462,38 +473,27 @@ int ITc_calendar_db_get_changes_by_version_p(void)
 {
        START_TEST;
 
-       int nURICount = 0;
+       int nURICount = 1;
        calendar_list_h list = NULL;
-       int nGivenVersion = -1;
+       int nGivenVersion = 1;
        int nCurrentVersion = -1;
 
        char szURI[MAX_ROW][MAX_COL];
        GetViewURIforDBByVersion(szURI);
-       int nTotalURICount = URI_COUNT_FOR_DB_BY_VERSION;
+       int nEventID =0;
+       
+       // Target APIs
+       int nRetVal = calendar_db_get_changes_by_version(_calendar_event._uri, nEventID, nGivenVersion, &list, &nCurrentVersion);
+       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_changes_by_version", CalendarServiceGetError(nRetVal));
 
-       //Precondition
-       int nRetVal = calendar_db_get_current_version(&nGivenVersion);
-       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_current_version", CalendarServiceGetError(nRetVal));
-       if ( nGivenVersion == -1 )
+       CHECK_HANDLE(list, "calendar_db_get_changes_by_version");
+       if ( nCurrentVersion == -1 )
        {
-               FPRINTF("[Line : %d][%s] calendar_db_get_current_version failed, error returned = Invalid output parameter\\n", __LINE__, API_NAMESPACE);
+               FPRINTF("[Line : %d][%s] calendar_db_get_changes_by_version failed, error returned = Invalid output parameter\\n", __LINE__, API_NAMESPACE);
+               calendar_list_destroy(list, true);
                return 1;
        }
-
-       for ( nURICount = 0; nURICount<nTotalURICount; nURICount++ )
-       {
-               // Target APIs
-               nRetVal = calendar_db_get_changes_by_version(szURI[nURICount], DEFAULT_EVENT_CALENDAR_BOOK_ID, nGivenVersion, &list, &nCurrentVersion);
-               PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_changes_by_version", CalendarServiceGetError(nRetVal));
-
-               CHECK_HANDLE(list, "calendar_db_get_changes_by_version");
-               if ( nCurrentVersion == -1 )
-               {
-                       FPRINTF("[Line : %d][%s] calendar_db_get_changes_by_version failed, error returned = Invalid output parameter\\n", __LINE__, API_NAMESPACE);
-                       calendar_list_destroy(list, true);
-                       return 1;
-               }
-       }
+       
        //Postconditions
        nRetVal = calendar_list_destroy(list, true);
        PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_list_destroy", CalendarServiceGetError(nRetVal));
@@ -524,44 +524,87 @@ int ITc_calendar_db_get_changes_exception_by_version_p(void)
        START_TEST;
 
        calendar_list_h list = NULL;
-       calendar_record_h record = NULL;
-       int nGivenVersion = -1;
-       int nRecordId = 0;
-
-       //Precondition
-       //get current db version
-       int nRetVal = calendar_db_get_current_version(&nGivenVersion);
-       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_current_version", CalendarServiceGetError(nRetVal));
-       if ( nGivenVersion == -1 )
-       {
-               FPRINTF("[Line : %d][%s] calendar_db_get_current_version failed, error returned = Invalid output parameter\\n", __LINE__, API_NAMESPACE);
-               return 1;
-       }
+       int nGivenVersion = 1;
+       int nEventId = 1;
+       int nCurrentVersion = 0;
+       int nEventID_F = 0;
+       
+       int nClone_ID = 0;
+       calendar_record_h hGet_event = NULL;
+       calendar_record_h hClone = NULL;        
+       calendar_record_h event = NULL;
+        
+       int nRetVal = calendar_record_create(_calendar_event._uri, &event);
+       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_create", CalendarServiceGetError(nRetVal));
+       CHECK_HANDLE(event, "calendar_record_create");
+
+        char buf[256] = {0};
+        snprintf(buf, sizeof(buf), "Test %ld", time(NULL));
+        nRetVal = calendar_record_set_str(event, _calendar_event.summary, buf);
+        PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_str", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));  
+
+        calendar_time_s st = {0};
+        st.type = CALENDAR_TIME_UTIME;
+        st.time.utime = get_utime(2010, 1, 5, 0, 0, 0);
+        
+         nRetVal = calendar_record_set_caltime(event, _calendar_event.start_time, st);
+         PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_caltime", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+       
 
-       // create and insert record
-       if ( CreateCalendarRecordInsertInDb(&record, &nRecordId) == FAIL )
-       {
-               return 1;
-       }
+        calendar_time_s et = {0};
+        et.type = CALENDAR_TIME_UTIME;
+        et.time.utime = st.time.utime + 3600;
+        nRetVal = calendar_record_set_caltime(event, _calendar_event.end_time, et);
+        PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_caltime", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
 
-       // Target API
-       nRetVal = calendar_db_get_changes_exception_by_version(_calendar_event._uri, nRecordId, nGivenVersion, &list);
-       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_changes_by_version", CalendarServiceGetError(nRetVal), calendar_record_destroy(record, true);calendar_db_delete_record(_calendar_event._uri,nRecordId));
-       CHECK_HANDLE_CLEANUP(list, "calendar_db_get_changes_by_version", calendar_record_destroy(record, true);calendar_db_delete_record(_calendar_event._uri,nRecordId));
+       nRetVal = calendar_record_set_int(event, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_int", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+       
+       nRetVal = calendar_record_set_int(event, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_int", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+       
+       nRetVal = calendar_record_set_int(event, _calendar_event.count, 10);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_int", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+        
+       nRetVal = calendar_db_insert_record(event, &nEventID_F);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_insert_record", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+       
+       
+       nRetVal = calendar_db_get_record(_calendar_event._uri, nEventID_F, &hGet_event);        
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_insert_record", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true));
+       CHECK_HANDLE(hGet_event, "calendar_db_get_record");
+       
 
-       //Postconditions
-       // destroy records
-       nRetVal = calendar_record_destroy(record, true);
-       PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_destroy", CalendarServiceGetError(nRetVal));
+       nRetVal = calendar_record_clone(hGet_event, &hClone);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_clone", CalendarServiceGetError(nRetVal),calendar_record_destroy(event, true);calendar_record_destroy(hGet_event, true));
+        
+       nRetVal = calendar_record_destroy(hGet_event, true);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_destroy", CalendarServiceGetError(nRetVal),calendar_record_destroy(hClone, true));
 
+       nRetVal = calendar_record_set_str(hClone, _calendar_event.summary, "exception");
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_str", CalendarServiceGetError(nRetVal),calendar_record_destroy(hClone, true));
+       
+       nRetVal = calendar_record_set_int(hClone, _calendar_event.original_event_id, nEventID_F);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_int", CalendarServiceGetError(nRetVal),calendar_record_destroy(hClone, true));
+        
+       nRetVal = calendar_record_set_str(hClone, _calendar_event.recurrence_id, "20100106000000Z");
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_set_str", CalendarServiceGetError(nRetVal),calendar_record_destroy(hClone, true));
+
+       nRetVal = calendar_db_insert_record(hClone, &nClone_ID);
+       PRINT_RESULT_CLEANUP(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_insert_record", CalendarServiceGetError(nRetVal),calendar_record_destroy(hClone, true));
+       
+       nRetVal = calendar_record_destroy(hClone, true);
+       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_record_destroy", CalendarServiceGetError(nRetVal));
+               
+       // Target API
+       nRetVal = calendar_db_get_changes_exception_by_version(_calendar_event._uri, nEventID_F, nCurrentVersion, &list);
+       PRINT_RESULT(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_get_changes_exception_by_version", CalendarServiceGetError(nRetVal));
+       CHECK_HANDLE(list, "calendar_db_get_changes_exception_by_version");
+       
        // destroy list
        nRetVal = calendar_list_destroy(list, true);
        PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_list_destroy", CalendarServiceGetError(nRetVal));
 
-       // delete record from database
-       nRetVal = calendar_db_delete_record(_calendar_event._uri,nRecordId);
-       PRINT_RESULT_NORETURN(CALENDAR_ERROR_NONE, nRetVal, "calendar_db_delete_record", CalendarServiceGetError(nRetVal));
-
        return 0;
 }