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_key.h"
33 #include "../include/persistence_client_library_file.h"
34 #include "../include/persistence_client_library_error_def.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];
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 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
64 unsigned char buffer[READ_SIZE];
66 pclInitLibrary(gTheAppId, shutdownReg);
68 memset(buffer, 0, READ_SIZE);
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, "language/country_code", 0, 0, buffer, READ_SIZE);
75 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle",
76 strlen((char*)buffer)) == 0, "Buffer not correctly read");
77 fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
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, "pos/last_position", 0, 0, buffer, READ_SIZE);
86 fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
87 strlen((char*)buffer)) == 0, "Buffer not correctly read");
88 fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
90 memset(buffer, 0, READ_SIZE);
93 * Logical DB ID: 0 with user 3 and seat 0
94 * ==> public shared user value (user 3, seat 0)
96 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
97 fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
99 memset(buffer, 0, READ_SIZE);
102 * Logical DB ID: 0xFF with user 3 and seat 2
103 * ==> local USER value (user 3, seat 2)
105 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
106 fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
108 memset(buffer, 0, READ_SIZE);
111 * Logical DB ID: 0x20 with user 4 and seat 0
112 * ==> shared user value accessible by a group (user 4 and seat 0)
114 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
115 fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
117 memset(buffer, 0, READ_SIZE);
120 * Logical DB ID: 0xFF with user 0 and seat 0
121 * ==> local value accessible by ALL USERS (user 0, seat 0)
123 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
124 fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
126 memset(buffer, 0, READ_SIZE);
129 * Logical DB ID: 0x84 with user 4 and seat 0
130 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
132 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
133 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
135 memset(buffer, 0, READ_SIZE);
138 * Logical DB ID: 0x84 with user 2 and seat 1
139 * ==> local merge value
141 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
142 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
144 pclDeinitLibrary(shutdownReg);
151 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
152 * Each resource below has an entry in the resource configuration table where
153 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
155 START_TEST (test_GetDataHandle)
157 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
158 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
160 unsigned char buffer[READ_SIZE];
163 char sysTimeBuffer[128];
165 pclInitLibrary(gTheAppId, shutdownReg);
168 memset(buffer, 0, READ_SIZE);
170 locTime = localtime(&t);
172 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),
173 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
176 // open handle ---------------------------------------------------
178 * Logical DB ID: 0xFF with user 0 and seat 0
179 * ==> local value accessible by ALL USERS (user 0, seat 0)
181 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
182 fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
184 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
185 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");
187 size = pclKeyHandleGetSize(handle);
188 fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
189 // ---------------------------------------------------------------------------------------------
192 // open handle ---------------------------------------------------
194 * Logical DB ID: 0xFF with user 3 and seat 2
195 * ==> local USER value (user 3, seat 2)
197 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
198 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
200 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
201 fail_unless(size = strlen(sysTimeBuffer));
203 ret = pclKeyHandleClose(handle2);
204 // ---------------------------------------------------------------------------------------------
207 // open handle ---------------------------------------------------
209 * Logical DB ID: 0xFF with user 0 and seat 0
210 * ==> local value accessible by ALL USERS (user 0, seat 0)
212 memset(buffer, 0, READ_SIZE);
213 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
214 fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
216 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
217 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", -1) == 0, "Buffer not correctly read");
219 size = pclKeyHandleGetSize(handle4);
220 fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
222 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
223 // ---------------------------------------------------------------------------------------------
226 // open handle ---------------------------------------------------
228 * Logical DB ID: 0xFF with user 3 and seat 2
229 * ==> local USER value (user 3, seat 2)
231 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
232 fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
234 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
235 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
237 size = pclKeyHandleGetSize(handle3);
238 fail_unless(size = strlen(sysTimeBuffer));
239 // ---------------------------------------------------------------------------------------------
243 ret = pclKeyHandleClose(handle);
244 ret = pclKeyHandleClose(handle3);
245 ret = pclKeyHandleClose(handle4);
247 pclDeinitLibrary(shutdownReg);
254 * Write data to a key using the key interface.
255 * First write data to different keys and after
256 * read the data for verification.
258 START_TEST(test_SetData)
261 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
262 unsigned char buffer[READ_SIZE];
263 char write1[READ_SIZE];
264 char write2[READ_SIZE];
265 char sysTimeBuffer[256];
269 pclInitLibrary(gTheAppId, shutdownReg);
273 locTime = localtime(&t);
274 memset(buffer, 0, READ_SIZE);
275 memset(write1, 0, READ_SIZE);
276 memset(write2, 0, READ_SIZE);
279 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),
280 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
283 * Logical DB ID: 0xFF with user 1 and seat 2
284 * ==> local USER value (user 1, seat 2)
287 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
288 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
290 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
292 * Logical DB ID: 0xFF with user 1 and seat 2
293 * ==> local USER value (user 1, seat 2)
296 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
297 fail_unless(ret == strlen(write1), "Wrong write size");
299 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
301 * Logical DB ID: 0xFF with user 1 and seat 2
302 * ==> local USER value (user 1, seat 2)
303 * Resource ID: key_70
305 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
306 fail_unless(ret == strlen(write2), "Wrong write size");
309 /*******************************************************************************************************************************************/
310 /* used for changed notification testing */
311 /*******************************************************************************************************************************************/
313 * Logical DB ID: 0x84 with user 2 and seat 1
314 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
316 * ==> used for shared testing
318 printf("Write data to trigger change notification\n");
319 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
322 * Logical DB ID: 0x84 with user 2 and seat 1
323 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
325 * ==> used for shared testing
327 printf("Write data to trigger change notification\n");
328 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
331 * Logical DB ID: 0x84 with user 2 and seat 1
332 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
334 * ==> used for shared testing
336 printf("Write data to trigger change notification\n");
337 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
338 /*******************************************************************************************************************************************/
339 /*******************************************************************************************************************************************/
343 * now read the data written in the previous steps to the keys
344 * and verify data has been written correctly.
346 memset(buffer, 0, READ_SIZE);
348 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
349 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
350 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
352 memset(buffer, 0, READ_SIZE);
354 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
355 fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
356 fail_unless(ret == strlen(write1), "Wrong read size");
358 memset(buffer, 0, READ_SIZE);
360 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
361 fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
362 fail_unless(ret == strlen(write2), "Wrong read size");
364 pclDeinitLibrary(shutdownReg);
371 * Write data to a key using the key interface.
372 * The key is not in the persistence resource table.
373 * The key sill then be stored to the location local and cached.
375 START_TEST(test_SetDataNoPRCT)
378 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
379 unsigned char buffer[READ_SIZE];
382 pclInitLibrary(gTheAppId, shutdownReg);
385 char sysTimeBuffer[128];
386 memset(buffer, 0, READ_SIZE);
388 locTime = localtime(&t);
390 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),
391 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
394 * Logical DB ID: 0xFF with user 1 and seat 2
395 * ==> local USER value (user 1, seat 2)
397 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
398 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
399 printf("Write Buffer : %s\n", sysTimeBuffer);
401 // read data again and and verify datat has been written correctly
402 memset(buffer, 0, READ_SIZE);
404 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
405 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
406 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
407 printf("read buffer : %s\n", buffer);
409 pclDeinitLibrary(shutdownReg);
416 * Test the key interface.
417 * Read the size of a key.
419 START_TEST(test_GetDataSize)
423 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
425 pclInitLibrary(gTheAppId, shutdownReg);
428 * Logical DB ID: 0xFF with user 3 and seat 2
429 * ==> local USER value (user 3, seat 2)
431 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
432 fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
436 * Logical DB ID: 0x84 with user 2 and seat 1
437 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
439 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
440 fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
442 pclDeinitLibrary(shutdownReg);
448 * Delete a key using the key value interface.
449 * First read a from a key, the delte the key
450 * and then try to read again. The Last read must fail.
452 START_TEST(test_DeleteData)
455 unsigned char buffer[READ_SIZE];
456 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
458 pclInitLibrary(gTheAppId, shutdownReg);
460 // read data from key
461 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
462 fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
465 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
466 fail_unless(rval == 0, "Failed to delete key");
468 // after deleting the key, reading from key must fail now!
469 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
470 fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
474 // read data from key
475 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
476 fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
479 rval = pclKeyDelete(0xFF, "70", 1, 2);
480 fail_unless(rval == 0, "Failed to delete key");
482 // after deleting the key, reading from key must fail now!
483 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
484 fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
486 pclDeinitLibrary(shutdownReg);
493 * Test the file interface:
500 START_TEST(test_DataFile)
502 int fd = 0, i = 0, idx = 0;
503 int size = 0, ret = 0;
504 int writeSize = 16*1024;
505 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL;
507 unsigned char buffer[READ_SIZE];
508 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
510 char* fileMap = NULL;
512 pclInitLibrary(gTheAppId, shutdownReg);
514 writeBuffer = malloc(writeSize);
517 // fill buffer a sequence
518 for(i = 0; i<(writeSize/8); i++)
520 writeBuffer[idx++] = 'A';
521 writeBuffer[idx++] = 'B';
522 writeBuffer[idx++] = 'C';
523 writeBuffer[idx++] = ' ';
524 writeBuffer[idx++] = 'D';
525 writeBuffer[idx++] = 'E';
526 writeBuffer[idx++] = 'F';
527 writeBuffer[idx++] = ' ';
529 memset(buffer, 0, READ_SIZE);
532 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
533 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
536 // open ------------------------------------------------------------
537 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
538 fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
540 size = pclFileGetSize(fd);
541 fail_unless(size == 68, "Wrong file size");
543 size = pclFileReadData(fd, buffer, READ_SIZE);
544 fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
545 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");
551 // open ------------------------------------------------------------
552 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
553 fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
555 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
556 fail_unless(size == strlen(writeBuffer), "Failed to write data");
558 ret = pclFileClose(fd);
559 fail_unless(ret == 0, "Failed to close file");
562 // remove ----------------------------------------------------------
563 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
564 fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
566 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
567 fail_unless(fd == -1, "Failed to remove file, file still exists");
571 // map file --------------------------------------------------------
572 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
574 size = pclFileGetSize(fd);
575 pclFileMapData(fileMap, size, 0, fd);
576 fail_unless(fileMap != MAP_FAILED, "Failed to map file");
578 ret = pclFileUnmapData(fileMap, size);
579 fail_unless(ret != -1, "Failed to unmap file");
582 size = pclFileGetSize(1024);
583 fail_unless(ret == 0, "Got size, but should not");
585 ret = pclFileClose(fd);
586 fail_unless(ret == 0, "Failed to close file");
590 pclDeinitLibrary(shutdownReg);
597 START_TEST(test_DataFileRecovery)
599 int fd_RW = 0, fd_RO = 0;
601 char* wBuffer = "This is a buffer to write";
602 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_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);
617 pclDeinitLibrary(shutdownReg);
622 * The the handle function of the key and file interface.
624 START_TEST(test_DataHandle)
626 int handle1 = 0, handle2 = 0;
628 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_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!!");
657 pclDeinitLibrary(shutdownReg);
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 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_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!!");
732 pclDeinitLibrary(shutdownReg);
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 int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_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");
762 fail_unless(handle != -1, "Failed to create cursor!!");
765 handle1 = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/wt.itz");
767 fail_unless(handle1 != -1, "Failed to create cursor!!");
771 memset(bufferKeySrc, 0, READ_SIZE);
772 memset(bufferDataSrc, 0, READ_SIZE);
773 memset(bufferKeyDst, 0, READ_SIZE);
774 memset(bufferDataDst, 0, READ_SIZE);
777 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 128);
778 fail_unless(rval != -1, "Cursor failed to get key!!");
780 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 128);
781 fail_unless(rval != -1, "Cursor failed to get data!!");
783 size = pers_db_cursor_get_data_size(handle);
784 fail_unless(size != -1, "Cursor failed to get size!!");
785 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
788 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 128);
789 fail_unless(rval != -1, "Cursor failed to get key!!");
791 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 128);
792 fail_unless(rval != -1, "Cursor failed to get data!!");
794 size = pers_db_cursor_get_data_size(handle1);
795 fail_unless(size != -1, "Cursor failed to get size!!");
796 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
798 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
801 rval = pers_db_cursor_destroy(handle);
802 fail_unless(rval != -1, "Failed to destroy cursor!!");
804 rval = pers_db_cursor_destroy(handle1);
805 fail_unless(rval != -1, "Failed to destroy cursor!!");
807 pclDeinitLibrary(shutdownReg);
813 static Suite * persistencyClientLib_suite()
815 Suite * s = suite_create("Persistency client library");
817 TCase * tc_persGetData = tcase_create("GetData");
818 tcase_add_test(tc_persGetData, test_GetData);
820 TCase * tc_persSetData = tcase_create("SetData");
821 tcase_add_test(tc_persSetData, test_SetData);
823 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
824 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
826 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
827 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
829 TCase * tc_persDeleteData = tcase_create("DeleteData");
830 tcase_add_test(tc_persDeleteData, test_DeleteData);
832 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
833 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
835 TCase * tc_persDataHandle = tcase_create("DataHandle");
836 tcase_add_test(tc_persDataHandle, test_DataHandle);
838 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
839 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
841 TCase * tc_persDataFile = tcase_create("DataFile");
842 tcase_add_test(tc_persDataFile, test_DataFile);
844 TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
845 tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
847 TCase * tc_Cursor = tcase_create("Cursor");
848 tcase_add_test(tc_Cursor, test_Cursor);
850 suite_add_tcase(s, tc_persGetData);
851 suite_add_tcase(s, tc_persSetData);
852 suite_add_tcase(s, tc_persSetDataNoPRCT);
853 suite_add_tcase(s, tc_persGetDataSize);
854 suite_add_tcase(s, tc_persDeleteData);
855 suite_add_tcase(s, tc_persGetDataHandle);
856 suite_add_tcase(s, tc_persDataHandle);
857 suite_add_tcase(s, tc_persDataHandleOpen);
858 suite_add_tcase(s, tc_persDataFile);
859 suite_add_tcase(s, tc_persDataFileRecovery);
860 suite_add_tcase(s, tc_Cursor);
868 int main(int argc, char *argv[])
872 // assign application name
873 strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
874 gTheAppId[MaxAppNameLen-1] = '\0';
876 printf("A p p l i c a t i o n n a m e => %s \n", gTheAppId /*program_invocation_short_name*/);
878 /// debug log and trace (DLT) setup
879 DLT_REGISTER_APP("test","tests the persistence client library");
881 Suite * s = persistencyClientLib_suite();
882 SRunner * sr = srunner_create(s);
883 srunner_run_all(sr, CK_VERBOSE);
884 nr_failed = srunner_ntests_failed(sr);
888 // unregister debug log and trace
889 DLT_UNREGISTER_APP();
891 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;