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.h"
35 // protected header, should be used only be persistence components
36 // included here for testing purpose
37 #include "../include_protected/persistence_client_library_db_access.h"
41 #define NUM_OF_FILES 3
42 #define READ_SIZE 1024
45 char gTheAppId[MaxAppNameLen];
47 // definition of weekday
48 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
53 * Test the key value interface using different logicalDB id's, users and seats.
54 * Each resource below has an entry in the resource configuration table where the
55 * storage location (cached or write through) and type (e.g. custom) has been configured.
57 START_TEST (test_GetData)
60 unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
62 unsigned char buffer[READ_SIZE];
64 pclInitLibrary(gTheAppId, shutdownReg);
66 memset(buffer, 0, READ_SIZE);
69 * Logical DB ID: 0xFF with user 0 and seat 0
70 * ==> local value accessible by all users (user 0, seat 0)
72 ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE);
73 fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
74 strlen((char*)buffer)) == 0, "Buffer not correctly read");
75 fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
77 memset(buffer, 0, READ_SIZE);
80 * Logical DB ID: 0xFF with user 0 and seat 0
81 * ==> local value accessible by all users (user 0, seat 0)
83 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
84 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
85 strlen((char*)buffer)) == 0, "Buffer not correctly read");
86 fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
88 memset(buffer, 0, READ_SIZE);
92 * Logical DB ID: 0 with user 3 and seat 0
93 * ==> public shared user value (user 3, seat 0)
95 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
96 fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
98 memset(buffer, 0, READ_SIZE);
101 * Logical DB ID: 0xFF with user 3 and seat 2
102 * ==> local USER value (user 3, seat 2)
104 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
105 fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
107 memset(buffer, 0, READ_SIZE);
110 * Logical DB ID: 0x20 with user 4 and seat 0
111 * ==> shared user value accessible by a group (user 4 and seat 0)
113 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
114 fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
116 memset(buffer, 0, READ_SIZE);
119 * Logical DB ID: 0xFF with user 0 and seat 0
120 * ==> local value accessible by ALL USERS (user 0, seat 0)
122 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
123 fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
125 memset(buffer, 0, READ_SIZE);
128 * Logical DB ID: 0x84 with user 4 and seat 0
129 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
131 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
132 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
134 memset(buffer, 0, READ_SIZE);
137 * Logical DB ID: 0x84 with user 2 and seat 1
138 * ==> local merge value
140 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
141 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
150 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
151 * Each resource below has an entry in the resource configuration table where
152 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
154 START_TEST (test_GetDataHandle)
156 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
157 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
159 unsigned char buffer[READ_SIZE];
162 char sysTimeBuffer[128];
164 pclInitLibrary(gTheAppId, shutdownReg);
167 memset(buffer, 0, READ_SIZE);
169 locTime = localtime(&t);
171 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),
172 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
175 // open handle ---------------------------------------------------
177 * Logical DB ID: 0xFF with user 0 and seat 0
178 * ==> local value accessible by ALL USERS (user 0, seat 0)
180 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
181 fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
183 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
184 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");
186 size = pclKeyHandleGetSize(handle);
187 fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
188 // ---------------------------------------------------------------------------------------------
191 // open handle ---------------------------------------------------
193 * Logical DB ID: 0xFF with user 3 and seat 2
194 * ==> local USER value (user 3, seat 2)
196 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
197 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
199 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
200 fail_unless(size = strlen(sysTimeBuffer));
202 ret = pclKeyHandleClose(handle2);
203 // ---------------------------------------------------------------------------------------------
206 // open handle ---------------------------------------------------
208 * Logical DB ID: 0xFF with user 0 and seat 0
209 * ==> local value accessible by ALL USERS (user 0, seat 0)
211 memset(buffer, 0, READ_SIZE);
212 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
213 fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
215 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
216 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
218 size = pclKeyHandleGetSize(handle4);
219 fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
221 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
222 // ---------------------------------------------------------------------------------------------
225 // open handle ---------------------------------------------------
227 * Logical DB ID: 0xFF with user 3 and seat 2
228 * ==> local USER value (user 3, seat 2)
230 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
231 fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
233 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
234 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
236 size = pclKeyHandleGetSize(handle3);
237 fail_unless(size = strlen(sysTimeBuffer));
238 // ---------------------------------------------------------------------------------------------
242 ret = pclKeyHandleClose(handle);
243 ret = pclKeyHandleClose(handle3);
244 ret = pclKeyHandleClose(handle4);
253 * Write data to a key using the key interface.
254 * First write data to different keys and after
255 * read the data for verification.
257 START_TEST(test_SetData)
260 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
261 unsigned char buffer[READ_SIZE];
262 char write1[READ_SIZE];
263 char write2[READ_SIZE];
264 char sysTimeBuffer[256];
268 pclInitLibrary(gTheAppId, shutdownReg);
272 locTime = localtime(&t);
273 memset(buffer, 0, READ_SIZE);
274 memset(write1, 0, READ_SIZE);
275 memset(write2, 0, READ_SIZE);
278 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),
279 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
282 * Logical DB ID: 0xFF with user 1 and seat 2
283 * ==> local USER value (user 1, seat 2)
286 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
287 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
289 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
291 * Logical DB ID: 0xFF with user 1 and seat 2
292 * ==> local USER value (user 1, seat 2)
295 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
296 fail_unless(ret == strlen(write1), "Wrong write size");
298 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
300 * Logical DB ID: 0xFF with user 1 and seat 2
301 * ==> local USER value (user 1, seat 2)
302 * Resource ID: key_70
304 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
305 fail_unless(ret == strlen(write2), "Wrong write size");
308 /*******************************************************************************************************************************************/
309 /* used for changed notification testing */
310 /*******************************************************************************************************************************************/
312 * Logical DB ID: 0x84 with user 2 and seat 1
313 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
315 * ==> used for shared testing
317 //printf("Write data to trigger change notification\n");
318 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
321 * Logical DB ID: 0x84 with user 2 and seat 1
322 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
324 * ==> used for shared testing
326 //printf("Write data to trigger change notification\n");
327 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
330 * Logical DB ID: 0x84 with user 2 and seat 1
331 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
333 * ==> used for shared testing
335 //printf("Write data to trigger change notification\n");
336 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
337 /*******************************************************************************************************************************************/
338 /*******************************************************************************************************************************************/
342 * now read the data written in the previous steps to the keys
343 * and verify data has been written correctly.
345 memset(buffer, 0, READ_SIZE);
347 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
348 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
349 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
351 memset(buffer, 0, READ_SIZE);
353 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
354 fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
355 fail_unless(ret == strlen(write1), "Wrong read size");
357 memset(buffer, 0, READ_SIZE);
359 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
360 fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
361 fail_unless(ret == strlen(write2), "Wrong read size");
370 * Write data to a key using the key interface.
371 * The key is not in the persistence resource table.
372 * The key sill then be stored to the location local and cached.
374 START_TEST(test_SetDataNoPRCT)
377 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
378 unsigned char buffer[READ_SIZE];
381 pclInitLibrary(gTheAppId, shutdownReg);
384 char sysTimeBuffer[128];
385 memset(buffer, 0, READ_SIZE);
387 locTime = localtime(&t);
389 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),
390 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
393 * Logical DB ID: 0xFF with user 1 and seat 2
394 * ==> local USER value (user 1, seat 2)
396 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
397 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
398 //printf("Write Buffer : %s\n", sysTimeBuffer);
400 // read data again and and verify datat has been written correctly
401 memset(buffer, 0, READ_SIZE);
403 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
404 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
405 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
406 //printf("read buffer : %s\n", buffer);
415 * Test the key interface.
416 * Read the size of a key.
418 START_TEST(test_GetDataSize)
422 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
424 pclInitLibrary(gTheAppId, shutdownReg);
427 * Logical DB ID: 0xFF with user 3 and seat 2
428 * ==> local USER value (user 3, seat 2)
430 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
431 fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
435 * Logical DB ID: 0x84 with user 2 and seat 1
436 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
438 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
439 fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
447 * Delete a key using the key value interface.
448 * First read a from a key, the delte the key
449 * and then try to read again. The Last read must fail.
451 START_TEST(test_DeleteData)
454 unsigned char buffer[READ_SIZE];
455 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
457 pclInitLibrary(gTheAppId, shutdownReg);
459 // read data from key
460 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
461 fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
464 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
465 fail_unless(rval == 0, "Failed to delete key");
467 // after deleting the key, reading from key must fail now!
468 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
469 fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
473 // read data from key
474 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
475 fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
478 rval = pclKeyDelete(0xFF, "70", 1, 2);
479 fail_unless(rval == 0, "Failed to delete key");
481 // after deleting the key, reading from key must fail now!
482 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
483 fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
492 * Test the file interface:
499 START_TEST(test_DataFile)
501 int fd = 0, i = 0, idx = 0;
502 int size = 0, ret = 0;
503 int writeSize = 16*1024;
504 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
506 unsigned char buffer[READ_SIZE];
507 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
509 char* fileMap = NULL;
511 pclInitLibrary(gTheAppId, shutdownReg);
513 writeBuffer = malloc(writeSize);
516 // fill buffer a sequence
517 for(i = 0; i<(writeSize/8); i++)
519 writeBuffer[idx++] = 'A';
520 writeBuffer[idx++] = 'B';
521 writeBuffer[idx++] = 'C';
522 writeBuffer[idx++] = ' ';
523 writeBuffer[idx++] = 'D';
524 writeBuffer[idx++] = 'E';
525 writeBuffer[idx++] = 'F';
526 writeBuffer[idx++] = ' ';
528 memset(buffer, 0, READ_SIZE);
531 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
532 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
535 // open ------------------------------------------------------------
536 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
537 fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
539 size = pclFileGetSize(fd);
540 fail_unless(size == 68, "Wrong file size");
542 size = pclFileReadData(fd, buffer, READ_SIZE);
543 fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
544 fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
547 ret = pclFileClose(fd);
548 fail_unless(ret == 0, "Failed to close file");
550 // open ------------------------------------------------------------
551 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
552 fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
554 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
555 fail_unless(size == strlen(writeBuffer), "Failed to write data");
557 ret = pclFileClose(fd);
558 fail_unless(ret == 0, "Failed to close file");
561 // remove ----------------------------------------------------------
562 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
563 fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
565 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
566 fail_unless(fd == -1, "Failed to remove file, file still exists");
570 // map file --------------------------------------------------------
571 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
573 size = pclFileGetSize(fd);
574 pclFileMapData(fileMap, size, 0, fd);
575 fail_unless(fileMap != MAP_FAILED, "Failed to map file");
577 ret = pclFileUnmapData(fileMap, size);
578 fail_unless(ret != -1, "Failed to unmap file");
581 size = pclFileGetSize(1024);
582 fail_unless(ret == 0, "Got size, but should not");
584 ret = pclFileClose(fd);
585 fail_unless(ret == 0, "Failed to close file");
597 START_TEST(test_DataFileRecovery)
599 int fd_RW = 0, fd_RO = 0;
601 char* wBuffer = "This is a buffer to write";
602 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
604 pclInitLibrary(gTheAppId, shutdownReg);
606 // test backup creation --------------------------------------------
607 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
608 fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
610 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
611 fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
612 pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
614 ret = pclFileClose(fd_RW);
615 ret = pclFileClose(fd_RO);
622 * The the handle function of the key and file interface.
624 START_TEST(test_DataHandle)
626 int handle1 = 0, handle2 = 0;
628 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
630 pclInitLibrary(gTheAppId, shutdownReg);
633 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
634 fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
636 ret = pclFileClose(handle1);
637 fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
639 ret = pclFileClose(1024);
640 fail_unless(ret == -1, "Could close file, but should not!!");
642 ret = pclFileClose(17);
643 fail_unless(ret == -1, "Could close file, but should not!!");
648 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
649 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
651 ret = pclKeyHandleClose(handle2);
652 fail_unless(ret != -1, "Failed to close handle!!");
654 ret = pclKeyHandleClose(1024);
655 fail_unless(ret == -1, "Could close, but should not!!");
664 * Extended key handle test.
665 * Test have been created after a bug in the key handle function occured.
667 START_TEST(test_DataHandleOpen)
669 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
670 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
672 pclInitLibrary(gTheAppId, shutdownReg);
674 // open handles ----------------------------------------------------
675 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
676 fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
678 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
679 fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
681 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
682 fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
684 // close handles ---------------------------------------------------
685 ret = pclKeyHandleClose(hd1);
686 fail_unless(ret != -1, "Failed to close handle!!");
688 ret = pclKeyHandleClose(hd2);
689 fail_unless(ret != -1, "Failed to close handle!!");
691 ret = pclKeyHandleClose(hd3);
692 fail_unless(ret != -1, "Failed to close handle!!");
694 // open handles ----------------------------------------------------
695 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
696 fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
698 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
699 fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
701 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
702 fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
704 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
705 fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
707 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
708 fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
710 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
711 fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
713 // close handles ---------------------------------------------------
714 ret = pclKeyHandleClose(hd4);
715 fail_unless(ret != -1, "Failed to close handle!!");
717 ret = pclKeyHandleClose(hd5);
718 fail_unless(ret != -1, "Failed to close handle!!");
720 ret = pclKeyHandleClose(hd6);
721 fail_unless(ret != -1, "Failed to close handle!!");
723 ret = pclKeyHandleClose(hd7);
724 fail_unless(ret != -1, "Failed to close handle!!");
726 ret = pclKeyHandleClose(hd8);
727 fail_unless(ret != -1, "Failed to close handle!!");
729 ret = pclKeyHandleClose(hd9);
730 fail_unless(ret != -1, "Failed to close handle!!");
739 * Test for i n t e r n a l structures.
740 * Test the cursor functions.
742 START_TEST(test_Cursor)
744 int handle = -1, rval = 0, size = 0, handle1 = 0;
745 char bufferKeySrc[READ_SIZE];
746 char bufferDataSrc[READ_SIZE];
747 char bufferKeyDst[READ_SIZE];
748 char bufferDataDst[READ_SIZE];
749 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
751 pclInitLibrary(gTheAppId, shutdownReg);
753 memset(bufferKeySrc, 0, READ_SIZE);
754 memset(bufferDataSrc, 0, READ_SIZE);
756 memset(bufferKeyDst, 0, READ_SIZE);
757 memset(bufferDataDst, 0, READ_SIZE);
760 handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
761 fail_unless(handle != -1, "Failed to create cursor!!");
764 handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
765 fail_unless(handle1 != -1, "Failed to create cursor!!");
769 memset(bufferKeySrc, 0, READ_SIZE);
770 memset(bufferDataSrc, 0, READ_SIZE);
771 memset(bufferKeyDst, 0, READ_SIZE);
772 memset(bufferDataDst, 0, READ_SIZE);
775 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 128);
776 fail_unless(rval != -1, "Cursor failed to get key!!");
778 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 128);
779 fail_unless(rval != -1, "Cursor failed to get data!!");
781 size = pers_db_cursor_get_data_size(handle);
782 fail_unless(size != -1, "Cursor failed to get size!!");
783 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
786 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 128);
787 fail_unless(rval != -1, "Cursor failed to get key!!");
789 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 128);
790 fail_unless(rval != -1, "Cursor failed to get data!!");
792 size = pers_db_cursor_get_data_size(handle1);
793 fail_unless(size != -1, "Cursor failed to get size!!");
794 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
796 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
799 rval = pers_db_cursor_destroy(handle);
800 fail_unless(rval != -1, "Failed to destroy cursor!!");
802 rval = pers_db_cursor_destroy(handle1);
803 fail_unless(rval != -1, "Failed to destroy cursor!!");
811 START_TEST(test_Plugin)
814 char buffer[READ_SIZE];
816 unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
817 pclInitLibrary(gTheAppId, shutdownReg);
819 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
820 //printf("B U F F E R - secure: %s\n", buffer);
821 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
822 strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
825 ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE);
826 //printf("B U F F E R - early: %s\n", buffer);
827 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
828 strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
830 ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
831 //printf("B U F F E R - emergency: %s\n", buffer);
832 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
833 strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
835 ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE);
836 //printf("B U F F E R - hwinfo: %s\n", buffer);
837 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
838 strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
840 ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE);
841 //printf("B U F F E R - hwinfo: %s\n", buffer);
842 fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
843 strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
851 static Suite * persistencyClientLib_suite()
853 Suite * s = suite_create("Persistency client library");
855 TCase * tc_persGetData = tcase_create("GetData");
856 tcase_add_test(tc_persGetData, test_GetData);
858 TCase * tc_persSetData = tcase_create("SetData");
859 tcase_add_test(tc_persSetData, test_SetData);
861 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
862 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
864 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
865 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
867 TCase * tc_persDeleteData = tcase_create("DeleteData");
868 tcase_add_test(tc_persDeleteData, test_DeleteData);
870 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
871 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
873 TCase * tc_persDataHandle = tcase_create("DataHandle");
874 tcase_add_test(tc_persDataHandle, test_DataHandle);
876 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
877 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
879 TCase * tc_persDataFile = tcase_create("DataFile");
880 tcase_add_test(tc_persDataFile, test_DataFile);
882 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
883 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
885 TCase * tc_Cursor = tcase_create("Cursor");
886 tcase_add_test(tc_Cursor, test_Cursor);
888 TCase * tc_Plugin = tcase_create("Plugin");
889 tcase_add_test(tc_Plugin, test_Plugin);
891 suite_add_tcase(s, tc_persGetData);
892 suite_add_tcase(s, tc_persSetData);
893 suite_add_tcase(s, tc_persSetDataNoPRCT);
894 suite_add_tcase(s, tc_persGetDataSize);
895 suite_add_tcase(s, tc_persDeleteData);
896 suite_add_tcase(s, tc_persGetDataHandle);
897 suite_add_tcase(s, tc_persDataHandle);
898 suite_add_tcase(s, tc_persDataHandleOpen);
899 suite_add_tcase(s, tc_persDataFile);
900 suite_add_tcase(s, tc_persDataFileRecovery);
901 suite_add_tcase(s, tc_Cursor);
903 suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
909 int main(int argc, char *argv[])
913 // assign application name
914 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
915 gTheAppId[MaxAppNameLen-1] = '\0';
917 /// debug log and trace (DLT) setup
918 DLT_REGISTER_APP("test","tests the persistence client library");
921 Suite * s = persistencyClientLib_suite();
922 SRunner * sr = srunner_create(s);
923 srunner_run_all(sr, CK_VERBOSE);
924 nr_failed = srunner_ntests_failed(sr);
931 // unregister debug log and trace
932 DLT_UNREGISTER_APP();
936 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;