From b52af93c62400b6bf53225a5ddcbb7439d684143 Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Tue, 3 Jan 2017 08:44:01 +0100 Subject: Added DLT log message for every API call New compiler flags Splitted tests in key and file api tests, make multi thread tests work again --- test/Makefile.am | 8 +- test/persCheck.h | 169 --- test/pers_test_base.h | 140 --- test/persistence_client_library_dbus_test.c | 37 +- test/persistence_client_library_test.c | 1662 ++++++++------------------- test/persistence_client_library_test_file.c | 1201 +++++++++++++++++++ test/persistence_test_customlib.c | 4 +- 7 files changed, 1683 insertions(+), 1538 deletions(-) delete mode 100644 test/persCheck.h delete mode 100644 test/pers_test_base.h create mode 100644 test/persistence_client_library_test_file.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 8a3fa87..d957dd2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = foreign if DEBUG -AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) -g +AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) #AM_CFLAGS = -fprofile-arcs -ftest-coverage $(DEPS_CFLAGS) $(CHECK_CFLAGS) -g else AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) @@ -9,6 +9,7 @@ AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) endif noinst_PROGRAMS = persistence_client_library_test \ + persistence_client_library_test_file \ persistence_client_library_dbus_test persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_test.c @@ -19,8 +20,11 @@ persistence_client_library_test_SOURCES = persistence_client_library_test.c persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ $(top_builddir)/src/libpersistence_client_library.la +persistence_client_library_test_file_SOURCES = persistence_client_library_test_file.c +persistence_client_library_test_file_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ + $(top_builddir)/src/libpersistence_client_library.la -TESTS=persistence_client_library_test +TESTS=persistence_client_library_test persistence_client_library_test_file diff --git a/test/persCheck.h b/test/persCheck.h deleted file mode 100644 index 8769d6a..0000000 --- a/test/persCheck.h +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2014 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file persCheck.h - * @ingroup Persistence client library test - * @author awehrle - * @brief Test of persistence client library - * @see - */ - -#ifndef PERSCHECK_H_ -#define PERSCHECK_H_ - -#include "pers_test_base.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum X_TEST_REPORTS{ - X_TEST_REPORTED_RESULT -}; - -int _optTestsReported; -char _optTestID[256]; - -#define X_TEST_INIT() do { \ - _optTestID[0] = '\0'; \ - } while(0) - -#define ___FILE___ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - -#define REPORT_WARNINGS(){ \ - if(0==(_optTestsReported & (1 << X_TEST_REPORTED_RESULT))) \ - X_TEST_REPORT_RESULT(PASSED); \ -} - -/** - * @brief: Report name of test. This has to be reported first. - * MANDATORY - */ -#define X_TEST_REPORT_TEST_NAME(...) do { \ - char buf[sizeof(_optTestID)]; \ - snprintf(buf,sizeof(buf), __VA_ARGS__); \ - snprintf (_optTestID, sizeof(_optTestID),"%s::%s", ___FILE___, buf); \ - X_TEST_REPORT_TEST_ID(_optTestID); \ - X_TEST_REPORT_TEST_NAME_ID(_optTestID, __VA_ARGS__); \ - } while(0) - -/** - * @brief: Path to root of source code directory under test - * MANDATORY - */ -#define X_TEST_REPORT_PATH(...) do { \ - X_TEST_REPORT_PATH_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Name of subcomponent under test, leave empty or set value NONE if not suitable for a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_COMP_NAME(...) do { \ - X_TEST_REPORT_COMP_NAME_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Name of class or file under test, leave empty or set value NONE for a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_FILE_NAME(...) do { \ - X_TEST_REPORT_FILE_NAME_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: If information exists: Reference to a requirement, feature or bug ID. Else leave empty or set value NONE - * MANDATORY - */ -#define X_TEST_REPORT_REFERENCE(...) do { \ - X_TEST_REPORT_REFERENCE_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: A short description of test case. - * Do not leave empty, can also be a internal department Test ID like CORE-OS-BOOT-0001 - * MANDATORY - */ -#define X_TEST_REPORT_DESCRIPTION(...) do { \ - X_TEST_REPORT_DESCRIPTION_ID( _optTestID, __VA_ARGS__ ); \ - } while(0) - -/** - * @brief: Reports weather this is a UNIT or a COMPONENT test - * MANDATORY - */ -#define X_TEST_REPORT_KIND(kind) do { \ - X_TEST_REPORT_KIND_ID( _optTestID, kind ); \ - } while(0) - -/** - * @brief: valid values: PASSED, FAILED or NONE. PASSED if test result is ok, FAILED if test result is not as expected, NONE if no test exists for whole file or class - * MANDATORY - */ -#define X_TEST_REPORT_RESULT(result) do { \ - X_TEST_REPORT_RESULT_ID( _optTestID, result); \ - _optTestsReported |= 1 << X_TEST_REPORTED_RESULT; \ - } while(0) - -/** - * @brief: Additional information, if test "just" checks common information flow inside structure (GOOD test case) or if structure is tested with invalid or border values(BORDER) - * OPTIONAL - */ -#define X_TEST_REPORT_TYPE(type) do { \ - X_TEST_REPORT_TYPE_ID( _optTestID, type ); \ - } while(0) - -#undef START_TEST -/* Start a unit test with START_TEST(unit_name), end with END_TEST - One must use braces within a START_/END_ pair to declare new variables -*/ -#define START_TEST(__testname)\ -static void __testname (int _i CK_ATTRIBUTE_UNUSED)\ -{\ - X_TEST_INIT(); \ - X_TEST_REPORT_TEST_NAME(""# __testname); \ - tcase_fn_start (""# __testname, __FILE__, __LINE__); - -#define x_fail_unless(exp, ...){\ - int result = exp; \ - if(!result){ \ - X_TEST_REPORT_RESULT(FAILED); \ - } \ - fail_unless(exp, ##__VA_ARGS__); \ -} while(0) - -#define x_fail_if(exp, ...) {\ - int result = exp; \ - if(result){ \ - X_TEST_REPORT_RESULT(FAILED); \ - } \ - fail_if(exp, ##__VA_ARGS__); \ -} while(0) - -/* Always fail */ -#define x_fail(...) {\ - X_TEST_REPORT_RESULT(FAILED); \ - fail(__VA_ARGS__); \ -} while(0) - -#undef END_TEST -/* End a unit test */ -#define END_TEST {\ - REPORT_WARNINGS(); \ - _optTestsReported = 0; }\ -} - -#ifdef __cplusplus -} -#endif - -#endif /* PERSCHECK_H_ */ diff --git a/test/pers_test_base.h b/test/pers_test_base.h deleted file mode 100644 index 83c7d95..0000000 --- a/test/pers_test_base.h +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2013 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file pers_test_base.h - * @ingroup Persistence client library test - * @author awehrle - * @brief Test of persistence client library - * @see - */ - - -#ifndef PERSBASETEST_H_ -#define PERSBASETEST_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAGIC_STRING "$$XS_TEST$$" - -#define FAILED 0 -#define PASSED 1 -#define NONE 2 - -#define BORDER 0 -#define GOOD 1 - -#define UNIT 0 -#define COMPONENT 1 - -/** -* @brief: Report name of test. This has to be reported first. -* MANDATORY -*/ -#define X_TEST_REPORT_TEST_ID(ID) do { \ -printf (MAGIC_STRING"%s", ID); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Report name of test. This has to be reported first. -* MANDATORY -*/ -#define X_TEST_REPORT_TEST_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("testName:%s", __VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Path to root of source code directory under test -* MANDATORY -*/ -#define X_TEST_REPORT_PATH_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("path:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Name of subcomponent under test, leave empty or set value NONE if not suitable for a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_COMP_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("compName:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Name of class or file under test, leave empty or set value NONE for a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_FILE_NAME_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("fileName:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: If information exists: Reference to a requirement, feature or bug ID. Else leave empty or set value NONE -* MANDATORY -*/ -#define X_TEST_REPORT_REFERENCE_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("ref:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: A short description of test case. -* Do not leave empty, can also be a internal department Test ID like CORE-OS-BOOT-0001 -* MANDATORY -*/ -#define X_TEST_REPORT_DESCRIPTION_ID(ID, ...) do { \ -printf (MAGIC_STRING"%s$$", ID); \ -printf ("desc:"__VA_ARGS__); \ -printf ("\n"); \ -} while(0) - -/** -* @brief: Reports weather this is a UNIT or a COMPONENT test -* MANDATORY -*/ -#define X_TEST_REPORT_KIND_ID(ID, kind) do { \ -printf (MAGIC_STRING"%s$$kind:%s\n", ID, kind==UNIT?"UNIT":kind==COMPONENT?"COMPONENT":"NONE"); \ -} while(0) - -/** -* @brief: valid values: PASSED, FAILED or NONE. PASSED if test result is ok, FAILED if test result is not as expected, NONE if no test exists for whole file or class -* MANDATORY -*/ -#define X_TEST_REPORT_RESULT_ID(ID, result) do { \ -printf (MAGIC_STRING"%s$$result:%s\n", ID, result==PASSED?"PASSED":result==FAILED?"FAILED":"NONE"); \ -} while(0) - -/** -* @brief: Additional information, if test "just" checks common information flow inside structure (GOOD test case) or if structure is tested with invalid or border values(BORDER) -* OPTIONAL -*/ -#define X_TEST_REPORT_TYPE_ID(ID, type) do { \ -printf (MAGIC_STRING"%s$$type:%s\n", ID, type==BORDER?"BORDER":"GOOD"); \ -} while(0) - -#ifdef __cplusplus -} -#endif - -#endif /* PERSBASETEST_H_ */ diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c index a9222ef..bbaa19e 100644 --- a/test/persistence_client_library_dbus_test.c +++ b/test/persistence_client_library_dbus_test.c @@ -35,6 +35,8 @@ pthread_mutex_t gMtx = PTHREAD_MUTEX_INITIALIZER; +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); int myChangeCallback(pclNotification_s * notifyStruct) @@ -58,10 +60,8 @@ int myChangeCallback(pclNotification_s * notifyStruct) int main(int argc, char *argv[]) { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - unsigned char readBuffer[READ_BUFFER_SIZE] = {0}; + int ret = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; const char* appID = "lt-persistence_client_library_dbus_test"; @@ -71,7 +71,10 @@ int main(int argc, char *argv[]) printf("Dbus interface test application\n"); /// debug log and trace (DLT) setup - DLT_REGISTER_APP("noty","tests the persistence client library"); + DLT_REGISTER_APP("NOTY","tests the persistence client library"); + + DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing"); + ret = pclInitLibrary(appID, shutdownReg); printf("pclInitLibrary - %s - : %d\n", appID, ret); @@ -81,7 +84,6 @@ int main(int argc, char *argv[]) ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link2", 2/*user_no*/, 1/*seat_no*/, &myChangeCallback); -#if 0 ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link3", 3/*user_no*/, 2/*seat_no*/, &myChangeCallback); ret = pclKeyRegisterNotifyOnChange(0x20, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback); @@ -118,33 +120,12 @@ int main(int argc, char *argv[]) printf("Press enter to end\n"); getchar(); - sleep(2); - -#else - - - - while(i<18) - { - memset(readBuffer, 0, READ_BUFFER_SIZE); - pthread_mutex_lock(&gMtx); - - pclKeyReadData(0x20, "links/last_link2", 2, 1, readBuffer, READ_BUFFER_SIZE); - printf("%d - Read value of resource \"links/last_link2\" = %s \n\n\n", i++, readBuffer); - } - -#endif - - pclDeinitLibrary(); - // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); DLT_UNREGISTER_APP(); - dlt_free(); - - printf("By\n"); return ret; } diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index a1b1d71..e475ae8 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -29,28 +29,31 @@ #include #include -//#include "persCheck.h" #include -#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" -#define BUF_SIZE 64 -#define NUM_OF_FILES 3 -#define READ_SIZE 1024 -#define MaxAppNameLen 256 +#define BUF_SIZE 64 +#define NUM_OF_FILES 3 +#define READ_SIZE 1024 +#define MaxAppNameLen 256 -#define NUM_THREADS 100 -#define NUM_OF_READS 100 -#define NUM_OF_WRITES 100 -#define NAME_LEN 24 +#define NUM_THREADS 20 +#define NUM_OF_READS 100 +#define NUM_OF_WRITES 100 +#define NAME_LEN 24 -static pthread_barrier_t barrier; +typedef struct s_threadData +{ + char threadName[NAME_LEN]; + int index; + int fd1; + int fd2; +} t_threadData; -static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL }; -static const char* gSourcePath = "/Data/mnt-c/lt-persistence_client_library_test/"; +static pthread_barrier_t gBarrierOne, gBarrierTwo; /// application id char gTheAppId[MaxAppNameLen] = {0}; @@ -59,28 +62,36 @@ char gTheAppId[MaxAppNameLen] = {0}; char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; char* gWriteBackupTestData = "This is the content of the file /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; -char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ +char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ + +extern const char* gWriteBuffer; +extern const char* gWriteBuffer2; + + +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); + // function prototype void run_concurrency_test(); void data_setup(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary(gTheAppId, shutdownReg); } void data_setup_browser(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary("browser", shutdownReg); } void data_setup_norct(void) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary("norct", shutdownReg); } @@ -108,59 +119,27 @@ int myChangeCallback(pclNotification_s * notifyStruct) */ START_TEST(test_GetData) { - /* 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 get data"); - X_TEST_REPORT_TYPE(GOOD);*/ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; - -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 * ==> local value accessible by all users (user 0, seat 0) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, buffer, READ_SIZE); //printf("----test_GetData => pos/last_position: \"%s\" => ret: %d \nReference: %s => size: %d\n", buffer, ret, "CACHE_ +48 10' 38.95, +8 44' 39.06", strlen("CACHE_ +48 10' 38.95, +8 44' 39.06")); - fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06", - strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position"); - fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06")); + ck_assert_str_eq( (char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06"); + ck_assert_int_eq( ret, (int)strlen("CACHE_ +48 10' 38.95, +8 44' 39.06") ); memset(buffer, 0, READ_SIZE); - /** - * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 - * ==> local value accessible by all users (user 0, seat 0) - */ - /* - ret = pclKeyReadData(PCL_LDBID_LOCAL, "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); - */ - - - /** - * Logical DB ID: 0 with user 3 and seat 0 - * ==> public shared user value (user 3, seat 0) - */ - //ret = pclKeyReadData(0, "language/current_language", 0, 0, buffer, READ_SIZE); - //printf("----test_GetData => language/current_language \"%s\" => ret: %d \n", buffer, ret); - //x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read"); - //memset(buffer, 0, READ_SIZE); - /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "status/open_document", 3, 2, buffer, READ_SIZE); //printf("----test_GetData => status/open_document \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, - "Buffer not correctly read - status/open_document"); - fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf")); + ck_assert_str_eq( (char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf"); + ck_assert_int_eq(ret, (int)strlen("WT_ /var/opt/user_manual_climateControl.pdf")); memset(buffer, 0, READ_SIZE); /** @@ -169,9 +148,8 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE); //printf("----test_GetData => address/home_address \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, - "Buffer not correctly read - address/home_address"); - fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31")); + ck_assert_str_eq( (char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31"); + ck_assert_int_eq(ret, (int)strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31")); memset(buffer, 0, READ_SIZE); /** @@ -180,9 +158,8 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_satellites", 0, 0, buffer, READ_SIZE); //printf("----test_GetData => pos/last_satellites \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, - "Buffer not correctly read - pos/last_satellites"); - fail_unless(ret == strlen("WT_ 17")); + ck_assert_str_eq( (char*)buffer, "WT_ 17"); + ck_assert_int_eq(ret, (int)strlen("WT_ 17")); memset(buffer, 0, READ_SIZE); /** @@ -191,20 +168,13 @@ START_TEST(test_GetData) */ ret = pclKeyReadData(0x20, "links/last_link", 2, 0, buffer, READ_SIZE); //printf("----test_GetData => links/last_link \"%s\" => ret: %d \n", buffer, ret); - fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, - "Buffer not correctly read - links/last_link"); - fail_unless(ret == strlen("CACHE_ /last_exit/queens")); + ck_assert_str_eq( (char*)buffer, "CACHE_ /last_exit/queens"); + ck_assert_int_eq(ret, (int)strlen("CACHE_ /last_exit/queens")); memset(buffer, 0, READ_SIZE); - - - -#endif - } END_TEST - /** * Test the key value h a n d l e interface using different logicalDB id's, users and seats * Each resource below has an entry in the resource configuration table where @@ -212,12 +182,6 @@ END_TEST */ START_TEST (test_GetDataHandle) { - /* 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 get data handle"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0; unsigned char buffer[READ_SIZE] = {0}; @@ -225,33 +189,29 @@ START_TEST (test_GetDataHandle) char sysTimeBuffer[128]; -#if 1 time_t t = time(0); locTime = localtime(&t); snprintf(sysTimeBuffer, 128, "TimeAndData: \"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon+1, (locTime->tm_year+1900), locTime->tm_hour, locTime->tm_min, locTime->tm_sec); - - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 * ==> local value accessible by ALL USERS (user 0, seat 0) */ handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); - fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); + ck_assert_int_gt(handle, 0); ret = pclKeyHandleReadData(handle, buffer, READ_SIZE); //printf("pclKeyHandleReadData: \nsoll: %s \nist : %s => ret: %d | strlen: %d\n", "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", buffer, ret, strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); - fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret) == 0, "Buffer not correctly read => 1"); + fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", (size_t)ret) == 0, "Buffer not correctly read => 1"); size = pclKeyHandleGetSize(handle); //printf("pclKeyHandleGetSize => size: %d\n", size); - fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); + ck_assert_int_eq(size, (int)strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); // --------------------------------------------------------------------------------------------- - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 @@ -260,34 +220,12 @@ START_TEST (test_GetDataHandle) handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); - size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(size == (int)strlen(sysTimeBuffer)); // close ret = pclKeyHandleClose(handle2); // --------------------------------------------------------------------------------------------- - - // open handle --------------------------------------------------- - /** - * Logical DB ID: PCL_LDBID_LOCAL with user 0 and seat 0 - * ==> local value accessible by ALL USERS (user 0, seat 0) - */ -#if 0 // plugin test case - memset(buffer, 0, READ_SIZE); - handle4 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "language/country_code", 0, 0); - fail_unless(handle4 >= 0, "Failed to open handle /language/country_code"); - - ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2"); - - size = pclKeyHandleGetSize(handle4); - fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle")); - - ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE); -#endif - // --------------------------------------------------------------------------------------------- - - // open handle --------------------------------------------------- /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 @@ -300,15 +238,13 @@ START_TEST (test_GetDataHandle) fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3"); size = pclKeyHandleGetSize(handle3); - fail_unless(size = strlen(sysTimeBuffer)); + fail_unless(size = (int)strlen(sysTimeBuffer)); // --------------------------------------------------------------------------------------------- - // close handle ret = pclKeyHandleClose(handle); ret = pclKeyHandleClose(handle3); ret = pclKeyHandleClose(handle4); -#endif } END_TEST @@ -320,12 +256,6 @@ END_TEST */ START_TEST(test_SetData) { - /* 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 set data"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; char write1[READ_SIZE] = {0}; @@ -334,7 +264,6 @@ START_TEST(test_SetData) struct tm *locTime; -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) @@ -348,9 +277,7 @@ START_TEST(test_SetData) ret = pclKeyWriteData(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0, (unsigned char*)"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\"")); 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); locTime = localtime(&t); @@ -363,16 +290,16 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: 69 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", 1, 2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); -#if 1 + snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer); /** * Logical DB ID: PCL_LDBID_LOCAL with user 1 and seat 2 * ==> local USER value (user 1, seat 2) * Resource ID: 70 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)write1, strlen(write1)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)write1, (int)strlen(write1)); fail_unless(ret == (int)strlen(write1), "Wrong write size"); snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer); @@ -381,7 +308,7 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: key_70 */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "key_70", 1, 2, (unsigned char*)write2, strlen(write2)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "key_70", 1, 2, (unsigned char*)write2, (int)strlen(write2)); fail_unless(ret == (int)strlen(write2), "Wrong write size"); @@ -442,8 +369,6 @@ START_TEST(test_SetData) ret = pclKeyReadData(PCL_LDBID_LOCAL, "key_70", 1, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read"); fail_unless(ret == (int)strlen(write2), "Wrong read size"); -#endif -#endif } END_TEST @@ -456,17 +381,10 @@ END_TEST */ START_TEST(test_SetDataNoPRCT) { - /* 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 set data no PRCT"); - X_TEST_REPORT_TYPE(GOOD);*/ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; struct tm *locTime; -#if 1 time_t t = time(0); char sysTimeBuffer[128]; @@ -480,7 +398,7 @@ START_TEST(test_SetDataNoPRCT) * Logical DB ID: PCL_LDBID_LOCAL with user 1 and seat 2 * ==> local USER value (user 1, seat 2) */ - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); //printf("Write Buffer : %s\n", sysTimeBuffer); @@ -491,7 +409,6 @@ START_TEST(test_SetDataNoPRCT) fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read"); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size"); //printf("read buffer : %s\n", buffer); -#endif } END_TEST @@ -503,14 +420,7 @@ END_TEST */ START_TEST(test_GetDataSize) { - /* 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 get data size"); - X_TEST_REPORT_TYPE(GOOD); */ - int size = 0; -#if 1 /** * Logical DB ID: PCL_LDBID_LOCAL with user 3 and seat 2 * ==> local USER value (user 3, seat 2) @@ -518,14 +428,12 @@ START_TEST(test_GetDataSize) size = pclKeyGetSize(PCL_LDBID_LOCAL, "status/open_document", 3, 2); fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size"); - /** * Logical DB ID: 0x84 with user 2 and seat 1 * ==> shared user value accessible by A GROUP (user 2 and seat 1) */ size = pclKeyGetSize(0x84, "links/last_link", 2, 1); fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size"); -#endif } END_TEST @@ -537,15 +445,9 @@ END_TEST */ START_TEST(test_DeleteData) { - /* 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 delete data"); - X_TEST_REPORT_TYPE(GOOD); */ - int rval = 0; unsigned char buffer[READ_SIZE]; -#if 1 + // read data from key rval = pclKeyReadData(PCL_LDBID_LOCAL, "key_70", 1, 2, buffer, READ_SIZE); fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails"); @@ -571,244 +473,6 @@ START_TEST(test_DeleteData) // after deleting the key, reading from key must fail now! rval = pclKeyReadData(PCL_LDBID_LOCAL, "70", 1, 2, buffer, READ_SIZE); fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail"); -#endif -} -END_TEST - - - -// creat blacklist file, if this does not exist -void data_setupBlacklist(void) -{ - -/// backup info -char gBackupInfo[] = { -"/media/doNotBackupMe.txt_START\n\ -/media/doNotBackupMe_01.txt\n\ -/media/doNotBackupMe_02.txt\n\ -/media/doNotBackupMe_03.txt\n\ -/media/doNotBackupMe_04.txt\n\ -/media/iDontWantDoBeBackuped_01.txt\n\ -/media/iDontWantDoBeBackuped_02.txt\n\ -/media/iDontWantDoBeBackuped_03.txt\n\ -/media/iDontWantDoBeBackuped_04.txt\n\ -/media/iDontWantDoBeBackuped_05.txt_END\n" -}; - - const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info"; - - if(access(backupBlacklist, F_OK) == -1) - { - int ret = 0; - int handle = open(backupBlacklist, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - - ret = write(handle, gBackupInfo, strlen(gBackupInfo)); - if(ret != (int)strlen(gBackupInfo)) - { - printf("data_setupBlacklist => Wrong size written: %d", ret); - } - close(handle); - } -} - - -/* - * Test the file interface: - * - open file - * - read / write - * - remove file - * - map file - * - get size - */ -START_TEST(test_DataFile) -{ - /* 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 data file"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd = 0, i = 0, idx = 0; - int size = 0, ret = 0, avail = 100; - int writeSize = 16*1024; - int fdArray[10] = {0}; - - unsigned char buffer[READ_SIZE] = {0}; - unsigned char wBuffer[READ_SIZE] = {0}; - const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media"; - char* writeBuffer; - char* fileMap = NULL; - -#if 1 - writeBuffer = malloc(writeSize); - - // fill buffer a sequence - for(i = 0; i<(writeSize/8); i++) - { - writeBuffer[idx++] = 'A'; - writeBuffer[idx++] = 'B'; - writeBuffer[idx++] = 'C'; - writeBuffer[idx++] = ' '; - writeBuffer[idx++] = 'D'; - writeBuffer[idx++] = 'E'; - writeBuffer[idx++] = 'F'; - writeBuffer[idx++] = ' '; - } - // create file - fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db", - O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - close(fd); - - // open ------------------------------------------------------------ - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db"); - - - size = pclFileGetSize(fd); - fail_unless(size == 68, "Wrong file size"); - - - size = pclFileReadData(fd, buffer, READ_SIZE); - //printf("pclFileReadData:\n ist : \"%s\"\n soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd); - fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); - fail_unless(size == ((int)strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf - - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // open ------------------------------------------------------------ - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); - - size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer)); - fail_unless(size == (int)strlen(writeBuffer), "Failed to write data"); - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // remove ---------------------------------------------------------- - ret = pclFileRemove(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); - fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); - - fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR); - fail_unless(fd == -1, "Failed to remove file, file still exists"); - close(fd); - - // map file -------------------------------------------------------- - - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - - size = pclFileGetSize(fd); - pclFileMapData(fileMap, size, 0, fd); - fail_unless(fileMap != MAP_FAILED, "Failed to map file"); - - ret = pclFileUnmapData(fileMap, size); - fail_unless(ret != -1, "Failed to unmap file"); - - // file seek - ret = pclFileSeek(fd, 0, SEEK_CUR); - fail_unless(ret == 0, "Failed to seek file - pos 0"); - - ret = pclFileSeek(fd, 8, SEEK_CUR); - fail_unless(ret == 8, "Failed to seek file - pos 8"); - - // negative test - size = pclFileGetSize(1024); - fail_unless(size < 0 , "Got size, but should not"); - - ret = pclFileClose(fd); - fail_unless(ret == 0, "Failed to close file"); - - // test backup blacklist functionality - fdArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 1); - fdArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 2); - fdArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 20, 10); - fdArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 200, 100); - - fdArray[4] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_01.txt", 2, 1); - fdArray[5] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_02.txt", 2, 1); - fdArray[6] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_03.txt", 2, 1); - fdArray[7] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_04.txt", 2, 1); - - fdArray[8] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_04.txt", 2, 1); - fdArray[9] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1); - - for(i=0; i<10; i++) - { - snprintf( (char*)wBuffer, 1024, "Test - %d", i); - pclFileWriteData(fdArray[i], wBuffer, strlen( (char*)wBuffer)); - } - - // - // test if backup blacklist works correctly - // - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "1. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "2. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "3. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK); - fail_unless(avail == -1, "4. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK); - fail_unless(avail == -1, "5. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK); - fail_unless(avail == -1, "6. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK); - fail_unless(avail == -1, "7. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK); - fail_unless(avail == -1, "8. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK); - fail_unless(avail == -1, "9. Failed backup => backup available, but should not"); - - avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK); - fail_unless(avail == -1, "10. Failed backup => backup available, but should not"); - - for(i=0; i<10; i++) - { - pclFileClose(fdArray[i]); - } - - // write to file not in RCT - fd = pclFileOpen(PCL_LDBID_LOCAL, "nonRCT/aNonRctFile.db", 1, 1); - size = pclFileGetSize(fd); - size = pclFileWriteData(fd, "nonRCT/mediaDB.db", strlen("nonRCT/mediaDB.db")); - - - free(writeBuffer); -#endif -} -END_TEST - - - -START_TEST(test_DataFileConfDefault) -{ - int fd = 0; - char readBuffer[READ_SIZE] = {0}; - char* refBuffer01 = "Some default file content: 01 Configurable default data 01."; - char* refBuffer02 = "Some default file content: 02 Configurable default data 02."; - - // -- file interface --- - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_01.configurable", 99, 99); - (void)pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp(readBuffer, refBuffer01, strlen(refBuffer01)) == 0, "Buffer not correctly read => mediaData_01.configurable"); - (void)pclFileClose(fd); - - - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_02.configurable", 99, 99); - (void)pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp(readBuffer, refBuffer02, strlen(refBuffer02)) == 0, "Buffer not correctly read => mediaData_01.configurable"); - (void)pclFileClose(fd); } END_TEST @@ -816,10 +480,10 @@ END_TEST void data_setupBackup(void) { - int handle = -1; - const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; + int handle = -1; + const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; (void)pclInitLibrary(gTheAppId, shutdownReg); handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); @@ -829,224 +493,9 @@ void data_setupBackup(void) } } -START_TEST(test_DataFileBackupCreation) -{ - /* 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 file backup creation"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1; - char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! "; - const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~"; - char rBuffer[1024] = {0}; - -#if 1 - - fd_RO = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); - fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); - - fd_RW = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadWrite.db", 1, 1); - fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db"); - - rval = pclFileReadData(fd_RW, rBuffer, 10); - fail_unless(rval == 10, "Failed read 10 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileReadData(fd_RW, rBuffer, 15); - fail_unless(rval == 15, "Failed read 15 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileReadData(fd_RW, rBuffer, 20); - fail_unless(rval == 20, "Failed read 20 bytes"); - memset(rBuffer, 0, 1024); - - rval = pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer)); - fail_unless(rval == (int)strlen(wBuffer), "Failed write data"); - - // verify the backup creation: - handle = open(path, O_RDWR); - fail_unless(handle != -1, "Could not open file ==> failed to access backup file"); - - rval = read(handle, rBuffer, 1024); - //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData); - fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read"); - - - (void)close(handle); - (void)pclFileClose(fd_RW); - (void)pclFileClose(fd_RO); - -#endif -} -END_TEST - - - -void data_setupRecovery(void) -{ - int i = 0; - char createPath[128] = {0}; - - int handleRecov = -1, handleToBackup = -1, handleToCs = -1; - char* corruptData = "Some corrupted data .. )=§?=34=/%&$%&()Ö:ÄNJH/)("; - const char* pathToRecover = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; - const char* pathToBackup = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~"; - const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc"; - - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - (void)pclInitLibrary(gTheAppId, shutdownReg); - - // create directory, even if exist - snprintf(createPath, 128, "%s", gSourcePath ); - while(gPathSegemnts[i] != NULL) - { - strncat(createPath, gPathSegemnts[i++], 128-1); - mkdir(createPath, 0744); - } - - handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleRecov, corruptData, strlen(corruptData)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToRecover); - } - - handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToBackup); - } - - handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1) - { - printf("setup test: failed to write test data: %s\n", pathToChecksum); - } - - close(handleRecov); - close(handleToBackup); - close(handleToCs); - -} - -START_TEST(test_DataFileRecovery) -{ - /* 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 file recovery form backup"); - X_TEST_REPORT_TYPE(GOOD); */ - - int handle = 0; - unsigned char buffer[READ_SIZE] = {0}; - - handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_DataRecovery.db", 1, 1); - //printf("pclFileOpen => handle: %d\n", handle); - fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db"); - - - /*ret = */(void)pclFileReadData(handle, buffer, READ_SIZE); - //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret); - //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)); - fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed"); - - (void)pclFileClose(handle); -} -END_TEST - - - -/* - * The the handle function of the key and file interface. - */ -START_TEST(test_DataHandle) -{ - /* 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 data handle"); - X_TEST_REPORT_TYPE(GOOD); */ - - int handle1 = 0, handle2 = 0; - int handleArray[4] = {0}; - int ret = 0; - unsigned char buffer[READ_SIZE] = {0}; - -#if 1 - // test multiple handles - handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db"); - - handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db"); - - handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db"); - - handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[0], buffer, READ_SIZE); - fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!"); - 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"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[1], buffer, READ_SIZE); - 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"); - - memset(buffer, 0, READ_SIZE); - ret = pclFileReadData(handleArray[2], buffer, READ_SIZE); - 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"); - - memset(buffer, 0, READ_SIZE); - (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); - 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"); - - ret = pclKeyHandleClose(handleArray[0]); - fail_unless(ret != -1, "Failed to close handle idx \"0\"!!"); - - ret = pclKeyHandleClose(handleArray[1]); - fail_unless(ret != -1, "Failed to close handle idx \"1\"!!"); - - ret = pclKeyHandleClose(handleArray[2]); - fail_unless(ret != -1, "Failed to close handle idx \"2\"!!"); - - ret = pclKeyHandleClose(handleArray[3]); - fail_unless(ret != -1, "Failed to close handle idx \"3\"!!"); - - // test key handles - handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); - fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); - - ret = pclKeyHandleClose(handle2); - fail_unless(ret != -1, "Failed to close handle!!"); - - ret = pclKeyHandleClose(1024); - fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!"); - - // test file handles - handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); - ret = pclFileClose(handle1); - fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); - ret = pclFileClose(1024); - fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!"); -#endif -} -END_TEST @@ -1056,14 +505,7 @@ END_TEST */ START_TEST(test_DataHandleOpen) { - /* 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 data handle open"); - X_TEST_REPORT_TYPE(GOOD); */ - int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0; -#if 1 // open handles ---------------------------------------------------- hd1 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position1", 0, 0); fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1"); @@ -1121,7 +563,6 @@ START_TEST(test_DataHandleOpen) ret = pclKeyHandleClose(hd9); fail_unless(ret != -1, "Failed to close handle!!"); -#endif } END_TEST @@ -1129,44 +570,36 @@ END_TEST START_TEST(test_Plugin) { - /* 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 plugins"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - unsigned char buffer[READ_SIZE] = {0}; - -#if 1 + int ret = 0; + unsigned char buffer[READ_SIZE] = {0}; - ret = pclKeyReadData(PCL_LDBID_LOCAL, "secured", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") ); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "secured", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") ); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!", strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "early", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!")); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "early", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!")); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!", strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "emergency", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!")); - fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!")); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "emergency", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!")); + fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!")); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!", strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "hwinfo", 0, 0, buffer, READ_SIZE); - //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!")); - fail_unless(ret != EPERS_NOT_INITIALIZED); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "hwinfo", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!")); + fail_unless(ret != EPERS_NOT_INITIALIZED); fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!", strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read"); - memset(buffer, 0, READ_SIZE); + memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(PCL_LDBID_LOCAL, "custom2", 0, 0, buffer, READ_SIZE); //printf("B U F F E R - custom2: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom2!")); @@ -1183,17 +616,15 @@ START_TEST(test_Plugin) memset(buffer, 0, READ_SIZE); ret = pclKeyWriteData(PCL_LDBID_LOCAL, "custom3", 0, 0, (unsigned char*)"This is a message to write", READ_SIZE); - fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456 + fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456 ret = pclKeyGetSize(PCL_LDBID_LOCAL, "custom3", 0, 0); - fail_unless(ret == 44332211, "Failed query custom data size"); // plugin should return 44332211 + fail_unless(ret == 44332211, "Failed query custom data size"); // plugin should return 44332211 ret = pclKeyDelete(PCL_LDBID_LOCAL, "custom3", 0, 0); - fail_unless(ret == 13579, "Failed query custom data size"); // plugin should return 13579 - -#endif + fail_unless(ret == 13579, "Failed query custom data size"); // plugin should return 13579 } END_TEST @@ -1203,16 +634,9 @@ END_TEST START_TEST(test_ReadDefault) { - /* 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 read default"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; -#if 1 ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/default01", 3, 2, buffer, READ_SIZE); //printf(" --- test_ReadConfDefault => statusHandle/default01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_01!")); fail_unless(ret == strlen("DEFAULT_01!")); @@ -1225,8 +649,6 @@ START_TEST(test_ReadDefault) ret = pclKeyGetSize(PCL_LDBID_LOCAL, "statusHandle/default01", 3, 2); fail_unless(ret == strlen("DEFAULT_01!"), "Invalid size"); - -#endif } END_TEST @@ -1234,12 +656,6 @@ END_TEST START_TEST(test_ReadConfDefault) { - /* 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 configurable default data"); - X_TEST_REPORT_TYPE(GOOD); */ - int ret = 0; unsigned char buffer[READ_SIZE] = {0}; #if 1 @@ -1264,20 +680,14 @@ END_TEST START_TEST(test_WriteConfDefault) { - /* 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("Write configurable default data"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0, fd = 0; + int ret = 0; unsigned char writeBuffer[] = "This is a test string"; unsigned char writeBuffer2[] = "And this is a test string which is different form previous test string"; unsigned char readBuffer[READ_SIZE] = {0}; // -- key-value interface --- - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer, strlen((char*)writeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer, (int)strlen((char*)writeBuffer)); fail_unless(ret == (int)strlen((char*)writeBuffer), "Write Conf default data: write size does not match"); ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", 3, 2, readBuffer, READ_SIZE); fail_unless(ret == (int)strlen((char*)writeBuffer), "Write Conf default data: read size does not match"); @@ -1285,87 +695,38 @@ START_TEST(test_WriteConfDefault) //printf(" --- test_ReadConfDefault => statusHandle/writeconfdefault01: \"%s\" => \"%s\" \n retIst: %d retSoll: %d\n", readBuffer, writeBuffer, ret, strlen((char*)writeBuffer)); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer2, strlen((char*)writeBuffer2)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", PCL_USER_DEFAULTDATA, 0, writeBuffer2, (int)strlen((char*)writeBuffer2)); fail_unless(ret == (int)strlen((char*)writeBuffer2), "Write Conf default data 2: write size does not match"); ret = pclKeyReadData(PCL_LDBID_LOCAL, "statusHandle/writeconfdefault01", 3, 2, readBuffer, READ_SIZE); fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)readBuffer)) == 0, "Buffer2 not correctly read"); //printf(" --- test_ReadConfDefault => statusHandle/writeconfdefault01: \"%s\" => \"%s\" \n retIst: %d retSoll: %d\n", readBuffer, writeBuffer2, ret, strlen((char*)writeBuffer2)); - - // -- file interface --- - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); - ret = pclFileWriteData(fd, writeBuffer, strlen((char*)writeBuffer)); - pclFileSeek(fd, 0, SEEK_SET); - ret = pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer, strlen((char*)writeBuffer)) == 0, "Buffer not correctly read"); - (void)pclFileClose(fd); - - memset(readBuffer, 0, READ_SIZE); - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); - ret = pclFileWriteData(fd, writeBuffer2, strlen((char*)writeBuffer2)); - pclFileSeek(fd, 0, SEEK_SET); - ret = pclFileReadData(fd, readBuffer, READ_SIZE); - fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)writeBuffer2)) == 0, "Buffer2 not correctly read"); - (void)pclFileClose(fd); - } END_TEST -START_TEST(test_GetPath) -{ - /* 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 get path"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - char* path = NULL; - const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; - unsigned int pathSize = 0; - -#if 1 - ret = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_create.db", 1, 1, &path, &pathSize); - - fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); - fail_unless(pathSize == strlen((char*)path), "Path size not correct"); - - pclFileReleasePath(ret); -#endif -} -END_TEST - - START_TEST(test_InitDeinit) { - /* 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("Init and deinit library"); - X_TEST_REPORT_TYPE(GOOD); */ - int i = 0, rval = -1, handle = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; for(i=0; i<5; i++) { - // initialize and deinitialize 1. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 1. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); - // initialize and deinitialize 2. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 2. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); - // initialize and deinitialize 3. time - (void)pclInitLibrary(gTheAppId, shutdownReg); - pclDeinitLibrary(); + // initialize and deinitialize 3. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); } @@ -1386,11 +747,6 @@ START_TEST(test_InitDeinit) pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE); - handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); - //printf("pclFileOpen: %d\n", handle); - fail_unless(handle >= 0, "Could not open file ==> /media/mediaDB.db"); - (void)pclFileClose(handle); - handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); //printf("pclKeyHandleOpen: %d\n", handle); fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); @@ -1406,7 +762,6 @@ START_TEST(test_InitDeinit) rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); - //EPERS_COMMON pclDeinitLibrary(); @@ -1417,12 +772,6 @@ END_TEST START_TEST(test_NegHandle) { - /* 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 negative handle"); - X_TEST_REPORT_TYPE(GOOD); */ - int handle = -1, ret = 0; int negativeHandle = -17; unsigned char buffer[128] = {0}; @@ -1461,19 +810,13 @@ END_TEST START_TEST(test_utf8_string) { - /* 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 UTF8 String"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0, size = 0; + int ret = 0, size = 0; const char* utf8StringBuffer = "String °^° Ñ text"; unsigned char buffer[128] = {0}; ret = pclKeyReadData(PCL_LDBID_LOCAL, "utf8String", 3, 2, buffer, READ_SIZE); fail_unless(ret == (int)strlen(utf8StringBuffer), "Wrong read size"); - fail_unless(strncmp((char*)buffer, utf8StringBuffer, ret-1) == 0, "Buffer not correctly read => 1"); + fail_unless(strncmp((char*)buffer, utf8StringBuffer, (size_t)ret-1) == 0, "Buffer not correctly read => 1"); size = pclKeyGetSize(PCL_LDBID_LOCAL, "utf8String", 3, 2); fail_unless(size == (int)strlen(utf8StringBuffer), "Invalid size"); @@ -1484,14 +827,21 @@ END_TEST START_TEST(test_Notifications) { - /* 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 notifications"); - X_TEST_REPORT_TYPE(GOOD); */ - - pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); - pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + int ret = 0; + ret = pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, myChangeCallback); + fail_unless(ret == 0, "Failed to register"); + + ret = pclKeyUnRegisterNotifyOnChange(PCL_LDBID_LOCAL, "status/open_document", 1, 1, myChangeCallback); + fail_unless(ret == EPERS_NOTIFY_NOT_ALLOWED, "Possible to register, but should not - is local variable"); + + ret = pclKeyUnRegisterNotifyOnChange(0x20, "notInRCT", 1, 1, myChangeCallback); + fail_unless(ret == EPERS_NOKEYDATA, "Possible to register, but should not - not in rct"); } END_TEST @@ -1499,14 +849,8 @@ END_TEST #if USE_APPCHECK START_TEST(test_ValidApplication) { - /* 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 valid applications"); - X_TEST_REPORT_TYPE(GOOD); */ - - int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int ret = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[128] = {0}; ret = pclInitLibrary("InvalidAppID", shutdownReg); @@ -1545,44 +889,6 @@ END_TEST #endif - -START_TEST(test_VerifyROnly) -{ - /* 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 read only file"); - X_TEST_REPORT_TYPE(GOOD); */ - - int fd = 0; - int rval = 0; - char* wBuffer = "This is a test string"; - - fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); - fail_unless(fd != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); - - rval = pclFileWriteData(fd, wBuffer, strlen(wBuffer)); - fail_unless(rval == EPERS_RESOURCE_READ_ONLY, "Write to read only file is possible, but should not ==> /media/mediaDB_ReadOnly.db"); - - rval = pclFileClose(fd); - fail_unless(rval == 0, "Failed to close file: media/mediaDB_ReadOnly.db"); - - /* - char* path = NULL; - unsigned int pathSize = 0; - const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadOnly.db"; - rval = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1, &path, &pathSize); - printf("pclFileCreatePath: %d | %s \n ", rval, path); - x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); - - pclFileReleasePath(rval); - */ -} -END_TEST - - - - START_TEST(test_PAS_DbusInterface) { // let the administration servis generate a message to the PCL @@ -1657,7 +963,7 @@ END_TEST START_TEST(test_SharedAccess) { int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[256] = {0}; char sysTimeBuffer[256]; struct tm *locTime; @@ -1671,7 +977,7 @@ START_TEST(test_SharedAccess) (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Failed to write shared data "); ret = pclKeyReadData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, buffer, 256); @@ -1683,7 +989,7 @@ START_TEST(test_SharedAccess) (void)pclInitLibrary("node-health-monitor", shutdownReg); // now use a different app id, which is not able to write this resource - ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)"This is a test Buffer", strlen("This is a test Buffer")); + ret = pclKeyWriteData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, (unsigned char*)"This is a test Buffer", (int)strlen("This is a test Buffer")); fail_unless(ret == EPERS_NOT_RESP_APP, "Able to write shared data, but should not!!"); ret = pclKeyReadData(PCL_LDBID_PUBLIC, "aSharedResource", 1, 1, buffer, 256); @@ -1699,7 +1005,7 @@ END_TEST START_TEST(test_VO722) { int ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[256] = {0}; char* writeBuffer[] = {"VO722 - TestString One", @@ -1711,7 +1017,7 @@ START_TEST(test_VO722) "2 - VO722 - Test - String Three -", }; (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[0], strlen(writeBuffer[0])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[0], (int)strlen(writeBuffer[0])); fail_unless(ret == (int)strlen(writeBuffer[0]), "Wrong write size"); memset(buffer, 0, 256); @@ -1720,7 +1026,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer[0]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer[0], strlen((char*)writeBuffer[0])) == 0, "Buffer not correctly read - 1.1"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[1], strlen(writeBuffer[1])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[1], (int)strlen(writeBuffer[1])); fail_unless(ret == (int)strlen(writeBuffer[1]), "Wrong write size"); memset(buffer, 0, 256); @@ -1729,7 +1035,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer[1]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer[1], strlen((char*)writeBuffer[1])) == 0, "Buffer not correctly read - 1.2"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[2], strlen(writeBuffer[2])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 1, 2, (unsigned char*)writeBuffer[2], (int)strlen(writeBuffer[2])); fail_unless(ret == (int)strlen(writeBuffer[2]), "Wrong write size"); pclDeinitLibrary(); @@ -1751,7 +1057,7 @@ START_TEST(test_VO722) (void)pclInitLibrary(gTheAppId, shutdownReg); // use the app id, the resource is registered for - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[0], strlen(writeBuffer2[0])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[0], (int)strlen(writeBuffer2[0])); fail_unless(ret == (int)strlen(writeBuffer2[0]), "Wrong write size"); memset(buffer, 0, 256); @@ -1761,7 +1067,7 @@ START_TEST(test_VO722) fail_unless(strncmp((char*)buffer, writeBuffer2[0], strlen((char*)writeBuffer2[0])) == 0, "Buffer not correctly read - 2.1"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[1], strlen(writeBuffer2[1])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[1], (int)strlen(writeBuffer2[1])); fail_unless(ret == (int)strlen(writeBuffer2[1]), "Wrong write size"); memset(buffer, 0, 256); @@ -1770,7 +1076,7 @@ START_TEST(test_VO722) fail_unless(ret == (int)strlen(writeBuffer2[1]), "Failed to read shared data "); fail_unless(strncmp((char*)buffer, writeBuffer2[1], strlen((char*)writeBuffer2[1])) == 0, "Buffer not correctly read - 2.2"); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[2], strlen(writeBuffer2[2])); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "ContactListViewSortOrder", 0, 0, (unsigned char*)writeBuffer2[2], (int)strlen(writeBuffer2[2])); fail_unless(ret == (int)strlen(writeBuffer2[2]), "Wrong write size"); pclDeinitLibrary(); @@ -1790,115 +1096,12 @@ END_TEST - -void runTestSequence(const char* resourceID) -{ - int fd1 = 0, fd2 = 0, rval = 0; - unsigned char buffer[READ_SIZE] = {0}; - unsigned char writebuffer[] = {" _Updates file_ "}; - unsigned char writebuffer2[] = {" _New Data_ "}; - - // part one: write to file - // ------------------------------------------ - fd1 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); - - (void)pclFileReadData(fd1, buffer, READ_SIZE); - (void)pclFileWriteData(fd1, writebuffer, strlen((char*)writebuffer)); - - #if 1 - rval = pclFileClose(fd1); - fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); - #else - printf("\nN O C L O S E\n\n"); - #endif - - // part two: remove file - // ------------------------------------------ - rval = pclFileRemove(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(rval == 0, "Could not remove file ==> dataLoc/file.txt"); - - - // part three: open file again, and write to it - // ------------------------------------------ - fd2 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); - fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); - - (void)pclFileWriteData(fd2, writebuffer2, strlen((char*)writebuffer2)); - - rval = pclFileClose(fd2); - fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); -} - - -START_TEST(test_FileTest) -{ - int i = 0; - const char* resourceID_01 = "dataLoc/fileB.txt"; - const char* resourceID_02 = "dataLoc/fileA.txt"; - int fdArray[10] = {0}; - - const char* resourceIDArray[] = {"dataLoc/fileC.txt", - "dataLoc/fileD.txt", - "dataLoc/fileE.txt", - "dataLoc/fileF.txt", - "dataLoc/fileG.txt"}; -#if 1 - const char* testStringsFirst[] = {"FIRST - - Test Data START - dataLoc/fileC.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileD.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileE.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileF.txt - Test Data END ", - "FIRST - - Test Data START - dataLoc/fileG.txt - Test Data END "}; - - const char* testStringsSecond[] = {"Second - - Test Data START - dataLoc/fileC.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileD.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileE.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileF.txt - Test Data END ", - "Second - - Test Data START - dataLoc/fileG.txt - Test Data END "}; -#endif - // open files - - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - fdArray[i] = pclFileOpen(PCL_LDBID_LOCAL, resourceIDArray[i], 1, 1); - //printf("******** test_FileTest => pclFileOpen: %s -- %d\n", resourceIDArray[i], fdArray[i] ); - fail_unless(fdArray[i] != -1, "Could not open file ==> file: %s", resourceIDArray[i]); - } - - // write to files - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - (void)pclFileWriteData(fdArray[i], testStringsFirst[i], strlen((char*)testStringsFirst[i])); - } - - runTestSequence(resourceID_01); - runTestSequence(resourceID_02); - - - // write to files again - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - (void)pclFileWriteData(fdArray[i], testStringsSecond[i], strlen((char*)testStringsSecond[i])); - } - - - // close files - for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) - { - fdArray[i] = pclFileClose(fdArray[i]); - fail_unless(fdArray[i] == 0, "Could not close file ==> file: %s - %d", resourceIDArray[i], fdArray[i]); - } -} -END_TEST - - - START_TEST(test_NoRct) { int ret = 0; const char writeBuffer[] = "This is a test string"; - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "someResourceId", 0, 0, (unsigned char*)writeBuffer, strlen(writeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "someResourceId", 0, 0, (unsigned char*)writeBuffer, (int)strlen(writeBuffer)); fail_unless(ret == EPERS_NOPRCTABLE, "RCT available, but should not"); } END_TEST @@ -1907,7 +1110,7 @@ END_TEST START_TEST(test_InvalidPluginfConf) { - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; const char* envVariable = "PERS_CLIENT_LIB_CUSTOM_LOAD"; // change to an invalid plugin configuration file using environment variable @@ -1966,11 +1169,16 @@ void* readThread(void* userData) { int ret = 0, i = 0; unsigned char buffer[READ_SIZE] = {0}; + char threadName[64] = {0}; + char* uData = NULL; + uData = (char*)userData; - pthread_barrier_wait(&barrier); - usleep(10000); + memset(threadName, 0, 64-1); + memcpy(threadName, uData, 64-1); + threadName[64-1] = '\0'; - (void)userData; + pthread_barrier_wait(&gBarrierOne); + usleep(5000); for(i=0; ithreadName, NAME_LEN); payload[NAME_LEN-1] = '\0'; // string end termination - pthread_barrier_wait(&barrier); + pthread_barrier_wait(&gBarrierTwo); usleep(5000); for(i=0; itm_wday], locTime->tm_mday, locTime->tm_mon+1, (locTime->tm_year+1900), - locTime->tm_hour, locTime->tm_min, locTime->tm_sec, (int)(curTime.tv_nsec / 1.0e6), curTime.tv_nsec ); + snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d::%.4d:%.8ld Uhr\"", dayOfWeek[locTime->tm_wday], (int)locTime->tm_mday, (int)locTime->tm_mon+1, (int)(locTime->tm_year+1900), + (int)locTime->tm_hour, (int)locTime->tm_min, (int)locTime->tm_sec, (int)((int)curTime.tv_nsec / 1.0e6), curTime.tv_nsec ); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "69", threadData->index, 2, (unsigned char*)payload, strlen(payload)); + ret = pclKeyWriteData((unsigned int)PCL_LDBID_LOCAL, "69", (unsigned int)threadData->index, 2, (unsigned char*)payload, (int)strlen(payload)); fail_unless(ret == (int)strlen(payload), "Wrong write size"); + usleep(2000); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, payload, 1, threadData->index, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, payload, 1, (unsigned int)threadData->index, (unsigned char*)sysTimeBuffer, (int)strlen(sysTimeBuffer)); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong write size"); + usleep(3000); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)staticString, strlen(staticString)); + ret = pclKeyWriteData(PCL_LDBID_LOCAL, "70", 1, 2, (unsigned char*)staticString, (int)strlen(staticString)); fail_unless(ret == (int)strlen(staticString), "Wrong write size"); - + usleep(3000); memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "69", threadData->index, 2, buffer, READ_SIZE); + ret = pclKeyReadData(PCL_LDBID_LOCAL, "69", (unsigned int)threadData->index, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, payload, strlen(payload)) == 0, "2: Buffer not correctly read"); fail_unless(ret == (int)strlen(payload), "Wrong read size"); + usleep(5000); memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(PCL_LDBID_LOCAL, payload, 1, threadData->index, buffer, READ_SIZE); + ret = pclKeyReadData(PCL_LDBID_LOCAL, payload, 1, (unsigned int)threadData->index, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "1: Buffer not correctly read"); fail_unless(ret == (int)strlen(sysTimeBuffer), "Wrong read size"); + usleep(2000); memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(PCL_LDBID_LOCAL, "70", 1, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, staticString, strlen(staticString)) == 0, "3: Buffer not correctly read"); fail_unless(ret == (int)strlen(staticString), "Wrong read size"); + usleep(3000); } - return NULL; + pthread_exit(0); } + START_TEST(test_MultiThreadedWrite) { - pthread_t threads[NUM_THREADS]; - int* retval; int i=0; - int success[NUM_THREADS] = {0}; + pthread_t gWritethreads[NUM_THREADS]; t_threadData threadData[NUM_THREADS]; - if(pthread_barrier_init(&barrier, NULL, NUM_THREADS) == 0) + if(pthread_barrier_init(&gBarrierTwo, NULL, NUM_THREADS) == 0) { for(i=0; i= 2) { - printf("Running concurrency tests\n"); + printf("Running concurrency tests\n"); - run_concurrency_test(); + run_concurrency_test(); } else { -#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_VERBOSE /*CK_NORMAL CK_VERBOSE*/); - - printf("Running automated tests\n"); - nr_failed = srunner_ntests_failed(sr); - nr_run = srunner_ntests_run(sr); - - tResult = srunner_results(sr); - for(i = 0; i< nr_run; i++) - { - (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); - } - - srunner_free(sr); + Suite * s = persistencyClientLib_suite(); + SRunner * sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); + srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml"); + srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log"); + + srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/); + + nr_failed = srunner_ntests_failed(sr); + srunner_ntests_run(sr); + + srunner_free(sr); } -#endif - pclDeinitLibrary(); + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test")); // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); DLT_UNREGISTER_APP(); - dlt_free(); - return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; } @@ -2575,65 +1623,285 @@ int main(int argc, char *argv[]) void do_pcl_concurrency_access(const char* applicationID, const char* resourceID, int operation) { - int ret = 0, i = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - unsigned char buffer[READ_SIZE] = {0}; - - (void)pclInitLibrary(applicationID, shutdownReg); - - for(i=0; i< 10; i++) - { - printf("[%d] - i: %d \n", operation, i); - if(operation == 0 ) - { - ret = pclKeyWriteData(0x20, resourceID, 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); - if(ret < 0) - printf("Failed to write data: %d\n", ret); - } - else if(operation == 1) - { - memset(buffer, 0, READ_SIZE); - ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, READ_SIZE); - if(ret < 0) - printf("Failed to read data: %d\n", ret); - } - else - { - printf("invalid operation - end!! \n"); - break; - } - } - - pclDeinitLibrary(); + int ret = 0, i = 0; + size_t bufferSize = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + unsigned char* buffer = NULL; + + char* writeBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß"; + + bufferSize = strlen(writeBuffer); + + buffer = malloc(bufferSize); + + if(buffer != NULL) + { + (void)pclInitLibrary(applicationID, shutdownReg); + + for(i=0; i< 10000; i++) + { + memset(buffer, 0, bufferSize); + + //printf("[%d] - i: %d \n", operation, i); + if(operation == 0 ) + { + ret = pclKeyWriteData(0x20, resourceID, 2, 1,(unsigned char* )writeBuffer, (int)bufferSize); + if(ret < 0) + printf("Failed to write data: %d\n", ret); + + ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, (int)bufferSize); + if(ret < 0) + { + printf("Failed to read data: %d\n", ret); + } + else + { + if(strncmp((char*)buffer, writeBuffer, (size_t)ret) != 0) + printf("Wrong buffer\n"); + } + } + else if(operation == 1) + { + ret = pclKeyReadData(0x20, resourceID, 2, 1, buffer, (int)bufferSize); + if(ret < 0) + { + printf("Failed to read data: %d\n", ret); + } + else + { + if(strncmp((char*)buffer, writeBuffer, (size_t)ret) != 0) + printf("Wrong buffer\n"); + } + } + else + { + printf("invalid operation - end!! \n"); + break; + } + + if(operation == 0) + usleep(1500); + else + usleep(1000); + } + + free(buffer); + + pclDeinitLibrary(); + } + } void run_concurrency_test() { - const char* appId_one = "lt-persistence_client_library_test"; - const char* appId_two = "concurrency_test"; + const char* appId_one = "lt-persistence_client_library_test"; + const char* appId_two = "concurrency_test"; - int pid = fork(); + int pid = fork(); - if (pid == 0) - { /*child*/ - printf("Started child process with PID: [%d] \n", pid); + if (pid == 0) + { /*child*/ + printf("Started child process with PID: [%d] \n", pid); - do_pcl_concurrency_access(appId_one, "links/last_link2", 0); //write + do_pcl_concurrency_access(appId_one, "links/last_link2", 0); //write - printf("CHILD exits! \n"); + printf("CHILD exits! \n"); - _exit(EXIT_SUCCESS); - } - else if (pid > 0) - { /*parent*/ - printf("Started father process with PID: [%d] \n", pid); + _exit(EXIT_SUCCESS); + } + else if (pid > 0) + { /*parent*/ + printf("Started father process with PID: [%d] \n", pid); - do_pcl_concurrency_access(appId_two, "links/last_link2", 1); //read + do_pcl_concurrency_access(appId_two, "links/last_link2", 1); //read - printf("PARENT exits! \n"); + printf("PARENT exits! \n"); - _exit(EXIT_SUCCESS); - } + _exit(EXIT_SUCCESS); + } } + +const char* gWriteBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste"; + +const char* gWriteBuffer2 = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - "; + diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c new file mode 100644 index 0000000..c336c45 --- /dev/null +++ b/test/persistence_client_library_test_file.c @@ -0,0 +1,1201 @@ +/****************************************************************************** + * Project Persistency + * (c) copyright 2012 + * Company XS Embedded GmbH + *****************************************************************************/ +/****************************************************************************** + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed + * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +******************************************************************************/ + /** + * @file persistence_client_library_test.c + * @author Ingo Huerner + * @brief Test of persistence client library + * @see + */ + +#include +#include +#include +#include +#include /* exit */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#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" + + +#define READ_SIZE 1024 +#define MaxAppNameLen 256 + +#define NUM_THREADS 100 +#define NUM_OF_WRITES 350 +#define NAME_LEN 24 + +typedef struct s_threadData +{ + char threadName[NAME_LEN]; + int index; + int fd1; + int fd2; +} t_threadData; + +static pthread_barrier_t gBarrierOne; + +static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL }; +static const char* gSourcePath = "/Data/mnt-c/lt-persistence_client_library_test/"; + +/// application id +char gTheAppId[MaxAppNameLen] = {0}; + +// definition of weekday +char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +char* gWriteBackupTestData = "This is the content of the file /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; +char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; +char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/ + +extern const char* gWriteBuffer; +extern const char* gWriteBuffer2; + + +/// debug log and trace (DLT) setup +DLT_DECLARE_CONTEXT(gPcltDLTContext); + + +// function prototype +void run_concurrency_test(); + +void data_setup(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); +} + + +void data_setup_browser(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary("browser", shutdownReg); +} + + +void data_setup_norct(void) +{ + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + (void)pclInitLibrary("norct", shutdownReg); +} + + +void data_teardown(void) +{ + pclDeinitLibrary(); +} + + +int myChangeCallback(pclNotification_s * notifyStruct) +{ + printf(" ==> * - * myChangeCallback * - *\n"); + (void)notifyStruct; + return 1; +} + + +// creat blacklist file, if this does not exist +void data_setupBlacklist(void) +{ + +/// backup info +char gBackupInfo[] = { +"/media/doNotBackupMe.txt_START\n\ +/media/doNotBackupMe_01.txt\n\ +/media/doNotBackupMe_02.txt\n\ +/media/doNotBackupMe_03.txt\n\ +/media/doNotBackupMe_04.txt\n\ +/media/iDontWantDoBeBackuped_01.txt\n\ +/media/iDontWantDoBeBackuped_02.txt\n\ +/media/iDontWantDoBeBackuped_03.txt\n\ +/media/iDontWantDoBeBackuped_04.txt\n\ +/media/iDontWantDoBeBackuped_05.txt_END\n" +}; + + const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info"; + + if(access(backupBlacklist, F_OK) == -1) + { + ssize_t ret = 0; + int handle = open(backupBlacklist, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + + ret = write(handle, gBackupInfo, strlen(gBackupInfo)); + if(ret != (int)strlen(gBackupInfo)) + { + printf("data_setupBlacklist => Wrong size written: %d", (int)ret); + } + close(handle); + } +} + + +/* + * Test the file interface: + * - open file + * - read / write + * - remove file + * - map file + * - get size + */ +START_TEST(test_DataFile) +{ + int fd = 0, i = 0, idx = 0; + int size = 0, ret = 0, avail = 100; + int writeSize = 16*1024; + int fdArray[10] = {0}; + + unsigned char buffer[READ_SIZE] = {0}; + unsigned char wBuffer[READ_SIZE] = {0}; + const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media"; + char* writeBuffer; + char* fileMap = NULL; + + writeBuffer = malloc((size_t)writeSize); + + // fill buffer a sequence + for(i = 0; i<(writeSize/8); i++) + { + writeBuffer[idx++] = 'A'; + writeBuffer[idx++] = 'B'; + writeBuffer[idx++] = 'C'; + writeBuffer[idx++] = ' '; + writeBuffer[idx++] = 'D'; + writeBuffer[idx++] = 'E'; + writeBuffer[idx++] = 'F'; + writeBuffer[idx++] = ' '; + } + // create file + fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db", + O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + close(fd); + + // open ------------------------------------------------------------ + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db"); + + + size = pclFileGetSize(fd); + fail_unless(size == 68, "Wrong file size"); + + + size = pclFileReadData(fd, buffer, READ_SIZE); + //printf("pclFileReadData:\n ist : \"%s\"\n soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd); + fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); + fail_unless(size == ((int)strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf + + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // open ------------------------------------------------------------ + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); + + size = pclFileWriteData(fd, writeBuffer, (int)strlen(writeBuffer)); + fail_unless(size == (int)strlen(writeBuffer), "Failed to write data"); + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // remove ---------------------------------------------------------- + ret = pclFileRemove(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); + + fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR); + fail_unless(fd == -1, "Failed to remove file, file still exists"); + close(fd); + + // map file -------------------------------------------------------- + + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + + size = pclFileGetSize(fd); + pclFileMapData(fileMap, size, 0, fd); + fail_unless(fileMap != MAP_FAILED, "Failed to map file"); + + ret = pclFileUnmapData(fileMap, size); + fail_unless(ret != -1, "Failed to unmap file"); + + // file seek + ret = pclFileSeek(fd, 0, SEEK_CUR); + fail_unless(ret == 0, "Failed to seek file - pos 0"); + + ret = pclFileSeek(fd, 8, SEEK_CUR); + fail_unless(ret == 8, "Failed to seek file - pos 8"); + + // negative test + size = pclFileGetSize(1024); + fail_unless(size < 0 , "Got size, but should not"); + + ret = pclFileClose(fd); + fail_unless(ret == 0, "Failed to close file"); + + // test backup blacklist functionality + fdArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 1); + fdArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 1, 2); + fdArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 20, 10); + fdArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe.txt_START", 200, 100); + + fdArray[4] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_01.txt", 2, 1); + fdArray[5] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_02.txt", 2, 1); + fdArray[6] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_03.txt", 2, 1); + fdArray[7] = pclFileOpen(PCL_LDBID_LOCAL, "media/doNotBackupMe_04.txt", 2, 1); + + fdArray[8] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_04.txt", 2, 1); + fdArray[9] = pclFileOpen(PCL_LDBID_LOCAL, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1); + + for(i=0; i<10; i++) + { + snprintf( (char*)wBuffer, 1024, "Test - %d", i); + pclFileWriteData(fdArray[i], wBuffer, (int)strlen((char*)wBuffer)); + } + + // + // test if backup blacklist works correctly + // + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "1. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "2. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "3. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK); + fail_unless(avail == -1, "4. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK); + fail_unless(avail == -1, "5. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK); + fail_unless(avail == -1, "6. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK); + fail_unless(avail == -1, "7. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK); + fail_unless(avail == -1, "8. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK); + fail_unless(avail == -1, "9. Failed backup => backup available, but should not"); + + avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK); + fail_unless(avail == -1, "10. Failed backup => backup available, but should not"); + + for(i=0; i<10; i++) + { + pclFileClose(fdArray[i]); + } + + // write to file not in RCT + fd = pclFileOpen(PCL_LDBID_LOCAL, "nonRCT/aNonRctFile.db", 1, 1); + size = pclFileGetSize(fd); + size = pclFileWriteData(fd, "nonRCT/mediaDB.db", strlen("nonRCT/mediaDB.db")); + + free(writeBuffer); +} +END_TEST + + + +START_TEST(test_DataFileConfDefault) +{ + int fd = 0; + char readBuffer[READ_SIZE] = {0}; + char* refBuffer01 = "Some default file content: 01 Configurable default data 01."; + char* refBuffer02 = "Some default file content: 02 Configurable default data 02."; + + // -- file interface --- + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_01.configurable", 99, 99); + (void)pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp(readBuffer, refBuffer01, strlen(refBuffer01)) == 0, "Buffer not correctly read => mediaData_01.configurable"); + (void)pclFileClose(fd); + + + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData_02.configurable", 99, 99); + (void)pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp(readBuffer, refBuffer02, strlen(refBuffer02)) == 0, "Buffer not correctly read => mediaData_01.configurable"); + (void)pclFileClose(fd); +} +END_TEST + + + +void data_setupBackup(void) +{ + int handle = -1; + const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db"; + + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); + + handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handle, gWriteBackupTestData, strlen(gWriteBackupTestData)) == -1) + { + printf("setup test: failed to write test data: %s\n", path); + } +} + +START_TEST(test_DataFileBackupCreation) +{ + int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1; + char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! "; + const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~"; + char rBuffer[1024] = {0}; + +#if 1 + + fd_RO = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); + fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); + + fd_RW = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadWrite.db", 1, 1); + fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db"); + + rval = pclFileReadData(fd_RW, rBuffer, 10); + fail_unless(rval == 10, "Failed read 10 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileReadData(fd_RW, rBuffer, 15); + fail_unless(rval == 15, "Failed read 15 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileReadData(fd_RW, rBuffer, 20); + fail_unless(rval == 20, "Failed read 20 bytes"); + memset(rBuffer, 0, 1024); + + rval = pclFileWriteData(fd_RW, wBuffer, (int)strlen(wBuffer)); + fail_unless(rval == (int)strlen(wBuffer), "Failed write data"); + + // verify the backup creation: + handle = open(path, O_RDWR); + fail_unless(handle != -1, "Could not open file ==> failed to access backup file"); + + rval = (int)read(handle, rBuffer, 1024); + //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData); + fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read"); + + + (void)close(handle); + (void)pclFileClose(fd_RW); + (void)pclFileClose(fd_RO); + +#endif +} +END_TEST + + + +void data_setupRecovery(void) +{ + int i = 0; + char createPath[128] = {0}; + + int handleRecov = -1, handleToBackup = -1, handleToCs = -1; + char* corruptData = "Some corrupted data .. )=§?=34=/%&$%&()Ö:ÄNJH/)("; + const char* pathToRecover = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db"; + const char* pathToBackup = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~"; + const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc"; + + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + (void)pclInitLibrary(gTheAppId, shutdownReg); + + // create directory, even if exist + snprintf(createPath, 128, "%s", gSourcePath ); + while(gPathSegemnts[i] != NULL) + { + strncat(createPath, gPathSegemnts[i++], 128-1); + mkdir(createPath, 0744); + } + + handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleRecov, corruptData, strlen(corruptData)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToRecover); + } + + handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToBackup); + } + + handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1) + { + printf("setup test: failed to write test data: %s\n", pathToChecksum); + } + + close(handleRecov); + close(handleToBackup); + close(handleToCs); + +} + +START_TEST(test_DataFileRecovery) +{ + int handle = 0; + unsigned char buffer[READ_SIZE] = {0}; + + handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_DataRecovery.db", 1, 1); + //printf("pclFileOpen => handle: %d\n", handle); + fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db"); + + + /*ret = */(void)pclFileReadData(handle, buffer, READ_SIZE); + //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret); + //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)); + fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed"); + + (void)pclFileClose(handle); +} +END_TEST + + + +/* + * The the handle function of the key and file interface. + */ +START_TEST(test_DataHandle) +{ + int handle1 = 0, handle2 = 0; + int handleArray[4] = {0}; + int ret = 0; + unsigned char buffer[READ_SIZE] = {0}; + + // test multiple handles + handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db"); + + handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db"); + + handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db"); + + handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[0], buffer, READ_SIZE); + fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!"); + 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"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[1], buffer, READ_SIZE); + 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"); + + memset(buffer, 0, READ_SIZE); + ret = pclFileReadData(handleArray[2], buffer, READ_SIZE); + 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"); + + memset(buffer, 0, READ_SIZE); + (void)pclFileReadData(handleArray[3], buffer, READ_SIZE); + 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"); + + ret = pclKeyHandleClose(handleArray[0]); + fail_unless(ret != -1, "Failed to close handle idx \"0\"!!"); + + ret = pclKeyHandleClose(handleArray[1]); + fail_unless(ret != -1, "Failed to close handle idx \"1\"!!"); + + ret = pclKeyHandleClose(handleArray[2]); + fail_unless(ret != -1, "Failed to close handle idx \"2\"!!"); + + ret = pclKeyHandleClose(handleArray[3]); + fail_unless(ret != -1, "Failed to close handle idx \"3\"!!"); + + // test key handles + handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2); + fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document"); + + ret = pclKeyHandleClose(handle2); + fail_unless(ret != -1, "Failed to close handle!!"); + + ret = pclKeyHandleClose(1024); + fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!"); + + + // test file handles + handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db"); + + ret = pclFileClose(handle1); + fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db"); + + ret = pclFileClose(1024); + fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!"); +} +END_TEST + + +START_TEST(test_WriteConfDefault) +{ + int ret = 0, fd = 0; + unsigned char writeBuffer[] = "This is a test string"; + unsigned char writeBuffer2[] = "And this is a test string which is different form previous test string"; + unsigned char readBuffer[READ_SIZE] = {0}; + + // -- file interface --- + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); + ret = pclFileWriteData(fd, writeBuffer, (int)strlen((char*)writeBuffer)); + fail_unless(ret >= 0, "Failed pclFileWriteData"); + pclFileSeek(fd, 0, SEEK_SET); + ret = pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer, strlen((char*)writeBuffer)) == 0, "Buffer not correctly read"); + (void)pclFileClose(fd); + + memset(readBuffer, 0, READ_SIZE); + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaData.configurable", PCL_USER_DEFAULTDATA, 99); + ret = pclFileWriteData(fd, writeBuffer2, (int)strlen((char*)writeBuffer2)); + fail_unless(ret >= 0, "Failed pclFileWriteData"); + pclFileSeek(fd, 0, SEEK_SET); + ret = pclFileReadData(fd, readBuffer, READ_SIZE); + fail_unless(strncmp((char*)readBuffer, (char*)writeBuffer2, strlen((char*)writeBuffer2)) == 0, "Buffer2 not correctly read"); + (void)pclFileClose(fd); +} +END_TEST + + + +START_TEST(test_GetPath) +{ + int ret = 0; + char* path = NULL; + const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db"; + unsigned int pathSize = 0; + + ret = pclFileCreatePath(PCL_LDBID_LOCAL, "media/mediaDB_create.db", 1, 1, &path, &pathSize); + + fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct"); + fail_unless(pathSize == strlen((char*)path), "Path size not correct"); + + pclFileReleasePath(ret); +} +END_TEST + + + +START_TEST(test_InitDeinit) +{ + int i = 0, rval = -1, handle = 0; + int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + for(i=0; i<5; i++) + { + // initialize and deinitialize 1. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + + + // initialize and deinitialize 2. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + + + // initialize and deinitialize 3. time + (void)pclInitLibrary(gTheAppId, shutdownReg); + pclDeinitLibrary(); + } + + // test multiple init/deinit + pclInitLibrary(gTheAppId, shutdownReg); + pclInitLibrary(gTheAppId, shutdownReg); + + pclDeinitLibrary(); + pclDeinitLibrary(); + pclDeinitLibrary(); + + // test lifecycle set + pclInitLibrary(gTheAppId, shutdownReg); + rval = pclLifecycleSet(PCL_SHUTDOWN); + fail_unless(rval == EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set allowed, but should not"); + pclDeinitLibrary(); + + + pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE); + + handle = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1); + //printf("pclFileOpen: %d\n", handle); + fail_unless(handle >= 0, "Could not open file ==> /media/mediaDB.db"); + (void)pclFileClose(handle); + + handle = pclKeyHandleOpen(PCL_LDBID_LOCAL, "posHandle/last_position", 0, 0); + //printf("pclKeyHandleOpen: %d\n", handle); + fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); + (void)pclKeyHandleClose(handle); + + rval = pclLifecycleSet(PCL_SHUTDOWN); + fail_unless(rval != EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set NOT allowed, but should"); + + + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + rval = pclLifecycleSet(PCL_SHUTDOWN_CANCEL); + + pclDeinitLibrary(); +} +END_TEST + + + +START_TEST(test_VerifyROnly) +{ + int fd = 0; + int rval = 0; + char* wBuffer = "This is a test string"; + + fd = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_ReadOnly.db", 1, 1); + fail_unless(fd != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db"); + + rval = pclFileWriteData(fd, wBuffer, (int)strlen(wBuffer)); + fail_unless(rval == EPERS_RESOURCE_READ_ONLY, "Write to read only file is possible, but should not ==> /media/mediaDB_ReadOnly.db"); + + rval = pclFileClose(fd); + fail_unless(rval == 0, "Failed to close file: media/mediaDB_ReadOnly.db"); +} +END_TEST + + + +void runTestSequence(const char* resourceID) +{ + int fd1 = 0, fd2 = 0, rval = 0; + unsigned char buffer[READ_SIZE] = {0}; + unsigned char writebuffer[] = {" _Updates file_ "}; + unsigned char writebuffer2[] = {" _New Data_ "}; + + // part one: write to file + // ------------------------------------------ + fd1 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); + + (void)pclFileReadData(fd1, buffer, READ_SIZE); + (void)pclFileWriteData(fd1, writebuffer, (int)strlen((char*)writebuffer)); + + #if 1 + rval = pclFileClose(fd1); + fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); + #else + printf("\nN O C L O S E\n\n"); + #endif + + // part two: remove file + // ------------------------------------------ + rval = pclFileRemove(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(rval == 0, "Could not remove file ==> dataLoc/file.txt"); + + + // part three: open file again, and write to it + // ------------------------------------------ + fd2 = pclFileOpen(PCL_LDBID_LOCAL, resourceID, 1, 1); + fail_unless(fd1 != -1, "Could not open file ==> dataLoc/file.txt"); + + (void)pclFileWriteData(fd2, writebuffer2, (int)strlen((char*)writebuffer2)); + + rval = pclFileClose(fd2); + fail_unless(rval == 0, "Could not close file ==> dataLoc/file.txt"); +} + + +START_TEST(test_FileTest) +{ + int i = 0; + const char* resourceID_01 = "dataLoc/fileB.txt"; + const char* resourceID_02 = "dataLoc/fileA.txt"; + int fdArray[10] = {0}; + + const char* resourceIDArray[] = {"dataLoc/fileC.txt", + "dataLoc/fileD.txt", + "dataLoc/fileE.txt", + "dataLoc/fileF.txt", + "dataLoc/fileG.txt"}; +#if 1 + const char* testStringsFirst[] = {"FIRST - - Test Data START - dataLoc/fileC.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileD.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileE.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileF.txt - Test Data END ", + "FIRST - - Test Data START - dataLoc/fileG.txt - Test Data END "}; + + const char* testStringsSecond[] = {"Second - - Test Data START - dataLoc/fileC.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileD.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileE.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileF.txt - Test Data END ", + "Second - - Test Data START - dataLoc/fileG.txt - Test Data END "}; +#endif + // open files + + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + fdArray[i] = pclFileOpen(PCL_LDBID_LOCAL, resourceIDArray[i], 1, 1); + //printf("******** test_FileTest => pclFileOpen: %s -- %d\n", resourceIDArray[i], fdArray[i] ); + fail_unless(fdArray[i] != -1, "Could not open file ==> file: %s", resourceIDArray[i]); + } + + // write to files + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + (void)pclFileWriteData(fdArray[i], testStringsFirst[i], (int)strlen((char*)testStringsFirst[i])); + } + + runTestSequence(resourceID_01); + runTestSequence(resourceID_02); + + + // write to files again + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + (void)pclFileWriteData(fdArray[i], testStringsSecond[i], (int)strlen((char*)testStringsSecond[i])); + } + + + // close files + for(i=0; i<(int)sizeof(resourceIDArray) / (int)sizeof(char*); i++) + { + fdArray[i] = pclFileClose(fdArray[i]); + fail_unless(fdArray[i] == 0, "Could not close file ==> file: %s - %d", resourceIDArray[i], fdArray[i]); + } +} +END_TEST + +void* fileWriteThread(void* userData) +{ + t_threadData* threadData = (t_threadData*)userData; + + static int i = 0; + + size_t bufferSize = strlen(gWriteBuffer); + size_t bufferSize2 = strlen(gWriteBuffer2); + + unsigned char* readbuffer = malloc(bufferSize); + unsigned char* readbuffer2 = malloc(bufferSize2); + + if(readbuffer != NULL && readbuffer2 != NULL) + { + pthread_barrier_wait(&gBarrierOne); + usleep(5000); + + for(i=0; ifd1, gWriteBuffer, (int)bufferSize); + ck_assert_int_ge(wsize, 0); + pclFileSeek(threadData->fd1, 0, SEEK_SET); + + rsize = pclFileReadData(threadData->fd1, readbuffer, (int)bufferSize); + ck_assert_int_eq(rsize, (int)bufferSize); + + usleep( (useconds_t)(50 * i * threadData->index)); // do some "random" sleep + + memset(readbuffer2, 0, bufferSize2); + + wsize2 = pclFileWriteData(threadData->fd2, gWriteBuffer2, (int)bufferSize2); + ck_assert_int_ge(wsize2, 0); + pclFileSeek(threadData->fd2, 0, SEEK_SET); + + rsize2 = pclFileReadData(threadData->fd2, readbuffer2, (int)bufferSize2); + ck_assert_int_eq(rsize2, (int)bufferSize2); + } + + free(readbuffer); + free(readbuffer2); + } + + return NULL; +} + + +START_TEST(test_MultFileReadWrite) +{ + int fd1 = -1; + int fd2 = -1; + + fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1); + fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 2, 1); + + if(fd1 != -1 && fd2 != 0) + { + pthread_t threads[NUM_THREADS]; + int* retval; + int i=0; + int success[NUM_THREADS] = {0}; + t_threadData threadData[NUM_THREADS]; + + if(pthread_barrier_init(&gBarrierOne, NULL, NUM_THREADS) == 0) + { + for(i=0; i /media/mediaDBWrite.db\n"); + } +} +END_TEST + + + + +static Suite * persistencyClientLib_suite() +{ + const char* testSuiteName = "Persistency Client Library (File-API)"; + + Suite * s = suite_create(testSuiteName); + + TCase * tc_persDataFile = tcase_create("DataFile"); + tcase_add_test(tc_persDataFile, test_DataFile); + tcase_set_timeout(tc_persDataFile, 3); + + TCase * tc_DataFileConfDefault = tcase_create("DataFileConfDefault"); + tcase_add_test(tc_DataFileConfDefault, test_DataFileConfDefault); + tcase_set_timeout(tc_DataFileConfDefault, 3); + + TCase * tc_persDataFileBackupCreation = tcase_create("DataFileBackupCreation"); + tcase_add_test(tc_persDataFileBackupCreation, test_DataFileBackupCreation); + tcase_set_timeout(tc_persDataFileBackupCreation, 3); + + TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery"); + tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery); + tcase_set_timeout(tc_persDataFileRecovery, 3); + + TCase * tc_WriteConfDefault = tcase_create("WriteConfDefault"); + tcase_add_test(tc_WriteConfDefault, test_WriteConfDefault); + tcase_set_timeout(tc_WriteConfDefault, 3); + + TCase * tc_GetPath = tcase_create("GetPath"); + tcase_add_test(tc_GetPath, test_GetPath); + tcase_set_timeout(tc_GetPath, 3); + + TCase * tc_InitDeinit = tcase_create("InitDeinit"); + tcase_add_test(tc_InitDeinit, test_InitDeinit); + tcase_set_timeout(tc_InitDeinit, 3); + + TCase * tc_VerifyROnly = tcase_create("VerifyROnly"); + tcase_add_test(tc_VerifyROnly, test_VerifyROnly); + tcase_set_timeout(tc_VerifyROnly, 3); + + TCase * tc_FileTest = tcase_create("FileTest"); + tcase_add_test(tc_FileTest, test_FileTest); + tcase_set_timeout(tc_FileTest, 3); + + TCase * tc_DataHandle= tcase_create("DataHandle"); + tcase_add_test(tc_DataHandle, test_DataHandle); + tcase_set_timeout(tc_DataHandle, 3); + + TCase * tc_MultiFileReadWrite = tcase_create("MultFileReadWrite"); + tcase_add_test(tc_MultiFileReadWrite, test_MultFileReadWrite); + tcase_set_timeout(tc_MultiFileReadWrite, 20); + + + suite_add_tcase(s, tc_WriteConfDefault); + tcase_add_checked_fixture(tc_WriteConfDefault, data_setup, data_teardown); + + suite_add_tcase(s, tc_persDataFile); + tcase_add_checked_fixture(tc_persDataFile, data_setup, data_teardown); + + suite_add_tcase(s, tc_persDataFileBackupCreation); + tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown); + + suite_add_tcase(s, tc_persDataFileRecovery); + tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown); + + suite_add_tcase(s, tc_GetPath); + tcase_add_checked_fixture(tc_GetPath, data_setup, data_teardown); + + suite_add_tcase(s, tc_VerifyROnly); + tcase_add_checked_fixture(tc_VerifyROnly, data_setup, data_teardown); + + suite_add_tcase(s, tc_DataFileConfDefault); + tcase_add_checked_fixture(tc_DataFileConfDefault, data_setup, data_teardown); + + suite_add_tcase(s, tc_FileTest); + tcase_add_checked_fixture(tc_FileTest, data_setup_browser, data_teardown); + + suite_add_tcase(s, tc_InitDeinit); + + suite_add_tcase(s, tc_DataHandle); + tcase_add_checked_fixture(tc_DataHandle, data_setup, data_teardown); + + suite_add_tcase(s, tc_MultiFileReadWrite); + tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown); + + return s; +} + + +int main(int argc, char *argv[]) +{ + int nr_failed = 0; + (void)argv; + (void)argc; + + // assign application name + strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen); + gTheAppId[MaxAppNameLen-1] = '\0'; + + /// debug log and trace (DLT) setup + DLT_REGISTER_APP("PCLT", "PCL tests"); + + DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing"); + + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("Starting PCL test")); + + data_setupBlacklist(); + + Suite * s = persistencyClientLib_suite(); + SRunner * sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); + + srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/); + + nr_failed = srunner_ntests_failed(sr); + srunner_ntests_run(sr); + srunner_free(sr); + + DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test")); + + // unregister debug log and trace + DLT_UNREGISTER_CONTEXT(gPcltDLTContext); + DLT_UNREGISTER_APP(); + + return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; + +} + +const char* gWriteBuffer = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste"; + +const char* gWriteBuffer2 = "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste""Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - " + "How vexingly quick daft zebras jump! - " + "Bright vixens jump; dozy fowl quack - " + "Sphinx of black quartz, judge my vow" + "Voyez le brick géant que j’examine près du wha" + "Zornig und gequält rügen jeweils Pontifex und Volk die maßlose bischöfliche Hybris" + "Xaver schreibt für Wikipedia zum Spaß quälend lang über Yoga, Soja und Öko" + "Polyfon zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark" + "Fix, Schwyz!“ quäkt Jürgen blöd vom Paß" + "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux" + "Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste" + "Pack my box with five dozen liquor jugs. - " + "Jackdaws love my big sphinx of quartz. - " + "The five boxing wizards jump quickly. - "; + diff --git a/test/persistence_test_customlib.c b/test/persistence_test_customlib.c index 9295df5..93cc80a 100644 --- a/test/persistence_test_customlib.c +++ b/test/persistence_test_customlib.c @@ -91,7 +91,7 @@ int plugin_handle_get_data(int handle, char* buffer, int size) //printf("plugin_handle_get_data: %s\n", LIBIDENT); (void)handle; - return snprintf(buffer, size, "Custom plugin -> plugin_get_data_handle: %s!", LIBIDENT); + return snprintf(buffer, (size_t)size, "Custom plugin -> plugin_get_data_handle: %s!", LIBIDENT); } /** * @brief get data @@ -111,7 +111,7 @@ int plugin_get_data(const char* path, char* buffer, int size) (void)buffer; (void)size; - return snprintf(buffer, size, "Custom plugin -> plugin_get_data: %s!", LIBIDENT); + return snprintf(buffer, (size_t)size, "Custom plugin -> plugin_get_data: %s!", LIBIDENT); } -- cgit v1.2.1