1 /******************************************************************************
4 * Company XS Embedded GmbH
5 *****************************************************************************/
6 /******************************************************************************
7 * This Source Code Form is subject to the terms of the
8 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
9 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 ******************************************************************************/
12 * @file persistence_client_library_test.c
13 * @author Ingo Huerner
14 * @brief Test of persistence client library
22 #include <unistd.h> /* exit */
29 #include <dlt/dlt_common.h>
31 #include "persCheck.h"
34 #include "../include/persistence_client_library_file.h"
35 #include "../include/persistence_client_library_key.h"
36 #include "../include/persistence_client_library.h"
37 #include "../include/persistence_client_library_error_def.h"
42 #define NUM_OF_FILES 3
43 #define READ_SIZE 1024
44 #define MaxAppNameLen 256
46 #define SOURCE_PATH "/Data/mnt-c/lt-persistence_client_library_test/"
49 static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL };
52 char gTheAppId[MaxAppNameLen] = {0};
54 // definition of weekday
55 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
56 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";
57 char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db";
58 char* gRecovChecksum = "608a3b5d"; // generated with http://www.tools4noobs.com/online_php_functions/crc32/
62 void data_teardown(void)
64 printf("* * * tear down * * *\n"); // nothing
68 int myChangeCallback(pclNotification_s * notifyStruct)
70 printf(" ==> * - * myChangeCallback * - *\n");
78 * Test the key value interface using different logicalDB id's, users and seats.
79 * Each resource below has an entry in the resource configuration table where the
80 * storage location (cached or write through) and type (e.g. custom) has been configured.
82 START_TEST(test_GetData)
84 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
85 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
86 X_TEST_REPORT_REFERENCE("NONE");
87 X_TEST_REPORT_DESCRIPTION("Test of get data");
88 X_TEST_REPORT_TYPE(GOOD);
91 unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
93 unsigned char buffer[READ_SIZE] = {0};
95 ret = pclInitLibrary(gTheAppId, shutdownReg);
96 x_fail_unless(ret <= 1, "Failed to init PCL");
100 * Logical DB ID: 0xFF with user 0 and seat 0
101 * ==> local value accessible by all users (user 0, seat 0)
103 ret = pclKeyReadData(0xFF, "pos/last_position", 1, 1, buffer, READ_SIZE);
104 //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"));
105 x_fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06",
106 strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position");
107 x_fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06"));
108 memset(buffer, 0, READ_SIZE);
111 * Logical DB ID: 0xFF with user 0 and seat 0
112 * ==> local value accessible by all users (user 0, seat 0)
115 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
116 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
117 strlen((char*)buffer)) == 0, "Buffer not correctly read");
118 x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
119 memset(buffer, 0, READ_SIZE);
124 * Logical DB ID: 0 with user 3 and seat 0
125 * ==> public shared user value (user 3, seat 0)
127 //ret = pclKeyReadData(0, "language/current_language", 0, 0, buffer, READ_SIZE);
128 //printf("----test_GetData => language/current_language \"%s\" => ret: %d \n", buffer, ret);
129 //x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
130 //memset(buffer, 0, READ_SIZE);
133 * Logical DB ID: 0xFF with user 3 and seat 2
134 * ==> local USER value (user 3, seat 2)
136 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
137 //printf("----test_GetData => status/open_document \"%s\" => ret: %d \n", buffer, ret);
138 x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0,
139 "Buffer not correctly read - status/open_document");
140 x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
141 memset(buffer, 0, READ_SIZE);
144 * Logical DB ID: 0x20 with user 4 and seat 0
145 * ==> shared user value accessible by a group (user 4 and seat 0)
147 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
148 //printf("----test_GetData => address/home_address \"%s\" => ret: %d \n", buffer, ret);
149 x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0,
150 "Buffer not correctly read - address/home_address");
151 x_fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31"));
152 memset(buffer, 0, READ_SIZE);
155 * Logical DB ID: 0xFF with user 0 and seat 0
156 * ==> local value accessible by ALL USERS (user 0, seat 0)
158 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
159 //printf("----test_GetData => pos/last_satellites \"%s\" => ret: %d \n", buffer, ret);
160 x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0,
161 "Buffer not correctly read - pos/last_satellites");
162 x_fail_unless(ret == strlen("WT_ 17"));
163 memset(buffer, 0, READ_SIZE);
166 * Logical DB ID: 0x20 with user 4 and seat 0
167 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
169 ret = pclKeyReadData(0x20, "links/last_link", 2, 0, buffer, READ_SIZE);
170 //printf("----test_GetData => links/last_link \"%s\" => ret: %d \n", buffer, ret);
171 x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0,
172 "Buffer not correctly read - links/last_link");
173 x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"));
174 memset(buffer, 0, READ_SIZE);
184 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
185 * Each resource below has an entry in the resource configuration table where
186 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
188 START_TEST (test_GetDataHandle)
190 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
191 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
192 X_TEST_REPORT_REFERENCE("NONE");
193 X_TEST_REPORT_DESCRIPTION("Test of get data handle");
194 X_TEST_REPORT_TYPE(GOOD);
196 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
197 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
199 unsigned char buffer[READ_SIZE] = {0};
202 char sysTimeBuffer[128];
204 ret = pclInitLibrary(gTheAppId, shutdownReg);
205 x_fail_unless(ret <= 1, "Failed to init PCL");
209 locTime = localtime(&t);
211 snprintf(sysTimeBuffer, 128, "TimeAndData: \"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
212 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
215 // open handle ---------------------------------------------------
217 * Logical DB ID: 0xFF with user 0 and seat 0
218 * ==> local value accessible by ALL USERS (user 0, seat 0)
220 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
221 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
223 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
224 x_fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read => 1");
226 size = pclKeyHandleGetSize(handle);
227 x_fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
228 // ---------------------------------------------------------------------------------------------
231 // open handle ---------------------------------------------------
233 * Logical DB ID: 0xFF with user 3 and seat 2
234 * ==> local USER value (user 3, seat 2)
236 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
237 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
239 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
240 x_fail_unless(size == strlen(sysTimeBuffer));
242 ret = pclKeyHandleClose(handle2);
243 // ---------------------------------------------------------------------------------------------
246 // open handle ---------------------------------------------------
248 * Logical DB ID: 0xFF with user 0 and seat 0
249 * ==> local value accessible by ALL USERS (user 0, seat 0)
251 #if 0 // plugin test case
252 memset(buffer, 0, READ_SIZE);
253 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
254 printf("H A N D L E: %d\n", handle4);
255 x_fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
257 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
258 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
260 size = pclKeyHandleGetSize(handle4);
261 x_fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
263 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
265 // ---------------------------------------------------------------------------------------------
268 // open handle ---------------------------------------------------
270 * Logical DB ID: 0xFF with user 3 and seat 2
271 * ==> local USER value (user 3, seat 2)
273 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
274 x_fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
276 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
277 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
279 size = pclKeyHandleGetSize(handle3);
280 x_fail_unless(size = strlen(sysTimeBuffer));
281 // ---------------------------------------------------------------------------------------------
285 ret = pclKeyHandleClose(handle);
286 ret = pclKeyHandleClose(handle3);
287 ret = pclKeyHandleClose(handle4);
295 * Write data to a key using the key interface.
296 * First write data to different keys and after
297 * read the data for verification.
299 START_TEST(test_SetData)
301 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
302 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
303 X_TEST_REPORT_REFERENCE("NONE");
304 X_TEST_REPORT_DESCRIPTION("Test of set data");
305 X_TEST_REPORT_TYPE(GOOD);
308 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
309 unsigned char buffer[READ_SIZE] = {0};
310 char write1[READ_SIZE] = {0};
311 char write2[READ_SIZE] = {0};
312 char sysTimeBuffer[256];
316 ret = pclInitLibrary(gTheAppId, shutdownReg);
317 x_fail_unless(ret <= 1, "Failed to init PCL");
321 * Logical DB ID: 0xFF with user 3 and seat 2
322 * ==> local USER value (user 3, seat 2)
324 ret = pclKeyWriteData(0xFF, "status/open_document", 3, 2, (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
325 x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Wrong write size");
328 ret = pclKeyWriteData(0x84, "links/last_link", 2, 1, (unsigned char*)"CACHE_ /last_exit/queens", strlen("CACHE_ /last_exit/queens"));
329 x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"), "Wrong write size");
331 ret = pclKeyWriteData(0xFF, "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\""));
332 x_fail_unless(ret == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""), "Wrong write size");
338 locTime = localtime(&t);
341 snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
342 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
345 * Logical DB ID: 0xFF with user 1 and seat 2
346 * ==> local USER value (user 1, seat 2)
349 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
350 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
352 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
354 * Logical DB ID: 0xFF with user 1 and seat 2
355 * ==> local USER value (user 1, seat 2)
358 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
359 x_fail_unless(ret == strlen(write1), "Wrong write size");
361 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
363 * Logical DB ID: 0xFF with user 1 and seat 2
364 * ==> local USER value (user 1, seat 2)
365 * Resource ID: key_70
367 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
368 x_fail_unless(ret == strlen(write2), "Wrong write size");
371 /*******************************************************************************************************************************************/
372 /* used for changed notification testing */
373 /*******************************************************************************************************************************************/
375 * Logical DB ID: 0x84 with user 2 and seat 1
376 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
378 * ==> used for shared testing
380 //printf("Write data to trigger change notification\n");
381 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
382 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
385 * Logical DB ID: 0x84 with user 2 and seat 1
386 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
388 * ==> used for shared testing
390 //printf("Write data to trigger change notification\n");
391 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
392 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
395 * Logical DB ID: 0x84 with user 2 and seat 1
396 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
398 * ==> used for shared testing
400 //printf("Write data to trigger change notification\n");
401 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
402 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
403 /*******************************************************************************************************************************************/
404 /*******************************************************************************************************************************************/
408 * now read the data written in the previous steps to the keys
409 * and verify data has been written correctly.
411 memset(buffer, 0, READ_SIZE);
413 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
414 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
415 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
417 memset(buffer, 0, READ_SIZE);
419 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
420 x_fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
421 x_fail_unless(ret == strlen(write1), "Wrong read size");
423 memset(buffer, 0, READ_SIZE);
425 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
426 x_fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
427 x_fail_unless(ret == strlen(write2), "Wrong read size");
437 * Write data to a key using the key interface.
438 * The key is not in the persistence resource table.
439 * The key sill then be stored to the location local and cached.
441 START_TEST(test_SetDataNoPRCT)
443 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
444 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
445 X_TEST_REPORT_REFERENCE("NONE");
446 X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT");
447 X_TEST_REPORT_TYPE(GOOD);
450 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
451 unsigned char buffer[READ_SIZE] = {0};
454 ret = pclInitLibrary(gTheAppId, shutdownReg);
455 x_fail_unless(ret <= 1, "Failed to init PCL");
459 char sysTimeBuffer[128];
461 locTime = localtime(&t);
463 snprintf(sysTimeBuffer, 128, "TimeAndData: \"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
464 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
467 * Logical DB ID: 0xFF with user 1 and seat 2
468 * ==> local USER value (user 1, seat 2)
470 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
471 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
472 //printf("Write Buffer : %s\n", sysTimeBuffer);
474 // read data again and and verify datat has been written correctly
475 memset(buffer, 0, READ_SIZE);
477 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
478 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
479 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
480 //printf("read buffer : %s\n", buffer);
489 * Test the key interface.
490 * Read the size of a key.
492 START_TEST(test_GetDataSize)
494 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
495 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
496 X_TEST_REPORT_REFERENCE("NONE");
497 X_TEST_REPORT_DESCRIPTION("Test of get data size");
498 X_TEST_REPORT_TYPE(GOOD);
500 int size = 0, ret = 0;
502 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
504 ret = pclInitLibrary(gTheAppId, shutdownReg);
505 x_fail_unless(ret <= 1, "Failed to init PCL");
508 * Logical DB ID: 0xFF with user 3 and seat 2
509 * ==> local USER value (user 3, seat 2)
511 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
512 x_fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
516 * Logical DB ID: 0x84 with user 2 and seat 1
517 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
519 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
520 x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
528 * Delete a key using the key value interface.
529 * First read a from a key, the delte the key
530 * and then try to read again. The Last read must fail.
532 START_TEST(test_DeleteData)
534 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
535 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
536 X_TEST_REPORT_REFERENCE("NONE");
537 X_TEST_REPORT_DESCRIPTION("Test of delete data");
538 X_TEST_REPORT_TYPE(GOOD);
541 unsigned char buffer[READ_SIZE];
542 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
544 rval = pclInitLibrary(gTheAppId, shutdownReg);
545 x_fail_unless(rval <= 1, "Failed to init PCL");
547 // read data from key
548 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
549 x_fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
552 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
553 x_fail_unless(rval >= 0, "Failed to delete key");
555 // after deleting the key, reading from key must fail now!
556 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
557 x_fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
561 // read data from key
562 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
563 x_fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
566 rval = pclKeyDelete(0xFF, "70", 1, 2);
567 x_fail_unless(rval >= 0, "Failed to delete key");
569 // after deleting the key, reading from key must fail now!
570 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
571 x_fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
579 // creat blacklist file, if this does not exist
580 void data_setupBlacklist(void)
584 char gBackupInfo[] = {
585 "/media/doNotBackupMe.txt_START\n\
586 /media/doNotBackupMe_01.txt\n\
587 /media/doNotBackupMe_02.txt\n\
588 /media/doNotBackupMe_03.txt\n\
589 /media/doNotBackupMe_04.txt\n\
590 /media/iDontWantDoBeBackuped_01.txt\n\
591 /media/iDontWantDoBeBackuped_02.txt\n\
592 /media/iDontWantDoBeBackuped_03.txt\n\
593 /media/iDontWantDoBeBackuped_04.txt\n\
594 /media/iDontWantDoBeBackuped_05.txt_END\n"
597 const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info";
599 if(access(backupBlacklist, F_OK) == -1)
602 int handle = open(backupBlacklist, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
604 ret = write(handle, gBackupInfo, strlen(gBackupInfo));
605 if(ret != strlen(gBackupInfo))
607 printf("data_setupBlacklist => Wrong size written: %d", ret);
615 * Test the file interface:
622 START_TEST(test_DataFile)
624 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
625 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
626 X_TEST_REPORT_REFERENCE("NONE");
627 X_TEST_REPORT_DESCRIPTION("Test of data file");
628 X_TEST_REPORT_TYPE(GOOD);
630 int fd = 0, i = 0, idx = 0;
631 int size = 0, ret = 0, avail = 100;
632 int writeSize = 16*1024;
633 int fdArray[10] = {0};
634 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
636 unsigned char buffer[READ_SIZE] = {0};
637 unsigned char wBuffer[READ_SIZE] = {0};
638 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
640 char* fileMap = NULL;
642 ret = pclInitLibrary(gTheAppId, shutdownReg);
643 x_fail_unless(ret <= 1, "Failed to init PCL");
645 writeBuffer = malloc(writeSize);
647 // fill buffer a sequence
648 for(i = 0; i<(writeSize/8); i++)
650 writeBuffer[idx++] = 'A';
651 writeBuffer[idx++] = 'B';
652 writeBuffer[idx++] = 'C';
653 writeBuffer[idx++] = ' ';
654 writeBuffer[idx++] = 'D';
655 writeBuffer[idx++] = 'E';
656 writeBuffer[idx++] = 'F';
657 writeBuffer[idx++] = ' ';
660 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
661 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
664 // open ------------------------------------------------------------
665 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
666 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
669 size = pclFileGetSize(fd);
670 x_fail_unless(size == 68, "Wrong file size");
673 size = pclFileReadData(fd, buffer, READ_SIZE);
674 //printf("pclFileReadData:\n ist : \"%s\"\n soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd);
675 x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
676 x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
678 ret = pclFileClose(fd);
679 x_fail_unless(ret == 0, "Failed to close file");
681 // open ------------------------------------------------------------
682 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
683 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
685 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
686 x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
687 ret = pclFileClose(fd);
688 x_fail_unless(ret == 0, "Failed to close file");
690 // remove ----------------------------------------------------------
691 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
692 x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
694 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
695 x_fail_unless(fd == -1, "Failed to remove file, file still exists");
698 // map file --------------------------------------------------------
700 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
702 size = pclFileGetSize(fd);
703 pclFileMapData(fileMap, size, 0, fd);
704 x_fail_unless(fileMap != MAP_FAILED, "Failed to map file");
706 ret = pclFileUnmapData(fileMap, size);
707 x_fail_unless(ret != -1, "Failed to unmap file");
710 ret = pclFileSeek(fd, 0, SEEK_CUR);
711 x_fail_unless(ret == 0, "Failed to seek file - pos 0");
713 ret = pclFileSeek(fd, 8, SEEK_CUR);
714 x_fail_unless(ret == 8, "Failed to seek file - pos 8");
717 size = pclFileGetSize(1024);
718 x_fail_unless(size < 0 , "Got size, but should not");
720 ret = pclFileClose(fd);
721 x_fail_unless(ret == 0, "Failed to close file");
724 // test backup blacklist functionality
725 fdArray[0] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 1, 1);
726 fdArray[1] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 1, 2);
727 fdArray[2] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 20, 10);
728 fdArray[3] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 200, 100);
730 fdArray[4] = pclFileOpen(0xFF, "media/doNotBackupMe_01.txt", 2, 1);
731 fdArray[5] = pclFileOpen(0xFF, "media/doNotBackupMe_02.txt", 2, 1);
732 fdArray[6] = pclFileOpen(0xFF, "media/doNotBackupMe_03.txt", 2, 1);
733 fdArray[7] = pclFileOpen(0xFF, "media/doNotBackupMe_04.txt", 2, 1);
735 fdArray[8] = pclFileOpen(0xFF, "media/iDontWantDoBeBackuped_04.txt", 2, 1);
736 fdArray[9] = pclFileOpen(0xFF, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1);
740 snprintf( (char*)wBuffer, 1024, "Test - %d", i);
741 pclFileWriteData(fdArray[i], wBuffer, strlen( (char*)wBuffer));
745 // test if backup blacklist works correctly
747 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK);
748 x_fail_unless(avail == -1, "1. Failed backup => backup available, but should not");
751 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK);
752 x_fail_unless(avail == -1, "2. Failed backup => backup available, but should not");
754 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK);
755 x_fail_unless(avail == -1, "3. Failed backup => backup available, but should not");
757 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK);
758 x_fail_unless(avail == -1, "4. Failed backup => backup available, but should not");
760 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK);
761 x_fail_unless(avail == -1, "5. Failed backup => backup available, but should not");
763 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK);
764 x_fail_unless(avail == -1, "6. Failed backup => backup available, but should not");
766 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK);
767 x_fail_unless(avail == -1, "7. Failed backup => backup available, but should not");
769 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK);
770 x_fail_unless(avail == -1, "8. Failed backup => backup available, but should not");
772 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK);
773 x_fail_unless(avail == -1, "9. Failed backup => backup available, but should not");
775 avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK);
776 x_fail_unless(avail == -1, "10. Failed backup => backup available, but should not");
780 pclFileClose(fdArray[i]);
791 void data_setupBackup(void)
794 const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db";
796 handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
797 if(write(handle, gWriteBackupTestData, strlen(gWriteBackupTestData)) == -1)
799 printf("setup test: failed to write test data: %s\n", path);
803 START_TEST(test_DataFileBackupCreation)
805 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
806 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
807 X_TEST_REPORT_REFERENCE("NONE");
808 X_TEST_REPORT_DESCRIPTION("Test of file backup creation");
809 X_TEST_REPORT_TYPE(GOOD);
811 int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1;
813 char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! ";
814 const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~";
815 char rBuffer[1024] = {0};
816 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
818 ret = pclInitLibrary(gTheAppId, shutdownReg);
819 x_fail_unless(ret <= 1, "Failed to init PCL");
822 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
823 x_fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
825 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
826 x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
828 rval = pclFileReadData(fd_RW, rBuffer, 10);
829 x_fail_unless(rval == 10, "Failed read 10 bytes");
830 memset(rBuffer, 0, 1024);
832 rval = pclFileReadData(fd_RW, rBuffer, 15);
833 x_fail_unless(rval == 15, "Failed read 15 bytes");
834 memset(rBuffer, 0, 1024);
836 rval = pclFileReadData(fd_RW, rBuffer, 20);
837 x_fail_unless(rval == 20, "Failed read 20 bytes");
838 memset(rBuffer, 0, 1024);
840 rval = pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
841 x_fail_unless(rval == strlen(wBuffer), "Failed write data");
843 // verify the backup creation:
844 handle = open(path, O_RDWR);
845 x_fail_unless(handle != -1, "Could not open file ==> failed to access backup file");
847 rval = read(handle, rBuffer, 1024);
848 //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData);
849 x_fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read");
853 (void)pclFileClose(fd_RW);
854 (void)pclFileClose(fd_RO);
864 void data_setupRecovery(void)
867 char createPath[128] = {0};
869 int handleRecov = -1, handleToBackup = -1, handleToCs = -1;
870 char* corruptData = "Some corrupted data .. )=§?=34=/%&$%&()Ö:ÄNJH/)(";
871 const char* pathToRecover = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db";
872 const char* pathToBackup = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~";
873 const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc";
875 // create directory, even if exist
876 snprintf(createPath, 128, "%s", SOURCE_PATH );
877 while(gPathSegemnts[i] != NULL)
879 strncat(createPath, gPathSegemnts[i++], 128-1);
880 mkdir(createPath, 0744);
883 handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
884 if(write(handleRecov, corruptData, strlen(corruptData)) == -1)
886 printf("setup test: failed to write test data: %s\n", pathToRecover);
889 handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
890 if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1)
892 printf("setup test: failed to write test data: %s\n", pathToBackup);
895 handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
896 if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1)
898 printf("setup test: failed to write test data: %s\n", pathToChecksum);
902 close(handleToBackup);
907 START_TEST(test_DataFileRecovery)
909 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
910 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
911 X_TEST_REPORT_REFERENCE("NONE");
912 X_TEST_REPORT_DESCRIPTION("Test file recovery form backup");
913 X_TEST_REPORT_TYPE(GOOD);
917 unsigned char buffer[READ_SIZE] = {0};
918 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
920 ret = pclInitLibrary(gTheAppId, shutdownReg);
921 x_fail_unless(ret <= 1, "Failed to init PCL");
924 handle = pclFileOpen(0xFF, "media/mediaDB_DataRecovery.db", 1, 1);
925 //printf("pclFileOpen => handle: %d\n", handle);
926 x_fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db");
929 ret = pclFileReadData(handle, buffer, READ_SIZE);
930 //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret);
931 //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData));
932 x_fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed");
934 (void)pclFileClose(handle);
944 * The the handle function of the key and file interface.
946 START_TEST(test_DataHandle)
948 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
949 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
950 X_TEST_REPORT_REFERENCE("NONE");
951 X_TEST_REPORT_DESCRIPTION("Test of data handle");
952 X_TEST_REPORT_TYPE(GOOD);
954 int handle1 = 0, handle2 = 0;
955 int handleArray[4] = {0};
957 unsigned char buffer[READ_SIZE] = {0};
958 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
960 ret = pclInitLibrary(gTheAppId, shutdownReg);
961 x_fail_unless(ret <= 1, "Failed to init PCL");
963 // test multiple handles
964 handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
965 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
967 handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
968 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
970 handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
971 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
973 handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
974 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
976 memset(buffer, 0, READ_SIZE);
977 ret = pclFileReadData(handleArray[0], buffer, READ_SIZE);
978 x_fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!");
979 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
980 strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
981 == 0, "Buffer not correctly read => mediaDB_write_01.db");
983 memset(buffer, 0, READ_SIZE);
984 ret = pclFileReadData(handleArray[1], buffer, READ_SIZE);
985 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
986 strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
987 == 0, "Buffer not correctly read => mediaDB_write_02.db");
989 memset(buffer, 0, READ_SIZE);
990 ret = pclFileReadData(handleArray[2], buffer, READ_SIZE);
991 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
992 strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
993 == 0, "Buffer not correctly read => mediaDB_write_03.db");
995 memset(buffer, 0, READ_SIZE);
996 (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
997 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
998 strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
999 == 0, "Buffer not correctly read => mediaDB_write_04.db");
1001 ret = pclKeyHandleClose(handleArray[0]);
1002 x_fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
1004 ret = pclKeyHandleClose(handleArray[1]);
1005 x_fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
1007 ret = pclKeyHandleClose(handleArray[2]);
1008 x_fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
1010 ret = pclKeyHandleClose(handleArray[3]);
1011 x_fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
1014 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
1015 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
1017 ret = pclKeyHandleClose(handle2);
1018 x_fail_unless(ret != -1, "Failed to close handle!!");
1020 ret = pclKeyHandleClose(1024);
1021 x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
1024 // test file handles
1025 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
1026 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
1028 ret = pclFileClose(handle1);
1029 x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
1031 ret = pclFileClose(1024);
1032 x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
1034 ret = pclFileClose(19);
1035 x_fail_unless(ret == -1, "Could close file, but should not!!");
1045 * Extended key handle test.
1046 * Test have been created after a bug in the key handle function occured.
1048 START_TEST(test_DataHandleOpen)
1050 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1051 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1052 X_TEST_REPORT_REFERENCE("NONE");
1053 X_TEST_REPORT_DESCRIPTION("Test of data handle open");
1054 X_TEST_REPORT_TYPE(GOOD);
1056 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
1057 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1059 ret = pclInitLibrary(gTheAppId, shutdownReg);
1060 x_fail_unless(ret <= 1, "Failed to init PCL");
1062 // open handles ----------------------------------------------------
1063 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
1064 x_fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
1066 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
1067 x_fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
1069 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
1070 x_fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
1072 // close handles ---------------------------------------------------
1073 ret = pclKeyHandleClose(hd1);
1074 x_fail_unless(ret != -1, "Failed to close handle!!");
1076 ret = pclKeyHandleClose(hd2);
1077 x_fail_unless(ret != -1, "Failed to close handle!!");
1079 ret = pclKeyHandleClose(hd3);
1080 x_fail_unless(ret != -1, "Failed to close handle!!");
1082 // open handles ----------------------------------------------------
1083 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
1084 x_fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
1086 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
1087 x_fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
1089 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
1090 x_fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
1092 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
1093 x_fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
1095 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
1096 x_fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
1098 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
1099 x_fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
1101 // close handles ---------------------------------------------------
1102 ret = pclKeyHandleClose(hd4);
1103 x_fail_unless(ret != -1, "Failed to close handle!!");
1105 ret = pclKeyHandleClose(hd5);
1106 x_fail_unless(ret != -1, "Failed to close handle!!");
1108 ret = pclKeyHandleClose(hd6);
1109 x_fail_unless(ret != -1, "Failed to close handle!!");
1111 ret = pclKeyHandleClose(hd7);
1112 x_fail_unless(ret != -1, "Failed to close handle!!");
1114 ret = pclKeyHandleClose(hd8);
1115 x_fail_unless(ret != -1, "Failed to close handle!!");
1117 ret = pclKeyHandleClose(hd9);
1118 x_fail_unless(ret != -1, "Failed to close handle!!");
1126 START_TEST(test_Plugin)
1128 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1129 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1130 X_TEST_REPORT_REFERENCE("NONE");
1131 X_TEST_REPORT_DESCRIPTION("Test of plugins");
1132 X_TEST_REPORT_TYPE(GOOD);
1135 unsigned char buffer[READ_SIZE] = {0};
1137 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1139 ret = pclInitLibrary(gTheAppId, shutdownReg);
1140 x_fail_unless(ret <= 1, "Failed to init PCL");
1144 ret = pclKeyReadData(0xFF, "secured", 0, 0, buffer, READ_SIZE);
1145 //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!"));
1146 x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") );
1147 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
1148 strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
1149 memset(buffer, 0, READ_SIZE);
1151 ret = pclKeyReadData(0xFF, "early", 0, 0, buffer, READ_SIZE);
1152 //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!"));
1153 x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!"));
1154 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
1155 strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
1156 memset(buffer, 0, READ_SIZE);
1158 ret = pclKeyReadData(0xFF, "emergency", 0, 0, buffer, READ_SIZE);
1159 //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!"));
1160 x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!"));
1161 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
1162 strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
1163 memset(buffer, 0, READ_SIZE);
1165 ret = pclKeyReadData(0xFF, "hwinfo", 0, 0, buffer, READ_SIZE);
1166 //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!"));
1167 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1168 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
1169 strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
1170 memset(buffer, 0, READ_SIZE);
1172 ret = pclKeyReadData(0xFF, "custom2", 0, 0, buffer, READ_SIZE);
1173 //printf("B U F F E R - custom2: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom2!"));
1174 x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom2!"));
1175 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom2!",
1176 strlen((char*)buffer)) == 0, "Buffer CUSTOM 2 not correctly read");
1177 memset(buffer, 0, READ_SIZE);
1179 ret = pclKeyReadData(0xFF, "custom3", 0, 0, buffer, READ_SIZE);
1180 //printf("B U F F E R - custom3: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom3!"));
1181 x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom3!"));
1182 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
1183 strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
1184 memset(buffer, 0, READ_SIZE);
1186 ret = pclKeyWriteData(0xFF, "custom3", 0, 0, (unsigned char*)"This is a message to write", READ_SIZE);
1187 x_fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456
1190 ret = pclKeyGetSize(0xFF, "custom3", 0, 0);
1191 x_fail_unless(ret == 44332211, "Failed query custom data size"); // plugin should return 44332211
1194 ret = pclKeyDelete(0xFF, "custom3", 0, 0);
1195 x_fail_unless(ret == 13579, "Failed query custom data size"); // plugin should return 13579
1206 START_TEST(test_ReadDefault)
1208 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1209 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1210 X_TEST_REPORT_REFERENCE("NONE");
1211 X_TEST_REPORT_DESCRIPTION("Test of read default");
1212 X_TEST_REPORT_TYPE(GOOD);
1215 unsigned char buffer[READ_SIZE] = {0};
1217 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1219 ret = pclInitLibrary(gTheAppId, shutdownReg);
1220 x_fail_unless(ret <= 1, "Failed to init PCL");
1222 ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
1223 //printf(" --- test_ReadConfDefault => statusHandle/default01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_01!"));
1224 x_fail_unless(ret == strlen("DEFAULT_01!"));
1225 x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1227 ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
1228 //printf(" --- test_ReadConfDefault => statusHandle/default02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_02!"));
1229 x_fail_unless(ret == strlen("DEFAULT_02!"));
1230 x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1232 ret = pclKeyGetSize(0xFF, "statusHandle/default01", 3, 2);
1233 x_fail_unless(ret == strlen("DEFAULT_01!"), "Invalid size");
1242 START_TEST(test_ReadConfDefault)
1244 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1245 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1246 X_TEST_REPORT_REFERENCE("NONE");
1247 X_TEST_REPORT_DESCRIPTION("Test of configurable default data");
1248 X_TEST_REPORT_TYPE(GOOD);
1251 unsigned char buffer[READ_SIZE] = {0};
1253 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1255 ret = pclInitLibrary(gTheAppId, shutdownReg);
1256 x_fail_unless(ret <= 1, "Failed to init PCL");
1258 ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
1259 //printf(" --- test_ReadConfDefault => statusHandle/confdefault01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_01!"));
1260 x_fail_unless(ret == strlen("CONF_DEFAULT_01!"));
1261 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1263 ret = pclKeyReadData(0xFF, "statusHandle/confdefault02", 3, 2, buffer, READ_SIZE);
1264 //printf(" --- test_ReadConfDefault => statusHandle/confdefault02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_02!"));
1265 x_fail_unless(ret == strlen("CONF_DEFAULT_02!"));
1266 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1268 ret = pclKeyGetSize(0xFF, "statusHandle/confdefault02", 3, 2);
1269 x_fail_unless(ret == strlen("CONF_DEFAULT_02!"), "Invalid size");
1278 START_TEST(test_GetPath)
1280 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1281 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1282 X_TEST_REPORT_REFERENCE("NONE");
1283 X_TEST_REPORT_DESCRIPTION("Test of get path");
1284 X_TEST_REPORT_TYPE(GOOD);
1288 const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db";
1289 unsigned int pathSize = 0;
1291 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1293 ret = pclInitLibrary(gTheAppId, shutdownReg);
1294 x_fail_unless(ret <= 1, "Failed to init PCL");
1296 ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize);
1298 x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
1299 x_fail_unless(pathSize == strlen((char*)path), "Path size not correct");
1301 pclFileReleasePath(ret);
1309 START_TEST(test_InitDeinit)
1311 int i = 0, rval = -1;
1312 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1316 // initialize and deinitialize 1. time
1317 (void)pclInitLibrary(gTheAppId, shutdownReg);
1321 // initialize and deinitialize 2. time
1322 (void)pclInitLibrary(gTheAppId, shutdownReg);
1326 // initialize and deinitialize 3. time
1327 (void)pclInitLibrary(gTheAppId, shutdownReg);
1332 // test multiple init/deinit
1333 pclInitLibrary(gTheAppId, shutdownReg);
1334 pclInitLibrary(gTheAppId, shutdownReg);
1340 // test lifecycle set
1341 pclInitLibrary(gTheAppId, shutdownReg);
1342 rval = pclLifecycleSet(PCL_SHUTDOWN);
1343 x_fail_unless(rval == EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set allowed, but should not");
1347 pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE);
1349 rval = pclLifecycleSet(PCL_SHUTDOWN);
1350 x_fail_unless(rval != EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set NOT allowed, but should");
1353 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1354 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1355 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1356 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1357 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1358 rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1368 START_TEST(test_NegHandle)
1370 int handle = -1, ret = 0;
1371 int negativeHandle = -17;
1372 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1374 unsigned char buffer[128] = {0};
1376 (void)pclInitLibrary(gTheAppId, shutdownReg);
1378 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
1379 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
1381 ret = pclKeyHandleReadData(negativeHandle, buffer, READ_SIZE);
1382 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1384 ret = pclKeyHandleClose(negativeHandle);
1385 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleClose => negative handle not detected");
1387 ret = pclKeyHandleGetSize(negativeHandle);
1388 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleGetSize => negative handle not detected");
1390 ret = pclKeyHandleReadData(negativeHandle, buffer, 128);
1391 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1393 ret = pclKeyHandleRegisterNotifyOnChange(negativeHandle, &myChangeCallback);
1394 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleRegisterNotifyOnChange => negative handle not detected");
1396 ret = pclKeyHandleWriteData(negativeHandle, (unsigned char*)"Whatever", strlen("Whatever"));
1397 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleWriteData => negative handle not detected");
1401 ret = pclKeyHandleClose(handle);
1409 START_TEST(test_utf8_string)
1411 int ret = 0, size = 0;
1412 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1413 const char* utf8StringBuffer = "String °^° Ñ text";
1414 unsigned char buffer[128] = {0};
1416 (void)pclInitLibrary(gTheAppId, shutdownReg);
1418 ret = pclKeyReadData(0xFF, "utf8String", 3, 2, buffer, READ_SIZE);
1419 x_fail_unless(ret == strlen(utf8StringBuffer), "Wrong read size");
1420 x_fail_unless(strncmp((char*)buffer, utf8StringBuffer, ret-1) == 0, "Buffer not correctly read => 1");
1422 size = pclKeyGetSize(0xFF, "utf8String", 3, 2);
1423 x_fail_unless(size == strlen(utf8StringBuffer), "Invalid size");
1431 START_TEST(test_Notifications)
1433 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1435 (void)pclInitLibrary(gTheAppId, shutdownReg);
1437 pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback);
1438 pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback);
1446 static Suite * persistencyClientLib_suite()
1448 Suite * s = suite_create("Persistency client library");
1450 TCase * tc_persGetData = tcase_create("GetData");
1451 tcase_add_test(tc_persGetData, test_GetData);
1452 tcase_set_timeout(tc_persGetData, 2);
1454 TCase * tc_persSetData = tcase_create("SetData");
1455 tcase_add_test(tc_persSetData, test_SetData);
1456 tcase_set_timeout(tc_persSetData, 2);
1458 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
1459 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
1460 tcase_set_timeout(tc_persSetDataNoPRCT, 2);
1462 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
1463 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
1464 tcase_set_timeout(tc_persGetDataSize, 2);
1466 TCase * tc_persDeleteData = tcase_create("DeleteData");
1467 tcase_add_test(tc_persDeleteData, test_DeleteData);
1468 tcase_set_timeout(tc_persDeleteData, 2);
1470 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
1471 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
1472 tcase_set_timeout(tc_persGetDataHandle, 2);
1474 TCase * tc_persDataHandle = tcase_create("DataHandle");
1475 tcase_add_test(tc_persDataHandle, test_DataHandle);
1476 tcase_set_timeout(tc_persGetData, 2);
1478 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
1479 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
1480 tcase_set_timeout(tc_persDataHandleOpen, 1);
1482 TCase * tc_persDataFile = tcase_create("DataFile");
1483 tcase_add_test(tc_persDataFile, test_DataFile);
1484 tcase_set_timeout(tc_persDataFile, 2);
1486 TCase * tc_persDataFileBackupCreation = tcase_create("DataFileBackupCreation");
1487 tcase_add_test(tc_persDataFileBackupCreation, test_DataFileBackupCreation);
1488 tcase_set_timeout(tc_persDataFileBackupCreation, 1);
1490 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
1491 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
1492 tcase_set_timeout(tc_persDataFileRecovery, 2);
1494 TCase * tc_Plugin = tcase_create("Plugin");
1495 tcase_add_test(tc_Plugin, test_Plugin);
1496 tcase_set_timeout(tc_Plugin, 2);
1498 TCase * tc_ReadDefault = tcase_create("ReadDefault");
1499 tcase_add_test(tc_ReadDefault, test_ReadDefault);
1500 tcase_set_timeout(tc_ReadDefault, 2);
1502 TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
1503 tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
1504 tcase_set_timeout(tc_ReadConfDefault, 2);
1506 TCase * tc_GetPath = tcase_create("GetPath");
1507 tcase_add_test(tc_GetPath, test_GetPath);
1508 tcase_set_timeout(tc_GetPath, 2);
1510 TCase * tc_InitDeinit = tcase_create("InitDeinit");
1511 tcase_add_test(tc_InitDeinit, test_InitDeinit);
1512 tcase_set_timeout(tc_InitDeinit, 3);
1514 TCase * tc_NegHandle = tcase_create("NegHandle");
1515 tcase_add_test(tc_NegHandle, test_NegHandle);
1516 tcase_set_timeout(tc_NegHandle, 2);
1518 TCase * tc_utf8_string = tcase_create("UTF-8");
1519 tcase_add_test(tc_utf8_string, test_utf8_string);
1520 tcase_set_timeout(tc_utf8_string, 2);
1522 TCase * tc_Notifications = tcase_create("Notifications");
1523 tcase_add_test(tc_Notifications, test_Notifications);
1524 tcase_set_timeout(tc_Notifications, 2);
1526 suite_add_tcase(s, tc_persSetData);
1527 suite_add_tcase(s, tc_persGetData);
1528 suite_add_tcase(s, tc_persSetDataNoPRCT);
1529 suite_add_tcase(s, tc_persGetDataSize);
1530 suite_add_tcase(s, tc_persDeleteData);
1531 suite_add_tcase(s, tc_persGetDataHandle);
1532 suite_add_tcase(s, tc_persDataHandle);
1533 suite_add_tcase(s, tc_persDataHandleOpen);
1534 suite_add_tcase(s, tc_ReadDefault);
1535 suite_add_tcase(s, tc_ReadConfDefault);
1537 suite_add_tcase(s, tc_persDataFile);
1538 tcase_add_checked_fixture(tc_persDataFile, data_setupBlacklist, data_teardown);
1540 suite_add_tcase(s, tc_persDataFileBackupCreation);
1541 tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown);
1543 suite_add_tcase(s, tc_persDataFileRecovery);
1544 tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown);
1546 suite_add_tcase(s, tc_GetPath);
1547 suite_add_tcase(s, tc_NegHandle);
1548 suite_add_tcase(s, tc_utf8_string);
1549 suite_add_tcase(s, tc_Notifications);
1550 suite_add_tcase(s, tc_Plugin);
1552 suite_add_tcase(s, tc_InitDeinit);
1558 int main(int argc, char *argv[])
1565 TestResult** tResult;
1567 // assign application name
1568 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1569 gTheAppId[MaxAppNameLen-1] = '\0';
1571 /// debug log and trace (DLT) setup
1572 DLT_REGISTER_APP("PCLt","tests the persistence client library");
1575 Suite * s = persistencyClientLib_suite();
1576 SRunner * sr = srunner_create(s);
1577 srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
1578 srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
1579 srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE*/);
1581 nr_failed = srunner_ntests_failed(sr);
1582 nr_run = srunner_ntests_run(sr);
1584 tResult = srunner_results(sr);
1585 for(i = 0; i< nr_run; i++)
1587 (void)tr_rtype(tResult[i]); // get status of each test
1588 //fail = tr_rtype(tResult[i]); // get status of each test
1589 //printf("[%d] Fail: %d \n", i, fail);
1595 // unregister debug log and trace
1596 DLT_UNREGISTER_APP();
1600 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;