X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fpersistence_client_library_test.c;h=18d0dbf4f06c7e67dc73af6346044f788eedf750;hb=8d6c63e7b1019479ce9eacf26d89d70cf1f0aa82;hp=fbb36bab716cd4cb428449c4a157a79f257ee7fd;hpb=e72c135c6abb6b491218a21cc6d471a5fb5e9cce;p=profile%2Fivi%2Fpersistence-client-library.git diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index fbb36ba..18d0dbf 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -10,7 +10,6 @@ ******************************************************************************/ /** * @file persistence_client_library_test.c - * @ingroup Persistence client library test * @author Ingo Huerner * @brief Test of persistence client library * @see @@ -34,16 +33,14 @@ #include "../include/persistence_client_library_file.h" #include "../include/persistence_client_library_key.h" #include "../include/persistence_client_library.h" +#include "../include/persistence_client_library_error_def.h" -// protected header, should be used only be persistence components -// included here for testing purpose -#include "../include_protected/persistence_client_library_db_access.h" - #define BUF_SIZE 64 #define NUM_OF_FILES 3 #define READ_SIZE 1024 +#define MaxAppNameLen 256 /// application id char gTheAppId[MaxAppNameLen] = {0}; @@ -51,8 +48,12 @@ char gTheAppId[MaxAppNameLen] = {0}; // definition of weekday char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +int myChangeCallback(pclNotification_s * notifyStruct) +{ + printf(" ==> * - * myChangeCallback * - *\n"); - + return 1; +} /** * Test the key value interface using different logicalDB id's, users and seats. * Each resource below has an entry in the resource configuration table where the @@ -90,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); + */ /** @@ -197,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); @@ -291,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); @@ -305,7 +326,6 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: 69 */ - ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size"); #if 1 @@ -510,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); @@ -524,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); @@ -596,7 +616,6 @@ START_TEST(test_DataFile) x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf - ret = pclFileClose(fd); x_fail_unless(ret == 0, "Failed to close file"); @@ -606,11 +625,9 @@ START_TEST(test_DataFile) size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer)); x_fail_unless(size == strlen(writeBuffer), "Failed to write data"); - ret = pclFileClose(fd); x_fail_unless(ret == 0, "Failed to close file"); - // remove ---------------------------------------------------------- ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1); x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); @@ -619,8 +636,8 @@ START_TEST(test_DataFile) x_fail_unless(fd == -1, "Failed to remove file, file still exists"); close(fd); - // map file -------------------------------------------------------- + fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1); size = pclFileGetSize(fd); @@ -694,7 +711,7 @@ START_TEST(test_DataHandle) X_TEST_REPORT_DESCRIPTION("Test of data handle"); X_TEST_REPORT_TYPE(GOOD); - int handle1 = 0, handle2 = 0, size = 0; + int handle1 = 0, handle2 = 0; int handleArray[4] = {0}; int ret = 0; unsigned char buffer[READ_SIZE] = {0}; @@ -729,22 +746,23 @@ 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"); - size = 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"); - size = 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"); - size = 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"); - size = pclFileReadData(handleArray[3], buffer, READ_SIZE); + (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db", strlen("/user/1/seat/1/media/mediaDB_write_04.db")) == 0, "Buffer not correctly read => mediaDB_write_04.db"); @@ -859,81 +877,6 @@ END_TEST -/** - * 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 - - - START_TEST(test_Plugin) { X_TEST_REPORT_TEST_NAME("persistence_client_library_test"); @@ -1069,6 +1012,7 @@ START_TEST(test_GetPath) x_fail_unless(ret <= 1, "Failed to init PCL"); #if 1 ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize); + x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); x_fail_unless(pathSize == strlen((char*)path), "Path size not correct"); @@ -1082,23 +1026,23 @@ END_TEST START_TEST(test_InitDeinit) { - int ret = 0, i = 0; + int i = 0; unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; for(i=0; i< 3; i++) { // initialize and deinitialize 1. time - ret = pclInitLibrary(gTheAppId, shutdownReg); + (void)pclInitLibrary(gTheAppId, shutdownReg); pclDeinitLibrary(); // initialize and deinitialize 2. time - ret = pclInitLibrary(gTheAppId, shutdownReg); + (void)pclInitLibrary(gTheAppId, shutdownReg); pclDeinitLibrary(); // initialize and deinitialize 3. time - ret = pclInitLibrary(gTheAppId, shutdownReg); + (void)pclInitLibrary(gTheAppId, shutdownReg); pclDeinitLibrary(); } } @@ -1106,6 +1050,54 @@ END_TEST +START_TEST(test_NegHandle) +{ + int handle = -1, ret = 0;; + int negativeHandle = -17; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + unsigned char buffer[128] = {0}; + + (void)pclInitLibrary(gTheAppId, shutdownReg); + + handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0); + x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); + + + + ret = pclKeyHandleReadData(negativeHandle, buffer, READ_SIZE); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected"); + + ret = pclKeyHandleClose(negativeHandle); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleClose => negative handle not detected"); + + ret = pclKeyHandleGetSize(negativeHandle); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleGetSize => negative handle not detected"); + + ret = pclKeyHandleReadData(negativeHandle, buffer, 128); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected"); + + ret = pclKeyHandleRegisterNotifyOnChange(negativeHandle, &myChangeCallback); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleRegisterNotifyOnChange => negative handle not detected"); + + ret = pclKeyHandleWriteData(negativeHandle, (unsigned char*)"Whatever", strlen("Whatever")); + x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleWriteData => negative handle not detected"); + + + // close handle + ret = pclKeyHandleClose(handle); + + pclDeinitLibrary(); +} +END_TEST + + + + + + + + static Suite * persistencyClientLib_suite() { Suite * s = suite_create("Persistency client library"); @@ -1125,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); @@ -1140,9 +1134,6 @@ static Suite * persistencyClientLib_suite() TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery"); tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery); - TCase * tc_Cursor = tcase_create("Cursor"); - tcase_add_test(tc_Cursor, test_Cursor); - TCase * tc_Plugin = tcase_create("Plugin"); tcase_add_test(tc_Plugin, test_Plugin); @@ -1158,6 +1149,9 @@ static Suite * persistencyClientLib_suite() TCase * tc_InitDeinit = tcase_create("InitDeinit"); tcase_add_test(tc_InitDeinit, test_InitDeinit); + TCase * tc_NegHandle = tcase_create("NegHandle"); + tcase_add_test(tc_NegHandle, test_NegHandle); + suite_add_tcase(s, tc_persSetData); suite_add_tcase(s, tc_persGetData); suite_add_tcase(s, tc_persSetDataNoPRCT); @@ -1168,12 +1162,14 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_persDataHandleOpen); suite_add_tcase(s, tc_persDataFile); suite_add_tcase(s, tc_persDataFileRecovery); - suite_add_tcase(s, tc_Cursor); suite_add_tcase(s, tc_ReadDefault); suite_add_tcase(s, tc_ReadConfDefault); suite_add_tcase(s, tc_GetPath); suite_add_tcase(s, tc_InitDeinit); + suite_add_tcase(s, tc_NegHandle); + //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available + return s; } @@ -1182,8 +1178,8 @@ int main(int argc, char *argv[]) { int nr_failed = 0, nr_run = 0, - fail = 0, i = 0; + //int fail = 0; TestResult** tResult; @@ -1192,14 +1188,14 @@ int main(int argc, char *argv[]) gTheAppId[MaxAppNameLen-1] = '\0'; /// debug log and trace (DLT) setup - DLT_REGISTER_APP("test","tests the persistence client library"); + DLT_REGISTER_APP("PCLt","tests the persistence client library"); #if 1 Suite * s = persistencyClientLib_suite(); 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); @@ -1207,7 +1203,8 @@ int main(int argc, char *argv[]) tResult = srunner_results(sr); for(i = 0; i< nr_run; i++) { - fail = tr_rtype(tResult[i]); // get status of each test + (void)tr_rtype(tResult[i]); // get status of each test + //fail = tr_rtype(tResult[i]); // get status of each test //printf("[%d] Fail: %d \n", i, fail); }