Added default file loading also to pclCreatePath function; fixed bugs 199 and 203
[profile/ivi/persistence-client-library.git] / test / persistence_client_library_test.c
index b1aa3b7..18d0dbf 100644 (file)
@@ -48,7 +48,6 @@ char gTheAppId[MaxAppNameLen] = {0};
 // definition of weekday
 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
-
 int myChangeCallback(pclNotification_s * notifyStruct)
 {
    printf(" ==> * - * myChangeCallback * - *\n");
@@ -92,12 +91,14 @@ START_TEST(test_GetData)
     * Logical DB ID: 0xFF with user 0 and seat 0
     *       ==> local value accessible by all users (user 0, seat 0)
     */
+   /*
    ret = pclKeyReadData(0xFF, "language/country_code",         0, 0, buffer, READ_SIZE);
    x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
                strlen((char*)buffer)) == 0, "Buffer not correctly read");
    x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
 
    memset(buffer, 0, READ_SIZE);
+   */
 
 
    /**
@@ -114,9 +115,6 @@ START_TEST(test_GetData)
     *       ==> local USER value (user 3, seat 2)
     */
    ret = pclKeyReadData(0xFF, "status/open_document",      3, 2, buffer, READ_SIZE);
-   printf("Ist:  %s\n", buffer);
-   printf("Soll: %s\n", "WT_ /var/opt/user_manual_climateControl.pdf");
-
    x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
 
    memset(buffer, 0, READ_SIZE);
@@ -202,6 +200,7 @@ START_TEST (test_GetDataHandle)
    x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
 
    ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
+   printf("* * * * * => => => B U F F E R : \"%s\"\n", buffer);
    x_fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read => 1");
 
    size = pclKeyHandleGetSize(handle);
@@ -296,6 +295,23 @@ START_TEST(test_SetData)
 
    ret = pclInitLibrary(gTheAppId, shutdownReg);
    x_fail_unless(ret <= 1, "Failed to init PCL");
+
+#if 1
+   /**
+    * Logical DB ID: 0xFF with user 3 and seat 2
+    *       ==> local USER value (user 3, seat 2)
+    */
+   ret = pclKeyWriteData(0xFF, "status/open_document",      3, 2, "WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
+   x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Wrong write size");
+
+
+   ret = pclKeyWriteData(0x84, "links/last_link",      2, 1, "CACHE_ /last_exit/queens", strlen("CACHE_ /last_exit/queens"));
+   x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"), "Wrong write size");
+
+   ret = pclKeyWriteData(0xFF, "posHandle/last_position", 0, 0, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
+   x_fail_unless(ret == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""), "Wrong write size");
+#endif
+
 #if 1
    time_t t = time(0);
 
@@ -310,11 +326,8 @@ START_TEST(test_SetData)
     *       ==> local USER value (user 1, seat 2)
     * Resource ID: 69
     */
-   printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
    ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
-   printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
-   printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
 #if 1
    snprintf(write1, 128, "%s %s", "/70",  sysTimeBuffer);
    /**
@@ -378,8 +391,6 @@ START_TEST(test_SetData)
    memset(buffer, 0, READ_SIZE);
 
    ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
-   printf("Verify ist  : %s \n", buffer);
-   printf("Verify soll : %s \n", sysTimeBuffer);
    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
 
@@ -486,7 +497,6 @@ START_TEST(test_GetDataSize)
     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
     */
    size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
-   printf("=>=>=>=> soll: %d | ist: %d\n", strlen("CACHE_ /last_exit/queens"), size);
    x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
 #endif
    pclDeinitLibrary();
@@ -520,7 +530,7 @@ START_TEST(test_DeleteData)
 
    // delete key
    rval = pclKeyDelete(0xFF, "key_70", 1, 2);
-   x_fail_unless(rval == 0, "Failed to delete key");
+   x_fail_unless(rval >= 0, "Failed to delete key");
 
    // after deleting the key, reading from key must fail now!
    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
@@ -534,7 +544,7 @@ START_TEST(test_DeleteData)
 
    // delete key
    rval = pclKeyDelete(0xFF, "70", 1, 2);
-   x_fail_unless(rval == 0, "Failed to delete key");
+   x_fail_unless(rval >= 0, "Failed to delete key");
 
    // after deleting the key, reading from key must fail now!
    rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
@@ -600,52 +610,31 @@ START_TEST(test_DataFile)
    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
 
    size = pclFileGetSize(fd);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
-   printf("Soll: 68 | Ist: %d\n", size);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(size == 68, "Wrong file size");
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
 
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    size = pclFileReadData(fd, buffer, READ_SIZE);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned");      // strlen + 1 ==> inlcude cr/lf
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
 
    ret = pclFileClose(fd);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(ret == 0, "Failed to close file");
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
 
    // open ------------------------------------------------------------
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
 
    size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
    x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    ret = pclFileClose(fd);
-   printf("%s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(ret == 0, "Failed to close file");
 
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
    // remove ----------------------------------------------------------
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
    ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
 
    fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
    x_fail_unless(fd == -1, "Failed to remove file, file still exists");
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
    close(fd);
-   printf("* * %s => %d\n", __FUNCTION__, __LINE__);
 
    // map file --------------------------------------------------------
 
@@ -757,17 +746,18 @@ START_TEST(test_DataHandle)
    handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
 
-   (void)pclFileReadData(handleArray[0], buffer, READ_SIZE);
+   ret = pclFileReadData(handleArray[0], buffer, READ_SIZE);
+   x_fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!");
    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
          strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
          == 0, "Buffer not correctly read => mediaDB_write_01.db");
 
-   (void)pclFileReadData(handleArray[1], buffer, READ_SIZE);
+   ret = pclFileReadData(handleArray[1], buffer, READ_SIZE);
    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
          strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
          == 0, "Buffer not correctly read => mediaDB_write_02.db");
 
-   (void)pclFileReadData(handleArray[2], buffer, READ_SIZE);
+   ret = pclFileReadData(handleArray[2], buffer, READ_SIZE);
    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
          strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
          == 0, "Buffer not correctly read => mediaDB_write_03.db");
@@ -887,83 +877,6 @@ END_TEST
 
 
 
-#if 0
-/**
- * Test for  i n t e r n a l  structures.
- * Test the cursor functions.
- */
-START_TEST(test_Cursor)
-{
-   X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
-   X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
-   X_TEST_REPORT_REFERENCE("NONE");
-   X_TEST_REPORT_DESCRIPTION("Test of cursor");
-   X_TEST_REPORT_TYPE(GOOD);
-
-   int handle = -1, rval = 0, size = 0, handle1 = 0;
-   char bufferKeySrc[READ_SIZE]  = {0};
-   char bufferDataSrc[READ_SIZE] = {0};
-   char bufferKeyDst[READ_SIZE]  = {0};
-   char bufferDataDst[READ_SIZE] = {0};
-   unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
-
-   rval = pclInitLibrary(gTheAppId, shutdownReg);
-   x_fail_unless(rval <= 1, "Failed to init PCL");
-#if 1
-   // create cursor
-   handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
-   x_fail_unless(handle != -1, "Failed to create cursor!!");
-
-   // create cursor
-   handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
-   x_fail_unless(handle1 != -1, "Failed to create cursor!!");
-
-   do
-   {
-      memset(bufferKeySrc, 0, READ_SIZE);
-      memset(bufferDataSrc, 0, READ_SIZE);
-      memset(bufferKeyDst, 0, READ_SIZE);
-      memset(bufferDataDst, 0, READ_SIZE);
-
-      // get key
-      rval = pers_db_cursor_get_key(handle, bufferKeySrc, 256);
-      x_fail_unless(rval != -1, "Cursor failed to get key!!");
-      // get data
-      rval = pers_db_cursor_get_data(handle, bufferDataSrc, 256);
-
-      x_fail_unless(rval != -1, "Cursor failed to get data!!");
-      // get size
-      size = pers_db_cursor_get_data_size(handle);
-      x_fail_unless(size != -1, "Cursor failed to get size!!");
-      //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
-
-      // get key
-      rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 256);
-      x_fail_unless(rval != -1, "Cursor failed to get key!!");
-      // get data
-      rval = pers_db_cursor_get_data(handle1, bufferDataDst, 256);
-      x_fail_unless(rval != -1, "Cursor failed to get data!!");
-      // get size
-      size = pers_db_cursor_get_data_size(handle1);
-      x_fail_unless(size != -1, "Cursor failed to get size!!");
-      //printf("  2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
-   }
-   while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
-
-   // destory cursor
-   rval = pers_db_cursor_destroy(handle);
-   x_fail_unless(rval != -1, "Failed to destroy cursor!!");
-
-   rval = pers_db_cursor_destroy(handle1);
-   x_fail_unless(rval != -1, "Failed to destroy cursor!!");
-#endif
-   pclDeinitLibrary();
-}
-END_TEST
-#endif
-
-
-
 START_TEST(test_Plugin)
 {
    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
@@ -1182,43 +1095,6 @@ END_TEST
 
 
 
-START_TEST(test_FileOpenCreate)
-{
-   int handle = -1, ret = 0;
-   unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
-   char buffer[128] = {0};
-   char* writeBuffer = "test_FileOpenCreate: write some data to the file!";
-
-   (void)pclInitLibrary(gTheAppId, shutdownReg);
-
-   // remove file
-   remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
-
-   handle = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
-   x_fail_unless(handle != -1, "Could not open file ==> /media/mediaDBWrite.db");
-
-
-   ret = pclFileWriteData(handle, writeBuffer, strlen(writeBuffer));
-   x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleWriteData => error writing data");
-
-
-   ret = pclFileSeek(handle, 0, SEEK_SET);
-   x_fail_unless(ret <= 0, "pclFileSeek => failed to position fd");
-
-
-   ret = pclFileReadData(handle, buffer, 128);
-   x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleReadData => error read data");
-   x_fail_unless(strncmp(buffer, writeBuffer, strlen(writeBuffer)) == 0, "pclKeyHandleReadData => Buffer not correctly read");
-
-   ret = pclFileClose(handle);
-   x_fail_unless(ret <= 0, "pclKeyHandleClose => failed to close");
-
-   // remove file
-   remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
-
-   pclDeinitLibrary();
-}
-END_TEST
 
 
 
@@ -1241,6 +1117,8 @@ static Suite * persistencyClientLib_suite()
    TCase * tc_persDeleteData = tcase_create("DeleteData");
    tcase_add_test(tc_persDeleteData, test_DeleteData);
 
+
+
    TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
    tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
 
@@ -1274,9 +1152,6 @@ static Suite * persistencyClientLib_suite()
    TCase * tc_NegHandle = tcase_create("NegHandle");
    tcase_add_test(tc_NegHandle, test_NegHandle);
 
-   TCase * tc_FileOpenCreate = tcase_create("FileOpenCreate");
-   tcase_add_test(tc_FileOpenCreate, test_FileOpenCreate);
-
    suite_add_tcase(s, tc_persSetData);
    suite_add_tcase(s, tc_persGetData);
    suite_add_tcase(s, tc_persSetDataNoPRCT);
@@ -1292,7 +1167,6 @@ static Suite * persistencyClientLib_suite()
    suite_add_tcase(s, tc_GetPath);
    suite_add_tcase(s, tc_InitDeinit);
    suite_add_tcase(s, tc_NegHandle);
-   suite_add_tcase(s, tc_FileOpenCreate);
 
    //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
 
@@ -1321,7 +1195,7 @@ int main(int argc, char *argv[])
    SRunner * sr = srunner_create(s);
    srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
    srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
-   srunner_run_all(sr, /*CK_NORMAL*/ CK_VERBOSE);
+   srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE*/);
 
    nr_failed = srunner_ntests_failed(sr);
    nr_run = srunner_ntests_run(sr);