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 * @ingroup Persistence client library test
14 * @author Ingo Huerner
15 * @brief Test of persistence client library
23 #include <unistd.h> /* exit */
30 #include <dlt/dlt_common.h>
32 #include "../include/persistence_client_library_file.h"
33 #include "../include/persistence_client_library_key.h"
34 #include "../include/persistence_client_library.h"
37 // protected header, should be used only be persistence components
38 // included here for testing purpose
39 #include "../include_protected/persistence_client_library_db_access.h"
43 #define NUM_OF_FILES 3
44 #define READ_SIZE 1024
47 char gTheAppId[MaxAppNameLen] = {0};
49 // definition of weekday
50 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
55 * Test the key value interface using different logicalDB id's, users and seats.
56 * Each resource below has an entry in the resource configuration table where the
57 * storage location (cached or write through) and type (e.g. custom) has been configured.
59 START_TEST (test_GetData)
62 unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
64 unsigned char buffer[READ_SIZE] = {0};
66 ret = pclInitLibrary(gTheAppId, shutdownReg);
67 fail_unless(ret <= 1, "Failed to init PCL");
71 * Logical DB ID: 0xFF with user 0 and seat 0
72 * ==> local value accessible by all users (user 0, seat 0)
74 ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE);
75 fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
76 strlen((char*)buffer)) == 0, "Buffer not correctly read");
77 fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
79 memset(buffer, 0, READ_SIZE);
82 * Logical DB ID: 0xFF with user 0 and seat 0
83 * ==> local value accessible by all users (user 0, seat 0)
85 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
86 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
87 strlen((char*)buffer)) == 0, "Buffer not correctly read");
88 fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
90 memset(buffer, 0, READ_SIZE);
94 * Logical DB ID: 0 with user 3 and seat 0
95 * ==> public shared user value (user 3, seat 0)
97 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
98 fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
100 memset(buffer, 0, READ_SIZE);
103 * Logical DB ID: 0xFF with user 3 and seat 2
104 * ==> local USER value (user 3, seat 2)
106 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
107 fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
109 memset(buffer, 0, READ_SIZE);
112 * Logical DB ID: 0x20 with user 4 and seat 0
113 * ==> shared user value accessible by a group (user 4 and seat 0)
115 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
116 fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
118 memset(buffer, 0, READ_SIZE);
121 * Logical DB ID: 0xFF with user 0 and seat 0
122 * ==> local value accessible by ALL USERS (user 0, seat 0)
124 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
125 fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
127 memset(buffer, 0, READ_SIZE);
130 * Logical DB ID: 0x84 with user 4 and seat 0
131 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
133 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
134 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
136 memset(buffer, 0, READ_SIZE);
139 * Logical DB ID: 0x84 with user 2 and seat 1
140 * ==> local merge value
142 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
143 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
152 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
153 * Each resource below has an entry in the resource configuration table where
154 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
156 START_TEST (test_GetDataHandle)
158 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
159 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
161 unsigned char buffer[READ_SIZE] = {0};
164 char sysTimeBuffer[128];
166 ret = pclInitLibrary(gTheAppId, shutdownReg);
167 fail_unless(ret <= 1, "Failed to init PCL");
171 locTime = localtime(&t);
173 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),
174 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
177 // open handle ---------------------------------------------------
179 * Logical DB ID: 0xFF with user 0 and seat 0
180 * ==> local value accessible by ALL USERS (user 0, seat 0)
182 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
183 fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
185 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
186 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");
188 size = pclKeyHandleGetSize(handle);
189 fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
190 // ---------------------------------------------------------------------------------------------
193 // open handle ---------------------------------------------------
195 * Logical DB ID: 0xFF with user 3 and seat 2
196 * ==> local USER value (user 3, seat 2)
198 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
199 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
201 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
202 fail_unless(size = strlen(sysTimeBuffer));
204 ret = pclKeyHandleClose(handle2);
205 // ---------------------------------------------------------------------------------------------
208 // open handle ---------------------------------------------------
210 * Logical DB ID: 0xFF with user 0 and seat 0
211 * ==> local value accessible by ALL USERS (user 0, seat 0)
213 #if 0 // plugin test case
214 memset(buffer, 0, READ_SIZE);
215 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
216 printf("H A N D L E: %d\n", handle4);
217 fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
219 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
220 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
222 size = pclKeyHandleGetSize(handle4);
223 fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
225 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
227 // ---------------------------------------------------------------------------------------------
230 // open handle ---------------------------------------------------
232 * Logical DB ID: 0xFF with user 3 and seat 2
233 * ==> local USER value (user 3, seat 2)
235 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
236 fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
238 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
239 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
241 size = pclKeyHandleGetSize(handle3);
242 fail_unless(size = strlen(sysTimeBuffer));
243 // ---------------------------------------------------------------------------------------------
247 ret = pclKeyHandleClose(handle);
248 ret = pclKeyHandleClose(handle3);
249 ret = pclKeyHandleClose(handle4);
257 * Write data to a key using the key interface.
258 * First write data to different keys and after
259 * read the data for verification.
261 START_TEST(test_SetData)
264 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
265 unsigned char buffer[READ_SIZE] = {0};
266 char write1[READ_SIZE] = {0};
267 char write2[READ_SIZE] = {0};
268 char sysTimeBuffer[256];
272 ret = pclInitLibrary(gTheAppId, shutdownReg);
273 fail_unless(ret <= 1, "Failed to init PCL");
277 locTime = localtime(&t);
280 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),
281 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
284 * Logical DB ID: 0xFF with user 1 and seat 2
285 * ==> local USER value (user 1, seat 2)
289 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
290 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
292 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
294 * Logical DB ID: 0xFF with user 1 and seat 2
295 * ==> local USER value (user 1, seat 2)
298 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
299 fail_unless(ret == strlen(write1), "Wrong write size");
301 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
303 * Logical DB ID: 0xFF with user 1 and seat 2
304 * ==> local USER value (user 1, seat 2)
305 * Resource ID: key_70
307 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
308 fail_unless(ret == strlen(write2), "Wrong write size");
311 /*******************************************************************************************************************************************/
312 /* used for changed notification testing */
313 /*******************************************************************************************************************************************/
315 * Logical DB ID: 0x84 with user 2 and seat 1
316 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
318 * ==> used for shared testing
320 //printf("Write data to trigger change notification\n");
321 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
324 * Logical DB ID: 0x84 with user 2 and seat 1
325 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
327 * ==> used for shared testing
329 //printf("Write data to trigger change notification\n");
330 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
333 * Logical DB ID: 0x84 with user 2 and seat 1
334 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
336 * ==> used for shared testing
338 //printf("Write data to trigger change notification\n");
339 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
340 /*******************************************************************************************************************************************/
341 /*******************************************************************************************************************************************/
345 * now read the data written in the previous steps to the keys
346 * and verify data has been written correctly.
348 memset(buffer, 0, READ_SIZE);
350 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
351 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
352 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
354 memset(buffer, 0, READ_SIZE);
356 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
357 fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
358 fail_unless(ret == strlen(write1), "Wrong read size");
360 memset(buffer, 0, READ_SIZE);
362 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
363 fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
364 fail_unless(ret == strlen(write2), "Wrong read size");
374 * Write data to a key using the key interface.
375 * The key is not in the persistence resource table.
376 * The key sill then be stored to the location local and cached.
378 START_TEST(test_SetDataNoPRCT)
381 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
382 unsigned char buffer[READ_SIZE] = {0};
385 ret = pclInitLibrary(gTheAppId, shutdownReg);
386 fail_unless(ret <= 1, "Failed to init PCL");
390 char sysTimeBuffer[128];
392 locTime = localtime(&t);
394 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),
395 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
398 * Logical DB ID: 0xFF with user 1 and seat 2
399 * ==> local USER value (user 1, seat 2)
401 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
402 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
403 //printf("Write Buffer : %s\n", sysTimeBuffer);
405 // read data again and and verify datat has been written correctly
406 memset(buffer, 0, READ_SIZE);
408 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
409 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
410 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
411 //printf("read buffer : %s\n", buffer);
420 * Test the key interface.
421 * Read the size of a key.
423 START_TEST(test_GetDataSize)
425 int size = 0, ret = 0;
427 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
429 ret = pclInitLibrary(gTheAppId, shutdownReg);
430 fail_unless(ret <= 1, "Failed to init PCL");
433 * Logical DB ID: 0xFF with user 3 and seat 2
434 * ==> local USER value (user 3, seat 2)
436 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
437 fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
441 * Logical DB ID: 0x84 with user 2 and seat 1
442 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
444 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
445 fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
453 * Delete a key using the key value interface.
454 * First read a from a key, the delte the key
455 * and then try to read again. The Last read must fail.
457 START_TEST(test_DeleteData)
460 unsigned char buffer[READ_SIZE];
461 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
463 rval = pclInitLibrary(gTheAppId, shutdownReg);
464 fail_unless(rval <= 1, "Failed to init PCL");
466 // read data from key
467 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
468 fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
471 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
472 fail_unless(rval == 0, "Failed to delete key");
474 // after deleting the key, reading from key must fail now!
475 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
476 fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
480 // read data from key
481 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
482 fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
485 rval = pclKeyDelete(0xFF, "70", 1, 2);
486 fail_unless(rval == 0, "Failed to delete key");
488 // after deleting the key, reading from key must fail now!
489 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
490 fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
499 * Test the file interface:
506 START_TEST(test_DataFile)
508 int fd = 0, i = 0, idx = 0;
509 int size = 0, ret = 0;
510 int writeSize = 16*1024;
511 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
513 unsigned char buffer[READ_SIZE] = {0};
514 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
516 char* fileMap = NULL;
518 ret = pclInitLibrary(gTheAppId, shutdownReg);
519 fail_unless(ret <= 1, "Failed to init PCL");
521 writeBuffer = malloc(writeSize);
524 // fill buffer a sequence
525 for(i = 0; i<(writeSize/8); i++)
527 writeBuffer[idx++] = 'A';
528 writeBuffer[idx++] = 'B';
529 writeBuffer[idx++] = 'C';
530 writeBuffer[idx++] = ' ';
531 writeBuffer[idx++] = 'D';
532 writeBuffer[idx++] = 'E';
533 writeBuffer[idx++] = 'F';
534 writeBuffer[idx++] = ' ';
537 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
538 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
541 // open ------------------------------------------------------------
542 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
543 fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
545 size = pclFileGetSize(fd);
546 fail_unless(size == 68, "Wrong file size");
548 size = pclFileReadData(fd, buffer, READ_SIZE);
549 fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
550 fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
553 ret = pclFileClose(fd);
554 fail_unless(ret == 0, "Failed to close file");
556 // open ------------------------------------------------------------
557 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
558 fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
560 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
561 fail_unless(size == strlen(writeBuffer), "Failed to write data");
563 ret = pclFileClose(fd);
564 fail_unless(ret == 0, "Failed to close file");
567 // remove ----------------------------------------------------------
568 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
569 fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
571 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
572 fail_unless(fd == -1, "Failed to remove file, file still exists");
576 // map file --------------------------------------------------------
577 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
579 size = pclFileGetSize(fd);
580 pclFileMapData(fileMap, size, 0, fd);
581 fail_unless(fileMap != MAP_FAILED, "Failed to map file");
583 ret = pclFileUnmapData(fileMap, size);
584 fail_unless(ret != -1, "Failed to unmap file");
587 size = pclFileGetSize(1024);
588 fail_unless(ret == 0, "Got size, but should not");
590 ret = pclFileClose(fd);
591 fail_unless(ret == 0, "Failed to close file");
603 START_TEST(test_DataFileRecovery)
605 int fd_RW = 0, fd_RO = 0;
607 char* wBuffer = "This is a buffer to write";
608 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
610 ret = pclInitLibrary(gTheAppId, shutdownReg);
611 fail_unless(ret <= 1, "Failed to init PCL");
613 // test backup creation --------------------------------------------
614 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
615 fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
617 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
618 fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
619 pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
621 ret = pclFileClose(fd_RW);
624 ret = pclFileClose(fd_RO);
633 * The the handle function of the key and file interface.
635 START_TEST(test_DataHandle)
637 int handle1 = 0, handle2 = 0;
639 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
641 ret = pclInitLibrary(gTheAppId, shutdownReg);
642 fail_unless(ret <= 1, "Failed to init PCL");
645 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
646 fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
648 ret = pclFileClose(handle1);
649 fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
651 ret = pclFileClose(1024);
652 fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
655 ret = pclFileClose(17);
656 fail_unless(ret == -1, "Could close file, but should not!!");
661 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
662 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
664 ret = pclKeyHandleClose(handle2);
665 fail_unless(ret != -1, "Failed to close handle!!");
667 ret = pclKeyHandleClose(1024);
668 fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
677 * Extended key handle test.
678 * Test have been created after a bug in the key handle function occured.
680 START_TEST(test_DataHandleOpen)
682 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
683 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
685 ret = pclInitLibrary(gTheAppId, shutdownReg);
686 fail_unless(ret <= 1, "Failed to init PCL");
688 // open handles ----------------------------------------------------
689 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
690 fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
692 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
693 fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
695 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
696 fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
698 // close handles ---------------------------------------------------
699 ret = pclKeyHandleClose(hd1);
700 fail_unless(ret != -1, "Failed to close handle!!");
702 ret = pclKeyHandleClose(hd2);
703 fail_unless(ret != -1, "Failed to close handle!!");
705 ret = pclKeyHandleClose(hd3);
706 fail_unless(ret != -1, "Failed to close handle!!");
708 // open handles ----------------------------------------------------
709 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
710 fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
712 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
713 fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
715 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
716 fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
718 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
719 fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
721 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
722 fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
724 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
725 fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
727 // close handles ---------------------------------------------------
728 ret = pclKeyHandleClose(hd4);
729 fail_unless(ret != -1, "Failed to close handle!!");
731 ret = pclKeyHandleClose(hd5);
732 fail_unless(ret != -1, "Failed to close handle!!");
734 ret = pclKeyHandleClose(hd6);
735 fail_unless(ret != -1, "Failed to close handle!!");
737 ret = pclKeyHandleClose(hd7);
738 fail_unless(ret != -1, "Failed to close handle!!");
740 ret = pclKeyHandleClose(hd8);
741 fail_unless(ret != -1, "Failed to close handle!!");
743 ret = pclKeyHandleClose(hd9);
744 fail_unless(ret != -1, "Failed to close handle!!");
753 * Test for i n t e r n a l structures.
754 * Test the cursor functions.
756 START_TEST(test_Cursor)
758 int handle = -1, rval = 0, size = 0, handle1 = 0;
759 char bufferKeySrc[READ_SIZE] = {0};
760 char bufferDataSrc[READ_SIZE] = {0};
761 char bufferKeyDst[READ_SIZE] = {0};
762 char bufferDataDst[READ_SIZE] = {0};
763 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
765 rval = pclInitLibrary(gTheAppId, shutdownReg);
766 fail_unless(rval <= 1, "Failed to init PCL");
769 handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
770 fail_unless(handle != -1, "Failed to create cursor!!");
773 handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
774 fail_unless(handle1 != -1, "Failed to create cursor!!");
778 memset(bufferKeySrc, 0, READ_SIZE);
779 memset(bufferDataSrc, 0, READ_SIZE);
780 memset(bufferKeyDst, 0, READ_SIZE);
781 memset(bufferDataDst, 0, READ_SIZE);
784 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 128);
785 fail_unless(rval != -1, "Cursor failed to get key!!");
787 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 128);
788 fail_unless(rval != -1, "Cursor failed to get data!!");
790 size = pers_db_cursor_get_data_size(handle);
791 fail_unless(size != -1, "Cursor failed to get size!!");
792 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
795 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 128);
796 fail_unless(rval != -1, "Cursor failed to get key!!");
798 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 128);
799 fail_unless(rval != -1, "Cursor failed to get data!!");
801 size = pers_db_cursor_get_data_size(handle1);
802 fail_unless(size != -1, "Cursor failed to get size!!");
803 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
805 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
808 rval = pers_db_cursor_destroy(handle);
809 fail_unless(rval != -1, "Failed to destroy cursor!!");
811 rval = pers_db_cursor_destroy(handle1);
812 fail_unless(rval != -1, "Failed to destroy cursor!!");
820 START_TEST(test_Plugin)
823 unsigned char buffer[READ_SIZE] = {0};
825 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
827 ret = pclInitLibrary(gTheAppId, shutdownReg);
828 fail_unless(ret <= 1, "Failed to init PCL");
830 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
831 fail_unless(ret != EPERS_NOT_INITIALIZED);
832 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
833 strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
836 ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE);
837 fail_unless(ret != EPERS_NOT_INITIALIZED);
838 //printf("B U F F E R - early: %s\n", buffer);
839 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
840 strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
842 ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
843 fail_unless(ret != EPERS_NOT_INITIALIZED);
844 //printf("B U F F E R - emergency: %s\n", buffer);
845 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
846 strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
848 ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE);
849 fail_unless(ret != EPERS_NOT_INITIALIZED);
850 //printf("B U F F E R - hwinfo: %s\n", buffer);
851 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
852 strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
854 ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE);
855 fail_unless(ret != EPERS_NOT_INITIALIZED);
856 //printf("B U F F E R - hwinfo: %s\n", buffer);
857 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
858 strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
868 START_TEST(test_ReadDefault)
871 unsigned char buffer[READ_SIZE] = {0};
873 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
875 ret = pclInitLibrary(gTheAppId, shutdownReg);
876 fail_unless(ret <= 1, "Failed to init PCL");
878 ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
879 fail_unless(ret != EPERS_NOT_INITIALIZED);
880 //printf("B U F F E R: %s\n", buffer);
881 fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
883 ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
884 fail_unless(ret != EPERS_NOT_INITIALIZED);
885 //printf("B U F F E R: %s\n", buffer);
886 fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
894 START_TEST(test_ReadConfDefault)
897 unsigned char buffer[READ_SIZE] = {0};
899 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
901 ret = pclInitLibrary(gTheAppId, shutdownReg);
902 fail_unless(ret <= 1, "Failed to init PCL");
904 ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
905 fail_unless(ret != EPERS_NOT_INITIALIZED);
906 fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
908 ret = pclKeyReadData(0xFF, "statusHandle/confdefault02", 3, 2, buffer, READ_SIZE);
909 fail_unless(ret != EPERS_NOT_INITIALIZED);
910 fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
918 START_TEST(test_GetPath)
922 const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB.db";
923 unsigned int pathSize = 0;
925 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
927 ret = pclInitLibrary(gTheAppId, shutdownReg);
928 fail_unless(ret <= 1, "Failed to init PCL");
930 ret = pclFileCreatePath(0xFF, "media/mediaDB.db", 1, 1, &path, &pathSize);
931 //printf("PATH: %s \n", path);
932 fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
933 fail_unless(pathSize == strlen((char*)path), "Path size not correct");
935 pclFileReleasePath(ret);
943 static Suite * persistencyClientLib_suite()
945 Suite * s = suite_create("Persistency client library");
947 TCase * tc_persGetData = tcase_create("GetData");
948 tcase_add_test(tc_persGetData, test_GetData);
950 TCase * tc_persSetData = tcase_create("SetData");
951 tcase_add_test(tc_persSetData, test_SetData);
953 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
954 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
956 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
957 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
959 TCase * tc_persDeleteData = tcase_create("DeleteData");
960 tcase_add_test(tc_persDeleteData, test_DeleteData);
962 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
963 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
965 TCase * tc_persDataHandle = tcase_create("DataHandle");
966 tcase_add_test(tc_persDataHandle, test_DataHandle);
968 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
969 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
971 TCase * tc_persDataFile = tcase_create("DataFile");
972 tcase_add_test(tc_persDataFile, test_DataFile);
974 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
975 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
977 TCase * tc_Cursor = tcase_create("Cursor");
978 tcase_add_test(tc_Cursor, test_Cursor);
980 TCase * tc_Plugin = tcase_create("Plugin");
981 tcase_add_test(tc_Plugin, test_Plugin);
983 TCase * tc_ReadDefault = tcase_create("ReadDefault");
984 tcase_add_test(tc_ReadDefault, test_ReadDefault);
986 TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
987 tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
989 TCase * tc_GetPath = tcase_create("GetPath");
990 tcase_add_test(tc_GetPath, test_GetPath);
992 suite_add_tcase(s, tc_persSetData);
995 suite_add_tcase(s, tc_persGetData);
996 suite_add_tcase(s, tc_persSetDataNoPRCT);
997 suite_add_tcase(s, tc_persGetDataSize);
998 suite_add_tcase(s, tc_persDeleteData);
999 suite_add_tcase(s, tc_persGetDataHandle);
1000 suite_add_tcase(s, tc_persDataHandle);
1001 suite_add_tcase(s, tc_persDataHandleOpen);
1002 suite_add_tcase(s, tc_persDataFile);
1003 suite_add_tcase(s, tc_persDataFileRecovery);
1004 suite_add_tcase(s, tc_Cursor);
1005 suite_add_tcase(s, tc_ReadDefault);
1006 suite_add_tcase(s, tc_ReadConfDefault);
1007 suite_add_tcase(s, tc_GetPath);
1009 //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
1014 int main(int argc, char *argv[])
1018 // assign application name
1019 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1020 gTheAppId[MaxAppNameLen-1] = '\0';
1022 /// debug log and trace (DLT) setup
1023 DLT_REGISTER_APP("test","tests the persistence client library");
1026 Suite * s = persistencyClientLib_suite();
1027 SRunner * sr = srunner_create(s);
1028 srunner_run_all(sr, CK_VERBOSE);
1029 nr_failed = srunner_ntests_failed(sr);
1036 // unregister debug log and trace
1037 DLT_UNREGISTER_APP();
1041 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;