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)
95 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
96 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
97 strlen((char*)buffer)) == 0, "Buffer not correctly read");
98 x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
100 memset(buffer, 0, READ_SIZE);
104 * Logical DB ID: 0 with user 3 and seat 0
105 * ==> public shared user value (user 3, seat 0)
107 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
108 x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
110 memset(buffer, 0, READ_SIZE);
113 * Logical DB ID: 0xFF with user 3 and seat 2
114 * ==> local USER value (user 3, seat 2)
116 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
117 printf("Ist: %s\n", buffer);
118 printf("Soll: %s\n", "WT_ /var/opt/user_manual_climateControl.pdf");
120 x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
122 memset(buffer, 0, READ_SIZE);
125 * Logical DB ID: 0x20 with user 4 and seat 0
126 * ==> shared user value accessible by a group (user 4 and seat 0)
128 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
129 x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
131 memset(buffer, 0, READ_SIZE);
134 * Logical DB ID: 0xFF with user 0 and seat 0
135 * ==> local value accessible by ALL USERS (user 0, seat 0)
137 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
138 x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
140 memset(buffer, 0, READ_SIZE);
143 * Logical DB ID: 0x84 with user 4 and seat 0
144 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
146 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
147 x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
149 memset(buffer, 0, READ_SIZE);
152 * Logical DB ID: 0x84 with user 2 and seat 1
153 * ==> local merge value
155 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
156 x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
165 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
166 * Each resource below has an entry in the resource configuration table where
167 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
169 START_TEST (test_GetDataHandle)
171 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
172 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
173 X_TEST_REPORT_REFERENCE("NONE");
174 X_TEST_REPORT_DESCRIPTION("Test of get data handle");
175 X_TEST_REPORT_TYPE(GOOD);
177 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
178 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
180 unsigned char buffer[READ_SIZE] = {0};
183 char sysTimeBuffer[128];
185 ret = pclInitLibrary(gTheAppId, shutdownReg);
186 x_fail_unless(ret <= 1, "Failed to init PCL");
190 locTime = localtime(&t);
192 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),
193 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
196 // open handle ---------------------------------------------------
198 * Logical DB ID: 0xFF with user 0 and seat 0
199 * ==> local value accessible by ALL USERS (user 0, seat 0)
201 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
202 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
204 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
205 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");
207 size = pclKeyHandleGetSize(handle);
208 x_fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
209 // ---------------------------------------------------------------------------------------------
212 // open handle ---------------------------------------------------
214 * Logical DB ID: 0xFF with user 3 and seat 2
215 * ==> local USER value (user 3, seat 2)
217 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
218 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
220 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
221 x_fail_unless(size == strlen(sysTimeBuffer));
223 ret = pclKeyHandleClose(handle2);
224 // ---------------------------------------------------------------------------------------------
227 // open handle ---------------------------------------------------
229 * Logical DB ID: 0xFF with user 0 and seat 0
230 * ==> local value accessible by ALL USERS (user 0, seat 0)
232 #if 0 // plugin test case
233 memset(buffer, 0, READ_SIZE);
234 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
235 printf("H A N D L E: %d\n", handle4);
236 x_fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
238 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
239 x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
241 size = pclKeyHandleGetSize(handle4);
242 x_fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
244 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
246 // ---------------------------------------------------------------------------------------------
249 // open handle ---------------------------------------------------
251 * Logical DB ID: 0xFF with user 3 and seat 2
252 * ==> local USER value (user 3, seat 2)
254 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
255 x_fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
257 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
258 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
260 size = pclKeyHandleGetSize(handle3);
261 x_fail_unless(size = strlen(sysTimeBuffer));
262 // ---------------------------------------------------------------------------------------------
266 ret = pclKeyHandleClose(handle);
267 ret = pclKeyHandleClose(handle3);
268 ret = pclKeyHandleClose(handle4);
276 * Write data to a key using the key interface.
277 * First write data to different keys and after
278 * read the data for verification.
280 START_TEST(test_SetData)
282 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
283 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
284 X_TEST_REPORT_REFERENCE("NONE");
285 X_TEST_REPORT_DESCRIPTION("Test of set data");
286 X_TEST_REPORT_TYPE(GOOD);
289 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
290 unsigned char buffer[READ_SIZE] = {0};
291 char write1[READ_SIZE] = {0};
292 char write2[READ_SIZE] = {0};
293 char sysTimeBuffer[256];
297 ret = pclInitLibrary(gTheAppId, shutdownReg);
298 x_fail_unless(ret <= 1, "Failed to init PCL");
302 locTime = localtime(&t);
305 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),
306 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
309 * Logical DB ID: 0xFF with user 1 and seat 2
310 * ==> local USER value (user 1, seat 2)
313 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
314 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
315 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
316 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
317 printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__);
319 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
321 * Logical DB ID: 0xFF with user 1 and seat 2
322 * ==> local USER value (user 1, seat 2)
325 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
326 x_fail_unless(ret == strlen(write1), "Wrong write size");
328 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
330 * Logical DB ID: 0xFF with user 1 and seat 2
331 * ==> local USER value (user 1, seat 2)
332 * Resource ID: key_70
334 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
335 x_fail_unless(ret == strlen(write2), "Wrong write size");
338 /*******************************************************************************************************************************************/
339 /* used for changed notification testing */
340 /*******************************************************************************************************************************************/
342 * Logical DB ID: 0x84 with user 2 and seat 1
343 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
345 * ==> used for shared testing
347 //printf("Write data to trigger change notification\n");
348 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
349 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
352 * Logical DB ID: 0x84 with user 2 and seat 1
353 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
355 * ==> used for shared testing
357 //printf("Write data to trigger change notification\n");
358 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
359 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
362 * Logical DB ID: 0x84 with user 2 and seat 1
363 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
365 * ==> used for shared testing
367 //printf("Write data to trigger change notification\n");
368 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
369 x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
370 /*******************************************************************************************************************************************/
371 /*******************************************************************************************************************************************/
375 * now read the data written in the previous steps to the keys
376 * and verify data has been written correctly.
378 memset(buffer, 0, READ_SIZE);
380 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
381 printf("Verify ist : %s \n", buffer);
382 printf("Verify soll : %s \n", sysTimeBuffer);
383 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
384 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
386 memset(buffer, 0, READ_SIZE);
388 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
389 x_fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
390 x_fail_unless(ret == strlen(write1), "Wrong read size");
392 memset(buffer, 0, READ_SIZE);
394 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
395 x_fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
396 x_fail_unless(ret == strlen(write2), "Wrong read size");
406 * Write data to a key using the key interface.
407 * The key is not in the persistence resource table.
408 * The key sill then be stored to the location local and cached.
410 START_TEST(test_SetDataNoPRCT)
412 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
413 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
414 X_TEST_REPORT_REFERENCE("NONE");
415 X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT");
416 X_TEST_REPORT_TYPE(GOOD);
419 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
420 unsigned char buffer[READ_SIZE] = {0};
423 ret = pclInitLibrary(gTheAppId, shutdownReg);
424 x_fail_unless(ret <= 1, "Failed to init PCL");
428 char sysTimeBuffer[128];
430 locTime = localtime(&t);
432 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),
433 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
436 * Logical DB ID: 0xFF with user 1 and seat 2
437 * ==> local USER value (user 1, seat 2)
439 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
440 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
441 //printf("Write Buffer : %s\n", sysTimeBuffer);
443 // read data again and and verify datat has been written correctly
444 memset(buffer, 0, READ_SIZE);
446 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
447 x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
448 x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
449 //printf("read buffer : %s\n", buffer);
458 * Test the key interface.
459 * Read the size of a key.
461 START_TEST(test_GetDataSize)
463 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
464 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
465 X_TEST_REPORT_REFERENCE("NONE");
466 X_TEST_REPORT_DESCRIPTION("Test of get data size");
467 X_TEST_REPORT_TYPE(GOOD);
469 int size = 0, ret = 0;
471 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
473 ret = pclInitLibrary(gTheAppId, shutdownReg);
474 x_fail_unless(ret <= 1, "Failed to init PCL");
477 * Logical DB ID: 0xFF with user 3 and seat 2
478 * ==> local USER value (user 3, seat 2)
480 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
481 x_fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
485 * Logical DB ID: 0x84 with user 2 and seat 1
486 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
488 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
489 printf("=>=>=>=> soll: %d | ist: %d\n", strlen("CACHE_ /last_exit/queens"), size);
490 x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
498 * Delete a key using the key value interface.
499 * First read a from a key, the delte the key
500 * and then try to read again. The Last read must fail.
502 START_TEST(test_DeleteData)
504 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
505 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
506 X_TEST_REPORT_REFERENCE("NONE");
507 X_TEST_REPORT_DESCRIPTION("Test of delete data");
508 X_TEST_REPORT_TYPE(GOOD);
511 unsigned char buffer[READ_SIZE];
512 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
514 rval = pclInitLibrary(gTheAppId, shutdownReg);
515 x_fail_unless(rval <= 1, "Failed to init PCL");
517 // read data from key
518 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
519 x_fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
522 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
523 x_fail_unless(rval == 0, "Failed to delete key");
525 // after deleting the key, reading from key must fail now!
526 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
527 x_fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
531 // read data from key
532 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
533 x_fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
536 rval = pclKeyDelete(0xFF, "70", 1, 2);
537 x_fail_unless(rval == 0, "Failed to delete key");
539 // after deleting the key, reading from key must fail now!
540 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
541 x_fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
550 * Test the file interface:
557 START_TEST(test_DataFile)
559 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
560 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
561 X_TEST_REPORT_REFERENCE("NONE");
562 X_TEST_REPORT_DESCRIPTION("Test of data file");
563 X_TEST_REPORT_TYPE(GOOD);
565 int fd = 0, i = 0, idx = 0;
566 int size = 0, ret = 0;
567 int writeSize = 16*1024;
568 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
570 unsigned char buffer[READ_SIZE] = {0};
571 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
573 char* fileMap = NULL;
575 ret = pclInitLibrary(gTheAppId, shutdownReg);
576 x_fail_unless(ret <= 1, "Failed to init PCL");
578 writeBuffer = malloc(writeSize);
581 // fill buffer a sequence
582 for(i = 0; i<(writeSize/8); i++)
584 writeBuffer[idx++] = 'A';
585 writeBuffer[idx++] = 'B';
586 writeBuffer[idx++] = 'C';
587 writeBuffer[idx++] = ' ';
588 writeBuffer[idx++] = 'D';
589 writeBuffer[idx++] = 'E';
590 writeBuffer[idx++] = 'F';
591 writeBuffer[idx++] = ' ';
594 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
595 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
598 // open ------------------------------------------------------------
599 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
600 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
602 size = pclFileGetSize(fd);
603 printf("%s => %d\n", __FUNCTION__, __LINE__);
604 printf("Soll: 68 | Ist: %d\n", size);
605 printf("%s => %d\n", __FUNCTION__, __LINE__);
606 x_fail_unless(size == 68, "Wrong file size");
607 printf("%s => %d\n", __FUNCTION__, __LINE__);
609 printf("%s => %d\n", __FUNCTION__, __LINE__);
610 size = pclFileReadData(fd, buffer, READ_SIZE);
611 printf("%s => %d\n", __FUNCTION__, __LINE__);
612 x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
613 printf("%s => %d\n", __FUNCTION__, __LINE__);
614 x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
615 printf("%s => %d\n", __FUNCTION__, __LINE__);
617 ret = pclFileClose(fd);
618 printf("%s => %d\n", __FUNCTION__, __LINE__);
619 x_fail_unless(ret == 0, "Failed to close file");
620 printf("%s => %d\n", __FUNCTION__, __LINE__);
622 // open ------------------------------------------------------------
623 printf("%s => %d\n", __FUNCTION__, __LINE__);
624 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
625 printf("%s => %d\n", __FUNCTION__, __LINE__);
626 x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
628 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
629 x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
630 printf("%s => %d\n", __FUNCTION__, __LINE__);
631 ret = pclFileClose(fd);
632 printf("%s => %d\n", __FUNCTION__, __LINE__);
633 x_fail_unless(ret == 0, "Failed to close file");
635 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
636 // remove ----------------------------------------------------------
637 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
638 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
639 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
640 x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
641 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
643 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
644 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
645 x_fail_unless(fd == -1, "Failed to remove file, file still exists");
646 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
648 printf("* * %s => %d\n", __FUNCTION__, __LINE__);
650 // map file --------------------------------------------------------
652 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
654 size = pclFileGetSize(fd);
655 pclFileMapData(fileMap, size, 0, fd);
656 x_fail_unless(fileMap != MAP_FAILED, "Failed to map file");
658 ret = pclFileUnmapData(fileMap, size);
659 x_fail_unless(ret != -1, "Failed to unmap file");
662 size = pclFileGetSize(1024);
663 x_fail_unless(ret == 0, "Got size, but should not");
665 ret = pclFileClose(fd);
666 x_fail_unless(ret == 0, "Failed to close file");
678 START_TEST(test_DataFileRecovery)
680 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
681 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
682 X_TEST_REPORT_REFERENCE("NONE");
683 X_TEST_REPORT_DESCRIPTION("Test of data file recovery");
684 X_TEST_REPORT_TYPE(GOOD);
686 int fd_RW = 0, fd_RO = 0;
688 char* wBuffer = "This is a buffer to write";
689 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
691 ret = pclInitLibrary(gTheAppId, shutdownReg);
692 x_fail_unless(ret <= 1, "Failed to init PCL");
695 // test backup creation --------------------------------------------
696 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
697 x_fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
699 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
700 x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
701 pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
703 ret = pclFileClose(fd_RW);
706 ret = pclFileClose(fd_RO);
715 * The the handle function of the key and file interface.
717 START_TEST(test_DataHandle)
719 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
720 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
721 X_TEST_REPORT_REFERENCE("NONE");
722 X_TEST_REPORT_DESCRIPTION("Test of data handle");
723 X_TEST_REPORT_TYPE(GOOD);
725 int handle1 = 0, handle2 = 0;
726 int handleArray[4] = {0};
728 unsigned char buffer[READ_SIZE] = {0};
729 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
731 ret = pclInitLibrary(gTheAppId, shutdownReg);
732 x_fail_unless(ret <= 1, "Failed to init PCL");
735 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
736 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
738 ret = pclFileClose(handle1);
739 x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
741 ret = pclFileClose(1024);
742 x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
744 ret = pclFileClose(17);
745 x_fail_unless(ret == -1, "Could close file, but should not!!");
747 // test multiple handles
748 handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
749 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
751 handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
752 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
754 handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
755 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
757 handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
758 x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
760 (void)pclFileReadData(handleArray[0], buffer, READ_SIZE);
761 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
762 strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
763 == 0, "Buffer not correctly read => mediaDB_write_01.db");
765 (void)pclFileReadData(handleArray[1], buffer, READ_SIZE);
766 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
767 strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
768 == 0, "Buffer not correctly read => mediaDB_write_02.db");
770 (void)pclFileReadData(handleArray[2], buffer, READ_SIZE);
771 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
772 strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
773 == 0, "Buffer not correctly read => mediaDB_write_03.db");
775 (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
776 x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
777 strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
778 == 0, "Buffer not correctly read => mediaDB_write_04.db");
780 ret = pclKeyHandleClose(handleArray[0]);
781 x_fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
783 ret = pclKeyHandleClose(handleArray[1]);
784 x_fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
786 ret = pclKeyHandleClose(handleArray[2]);
787 x_fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
789 ret = pclKeyHandleClose(handleArray[3]);
790 x_fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
793 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
794 x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
796 ret = pclKeyHandleClose(handle2);
797 x_fail_unless(ret != -1, "Failed to close handle!!");
799 ret = pclKeyHandleClose(1024);
800 x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
809 * Extended key handle test.
810 * Test have been created after a bug in the key handle function occured.
812 START_TEST(test_DataHandleOpen)
814 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
815 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
816 X_TEST_REPORT_REFERENCE("NONE");
817 X_TEST_REPORT_DESCRIPTION("Test of data handle open");
818 X_TEST_REPORT_TYPE(GOOD);
820 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
821 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
823 ret = pclInitLibrary(gTheAppId, shutdownReg);
824 x_fail_unless(ret <= 1, "Failed to init PCL");
826 // open handles ----------------------------------------------------
827 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
828 x_fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
830 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
831 x_fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
833 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
834 x_fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
836 // close handles ---------------------------------------------------
837 ret = pclKeyHandleClose(hd1);
838 x_fail_unless(ret != -1, "Failed to close handle!!");
840 ret = pclKeyHandleClose(hd2);
841 x_fail_unless(ret != -1, "Failed to close handle!!");
843 ret = pclKeyHandleClose(hd3);
844 x_fail_unless(ret != -1, "Failed to close handle!!");
846 // open handles ----------------------------------------------------
847 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
848 x_fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
850 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
851 x_fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
853 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
854 x_fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
856 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
857 x_fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
859 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
860 x_fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
862 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
863 x_fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
865 // close handles ---------------------------------------------------
866 ret = pclKeyHandleClose(hd4);
867 x_fail_unless(ret != -1, "Failed to close handle!!");
869 ret = pclKeyHandleClose(hd5);
870 x_fail_unless(ret != -1, "Failed to close handle!!");
872 ret = pclKeyHandleClose(hd6);
873 x_fail_unless(ret != -1, "Failed to close handle!!");
875 ret = pclKeyHandleClose(hd7);
876 x_fail_unless(ret != -1, "Failed to close handle!!");
878 ret = pclKeyHandleClose(hd8);
879 x_fail_unless(ret != -1, "Failed to close handle!!");
881 ret = pclKeyHandleClose(hd9);
882 x_fail_unless(ret != -1, "Failed to close handle!!");
892 * Test for i n t e r n a l structures.
893 * Test the cursor functions.
895 START_TEST(test_Cursor)
897 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
898 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
899 X_TEST_REPORT_REFERENCE("NONE");
900 X_TEST_REPORT_DESCRIPTION("Test of cursor");
901 X_TEST_REPORT_TYPE(GOOD);
903 int handle = -1, rval = 0, size = 0, handle1 = 0;
904 char bufferKeySrc[READ_SIZE] = {0};
905 char bufferDataSrc[READ_SIZE] = {0};
906 char bufferKeyDst[READ_SIZE] = {0};
907 char bufferDataDst[READ_SIZE] = {0};
908 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
910 rval = pclInitLibrary(gTheAppId, shutdownReg);
911 x_fail_unless(rval <= 1, "Failed to init PCL");
914 handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
915 x_fail_unless(handle != -1, "Failed to create cursor!!");
918 handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
919 x_fail_unless(handle1 != -1, "Failed to create cursor!!");
923 memset(bufferKeySrc, 0, READ_SIZE);
924 memset(bufferDataSrc, 0, READ_SIZE);
925 memset(bufferKeyDst, 0, READ_SIZE);
926 memset(bufferDataDst, 0, READ_SIZE);
929 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 256);
930 x_fail_unless(rval != -1, "Cursor failed to get key!!");
932 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 256);
934 x_fail_unless(rval != -1, "Cursor failed to get data!!");
936 size = pers_db_cursor_get_data_size(handle);
937 x_fail_unless(size != -1, "Cursor failed to get size!!");
938 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
941 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 256);
942 x_fail_unless(rval != -1, "Cursor failed to get key!!");
944 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 256);
945 x_fail_unless(rval != -1, "Cursor failed to get data!!");
947 size = pers_db_cursor_get_data_size(handle1);
948 x_fail_unless(size != -1, "Cursor failed to get size!!");
949 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
951 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
954 rval = pers_db_cursor_destroy(handle);
955 x_fail_unless(rval != -1, "Failed to destroy cursor!!");
957 rval = pers_db_cursor_destroy(handle1);
958 x_fail_unless(rval != -1, "Failed to destroy cursor!!");
967 START_TEST(test_Plugin)
969 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
970 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
971 X_TEST_REPORT_REFERENCE("NONE");
972 X_TEST_REPORT_DESCRIPTION("Test of plugins");
973 X_TEST_REPORT_TYPE(GOOD);
976 unsigned char buffer[READ_SIZE] = {0};
978 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
980 ret = pclInitLibrary(gTheAppId, shutdownReg);
981 x_fail_unless(ret <= 1, "Failed to init PCL");
983 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
984 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
985 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
986 strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
989 ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE);
990 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
991 //printf("B U F F E R - early: %s\n", buffer);
992 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
993 strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
995 ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
996 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
997 //printf("B U F F E R - emergency: %s\n", buffer);
998 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
999 strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
1001 ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE);
1002 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1003 //printf("B U F F E R - hwinfo: %s\n", buffer);
1004 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
1005 strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
1007 ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE);
1008 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1009 //printf("B U F F E R - hwinfo: %s\n", buffer);
1010 x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
1011 strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
1021 START_TEST(test_ReadDefault)
1023 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1024 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1025 X_TEST_REPORT_REFERENCE("NONE");
1026 X_TEST_REPORT_DESCRIPTION("Test of read default");
1027 X_TEST_REPORT_TYPE(GOOD);
1030 unsigned char buffer[READ_SIZE] = {0};
1032 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1034 ret = pclInitLibrary(gTheAppId, shutdownReg);
1035 x_fail_unless(ret <= 1, "Failed to init PCL");
1037 ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
1038 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1039 //printf("B U F F E R: %s\n", buffer);
1040 x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1042 ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
1043 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1044 //printf("B U F F E R: %s\n", buffer);
1045 x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1053 START_TEST(test_ReadConfDefault)
1055 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1056 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1057 X_TEST_REPORT_REFERENCE("NONE");
1058 X_TEST_REPORT_DESCRIPTION("Test of configurable default data");
1059 X_TEST_REPORT_TYPE(GOOD);
1062 unsigned char buffer[READ_SIZE] = {0};
1064 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1066 ret = pclInitLibrary(gTheAppId, shutdownReg);
1067 x_fail_unless(ret <= 1, "Failed to init PCL");
1069 ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
1070 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1071 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1073 ret = pclKeyReadData(0xFF, "statusHandle/confdefault02", 3, 2, buffer, READ_SIZE);
1074 x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1075 x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1083 START_TEST(test_GetPath)
1085 X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1086 X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1087 X_TEST_REPORT_REFERENCE("NONE");
1088 X_TEST_REPORT_DESCRIPTION("Test of get path");
1089 X_TEST_REPORT_TYPE(GOOD);
1093 const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db";
1094 unsigned int pathSize = 0;
1096 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1098 ret = pclInitLibrary(gTheAppId, shutdownReg);
1099 x_fail_unless(ret <= 1, "Failed to init PCL");
1101 ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize);
1103 x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
1104 x_fail_unless(pathSize == strlen((char*)path), "Path size not correct");
1106 pclFileReleasePath(ret);
1114 START_TEST(test_InitDeinit)
1117 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1121 // initialize and deinitialize 1. time
1122 (void)pclInitLibrary(gTheAppId, shutdownReg);
1126 // initialize and deinitialize 2. time
1127 (void)pclInitLibrary(gTheAppId, shutdownReg);
1131 // initialize and deinitialize 3. time
1132 (void)pclInitLibrary(gTheAppId, shutdownReg);
1140 START_TEST(test_NegHandle)
1142 int handle = -1, ret = 0;;
1143 int negativeHandle = -17;
1144 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1146 unsigned char buffer[128] = {0};
1148 (void)pclInitLibrary(gTheAppId, shutdownReg);
1150 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
1151 x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
1155 ret = pclKeyHandleReadData(negativeHandle, buffer, READ_SIZE);
1156 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1158 ret = pclKeyHandleClose(negativeHandle);
1159 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleClose => negative handle not detected");
1161 ret = pclKeyHandleGetSize(negativeHandle);
1162 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleGetSize => negative handle not detected");
1164 ret = pclKeyHandleReadData(negativeHandle, buffer, 128);
1165 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1167 ret = pclKeyHandleRegisterNotifyOnChange(negativeHandle, &myChangeCallback);
1168 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleRegisterNotifyOnChange => negative handle not detected");
1170 ret = pclKeyHandleWriteData(negativeHandle, (unsigned char*)"Whatever", strlen("Whatever"));
1171 x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleWriteData => negative handle not detected");
1175 ret = pclKeyHandleClose(handle);
1185 START_TEST(test_FileOpenCreate)
1187 int handle = -1, ret = 0;
1188 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1189 char buffer[128] = {0};
1190 char* writeBuffer = "test_FileOpenCreate: write some data to the file!";
1192 (void)pclInitLibrary(gTheAppId, shutdownReg);
1195 remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
1197 handle = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
1198 x_fail_unless(handle != -1, "Could not open file ==> /media/mediaDBWrite.db");
1201 ret = pclFileWriteData(handle, writeBuffer, strlen(writeBuffer));
1202 x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleWriteData => error writing data");
1205 ret = pclFileSeek(handle, 0, SEEK_SET);
1206 x_fail_unless(ret <= 0, "pclFileSeek => failed to position fd");
1209 ret = pclFileReadData(handle, buffer, 128);
1210 x_fail_unless(ret == strlen(writeBuffer), "pclKeyHandleReadData => error read data");
1211 x_fail_unless(strncmp(buffer, writeBuffer, strlen(writeBuffer)) == 0, "pclKeyHandleReadData => Buffer not correctly read");
1213 ret = pclFileClose(handle);
1214 x_fail_unless(ret <= 0, "pclKeyHandleClose => failed to close");
1217 remove("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db");
1225 static Suite * persistencyClientLib_suite()
1227 Suite * s = suite_create("Persistency client library");
1229 TCase * tc_persGetData = tcase_create("GetData");
1230 tcase_add_test(tc_persGetData, test_GetData);
1232 TCase * tc_persSetData = tcase_create("SetData");
1233 tcase_add_test(tc_persSetData, test_SetData);
1235 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
1236 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
1238 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
1239 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
1241 TCase * tc_persDeleteData = tcase_create("DeleteData");
1242 tcase_add_test(tc_persDeleteData, test_DeleteData);
1244 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
1245 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
1247 TCase * tc_persDataHandle = tcase_create("DataHandle");
1248 tcase_add_test(tc_persDataHandle, test_DataHandle);
1250 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
1251 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
1253 TCase * tc_persDataFile = tcase_create("DataFile");
1254 tcase_add_test(tc_persDataFile, test_DataFile);
1256 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
1257 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
1259 TCase * tc_Plugin = tcase_create("Plugin");
1260 tcase_add_test(tc_Plugin, test_Plugin);
1262 TCase * tc_ReadDefault = tcase_create("ReadDefault");
1263 tcase_add_test(tc_ReadDefault, test_ReadDefault);
1265 TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
1266 tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
1268 TCase * tc_GetPath = tcase_create("GetPath");
1269 tcase_add_test(tc_GetPath, test_GetPath);
1271 TCase * tc_InitDeinit = tcase_create("InitDeinit");
1272 tcase_add_test(tc_InitDeinit, test_InitDeinit);
1274 TCase * tc_NegHandle = tcase_create("NegHandle");
1275 tcase_add_test(tc_NegHandle, test_NegHandle);
1277 TCase * tc_FileOpenCreate = tcase_create("FileOpenCreate");
1278 tcase_add_test(tc_FileOpenCreate, test_FileOpenCreate);
1280 suite_add_tcase(s, tc_persSetData);
1281 suite_add_tcase(s, tc_persGetData);
1282 suite_add_tcase(s, tc_persSetDataNoPRCT);
1283 suite_add_tcase(s, tc_persGetDataSize);
1284 suite_add_tcase(s, tc_persDeleteData);
1285 suite_add_tcase(s, tc_persGetDataHandle);
1286 suite_add_tcase(s, tc_persDataHandle);
1287 suite_add_tcase(s, tc_persDataHandleOpen);
1288 suite_add_tcase(s, tc_persDataFile);
1289 suite_add_tcase(s, tc_persDataFileRecovery);
1290 suite_add_tcase(s, tc_ReadDefault);
1291 suite_add_tcase(s, tc_ReadConfDefault);
1292 suite_add_tcase(s, tc_GetPath);
1293 suite_add_tcase(s, tc_InitDeinit);
1294 suite_add_tcase(s, tc_NegHandle);
1295 suite_add_tcase(s, tc_FileOpenCreate);
1297 //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
1303 int main(int argc, char *argv[])
1310 TestResult** tResult;
1312 // assign application name
1313 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1314 gTheAppId[MaxAppNameLen-1] = '\0';
1316 /// debug log and trace (DLT) setup
1317 DLT_REGISTER_APP("PCLt","tests the persistence client library");
1320 Suite * s = persistencyClientLib_suite();
1321 SRunner * sr = srunner_create(s);
1322 srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
1323 srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
1324 srunner_run_all(sr, /*CK_NORMAL*/ CK_VERBOSE);
1326 nr_failed = srunner_ntests_failed(sr);
1327 nr_run = srunner_ntests_run(sr);
1329 tResult = srunner_results(sr);
1330 for(i = 0; i< nr_run; i++)
1332 (void)tr_rtype(tResult[i]); // get status of each test
1333 //fail = tr_rtype(tResult[i]); // get status of each test
1334 //printf("[%d] Fail: %d \n", i, fail);
1340 // unregister debug log and trace
1341 DLT_UNREGISTER_APP();
1345 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;