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 */
29 #include "../include/persistence_client_library_key.h"
30 #include "../include/persistence_client_library_file.h"
31 #include "../include/persistence_client_library_error_def.h"
34 // protected header, should be used only be persistence components
35 // included here for testing purpose
36 #include "../include_protected/persistence_client_library_db_access.h"
40 #define NUM_OF_FILES 3
41 #define READ_SIZE 1024
43 // definition of weekday
44 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
49 * Test the key value interface using different logicalDB id's, users and seats.
50 * Each resource below has an entry in the resource configuration table where the
51 * storage location (cached or write through) and type (e.g. custom) has been configured.
53 START_TEST (test_GetData)
56 unsigned char buffer[READ_SIZE];
57 memset(buffer, 0, READ_SIZE);
60 * Logical DB ID: 0xFF with user 0 and seat 0
61 * ==> local value accessible by all users (user 0, seat 0)
63 ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
64 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle",
65 strlen((char*)buffer)) == 0, "Buffer not correctly read");
66 fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
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, "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: 0 with user 3 and seat 0
83 * ==> public shared user value (user 3, seat 0)
85 ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
86 fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
88 memset(buffer, 0, READ_SIZE);
91 * Logical DB ID: 0xFF with user 3 and seat 2
92 * ==> local USER value (user 3, seat 2)
94 ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
95 fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
97 memset(buffer, 0, READ_SIZE);
100 * Logical DB ID: 0x20 with user 4 and seat 0
101 * ==> shared user value accessible by a group (user 4 and seat 0)
103 ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
104 fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
106 memset(buffer, 0, READ_SIZE);
109 * Logical DB ID: 0xFF with user 0 and seat 0
110 * ==> local value accessible by ALL USERS (user 0, seat 0)
112 ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
113 fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
115 memset(buffer, 0, READ_SIZE);
118 * Logical DB ID: 0x84 with user 4 and seat 0
119 * ==> shared user value accessible by A GROUP (user 4 and seat 0)
121 ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
122 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
124 memset(buffer, 0, READ_SIZE);
127 * Logical DB ID: 0x84 with user 2 and seat 1
128 * ==> local merge value
130 ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
131 fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
138 * Test the key value h a n d l e interface using different logicalDB id's, users and seats
139 * Each resource below has an entry in the resource configuration table where
140 * the storage location (cached or write through) and type (e.g. custom) has bee configured.
142 START_TEST (test_GetDataHandle)
144 int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
145 unsigned char buffer[READ_SIZE];
149 char sysTimeBuffer[128];
150 memset(buffer, 0, READ_SIZE);
152 locTime = localtime(&t);
154 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),
155 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
158 // open handle ---------------------------------------------------
160 * Logical DB ID: 0xFF with user 0 and seat 0
161 * ==> local value accessible by ALL USERS (user 0, seat 0)
163 handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
164 fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
166 ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
167 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");
169 size = pclKeyHandleGetSize(handle);
170 fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
171 // ---------------------------------------------------------------------------------------------
174 // open handle ---------------------------------------------------
176 * Logical DB ID: 0xFF with user 3 and seat 2
177 * ==> local USER value (user 3, seat 2)
179 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
180 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
182 size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
183 fail_unless(size = strlen(sysTimeBuffer));
185 ret = pclKeyHandleClose(handle2);
186 // ---------------------------------------------------------------------------------------------
189 // open handle ---------------------------------------------------
191 * Logical DB ID: 0xFF with user 0 and seat 0
192 * ==> local value accessible by ALL USERS (user 0, seat 0)
194 memset(buffer, 0, READ_SIZE);
195 handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
196 fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
198 ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
199 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", -1) == 0, "Buffer not correctly read");
201 size = pclKeyHandleGetSize(handle4);
202 fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
204 ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
205 // ---------------------------------------------------------------------------------------------
208 // open handle ---------------------------------------------------
210 * Logical DB ID: 0xFF with user 3 and seat 2
211 * ==> local USER value (user 3, seat 2)
213 handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
214 fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
216 ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
217 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
219 size = pclKeyHandleGetSize(handle3);
220 fail_unless(size = strlen(sysTimeBuffer));
221 // ---------------------------------------------------------------------------------------------
225 ret = pclKeyHandleClose(handle);
226 ret = pclKeyHandleClose(handle3);
227 ret = pclKeyHandleClose(handle4);
234 * Write data to a key using the key interface.
235 * First write data to different keys and after
236 * read the data for verification.
238 START_TEST(test_SetData)
241 unsigned char buffer[READ_SIZE];
242 char write1[READ_SIZE];
243 char write2[READ_SIZE];
244 char sysTimeBuffer[256];
249 locTime = localtime(&t);
250 memset(buffer, 0, READ_SIZE);
251 memset(write1, 0, READ_SIZE);
252 memset(write2, 0, READ_SIZE);
255 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),
256 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
259 * Logical DB ID: 0xFF with user 1 and seat 2
260 * ==> local USER value (user 1, seat 2)
263 ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
264 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
266 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer);
268 * Logical DB ID: 0xFF with user 1 and seat 2
269 * ==> local USER value (user 1, seat 2)
272 ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
273 fail_unless(ret == strlen(write1), "Wrong write size");
275 snprintf(write2, 128, "%s %s", "/key_70", sysTimeBuffer);
277 * Logical DB ID: 0xFF with user 1 and seat 2
278 * ==> local USER value (user 1, seat 2)
279 * Resource ID: key_70
281 ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
282 fail_unless(ret == strlen(write2), "Wrong write size");
285 /*******************************************************************************************************************************************/
286 /* used for changed notification testing */
287 /*******************************************************************************************************************************************/
289 * Logical DB ID: 0x84 with user 2 and seat 1
290 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
292 * ==> used for shared testing
294 printf("Write data to trigger change notification\n");
295 ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
298 * Logical DB ID: 0x84 with user 2 and seat 1
299 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
301 * ==> used for shared testing
303 printf("Write data to trigger change notification\n");
304 ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
307 * Logical DB ID: 0x84 with user 2 and seat 1
308 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
310 * ==> used for shared testing
312 printf("Write data to trigger change notification\n");
313 ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
314 /*******************************************************************************************************************************************/
315 /*******************************************************************************************************************************************/
319 * now read the data written in the previous steps to the keys
320 * and verify data has been written correctly.
322 memset(buffer, 0, READ_SIZE);
324 ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
325 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
326 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
328 memset(buffer, 0, READ_SIZE);
330 ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
331 fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
332 fail_unless(ret == strlen(write1), "Wrong read size");
334 memset(buffer, 0, READ_SIZE);
336 ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
337 fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
338 fail_unless(ret == strlen(write2), "Wrong read size");
346 * Write data to a key using the key interface.
347 * The key is not in the persistence resource table.
348 * The key sill then be stored to the location local and cached.
350 START_TEST(test_SetDataNoPRCT)
353 unsigned char buffer[READ_SIZE];
357 char sysTimeBuffer[128];
358 memset(buffer, 0, READ_SIZE);
360 locTime = localtime(&t);
362 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),
363 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
366 * Logical DB ID: 0xFF with user 1 and seat 2
367 * ==> local USER value (user 1, seat 2)
369 ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
370 fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
371 printf("Write Buffer : %s\n", sysTimeBuffer);
373 // read data again and and verify datat has been written correctly
374 memset(buffer, 0, READ_SIZE);
376 ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
377 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
378 fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
379 printf("read buffer : %s\n", buffer);
387 * Test the key interface.
388 * Read the size of a key.
390 START_TEST(test_GetDataSize)
395 * Logical DB ID: 0xFF with user 3 and seat 2
396 * ==> local USER value (user 3, seat 2)
398 size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
399 fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
403 * Logical DB ID: 0x84 with user 2 and seat 1
404 * ==> shared user value accessible by A GROUP (user 2 and seat 1)
406 size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
407 fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
413 * Delete a key using the key value interface.
414 * First read a from a key, the delte the key
415 * and then try to read again. The Last read must fail.
417 START_TEST(test_DeleteData)
420 unsigned char buffer[READ_SIZE];
422 // read data from key
423 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
424 fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
427 rval = pclKeyDelete(0xFF, "key_70", 1, 2);
428 fail_unless(rval == 0, "Failed to delete key");
430 // after deleting the key, reading from key must fail now!
431 rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
432 fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
436 // read data from key
437 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
438 fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
441 rval = pclKeyDelete(0xFF, "70", 1, 2);
442 fail_unless(rval == 0, "Failed to delete key");
444 // after deleting the key, reading from key must fail now!
445 rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
446 fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
453 * Test the file interface:
460 START_TEST(test_DataFile)
462 int fd = 0, i = 0, idx = 0, fd_RW = 0, fd_RO = 0;
463 int size = 0, ret = 0;
464 int writeSize = 16*1024;
465 unsigned char buffer[READ_SIZE];
466 const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
468 char* wBuffer = "This is a buffer to write";
469 char* fileMap = NULL;
470 writeBuffer = malloc(writeSize);
473 // fill buffer a sequence
474 for(i = 0; i<(writeSize/8); i++)
476 writeBuffer[idx++] = 'A';
477 writeBuffer[idx++] = 'B';
478 writeBuffer[idx++] = 'C';
479 writeBuffer[idx++] = ' ';
480 writeBuffer[idx++] = 'D';
481 writeBuffer[idx++] = 'E';
482 writeBuffer[idx++] = 'F';
483 writeBuffer[idx++] = ' ';
485 memset(buffer, 0, READ_SIZE);
488 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
489 O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
492 // open ------------------------------------------------------------
493 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
494 fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
496 size = pclFileGetSize(fd);
497 fail_unless(size == 68, "Wrong file size");
499 size = pclFileReadData(fd, buffer, READ_SIZE);
500 fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
501 fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf
503 ret = pclFileClose(fd);
504 fail_unless(ret == 0, "Failed to close file");
507 // open ------------------------------------------------------------
508 fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
509 fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
511 size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
512 fail_unless(size == strlen(writeBuffer), "Failed to write data");
514 ret = pclFileClose(fd);
515 fail_unless(ret == 0, "Failed to close file");
518 // remove ----------------------------------------------------------
519 ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
520 fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
522 fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
523 fail_unless(fd == -1, "Failed to remove file, file still exists");
527 // map file --------------------------------------------------------
528 fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
530 size = pclFileGetSize(fd);
531 pclFileMapData(fileMap, size, 0, fd);
532 fail_unless(fileMap != MAP_FAILED, "Failed to map file");
534 ret = pclFileUnmapData(fileMap, size);
535 fail_unless(ret != -1, "Failed to unmap file");
538 size = pclFileGetSize(1024);
539 fail_unless(ret == 0, "Got size, but should not");
541 ret = pclFileClose(fd);
542 fail_unless(ret == 0, "Failed to close file");
545 // test backup creation --------------------------------------------
546 fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
547 fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
549 fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
550 fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
551 pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
553 ret = pclFileClose(fd_RW);
554 ret = pclFileClose(fd_RO);
563 * The the handle function of the key and file interface.
565 START_TEST(test_DataHandle)
567 int handle1 = 0, handle2 = 0;
571 handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
572 fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
574 ret = pclFileClose(handle1);
575 fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
577 ret = pclFileClose(1024);
578 fail_unless(ret == -1, "Could close file, but should not!!");
580 ret = pclFileClose(17);
581 fail_unless(ret == -1, "Could close file, but should not!!");
586 handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
587 fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
589 ret = pclKeyHandleClose(handle2);
590 fail_unless(ret != -1, "Failed to close handle!!");
592 ret = pclKeyHandleClose(1024);
593 fail_unless(ret == -1, "Could close, but should not!!");
600 * Extended key handle test.
601 * Test have been created after a bug in the key handle function occured.
603 START_TEST(test_DataHandleOpen)
605 int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
607 // open handles ----------------------------------------------------
608 hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
609 fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
611 hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
612 fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
614 hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
615 fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
617 // close handles ---------------------------------------------------
618 ret = pclKeyHandleClose(hd1);
619 fail_unless(ret != -1, "Failed to close handle!!");
621 ret = pclKeyHandleClose(hd2);
622 fail_unless(ret != -1, "Failed to close handle!!");
624 ret = pclKeyHandleClose(hd3);
625 fail_unless(ret != -1, "Failed to close handle!!");
627 // open handles ----------------------------------------------------
628 hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
629 fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
631 hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
632 fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
634 hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
635 fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
637 hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
638 fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
640 hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
641 fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
643 hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
644 fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
646 // close handles ---------------------------------------------------
647 ret = pclKeyHandleClose(hd4);
648 fail_unless(ret != -1, "Failed to close handle!!");
650 ret = pclKeyHandleClose(hd5);
651 fail_unless(ret != -1, "Failed to close handle!!");
653 ret = pclKeyHandleClose(hd6);
654 fail_unless(ret != -1, "Failed to close handle!!");
656 ret = pclKeyHandleClose(hd7);
657 fail_unless(ret != -1, "Failed to close handle!!");
659 ret = pclKeyHandleClose(hd8);
660 fail_unless(ret != -1, "Failed to close handle!!");
662 ret = pclKeyHandleClose(hd9);
663 fail_unless(ret != -1, "Failed to close handle!!");
670 * Test for i n t e r n a l structures.
671 * Test the cursor functions.
673 START_TEST(test_Cursor)
675 int handle = -1, rval = 0, size = 0, handle1 = 0;
676 char bufferKeySrc[READ_SIZE];
677 char bufferDataSrc[READ_SIZE];
678 char bufferKeyDst[READ_SIZE];
679 char bufferDataDst[READ_SIZE];
681 memset(bufferKeySrc, 0, READ_SIZE);
682 memset(bufferDataSrc, 0, READ_SIZE);
684 memset(bufferKeyDst, 0, READ_SIZE);
685 memset(bufferDataDst, 0, READ_SIZE);
688 handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
690 fail_unless(handle != -1, "Failed to create cursor!!");
693 handle1 = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/wt.itz");
695 fail_unless(handle1 != -1, "Failed to create cursor!!");
699 memset(bufferKeySrc, 0, READ_SIZE);
700 memset(bufferDataSrc, 0, READ_SIZE);
701 memset(bufferKeyDst, 0, READ_SIZE);
702 memset(bufferDataDst, 0, READ_SIZE);
705 rval = pers_db_cursor_get_key(handle, bufferKeySrc, 128);
706 fail_unless(rval != -1, "Cursor failed to get key!!");
708 rval = pers_db_cursor_get_data(handle, bufferDataSrc, 128);
709 fail_unless(rval != -1, "Cursor failed to get data!!");
711 size = pers_db_cursor_get_data_size(handle);
712 fail_unless(size != -1, "Cursor failed to get size!!");
713 //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
716 rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 128);
717 fail_unless(rval != -1, "Cursor failed to get key!!");
719 rval = pers_db_cursor_get_data(handle1, bufferDataDst, 128);
720 fail_unless(rval != -1, "Cursor failed to get data!!");
722 size = pers_db_cursor_get_data_size(handle1);
723 fail_unless(size != -1, "Cursor failed to get size!!");
724 //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
726 while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
729 rval = pers_db_cursor_destroy(handle);
730 fail_unless(rval != -1, "Failed to destroy cursor!!");
732 rval = pers_db_cursor_destroy(handle1);
733 fail_unless(rval != -1, "Failed to destroy cursor!!");
739 static Suite * persistencyClientLib_suite()
741 Suite * s = suite_create("Persistency client library");
743 TCase * tc_persGetData = tcase_create("GetData");
744 tcase_add_test(tc_persGetData, test_GetData);
746 TCase * tc_persSetData = tcase_create("SetData");
747 tcase_add_test(tc_persSetData, test_SetData);
749 TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
750 tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
752 TCase * tc_persGetDataSize = tcase_create("GetDataSize");
753 tcase_add_test(tc_persGetDataSize, test_GetDataSize);
755 TCase * tc_persDeleteData = tcase_create("DeleteData");
756 tcase_add_test(tc_persDeleteData, test_DeleteData);
758 TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
759 tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
761 TCase * tc_persDataHandle = tcase_create("DataHandle");
762 tcase_add_test(tc_persDataHandle, test_DataHandle);
764 TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
765 tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
767 TCase * tc_persDataFile = tcase_create("DataFile");
768 tcase_add_test(tc_persDataFile, test_DataFile);
770 TCase * tc_Cursor = tcase_create("Cursor");
771 tcase_add_test(tc_Cursor, test_Cursor);
773 suite_add_tcase(s, tc_persGetData);
774 suite_add_tcase(s, tc_persSetData);
775 suite_add_tcase(s, tc_persSetDataNoPRCT);
776 suite_add_tcase(s, tc_persGetDataSize);
777 suite_add_tcase(s, tc_persDeleteData);
778 suite_add_tcase(s, tc_persGetDataHandle);
779 suite_add_tcase(s, tc_persDataHandle);
780 suite_add_tcase(s, tc_persDataHandleOpen);
781 suite_add_tcase(s, tc_persDataFile);
782 suite_add_tcase(s, tc_Cursor);
790 int main(int argc, char *argv[])
794 Suite * s = persistencyClientLib_suite();
795 SRunner * sr = srunner_create(s);
796 srunner_run_all(sr, CK_VERBOSE);
797 nr_failed = srunner_ntests_failed(sr);
800 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;