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 */
28 #include <dlt/dlt_common.h>
30 #include "persCheck.h"
33 #include "../include/persistence_client_library_file.h"
34 #include "../include/persistence_client_library_key.h"
35 #include "../include/persistence_client_library.h"
36 #include "../include/persistence_client_library_error_def.h"
41 #define NUM_OF_FILES 3
42 #define READ_SIZE 1024
43 #define MaxAppNameLen 256
46 char gTheAppId[MaxAppNameLen] = {0};
48 // definition of weekday
49 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
52 int myChangeCallback(pclNotification_s * notifyStruct)
54 printf(" ==> * - * myChangeCallback * - *\n");
59 * Test the key value interface using different logicalDB id's, users and seats.
60 * Each resource below has an entry in the resource configuration table where the
61 * storage location (cached or write through) and type (e.g. custom) has been configured.
63 START_TEST(test_GetData)
65 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
66 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
67 X_TEST_REPORT_REFERENCE("NONE");
68 X_TEST_REPORT_DESCRIPTION("Test of get data");
69 X_TEST_REPORT_TYPE(GOOD);
72 unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
74 unsigned char buffer[READ_SIZE] = {0};
76 ret = pclInitLibrary(gTheAppId, shutdownReg);
77 x_fail_unless(ret <= 1, "Failed to init PCL");
81 * Logical DB ID: 0xFF with user 0 and seat 0
82 * ==> local value accessible by all users (user 0, seat 0)
84 ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE);
85 x_fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
86 strlen((char*)buffer)) == 0, "Buffer not correctly read");
87 x_fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
89 memset(buffer, 0, READ_SIZE);
92 * Logical DB ID: 0xFF with user 0 and seat 0
93 * ==> local value accessible by all users (user 0, seat 0)
96 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
97 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
98 strlen((char*)buffer)) == 0, "Buffer not correctly read");
99 x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
101 memset(buffer, 0, READ_SIZE);
106 * Logical DB ID: 0 with user 3 and seat 0
107 * ==> public shared user value (user 3, seat 0)
109 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
110 x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
112 memset(buffer, 0, READ_SIZE);
115 * Logical DB ID: 0xFF with user 3 and seat 2
116 * ==> local USER value (user 3, seat 2)
118 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
119 printf("Ist: %s\n", buffer);
120 printf("Soll: %s\n", "WT_ /var/opt/user_manual_climateControl.pdf");
122 x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
124 memset(buffer, 0, READ_SIZE);
127 * Logical DB ID: 0x20 with user 4 and seat 0
128 * ==> shared user value accessible by a group (user 4 and seat 0)
130 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
131 x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
133 memset(buffer, 0, READ_SIZE);
136 * Logical DB ID: 0xFF with user 0 and seat 0
137 * ==> local value accessible by ALL USERS (user 0, seat 0)
139 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
140 x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
142 memset(buffer, 0, READ_SIZE);
145 * Logical DB ID: 0x84 with user 4 and seat 0
146 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
148 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
149 x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
151 memset(buffer, 0, READ_SIZE);
154 * Logical DB ID: 0x84 with user 2 and seat 1
155 * ==> local merge value
157 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
158 x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
167 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
168 * Each resource below has an entry in the resource configuration table where
169 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
171 START_TEST (test_GetDataHandle)
173 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
174 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
175 X_TEST_REPORT_REFERENCE("NONE");
176 X_TEST_REPORT_DESCRIPTION("Test of get data handle");
177 X_TEST_REPORT_TYPE(GOOD);
179 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
180 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
182 unsigned char buffer[READ_SIZE] = {0};
185 char sysTimeBuffer[128];
187 ret = pclInitLibrary(gTheAppId, shutdownReg);
188 x_fail_unless(ret <= 1, "Failed to init PCL");
192 locTime = localtime(&t);
194 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),
195 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
198 // open handle ---------------------------------------------------
200 * Logical DB ID: 0xFF with user 0 and seat 0
201 * ==> local value accessible by ALL USERS (user 0, seat 0)
203 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
204 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
206 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
207 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");
209 size = pclKeyHandleGetSize(handle);
210 x_fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
211 // ---------------------------------------------------------------------------------------------
214 // open handle ---------------------------------------------------
216 * Logical DB ID: 0xFF with user 3 and seat 2
217 * ==> local USER value (user 3, seat 2)
219 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
220 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
222 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
223 x_fail_unless(size == strlen(sysTimeBuffer));
225 ret = pclKeyHandleClose(handle2);
226 // ---------------------------------------------------------------------------------------------
229 // open handle ---------------------------------------------------
231 * Logical DB ID: 0xFF with user 0 and seat 0
232 * ==> local value accessible by ALL USERS (user 0, seat 0)
234 #if 0 // plugin test case
235 memset(buffer, 0, READ_SIZE);
236 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
237 printf("H A N D L E: %d\n", handle4);
238 x_fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
240 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
241 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
243 size = pclKeyHandleGetSize(handle4);
244 x_fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
246 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
248 // ---------------------------------------------------------------------------------------------
251 // open handle ---------------------------------------------------
253 * Logical DB ID: 0xFF with user 3 and seat 2
254 * ==> local USER value (user 3, seat 2)
256 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
257 x_fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
259 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
260 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
262 size = pclKeyHandleGetSize(handle3);
263 x_fail_unless(size = strlen(sysTimeBuffer));
264 // ---------------------------------------------------------------------------------------------
268 ret = pclKeyHandleClose(handle);
269 ret = pclKeyHandleClose(handle3);
270 ret = pclKeyHandleClose(handle4);
278 * Write data to a key using the key interface.
279 * First write data to different keys and after
280 * read the data for verification.
282 START_TEST(test_SetData)
284 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
285 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
286 X_TEST_REPORT_REFERENCE("NONE");
287 X_TEST_REPORT_DESCRIPTION("Test of set data");
288 X_TEST_REPORT_TYPE(GOOD);
291 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
292 unsigned char buffer[READ_SIZE] = {0};
293 char write1[READ_SIZE] = {0};
294 char write2[READ_SIZE] = {0};
295 char sysTimeBuffer[256];
299 ret = pclInitLibrary(gTheAppId, shutdownReg);
300 x_fail_unless(ret <= 1, "Failed to init PCL");
304 locTime = localtime(&t);
307 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),
308 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
311 * Logical DB ID: 0xFF with user 1 and seat 2
312 * ==> local USER value (user 1, seat 2)
315 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
316 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
317 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
318 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
319 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
321 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
323 * Logical DB ID: 0xFF with user 1 and seat 2
324 * ==> local USER value (user 1, seat 2)
327 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
328 x_fail_unless(ret == strlen(write1), "Wrong write size");
330 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
332 * Logical DB ID: 0xFF with user 1 and seat 2
333 * ==> local USER value (user 1, seat 2)
334 * Resource ID: key_70
336 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
337 x_fail_unless(ret == strlen(write2), "Wrong write size");
340 /*******************************************************************************************************************************************/
341 /* used for changed notification testing */
342 /*******************************************************************************************************************************************/
344 * Logical DB ID: 0x84 with user 2 and seat 1
345 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
347 * ==> used for shared testing
349 //printf("Write data to trigger change notification\n");
350 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
351 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
354 * Logical DB ID: 0x84 with user 2 and seat 1
355 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
357 * ==> used for shared testing
359 //printf("Write data to trigger change notification\n");
360 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
361 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
364 * Logical DB ID: 0x84 with user 2 and seat 1
365 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
367 * ==> used for shared testing
369 //printf("Write data to trigger change notification\n");
370 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
371 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
372 /*******************************************************************************************************************************************/
373 /*******************************************************************************************************************************************/
377 * now read the data written in the previous steps to the keys
378 * and verify data has been written correctly.
380 memset(buffer, 0, READ_SIZE);
382 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
383 printf("Verify ist : %s \n", buffer);
384 printf("Verify soll : %s \n", sysTimeBuffer);
385 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
386 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
388 memset(buffer, 0, READ_SIZE);
390 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
391 x_fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
392 x_fail_unless(ret == strlen(write1), "Wrong read size");
394 memset(buffer, 0, READ_SIZE);
396 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
397 x_fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
398 x_fail_unless(ret == strlen(write2), "Wrong read size");
408 * Write data to a key using the key interface.
409 * The key is not in the persistence resource table.
410 * The key sill then be stored to the location local and cached.
412 START_TEST(test_SetDataNoPRCT)
414 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
415 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
416 X_TEST_REPORT_REFERENCE("NONE");
417 X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT");
418 X_TEST_REPORT_TYPE(GOOD);
421 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
422 unsigned char buffer[READ_SIZE] = {0};
425 ret = pclInitLibrary(gTheAppId, shutdownReg);
426 x_fail_unless(ret <= 1, "Failed to init PCL");
430 char sysTimeBuffer[128];
432 locTime = localtime(&t);
434 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),
435 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
438 * Logical DB ID: 0xFF with user 1 and seat 2
439 * ==> local USER value (user 1, seat 2)
441 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
442 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
443 //printf("Write Buffer : %s\n", sysTimeBuffer);
445 // read data again and and verify datat has been written correctly
446 memset(buffer, 0, READ_SIZE);
448 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
449 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
450 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
451 //printf("read buffer : %s\n", buffer);
460 * Test the key interface.
461 * Read the size of a key.
463 START_TEST(test_GetDataSize)
465 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
466 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
467 X_TEST_REPORT_REFERENCE("NONE");
468 X_TEST_REPORT_DESCRIPTION("Test of get data size");
469 X_TEST_REPORT_TYPE(GOOD);
471 int size = 0, ret = 0;
473 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
475 ret = pclInitLibrary(gTheAppId, shutdownReg);
476 x_fail_unless(ret <= 1, "Failed to init PCL");
479 * Logical DB ID: 0xFF with user 3 and seat 2
480 * ==> local USER value (user 3, seat 2)
482 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
483 x_fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
487 * Logical DB ID: 0x84 with user 2 and seat 1
488 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
490 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
491 printf("=>=>=>=> soll: %d | ist: %d\n", strlen("CACHE_ /last_exit/queens"), size);
492 x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
500 * Delete a key using the key value interface.
501 * First read a from a key, the delte the key
502 * and then try to read again. The Last read must fail.
504 START_TEST(test_DeleteData)
506 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
507 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
508 X_TEST_REPORT_REFERENCE("NONE");
509 X_TEST_REPORT_DESCRIPTION("Test of delete data");
510 X_TEST_REPORT_TYPE(GOOD);
513 unsigned char buffer[READ_SIZE];
514 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
516 rval = pclInitLibrary(gTheAppId, shutdownReg);
517 x_fail_unless(rval <= 1, "Failed to init PCL");
519 // read data from key
520 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
521 x_fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
524 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
525 printf("pclKeyDelete => soll: 0 | ist: %d\n", rval);
526 x_fail_unless(rval >= 0, "Failed to delete key");
528 // after deleting the key, reading from key must fail now!
529 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
530 x_fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
534 // read data from key
535 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
536 x_fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
539 rval = pclKeyDelete(0xFF, "70", 1, 2);
540 x_fail_unless(rval >= 0, "Failed to delete key");
542 // after deleting the key, reading from key must fail now!
543 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
544 x_fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
553 * Test the file interface:
560 START_TEST(test_DataFile)
562 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
563 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
564 X_TEST_REPORT_REFERENCE("NONE");
565 X_TEST_REPORT_DESCRIPTION("Test of data file");
566 X_TEST_REPORT_TYPE(GOOD);
568 int fd = 0, i = 0, idx = 0;
569 int size = 0, ret = 0;
570 int writeSize = 16*1024;
571 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
573 unsigned char buffer[READ_SIZE] = {0};
574 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
576 char* fileMap = NULL;
578 ret = pclInitLibrary(gTheAppId, shutdownReg);
579 x_fail_unless(ret <= 1, "Failed to init PCL");
581 writeBuffer = malloc(writeSize);
584 // fill buffer a sequence
585 for(i = 0; i<(writeSize/8); i++)
587 writeBuffer[idx++] = 'A';
588 writeBuffer[idx++] = 'B';
589 writeBuffer[idx++] = 'C';
590 writeBuffer[idx++] = ' ';
591 writeBuffer[idx++] = 'D';
592 writeBuffer[idx++] = 'E';
593 writeBuffer[idx++] = 'F';
594 writeBuffer[idx++] = ' ';
597 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
598 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
601 // open ------------------------------------------------------------
602 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
603 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
605 size = pclFileGetSize(fd);
606 printf("%s => %d\n", __FUNCTION__, __LINE__);
607 printf("Soll: 68 | Ist: %d\n", size);
608 printf("%s => %d\n", __FUNCTION__, __LINE__);
609 x_fail_unless(size == 68, "Wrong file size");
610 printf("%s => %d\n", __FUNCTION__, __LINE__);
612 printf("%s => %d\n", __FUNCTION__, __LINE__);
613 size = pclFileReadData(fd, buffer, READ_SIZE);
614 printf("%s => %d\n", __FUNCTION__, __LINE__);
615 x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
616 printf("%s => %d\n", __FUNCTION__, __LINE__);
617 x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
618 printf("%s => %d\n", __FUNCTION__, __LINE__);
620 ret = pclFileClose(fd);
621 printf("%s => %d\n", __FUNCTION__, __LINE__);
622 x_fail_unless(ret == 0, "Failed to close file");
623 printf("%s => %d\n", __FUNCTION__, __LINE__);
625 // open ------------------------------------------------------------
626 printf("%s => %d\n", __FUNCTION__, __LINE__);
627 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
628 printf("%s => %d\n", __FUNCTION__, __LINE__);
629 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
631 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
632 x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
633 printf("%s => %d\n", __FUNCTION__, __LINE__);
634 ret = pclFileClose(fd);
635 printf("%s => %d\n", __FUNCTION__, __LINE__);
636 x_fail_unless(ret == 0, "Failed to close file");
638 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
639 // remove ----------------------------------------------------------
640 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
641 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
642 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
643 x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
644 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
646 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
647 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
648 x_fail_unless(fd == -1, "Failed to remove file, file still exists");
649 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
651 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
653 // map file --------------------------------------------------------
655 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
657 size = pclFileGetSize(fd);
658 pclFileMapData(fileMap, size, 0, fd);
659 x_fail_unless(fileMap != MAP_FAILED, "Failed to map file");
661 ret = pclFileUnmapData(fileMap, size);
662 x_fail_unless(ret != -1, "Failed to unmap file");
665 size = pclFileGetSize(1024);
666 x_fail_unless(ret == 0, "Got size, but should not");
668 ret = pclFileClose(fd);
669 x_fail_unless(ret == 0, "Failed to close file");
681 START_TEST(test_DataFileRecovery)
683 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
684 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
685 X_TEST_REPORT_REFERENCE("NONE");
686 X_TEST_REPORT_DESCRIPTION("Test of data file recovery");
687 X_TEST_REPORT_TYPE(GOOD);
689 int fd_RW = 0, fd_RO = 0;
691 char* wBuffer = "This is a buffer to write";
692 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
694 ret = pclInitLibrary(gTheAppId, shutdownReg);
695 x_fail_unless(ret <= 1, "Failed to init PCL");
698 // test backup creation --------------------------------------------
699 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
700 x_fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
702 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
703 x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
704 pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
706 ret = pclFileClose(fd_RW);
709 ret = pclFileClose(fd_RO);
718 * The the handle function of the key and file interface.
720 START_TEST(test_DataHandle)
722 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
723 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
724 X_TEST_REPORT_REFERENCE("NONE");
725 X_TEST_REPORT_DESCRIPTION("Test of data handle");
726 X_TEST_REPORT_TYPE(GOOD);
728 int handle1 = 0, handle2 = 0;
729 int handleArray[4] = {0};
731 unsigned char buffer[READ_SIZE] = {0};
732 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
734 ret = pclInitLibrary(gTheAppId, shutdownReg);
735 x_fail_unless(ret <= 1, "Failed to init PCL");
738 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
739 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
741 ret = pclFileClose(handle1);
742 x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
744 ret = pclFileClose(1024);
745 x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
747 ret = pclFileClose(17);
748 x_fail_unless(ret == -1, "Could close file, but should not!!");
750 // test multiple handles
751 handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
752 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
754 handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
755 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
757 handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
758 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
760 handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
761 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
763 (void)pclFileReadData(handleArray[0], buffer, READ_SIZE);
764 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
765 strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
766 == 0, "Buffer not correctly read => mediaDB_write_01.db");
768 (void)pclFileReadData(handleArray[1], buffer, READ_SIZE);
769 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
770 strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
771 == 0, "Buffer not correctly read => mediaDB_write_02.db");
773 (void)pclFileReadData(handleArray[2], buffer, READ_SIZE);
774 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
775 strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
776 == 0, "Buffer not correctly read => mediaDB_write_03.db");
778 (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
779 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
780 strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
781 == 0, "Buffer not correctly read => mediaDB_write_04.db");
783 ret = pclKeyHandleClose(handleArray[0]);
784 x_fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
786 ret = pclKeyHandleClose(handleArray[1]);
787 x_fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
789 ret = pclKeyHandleClose(handleArray[2]);
790 x_fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
792 ret = pclKeyHandleClose(handleArray[3]);
793 x_fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
796 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
797 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
799 ret = pclKeyHandleClose(handle2);
800 x_fail_unless(ret != -1, "Failed to close handle!!");
802 ret = pclKeyHandleClose(1024);
803 x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
812 * Extended key handle test.
813 * Test have been created after a bug in the key handle function occured.
815 START_TEST(test_DataHandleOpen)
817 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
818 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
819 X_TEST_REPORT_REFERENCE("NONE");
820 X_TEST_REPORT_DESCRIPTION("Test of data handle open");
821 X_TEST_REPORT_TYPE(GOOD);
823 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
824 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
826 ret = pclInitLibrary(gTheAppId, shutdownReg);
827 x_fail_unless(ret <= 1, "Failed to init PCL");
829 // open handles ----------------------------------------------------
830 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
831 x_fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
833 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
834 x_fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
836 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
837 x_fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
839 // close handles ---------------------------------------------------
840 ret = pclKeyHandleClose(hd1);
841 x_fail_unless(ret != -1, "Failed to close handle!!");
843 ret = pclKeyHandleClose(hd2);
844 x_fail_unless(ret != -1, "Failed to close handle!!");
846 ret = pclKeyHandleClose(hd3);
847 x_fail_unless(ret != -1, "Failed to close handle!!");
849 // open handles ----------------------------------------------------
850 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
851 x_fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
853 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
854 x_fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
856 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
857 x_fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
859 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
860 x_fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
862 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
863 x_fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
865 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
866 x_fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
868 // close handles ---------------------------------------------------
869 ret = pclKeyHandleClose(hd4);
870 x_fail_unless(ret != -1, "Failed to close handle!!");
872 ret = pclKeyHandleClose(hd5);
873 x_fail_unless(ret != -1, "Failed to close handle!!");
875 ret = pclKeyHandleClose(hd6);
876 x_fail_unless(ret != -1, "Failed to close handle!!");
878 ret = pclKeyHandleClose(hd7);
879 x_fail_unless(ret != -1, "Failed to close handle!!");
881 ret = pclKeyHandleClose(hd8);
882 x_fail_unless(ret != -1, "Failed to close handle!!");
884 ret = pclKeyHandleClose(hd9);
885 x_fail_unless(ret != -1, "Failed to close handle!!");
895 * Test for i n t e r n a l structures.
896 * Test the cursor functions.
898 START_TEST(test_Cursor)
900 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
901 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
902 X_TEST_REPORT_REFERENCE("NONE");
903 X_TEST_REPORT_DESCRIPTION("Test of cursor");
904 X_TEST_REPORT_TYPE(GOOD);
906 int handle = -1, rval = 0, size = 0, handle1 = 0;
907 char bufferKeySrc[READ_SIZE] = {0};
908 char bufferDataSrc[READ_SIZE] = {0};
909 char bufferKeyDst[READ_SIZE] = {0};
910 char bufferDataDst[READ_SIZE] = {0};
911 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
913 rval = pclInitLibrary(gTheAppId, shutdownReg);
914 x_fail_unless(rval <= 1, "Failed to init PCL");
917 handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
918 x_fail_unless(handle != -1, "Failed to create cursor!!");
921 handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
922 x_fail_unless(handle1 != -1, "Failed to create cursor!!");
926 memset(bufferKeySrc, 0, READ_SIZE);
927 memset(bufferDataSrc, 0, READ_SIZE);
928 memset(bufferKeyDst, 0, READ_SIZE);
929 memset(bufferDataDst, 0, READ_SIZE);
932 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 256);
933 x_fail_unless(rval != -1, "Cursor failed to get key!!");
935 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 256);
937 x_fail_unless(rval != -1, "Cursor failed to get data!!");
939 size = pers_db_cursor_get_data_size(handle);
940 x_fail_unless(size != -1, "Cursor failed to get size!!");
941 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
944 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 256);
945 x_fail_unless(rval != -1, "Cursor failed to get key!!");
947 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 256);
948 x_fail_unless(rval != -1, "Cursor failed to get data!!");
950 size = pers_db_cursor_get_data_size(handle1);
951 x_fail_unless(size != -1, "Cursor failed to get size!!");
952 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
954 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
957 rval = pers_db_cursor_destroy(handle);
958 x_fail_unless(rval != -1, "Failed to destroy cursor!!");
960 rval = pers_db_cursor_destroy(handle1);
961 x_fail_unless(rval != -1, "Failed to destroy cursor!!");
970 START_TEST(test_Plugin)
972 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
973 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
974 X_TEST_REPORT_REFERENCE("NONE");
975 X_TEST_REPORT_DESCRIPTION("Test of plugins");
976 X_TEST_REPORT_TYPE(GOOD);
979 unsigned char buffer[READ_SIZE] = {0};
981 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
983 ret = pclInitLibrary(gTheAppId, shutdownReg);
984 x_fail_unless(ret <= 1, "Failed to init PCL");
986 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
987 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
988 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
989 strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
992 ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE);
993 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
994 //printf("B U F F E R - early: %s\n", buffer);
995 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
996 strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
998 ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
999 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1000 //printf("B U F F E R - emergency: %s\n", buffer);
1001 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
1002 strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
1004 ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE);
1005 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1006 //printf("B U F F E R - hwinfo: %s\n", buffer);
1007 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
1008 strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
1010 ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE);
1011 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1012 //printf("B U F F E R - hwinfo: %s\n", buffer);
1013 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
1014 strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
1024 START_TEST(test_ReadDefault)
1026 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1027 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1028 X_TEST_REPORT_REFERENCE("NONE");
1029 X_TEST_REPORT_DESCRIPTION("Test of read default");
1030 X_TEST_REPORT_TYPE(GOOD);
1033 unsigned char buffer[READ_SIZE] = {0};
1035 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1037 ret = pclInitLibrary(gTheAppId, shutdownReg);
1038 x_fail_unless(ret <= 1, "Failed to init PCL");
1040 ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
1041 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1042 //printf("B U F F E R: %s\n", buffer);
1043 x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1045 ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
1046 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1047 //printf("B U F F E R: %s\n", buffer);
1048 x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1056 START_TEST(test_ReadConfDefault)
1058 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1059 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1060 X_TEST_REPORT_REFERENCE("NONE");
1061 X_TEST_REPORT_DESCRIPTION("Test of configurable default data");
1062 X_TEST_REPORT_TYPE(GOOD);
1065 unsigned char buffer[READ_SIZE] = {0};
1067 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1069 ret = pclInitLibrary(gTheAppId, shutdownReg);
1070 x_fail_unless(ret <= 1, "Failed to init PCL");
1072 ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
1073 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1074 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1076 ret = pclKeyReadData(0xFF, "statusHandle/confdefault02", 3, 2, buffer, READ_SIZE);
1077 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1078 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1086 START_TEST(test_GetPath)
1088 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1089 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1090 X_TEST_REPORT_REFERENCE("NONE");
1091 X_TEST_REPORT_DESCRIPTION("Test of get path");
1092 X_TEST_REPORT_TYPE(GOOD);
1096 const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db";
1097 unsigned int pathSize = 0;
1099 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1101 ret = pclInitLibrary(gTheAppId, shutdownReg);
1102 x_fail_unless(ret <= 1, "Failed to init PCL");
1104 ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize);
1106 x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
1107 x_fail_unless(pathSize == strlen((char*)path), "Path size not correct");
1109 pclFileReleasePath(ret);
1117 START_TEST(test_InitDeinit)
1120 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1124 // initialize and deinitialize 1. time
1125 (void)pclInitLibrary(gTheAppId, shutdownReg);
1129 // initialize and deinitialize 2. time
1130 (void)pclInitLibrary(gTheAppId, shutdownReg);
1134 // initialize and deinitialize 3. time
1135 (void)pclInitLibrary(gTheAppId, shutdownReg);
1143 START_TEST(test_NegHandle)
1145 int handle = -1, ret = 0;;
1146 int negativeHandle = -17;
1147 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1149 unsigned char buffer[128] = {0};
1151 (void)pclInitLibrary(gTheAppId, shutdownReg);
1153 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
1154 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
1158 ret = pclKeyHandleReadData(negativeHandle, buffer, READ_SIZE);
1159 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1161 ret = pclKeyHandleClose(negativeHandle);
1162 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleClose => negative handle not detected");
1164 ret = pclKeyHandleGetSize(negativeHandle);
1165 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleGetSize => negative handle not detected");
1167 ret = pclKeyHandleReadData(negativeHandle, buffer, 128);
1168 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1170 ret = pclKeyHandleRegisterNotifyOnChange(negativeHandle, &myChangeCallback);
1171 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleRegisterNotifyOnChange => negative handle not detected");
1173 ret = pclKeyHandleWriteData(negativeHandle, (unsigned char*)"Whatever", strlen("Whatever"));
1174 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleWriteData => negative handle not detected");
1178 ret = pclKeyHandleClose(handle);
1188 START_TEST(test_FileOpenCreate)
1190 int handle = -1, ret = 0;
1191 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1192 char buffer[128] = {0};
1193 char* writeBuffer = "test_FileOpenCreate: write some data to the file!";
1195 (void)pclInitLibrary(gTheAppId, shutdownReg);
1198 remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
1200 handle = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
1201 x_fail_unless(handle != -1, "Could not open file ==> /media/mediaDBWrite.db");
1204 ret = pclFileWriteData(handle, writeBuffer, strlen(writeBuffer));
1205 x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleWriteData => error writing data");
1208 ret = pclFileSeek(handle, 0, SEEK_SET);
1209 x_fail_unless(ret <= 0, "pclFileSeek => failed to position fd");
1212 ret = pclFileReadData(handle, buffer, 128);
1213 x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleReadData => error read data");
1214 x_fail_unless(strncmp(buffer, writeBuffer, strlen(writeBuffer)) == 0, "pclKeyHandleReadData => Buffer not correctly read");
1216 ret = pclFileClose(handle);
1217 x_fail_unless(ret <= 0, "pclKeyHandleClose => failed to close");
1220 remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
1228 static Suite * persistencyClientLib_suite()
1230 Suite * s = suite_create("Persistency client library");
1232 TCase * tc_persGetData = tcase_create("GetData");
1233 tcase_add_test(tc_persGetData, test_GetData);
1235 TCase * tc_persSetData = tcase_create("SetData");
1236 tcase_add_test(tc_persSetData, test_SetData);
1238 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
1239 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
1241 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
1242 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
1244 TCase * tc_persDeleteData = tcase_create("DeleteData");
1245 tcase_add_test(tc_persDeleteData, test_DeleteData);
1247 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
1248 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
1250 TCase * tc_persDataHandle = tcase_create("DataHandle");
1251 tcase_add_test(tc_persDataHandle, test_DataHandle);
1253 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
1254 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
1256 TCase * tc_persDataFile = tcase_create("DataFile");
1257 tcase_add_test(tc_persDataFile, test_DataFile);
1259 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
1260 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
1262 TCase * tc_Plugin = tcase_create("Plugin");
1263 tcase_add_test(tc_Plugin, test_Plugin);
1265 TCase * tc_ReadDefault = tcase_create("ReadDefault");
1266 tcase_add_test(tc_ReadDefault, test_ReadDefault);
1268 TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
1269 tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
1271 TCase * tc_GetPath = tcase_create("GetPath");
1272 tcase_add_test(tc_GetPath, test_GetPath);
1274 TCase * tc_InitDeinit = tcase_create("InitDeinit");
1275 tcase_add_test(tc_InitDeinit, test_InitDeinit);
1277 TCase * tc_NegHandle = tcase_create("NegHandle");
1278 tcase_add_test(tc_NegHandle, test_NegHandle);
1280 TCase * tc_FileOpenCreate = tcase_create("FileOpenCreate");
1281 tcase_add_test(tc_FileOpenCreate, test_FileOpenCreate);
1283 suite_add_tcase(s, tc_persSetData);
1284 suite_add_tcase(s, tc_persGetData);
1285 suite_add_tcase(s, tc_persSetDataNoPRCT);
1286 suite_add_tcase(s, tc_persGetDataSize);
1287 suite_add_tcase(s, tc_persDeleteData);
1288 suite_add_tcase(s, tc_persGetDataHandle);
1289 suite_add_tcase(s, tc_persDataHandle);
1290 suite_add_tcase(s, tc_persDataHandleOpen);
1291 suite_add_tcase(s, tc_persDataFile);
1292 suite_add_tcase(s, tc_persDataFileRecovery);
1293 suite_add_tcase(s, tc_ReadDefault);
1294 suite_add_tcase(s, tc_ReadConfDefault);
1295 suite_add_tcase(s, tc_GetPath);
1296 suite_add_tcase(s, tc_InitDeinit);
1297 suite_add_tcase(s, tc_NegHandle);
1298 suite_add_tcase(s, tc_FileOpenCreate);
1300 //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
1306 int main(int argc, char *argv[])
1313 TestResult** tResult;
1315 // assign application name
1316 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1317 gTheAppId[MaxAppNameLen-1] = '\0';
1319 /// debug log and trace (DLT) setup
1320 DLT_REGISTER_APP("PCLt","tests the persistence client library");
1323 Suite * s = persistencyClientLib_suite();
1324 SRunner * sr = srunner_create(s);
1325 srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
1326 srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
1327 srunner_run_all(sr, /*CK_NORMAL*/ CK_VERBOSE);
1329 nr_failed = srunner_ntests_failed(sr);
1330 nr_run = srunner_ntests_run(sr);
1332 tResult = srunner_results(sr);
1333 for(i = 0; i< nr_run; i++)
1335 (void)tr_rtype(tResult[i]); // get status of each test
1336 //fail = tr_rtype(tResult[i]); // get status of each test
1337 //printf("[%d] Fail: %d \n", i, fail);
1343 // unregister debug log and trace
1344 DLT_UNREGISTER_APP();
1348 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;