9de598fa01b9f2dbfb0bf60983631545e6978f20
[profile/ivi/persistence-client-library.git] / test / persistence_client_library_test.c
1 /******************************************************************************
2  * Project         Persistency
3  * (c) copyright   2012
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 ******************************************************************************/
11  /**
12  * @file           persistence_client_library_test.c
13  * @author         Ingo Huerner
14  * @brief          Test of persistence client library
15  * @see            
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <unistd.h>     /* exit */
23 #include <time.h>
24 #include <fcntl.h>
25 #include <sys/mman.h>
26 #include <sys/stat.h>
27
28 #include <dlt/dlt.h>
29 #include <dlt/dlt_common.h>
30
31 #include "persCheck.h"
32
33
34 #include "../include/persistence_client_library_file.h"
35 #include "../include/persistence_client_library_key.h"
36 #include "../include/persistence_client_library.h"
37 #include "../include/persistence_client_library_error_def.h"
38
39
40
41 #define BUF_SIZE     64
42 #define NUM_OF_FILES 3
43 #define READ_SIZE    1024
44 #define MaxAppNameLen 256
45
46 #define SOURCE_PATH "/Data/mnt-c/lt-persistence_client_library_test/"
47
48
49 static const char* gPathSegemnts[] = {"user/", "1/", "seat/", "1/", "media", NULL };
50
51 /// application id
52 char gTheAppId[MaxAppNameLen] = {0};
53
54 // definition of weekday
55 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
56 char* gWriteBackupTestData  = "This is the content of the file /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db";
57 char* gWriteRecoveryTestData = "This is the data to recover: /Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db";
58 char* gRecovChecksum = "608a3b5d";      // generated with http://www.tools4noobs.com/online_php_functions/crc32/
59
60
61
62 void data_teardown(void)
63 {
64    printf("* * * tear down * * *\n");   // nothing
65 }
66
67
68 int myChangeCallback(pclNotification_s * notifyStruct)
69 {
70    printf(" ==> * - * myChangeCallback * - *\n");
71
72    return 1;
73 }
74
75
76
77 /**
78  * Test the key value interface using different logicalDB id's, users and seats.
79  * Each resource below has an entry in the resource configuration table where the
80  * storage location (cached or write through) and type (e.g. custom) has been configured.
81  */
82 START_TEST(test_GetData)
83 {
84    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
85    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
86    X_TEST_REPORT_REFERENCE("NONE");
87    X_TEST_REPORT_DESCRIPTION("Test of get data");
88    X_TEST_REPORT_TYPE(GOOD);
89
90    int ret = 0;
91    unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
92
93    unsigned char buffer[READ_SIZE] = {0};
94
95    ret = pclInitLibrary(gTheAppId, shutdownReg);
96    x_fail_unless(ret <= 1, "Failed to init PCL");
97
98 #if 1
99    /**
100     * Logical DB ID: 0xFF with user 0 and seat 0
101     *       ==> local value accessible by all users (user 0, seat 0)
102     */
103    ret = pclKeyReadData(0xFF, "pos/last_position",         1, 1, buffer, READ_SIZE);
104    //printf("----test_GetData => pos/last_position: \"%s\" => ret: %d \nReference: %s => size: %d\n", buffer, ret, "CACHE_ +48 10' 38.95, +8 44' 39.06", strlen("CACHE_ +48 10' 38.95, +8 44' 39.06"));
105    x_fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06",
106                  strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position");
107    x_fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06"));
108    memset(buffer, 0, READ_SIZE);
109
110    /**
111     * Logical DB ID: 0xFF with user 0 and seat 0
112     *       ==> local value accessible by all users (user 0, seat 0)
113     */
114    /*
115    ret = pclKeyReadData(0xFF, "language/country_code",         0, 0, buffer, READ_SIZE);
116    x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
117                strlen((char*)buffer)) == 0, "Buffer not correctly read");
118    x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
119    memset(buffer, 0, READ_SIZE);
120    */
121
122
123    /**
124     * Logical DB ID: 0 with user 3 and seat 0
125     *       ==> public shared user value (user 3, seat 0)
126     */
127    //ret = pclKeyReadData(0,    "language/current_language", 0, 0, buffer, READ_SIZE);
128    //printf("----test_GetData => language/current_language \"%s\" => ret: %d \n", buffer, ret);
129    //x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
130    //memset(buffer, 0, READ_SIZE);
131
132    /**
133     * Logical DB ID: 0xFF with user 3 and seat 2
134     *       ==> local USER value (user 3, seat 2)
135     */
136    ret = pclKeyReadData(0xFF, "status/open_document",      3, 2, buffer, READ_SIZE);
137    //printf("----test_GetData => status/open_document \"%s\" => ret: %d \n", buffer, ret);
138    x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0,
139                         "Buffer not correctly read - status/open_document");
140    x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
141    memset(buffer, 0, READ_SIZE);
142
143    /**
144     * Logical DB ID: 0x20 with user 4 and seat 0
145     *       ==> shared user value accessible by a group (user 4 and seat 0)
146     */
147    ret = pclKeyReadData(0x20, "address/home_address",      4, 0, buffer, READ_SIZE);
148    //printf("----test_GetData => address/home_address \"%s\" => ret: %d \n", buffer, ret);
149    x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0,
150                         "Buffer not correctly read - address/home_address");
151    x_fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31"));
152    memset(buffer, 0, READ_SIZE);
153
154    /**
155     * Logical DB ID: 0xFF with user 0 and seat 0
156     *       ==> local value accessible by ALL USERS (user 0, seat 0)
157     */
158    ret = pclKeyReadData(0xFF, "pos/last_satellites",       0, 0, buffer, READ_SIZE);
159    //printf("----test_GetData => pos/last_satellites \"%s\" => ret: %d \n", buffer, ret);
160    x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0,
161                         "Buffer not correctly read - pos/last_satellites");
162    x_fail_unless(ret == strlen("WT_ 17"));
163    memset(buffer, 0, READ_SIZE);
164
165    /**
166     * Logical DB ID: 0x20 with user 4 and seat 0
167     *       ==> shared user value accessible by A GROUP (user 4 and seat 0)
168     */
169    ret = pclKeyReadData(0x20, "links/last_link",           2, 0, buffer, READ_SIZE);
170    //printf("----test_GetData => links/last_link \"%s\" => ret: %d \n", buffer, ret);
171    x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0,
172                         "Buffer not correctly read - links/last_link");
173    x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"));
174    memset(buffer, 0, READ_SIZE);
175
176 #endif
177    pclDeinitLibrary();
178 }
179 END_TEST
180
181
182
183 /**
184  * Test the key value  h a n d l e  interface using different logicalDB id's, users and seats
185  * Each resource below has an entry in the resource configuration table where
186  * the storage location (cached or write through) and type (e.g. custom) has bee configured.
187  */
188 START_TEST (test_GetDataHandle)
189 {
190    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
191    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
192    X_TEST_REPORT_REFERENCE("NONE");
193    X_TEST_REPORT_DESCRIPTION("Test of get data handle");
194    X_TEST_REPORT_TYPE(GOOD);
195
196    int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
197    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
198
199    unsigned char buffer[READ_SIZE] = {0};
200    struct tm *locTime;
201
202    char sysTimeBuffer[128];
203
204    ret = pclInitLibrary(gTheAppId, shutdownReg);
205    x_fail_unless(ret <= 1, "Failed to init PCL");
206 #if 1
207    time_t t = time(0);
208
209    locTime = localtime(&t);
210
211    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),
212                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
213
214
215    // open handle ---------------------------------------------------
216    /**
217     * Logical DB ID: 0xFF with user 0 and seat 0
218     *       ==> local value accessible by ALL USERS (user 0, seat 0)
219     */
220    handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
221    x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
222
223    ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
224    x_fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read => 1");
225
226    size = pclKeyHandleGetSize(handle);
227    x_fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
228    // ---------------------------------------------------------------------------------------------
229
230
231    // open handle ---------------------------------------------------
232    /**
233     * Logical DB ID: 0xFF with user 3 and seat 2
234     *       ==> local USER value (user 3, seat 2)
235     */
236    handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
237    x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
238
239    size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
240    x_fail_unless(size == strlen(sysTimeBuffer));
241    // close
242    ret = pclKeyHandleClose(handle2);
243    // ---------------------------------------------------------------------------------------------
244
245
246    // open handle ---------------------------------------------------
247    /**
248     * Logical DB ID: 0xFF with user 0 and seat 0
249     *       ==> local value accessible by ALL USERS (user 0, seat 0)
250     */
251 #if 0 // plugin test case
252    memset(buffer, 0, READ_SIZE);
253    handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
254    printf("H A N D L E: %d\n", handle4);
255    x_fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
256
257    ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
258    x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
259
260    size = pclKeyHandleGetSize(handle4);
261    x_fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
262
263    ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
264 #endif
265    // ---------------------------------------------------------------------------------------------
266
267
268    // open handle ---------------------------------------------------
269    /**
270     * Logical DB ID: 0xFF with user 3 and seat 2
271     *       ==> local USER value (user 3, seat 2)
272     */
273    handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
274    x_fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
275
276    ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
277    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
278
279    size = pclKeyHandleGetSize(handle3);
280    x_fail_unless(size = strlen(sysTimeBuffer));
281    // ---------------------------------------------------------------------------------------------
282
283
284    // close handle
285    ret = pclKeyHandleClose(handle);
286    ret = pclKeyHandleClose(handle3);
287    ret = pclKeyHandleClose(handle4);
288 #endif
289    pclDeinitLibrary();
290 }
291 END_TEST
292
293
294 /*
295  * Write data to a key using the key interface.
296  * First write data to different keys and after
297  * read the data for verification.
298  */
299 START_TEST(test_SetData)
300 {
301    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
302    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
303    X_TEST_REPORT_REFERENCE("NONE");
304    X_TEST_REPORT_DESCRIPTION("Test of set data");
305    X_TEST_REPORT_TYPE(GOOD);
306
307    int ret = 0;
308    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
309    unsigned char buffer[READ_SIZE]  = {0};
310    char write1[READ_SIZE] = {0};
311    char write2[READ_SIZE] = {0};
312    char sysTimeBuffer[256];
313
314    struct tm *locTime;
315
316    ret = pclInitLibrary(gTheAppId, shutdownReg);
317    x_fail_unless(ret <= 1, "Failed to init PCL");
318
319 #if 1
320    /**
321     * Logical DB ID: 0xFF with user 3 and seat 2
322     *       ==> local USER value (user 3, seat 2)
323     */
324    ret = pclKeyWriteData(0xFF, "status/open_document",      3, 2, (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
325    x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Wrong write size");
326
327
328    ret = pclKeyWriteData(0x84, "links/last_link",      2, 1, (unsigned char*)"CACHE_ /last_exit/queens", strlen("CACHE_ /last_exit/queens"));
329    x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"), "Wrong write size");
330
331    ret = pclKeyWriteData(0xFF, "posHandle/last_position", 0, 0, (unsigned char*)"WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
332    x_fail_unless(ret == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""), "Wrong write size");
333 #endif
334
335 #if 1
336    time_t t = time(0);
337
338    locTime = localtime(&t);
339
340    // write data
341    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),
342                                                                  locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
343
344    /**
345     * Logical DB ID: 0xFF with user 1 and seat 2
346     *       ==> local USER value (user 1, seat 2)
347     * Resource ID: 69
348     */
349    ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
350    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
351 #if 1
352    snprintf(write1, 128, "%s %s", "/70",  sysTimeBuffer);
353    /**
354     * Logical DB ID: 0xFF with user 1 and seat 2
355     *       ==> local USER value (user 1, seat 2)
356     * Resource ID: 70
357     */
358    ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
359    x_fail_unless(ret == strlen(write1), "Wrong write size");
360
361    snprintf(write2, 128, "%s %s", "/key_70",  sysTimeBuffer);
362    /**
363     * Logical DB ID: 0xFF with user 1 and seat 2
364     *       ==> local USER value (user 1, seat 2)
365     * Resource ID: key_70
366     */
367    ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
368    x_fail_unless(ret == strlen(write2), "Wrong write size");
369
370
371    /*******************************************************************************************************************************************/
372    /* used for changed notification testing */
373    /*******************************************************************************************************************************************/
374    /**
375     * Logical DB ID: 0x84 with user 2 and seat 1
376     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
377     *
378     *       ==> used for shared testing
379     */
380    //printf("Write data to trigger change notification\n");
381    ret = pclKeyWriteData(0x84, "links/last_link2",  2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
382    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
383
384    /**
385     * Logical DB ID: 0x84 with user 2 and seat 1
386     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
387     *
388     *       ==> used for shared testing
389     */
390    //printf("Write data to trigger change notification\n");
391    ret = pclKeyWriteData(0x84, "links/last_link3",  3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
392    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
393
394    /**
395     * Logical DB ID: 0x84 with user 2 and seat 1
396     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
397     *
398     *       ==> used for shared testing
399     */
400    //printf("Write data to trigger change notification\n");
401    ret = pclKeyWriteData(0x84, "links/last_link4",  4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
402    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
403    /*******************************************************************************************************************************************/
404    /*******************************************************************************************************************************************/
405
406
407    /*
408     * now read the data written in the previous steps to the keys
409     * and verify data has been written correctly.
410     */
411    memset(buffer, 0, READ_SIZE);
412
413    ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
414    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
415    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
416
417    memset(buffer, 0, READ_SIZE);
418
419    ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
420    x_fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
421    x_fail_unless(ret == strlen(write1), "Wrong read size");
422
423    memset(buffer, 0, READ_SIZE);
424
425    ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
426    x_fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
427    x_fail_unless(ret == strlen(write2), "Wrong read size");
428 #endif
429 #endif
430    pclDeinitLibrary();
431 }
432 END_TEST
433
434
435
436 /**
437  * Write data to a key using the key interface.
438  * The key is not in the persistence resource table.
439  * The key sill then be stored to the location local and cached.
440  */
441 START_TEST(test_SetDataNoPRCT)
442 {
443    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
444    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
445    X_TEST_REPORT_REFERENCE("NONE");
446    X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT");
447    X_TEST_REPORT_TYPE(GOOD);
448
449    int ret = 0;
450    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
451    unsigned char buffer[READ_SIZE] = {0};
452    struct tm *locTime;
453
454    ret = pclInitLibrary(gTheAppId, shutdownReg);
455    x_fail_unless(ret <= 1, "Failed to init PCL");
456 #if 1
457    time_t t = time(0);
458
459    char sysTimeBuffer[128];
460
461    locTime = localtime(&t);
462
463    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),
464                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
465
466    /**
467     * Logical DB ID: 0xFF with user 1 and seat 2
468     *       ==> local USER value (user 1, seat 2)
469     */
470    ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
471    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
472    //printf("Write Buffer : %s\n", sysTimeBuffer);
473
474    // read data again and and verify datat has been written correctly
475    memset(buffer, 0, READ_SIZE);
476
477    ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
478    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
479    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
480    //printf("read buffer  : %s\n", buffer);
481 #endif
482    pclDeinitLibrary();
483 }
484 END_TEST
485
486
487
488 /*
489  * Test the key interface.
490  * Read the size of a key.
491  */
492 START_TEST(test_GetDataSize)
493 {
494    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
495    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
496    X_TEST_REPORT_REFERENCE("NONE");
497    X_TEST_REPORT_DESCRIPTION("Test of get data size");
498    X_TEST_REPORT_TYPE(GOOD);
499
500    int size = 0, ret = 0;
501
502    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
503
504    ret = pclInitLibrary(gTheAppId, shutdownReg);
505    x_fail_unless(ret <= 1, "Failed to init PCL");
506 #if 1
507    /**
508     * Logical DB ID: 0xFF with user 3 and seat 2
509     *       ==> local USER value (user 3, seat 2)
510     */
511    size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
512    x_fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
513
514
515    /**
516     * Logical DB ID: 0x84 with user 2 and seat 1
517     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
518     */
519    size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
520    x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
521 #endif
522    pclDeinitLibrary();
523 }
524 END_TEST
525
526
527 /*
528  * Delete a key using the key value interface.
529  * First read a from a key, the delte the key
530  * and then try to read again. The Last read must fail.
531  */
532 START_TEST(test_DeleteData)
533 {
534    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
535    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
536    X_TEST_REPORT_REFERENCE("NONE");
537    X_TEST_REPORT_DESCRIPTION("Test of delete data");
538    X_TEST_REPORT_TYPE(GOOD);
539
540    int rval = 0;
541    unsigned char buffer[READ_SIZE];
542    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
543
544    rval = pclInitLibrary(gTheAppId, shutdownReg);
545    x_fail_unless(rval <= 1, "Failed to init PCL");
546 #if 1
547    // read data from key
548    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
549    x_fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
550
551    // delete key
552    rval = pclKeyDelete(0xFF, "key_70", 1, 2);
553    x_fail_unless(rval >= 0, "Failed to delete key");
554
555    // after deleting the key, reading from key must fail now!
556    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
557    x_fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
558
559
560
561    // read data from key
562    rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
563    x_fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
564
565    // delete key
566    rval = pclKeyDelete(0xFF, "70", 1, 2);
567    x_fail_unless(rval >= 0, "Failed to delete key");
568
569    // after deleting the key, reading from key must fail now!
570    rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
571    x_fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
572 #endif
573    pclDeinitLibrary();
574 }
575 END_TEST
576
577
578
579 // creat blacklist file, if this does not exist
580 void data_setupBlacklist(void)
581 {
582
583 /// backup info
584 char gBackupInfo[] = {
585 "/media/doNotBackupMe.txt_START\n\
586 /media/doNotBackupMe_01.txt\n\
587 /media/doNotBackupMe_02.txt\n\
588 /media/doNotBackupMe_03.txt\n\
589 /media/doNotBackupMe_04.txt\n\
590 /media/iDontWantDoBeBackuped_01.txt\n\
591 /media/iDontWantDoBeBackuped_02.txt\n\
592 /media/iDontWantDoBeBackuped_03.txt\n\
593 /media/iDontWantDoBeBackuped_04.txt\n\
594 /media/iDontWantDoBeBackuped_05.txt_END\n"
595 };
596
597         const char* backupBlacklist = "/Data/mnt-c/lt-persistence_client_library_test/BackupFileList.info";
598
599         if(access(backupBlacklist, F_OK) == -1)
600         {
601                 int ret = 0;
602                 int handle = open(backupBlacklist, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
603
604                 ret = write(handle, gBackupInfo, strlen(gBackupInfo));
605                 if(ret != strlen(gBackupInfo))
606                 {
607                         printf("data_setupBlacklist => Wrong size written: %d", ret);
608                 }
609                 close(handle);
610         }
611 }
612
613
614 /*
615  * Test the file interface:
616  * - open file
617  * - read / write
618  * - remove file
619  * - map file
620  * - get size
621  */
622 START_TEST(test_DataFile)
623 {
624    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
625    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
626    X_TEST_REPORT_REFERENCE("NONE");
627    X_TEST_REPORT_DESCRIPTION("Test of data file");
628    X_TEST_REPORT_TYPE(GOOD);
629
630    int fd = 0, i = 0, idx = 0;
631    int size = 0, ret = 0, avail = 100;
632    int writeSize = 16*1024;
633    int fdArray[10] = {0};
634    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
635
636    unsigned char buffer[READ_SIZE] = {0};
637    unsigned char wBuffer[READ_SIZE] = {0};
638    const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
639    char* writeBuffer;
640    char* fileMap = NULL;
641
642    ret = pclInitLibrary(gTheAppId, shutdownReg);
643    x_fail_unless(ret <= 1, "Failed to init PCL");
644 #if 1
645    writeBuffer = malloc(writeSize);
646
647    // fill buffer a sequence
648    for(i = 0; i<(writeSize/8); i++)
649    {
650       writeBuffer[idx++] = 'A';
651       writeBuffer[idx++] = 'B';
652       writeBuffer[idx++] = 'C';
653       writeBuffer[idx++] = ' ';
654       writeBuffer[idx++] = 'D';
655       writeBuffer[idx++] = 'E';
656       writeBuffer[idx++] = 'F';
657       writeBuffer[idx++] = ' ';
658    }
659    // create file
660    fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
661              O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
662    close(fd);
663
664    // open ------------------------------------------------------------
665    fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
666    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
667
668
669    size = pclFileGetSize(fd);
670    x_fail_unless(size == 68, "Wrong file size");
671
672
673    size = pclFileReadData(fd, buffer, READ_SIZE);
674    //printf("pclFileReadData:\n   ist : \"%s\"\n   soll: \"%s\" ==> ret: %d => fd: %d\n", buffer, refBuffer, size, fd);
675    x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
676    x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned");      // strlen + 1 ==> inlcude cr/lf
677
678    ret = pclFileClose(fd);
679    x_fail_unless(ret == 0, "Failed to close file");
680
681    // open ------------------------------------------------------------
682    fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
683    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
684
685    size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
686    x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
687    ret = pclFileClose(fd);
688    x_fail_unless(ret == 0, "Failed to close file");
689
690    // remove ----------------------------------------------------------
691    ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
692    x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
693
694    fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
695    x_fail_unless(fd == -1, "Failed to remove file, file still exists");
696    close(fd);
697
698    // map file --------------------------------------------------------
699
700    fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
701
702    size = pclFileGetSize(fd);
703    pclFileMapData(fileMap, size, 0, fd);
704    x_fail_unless(fileMap != MAP_FAILED, "Failed to map file");
705
706    ret = pclFileUnmapData(fileMap, size);
707    x_fail_unless(ret != -1, "Failed to unmap file");
708
709    // file seek
710    ret = pclFileSeek(fd, 0, SEEK_CUR);
711    x_fail_unless(ret == 0, "Failed to seek file - pos 0");
712
713    ret = pclFileSeek(fd, 8, SEEK_CUR);
714    x_fail_unless(ret == 8, "Failed to seek file - pos 8");
715
716    // negative test
717    size = pclFileGetSize(1024);
718    x_fail_unless(size < 0 , "Got size, but should not");
719    /*
720    ret = pclFileClose(fd);
721    x_fail_unless(ret == 0, "Failed to close file");
722 */
723
724    // test backup blacklist functionality
725    fdArray[0] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 1, 1);
726    fdArray[1] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 1, 2);
727    fdArray[2] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 20, 10);
728    fdArray[3] = pclFileOpen(0xFF, "media/doNotBackupMe.txt_START", 200, 100);
729
730    fdArray[4] = pclFileOpen(0xFF, "media/doNotBackupMe_01.txt", 2, 1);
731    fdArray[5] = pclFileOpen(0xFF, "media/doNotBackupMe_02.txt", 2, 1);
732    fdArray[6] = pclFileOpen(0xFF, "media/doNotBackupMe_03.txt", 2, 1);
733    fdArray[7] = pclFileOpen(0xFF, "media/doNotBackupMe_04.txt", 2, 1);
734
735    fdArray[8] = pclFileOpen(0xFF, "media/iDontWantDoBeBackuped_04.txt", 2, 1);
736    fdArray[9] = pclFileOpen(0xFF, "media/iDontWantDoBeBackuped_05.txt_END", 2, 1);
737
738    for(i=0; i<10; i++)
739    {
740         snprintf( (char*)wBuffer, 1024, "Test - %d", i);
741         pclFileWriteData(fdArray[i], wBuffer, strlen( (char*)wBuffer));
742    }
743
744    //
745    // test if backup blacklist works correctly
746    //
747         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/doNotBackupMe.txt_START~", F_OK);
748         x_fail_unless(avail == -1, "1. Failed backup => backup available, but should not");
749
750
751         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/2/media/doNotBackupMe.txt_START~", F_OK);
752         x_fail_unless(avail == -1, "2. Failed backup => backup available, but should not");
753
754         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/20/seat/10/media/doNotBackupMe.txt_START~", F_OK);
755         x_fail_unless(avail == -1, "3. Failed backup => backup available, but should not");
756
757         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/200/seat/100/media/doNotBackupMe.txt_START~", F_OK);
758         x_fail_unless(avail == -1, "4. Failed backup => backup available, but should not");
759
760         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_01.txt~", F_OK);
761         x_fail_unless(avail == -1, "5. Failed backup => backup available, but should not");
762
763         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_02.txt~", F_OK);
764         x_fail_unless(avail == -1, "6. Failed backup => backup available, but should not");
765
766         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_03.txt~", F_OK);
767         x_fail_unless(avail == -1, "7. Failed backup => backup available, but should not");
768
769         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/doNotBackupMe_04.txt~", F_OK);
770         x_fail_unless(avail == -1, "8. Failed backup => backup available, but should not");
771
772         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_04.txt~", F_OK);
773         x_fail_unless(avail == -1, "9. Failed backup => backup available, but should not");
774
775         avail = access("/Data/mnt-backup/lt-persistence_client_library_test/user/2/seat/1/media/iDontWantDoBeBackuped_05.txt_END~", F_OK);
776         x_fail_unless(avail == -1, "10. Failed backup => backup available, but should not");
777
778    for(i=0; i<10; i++)
779    {
780         pclFileClose(fdArray[i]);
781    }
782
783    free(writeBuffer);
784 #endif
785    pclDeinitLibrary();
786 }
787 END_TEST
788
789
790
791 void data_setupBackup(void)
792 {
793         int handle = -1;
794         const char* path = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db";
795
796    handle = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
797    if(write(handle, gWriteBackupTestData, strlen(gWriteBackupTestData)) == -1)
798    {
799       printf("setup test: failed to write test data: %s\n", path);
800    }
801 }
802
803 START_TEST(test_DataFileBackupCreation)
804 {
805    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
806    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
807    X_TEST_REPORT_REFERENCE("NONE");
808    X_TEST_REPORT_DESCRIPTION("Test of file backup creation");
809    X_TEST_REPORT_TYPE(GOOD);
810
811    int fd_RW = 0, fd_RO = 0, rval = -1, handle = -1;
812    int ret = 0;
813    char* wBuffer = " ==> Appended: Test Data - test_DataFileRecovery! ";
814    const char* path = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_ReadWrite.db~";
815    char rBuffer[1024] = {0};
816    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
817
818    ret = pclInitLibrary(gTheAppId, shutdownReg);
819    x_fail_unless(ret <= 1, "Failed to init PCL");
820 #if 1
821
822    fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
823    x_fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
824
825    fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
826    x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
827
828    rval = pclFileReadData(fd_RW, rBuffer, 10);
829    x_fail_unless(rval == 10, "Failed read 10 bytes");
830    memset(rBuffer, 0, 1024);
831
832    rval = pclFileReadData(fd_RW, rBuffer, 15);
833    x_fail_unless(rval == 15, "Failed read 15 bytes");
834    memset(rBuffer, 0, 1024);
835
836    rval = pclFileReadData(fd_RW, rBuffer, 20);
837    x_fail_unless(rval == 20, "Failed read 20 bytes");
838    memset(rBuffer, 0, 1024);
839
840    rval = pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
841    x_fail_unless(rval == strlen(wBuffer), "Failed write data");
842
843    // verify the backup creation:
844    handle = open(path,  O_RDWR);
845    x_fail_unless(handle != -1, "Could not open file ==> failed to access backup file");
846
847    rval = read(handle, rBuffer, 1024);
848    //printf(" * * * Backup: \nIst : %s \nSoll: %s\n", rBuffer, gWriteBackupTestData);
849    x_fail_unless(strncmp((char*)rBuffer, gWriteBackupTestData, strlen(gWriteBackupTestData)) == 0, "Backup not correctly read");
850
851
852    (void)close(handle);
853    (void)pclFileClose(fd_RW);
854    (void)pclFileClose(fd_RO);
855
856 #endif
857
858    pclDeinitLibrary();
859 }
860 END_TEST
861
862
863
864 void data_setupRecovery(void)
865 {
866         int i = 0;
867    char createPath[128] = {0};
868
869         int handleRecov = -1, handleToBackup = -1, handleToCs = -1;
870         char* corruptData = "Some corrupted data ..  )=§?=34=/%&$%&()Ö:ÄNJH/)(";
871         const char* pathToRecover  = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db";
872         const char* pathToBackup   = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~";
873         const char* pathToChecksum = "/Data/mnt-backup/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_DataRecovery.db~.crc";
874
875    // create directory, even if exist
876    snprintf(createPath, 128, "%s", SOURCE_PATH );
877    while(gPathSegemnts[i] != NULL)
878    {
879         strncat(createPath, gPathSegemnts[i++], 128-1);
880         mkdir(createPath, 0744);
881    }
882
883    handleRecov = open(pathToRecover, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
884    if(write(handleRecov, corruptData, strlen(corruptData)) == -1)
885    {
886       printf("setup test: failed to write test data: %s\n", pathToRecover);
887    }
888
889    handleToBackup = open(pathToBackup, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
890         if(write(handleToBackup, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == -1)
891         {
892                 printf("setup test: failed to write test data: %s\n", pathToBackup);
893         }
894
895    handleToCs = open(pathToChecksum, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
896         if(write(handleToCs, gRecovChecksum, strlen(gRecovChecksum)) == -1)
897         {
898                 printf("setup test: failed to write test data: %s\n", pathToChecksum);
899         }
900
901         close(handleRecov);
902         close(handleToBackup);
903         close(handleToCs);
904
905 }
906
907 START_TEST(test_DataFileRecovery)
908 {
909    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
910         X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
911         X_TEST_REPORT_REFERENCE("NONE");
912         X_TEST_REPORT_DESCRIPTION("Test file recovery form backup");
913         X_TEST_REPORT_TYPE(GOOD);
914
915         int handle = 0;
916         int ret = 0;
917         unsigned char buffer[READ_SIZE] = {0};
918         unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
919
920         ret = pclInitLibrary(gTheAppId, shutdownReg);
921         x_fail_unless(ret <= 1, "Failed to init PCL");
922
923
924         handle = pclFileOpen(0xFF, "media/mediaDB_DataRecovery.db", 1, 1);
925         //printf("pclFileOpen => handle: %d\n", handle);
926    x_fail_unless(handle != -1, "Could not open file ==> /media/mediaDB_DataRecovery.db");
927
928
929         ret = pclFileReadData(handle, buffer, READ_SIZE);
930         //printf(" ** pclFileReadData => ist-buffer : %s | size: %d\n", buffer, ret);
931         //printf(" ** pclFileReadData => soll-buffer: %s | size: %d\n", gWriteRecoveryTestData, strlen(gWriteRecoveryTestData));
932         x_fail_unless(strncmp((char*)buffer, gWriteRecoveryTestData, strlen(gWriteRecoveryTestData)) == 0, "Recovery failed");
933
934    (void)pclFileClose(handle);
935
936    pclDeinitLibrary();
937
938 }
939 END_TEST
940
941
942
943 /*
944  * The the handle function of the key and file interface.
945  */
946 START_TEST(test_DataHandle)
947 {
948    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
949    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
950    X_TEST_REPORT_REFERENCE("NONE");
951    X_TEST_REPORT_DESCRIPTION("Test of data handle");
952    X_TEST_REPORT_TYPE(GOOD);
953
954    int handle1 = 0, handle2 = 0;
955    int handleArray[4] = {0};
956    int ret = 0;
957    unsigned char buffer[READ_SIZE] = {0};
958    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
959
960    ret = pclInitLibrary(gTheAppId, shutdownReg);
961    x_fail_unless(ret <= 1, "Failed to init PCL");
962 #if 1
963    // test multiple handles
964    handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
965    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
966
967    handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
968    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
969
970    handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
971    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
972
973    handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
974    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
975
976    memset(buffer, 0, READ_SIZE);
977    ret = pclFileReadData(handleArray[0], buffer, READ_SIZE);
978    x_fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!");
979    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
980          strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
981          == 0, "Buffer not correctly read => mediaDB_write_01.db");
982
983    memset(buffer, 0, READ_SIZE);
984    ret = pclFileReadData(handleArray[1], buffer, READ_SIZE);
985    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
986          strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
987          == 0, "Buffer not correctly read => mediaDB_write_02.db");
988
989    memset(buffer, 0, READ_SIZE);
990    ret = pclFileReadData(handleArray[2], buffer, READ_SIZE);
991    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
992          strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
993          == 0, "Buffer not correctly read => mediaDB_write_03.db");
994
995    memset(buffer, 0, READ_SIZE);
996    (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
997    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
998          strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
999          == 0, "Buffer not correctly read => mediaDB_write_04.db");
1000
1001    ret = pclKeyHandleClose(handleArray[0]);
1002    x_fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
1003
1004    ret = pclKeyHandleClose(handleArray[1]);
1005    x_fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
1006
1007    ret = pclKeyHandleClose(handleArray[2]);
1008    x_fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
1009
1010    ret = pclKeyHandleClose(handleArray[3]);
1011    x_fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
1012
1013    // test key handles
1014    handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
1015    x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
1016
1017    ret = pclKeyHandleClose(handle2);
1018    x_fail_unless(ret != -1, "Failed to close handle!!");
1019
1020    ret = pclKeyHandleClose(1024);
1021    x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
1022
1023
1024    // test file handles
1025         handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
1026         x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
1027
1028         ret = pclFileClose(handle1);
1029         x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
1030
1031         ret = pclFileClose(1024);
1032         x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
1033
1034         ret = pclFileClose(19);
1035         x_fail_unless(ret == -1, "Could close file, but should not!!");
1036
1037 #endif
1038    pclDeinitLibrary();
1039 }
1040 END_TEST
1041
1042
1043
1044 /*
1045  * Extended key handle test.
1046  * Test have been created after a bug in the key handle function occured.
1047  */
1048 START_TEST(test_DataHandleOpen)
1049 {
1050    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1051    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1052    X_TEST_REPORT_REFERENCE("NONE");
1053    X_TEST_REPORT_DESCRIPTION("Test of data handle open");
1054    X_TEST_REPORT_TYPE(GOOD);
1055
1056    int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
1057    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1058
1059    ret = pclInitLibrary(gTheAppId, shutdownReg);
1060    x_fail_unless(ret <= 1, "Failed to init PCL");
1061 #if 1
1062    // open handles ----------------------------------------------------
1063    hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
1064    x_fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
1065
1066    hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
1067    x_fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
1068
1069    hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
1070    x_fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
1071
1072    // close handles ---------------------------------------------------
1073    ret = pclKeyHandleClose(hd1);
1074    x_fail_unless(ret != -1, "Failed to close handle!!");
1075
1076    ret = pclKeyHandleClose(hd2);
1077    x_fail_unless(ret != -1, "Failed to close handle!!");
1078
1079    ret = pclKeyHandleClose(hd3);
1080    x_fail_unless(ret != -1, "Failed to close handle!!");
1081
1082    // open handles ----------------------------------------------------
1083    hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
1084    x_fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
1085
1086    hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
1087    x_fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
1088
1089    hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
1090    x_fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
1091
1092    hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
1093    x_fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
1094
1095    hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
1096    x_fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
1097
1098    hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
1099    x_fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
1100
1101    // close handles ---------------------------------------------------
1102    ret = pclKeyHandleClose(hd4);
1103    x_fail_unless(ret != -1, "Failed to close handle!!");
1104
1105    ret = pclKeyHandleClose(hd5);
1106    x_fail_unless(ret != -1, "Failed to close handle!!");
1107
1108    ret = pclKeyHandleClose(hd6);
1109    x_fail_unless(ret != -1, "Failed to close handle!!");
1110
1111    ret = pclKeyHandleClose(hd7);
1112    x_fail_unless(ret != -1, "Failed to close handle!!");
1113
1114    ret = pclKeyHandleClose(hd8);
1115    x_fail_unless(ret != -1, "Failed to close handle!!");
1116
1117    ret = pclKeyHandleClose(hd9);
1118    x_fail_unless(ret != -1, "Failed to close handle!!");
1119 #endif
1120    pclDeinitLibrary();
1121 }
1122 END_TEST
1123
1124
1125
1126 START_TEST(test_Plugin)
1127 {
1128    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1129    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1130    X_TEST_REPORT_REFERENCE("NONE");
1131    X_TEST_REPORT_DESCRIPTION("Test of plugins");
1132    X_TEST_REPORT_TYPE(GOOD);
1133
1134         int ret = 0;
1135         unsigned char buffer[READ_SIZE]  = {0};
1136
1137         unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1138
1139    ret = pclInitLibrary(gTheAppId, shutdownReg);
1140    x_fail_unless(ret <= 1, "Failed to init PCL");
1141
1142 #if 1
1143
1144         ret = pclKeyReadData(0xFF, "secured",           0, 0, buffer, READ_SIZE);
1145         //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!"));
1146         x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") );
1147    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
1148                  strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
1149         memset(buffer, 0, READ_SIZE);
1150
1151         ret = pclKeyReadData(0xFF, "early",     0, 0, buffer, READ_SIZE);
1152         //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!"));
1153         x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!"));
1154    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
1155                strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
1156         memset(buffer, 0, READ_SIZE);
1157
1158         ret = pclKeyReadData(0xFF, "emergency", 0, 0, buffer, READ_SIZE);
1159         //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!"));
1160         x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!"));
1161    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
1162                strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
1163         memset(buffer, 0, READ_SIZE);
1164
1165         ret = pclKeyReadData(0xFF, "hwinfo",   0, 0, buffer, READ_SIZE);
1166         //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!"));
1167         x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1168    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
1169                strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
1170         memset(buffer, 0, READ_SIZE);
1171
1172    ret = pclKeyReadData(0xFF, "custom2",   0, 0, buffer, READ_SIZE);
1173    //printf("B U F F E R - custom2: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom2!"));
1174    x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom2!"));
1175    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom2!",
1176                strlen((char*)buffer)) == 0, "Buffer CUSTOM 2 not correctly read");
1177    memset(buffer, 0, READ_SIZE);
1178
1179    ret = pclKeyReadData(0xFF, "custom3",   0, 0, buffer, READ_SIZE);
1180    //printf("B U F F E R - custom3: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom3!"));
1181    x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom3!"));
1182    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
1183                  strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
1184    memset(buffer, 0, READ_SIZE);
1185
1186    ret = pclKeyWriteData(0xFF, "custom3",   0, 0, (unsigned char*)"This is a message to write", READ_SIZE);
1187    x_fail_unless(ret == 321456, "Failed to write custom data"); // plugin should return 321456
1188
1189
1190    ret = pclKeyGetSize(0xFF, "custom3",   0, 0);
1191    x_fail_unless(ret == 44332211, "Failed query custom data size");     // plugin should return 44332211
1192
1193
1194    ret = pclKeyDelete(0xFF, "custom3",   0, 0);
1195    x_fail_unless(ret == 13579, "Failed query custom data size");        // plugin should return 13579
1196
1197 #endif
1198         pclDeinitLibrary();
1199 }
1200 END_TEST
1201
1202
1203
1204
1205
1206 START_TEST(test_ReadDefault)
1207 {
1208    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1209    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1210    X_TEST_REPORT_REFERENCE("NONE");
1211    X_TEST_REPORT_DESCRIPTION("Test of read default");
1212    X_TEST_REPORT_TYPE(GOOD);
1213
1214    int ret = 0;
1215    unsigned char buffer[READ_SIZE]  = {0};
1216
1217    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1218
1219    ret = pclInitLibrary(gTheAppId, shutdownReg);
1220    x_fail_unless(ret <= 1, "Failed to init PCL");
1221 #if 1
1222    ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
1223    //printf(" --- test_ReadConfDefault => statusHandle/default01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_01!"));
1224    x_fail_unless(ret == strlen("DEFAULT_01!"));
1225    x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1226
1227    ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
1228    //printf(" --- test_ReadConfDefault => statusHandle/default02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_02!"));
1229    x_fail_unless(ret == strlen("DEFAULT_02!"));
1230    x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1231
1232    ret = pclKeyGetSize(0xFF, "statusHandle/default01", 3, 2);
1233    x_fail_unless(ret == strlen("DEFAULT_01!"), "Invalid size");
1234
1235 #endif
1236    pclDeinitLibrary();
1237 }
1238 END_TEST
1239
1240
1241
1242 START_TEST(test_ReadConfDefault)
1243 {
1244    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1245    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1246    X_TEST_REPORT_REFERENCE("NONE");
1247    X_TEST_REPORT_DESCRIPTION("Test of configurable default data");
1248    X_TEST_REPORT_TYPE(GOOD);
1249
1250    int ret = 0;
1251    unsigned char buffer[READ_SIZE]  = {0};
1252
1253    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1254
1255    ret = pclInitLibrary(gTheAppId, shutdownReg);
1256    x_fail_unless(ret <= 1, "Failed to init PCL");
1257 #if 1
1258    ret = pclKeyReadData(0xFF, "statusHandle/confdefault01",     3, 2, buffer, READ_SIZE);
1259    //printf(" --- test_ReadConfDefault => statusHandle/confdefault01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_01!"));
1260    x_fail_unless(ret == strlen("CONF_DEFAULT_01!"));
1261    x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1262
1263    ret = pclKeyReadData(0xFF, "statusHandle/confdefault02",     3, 2, buffer, READ_SIZE);
1264    //printf(" --- test_ReadConfDefault => statusHandle/confdefault02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_02!"));
1265    x_fail_unless(ret == strlen("CONF_DEFAULT_02!"));
1266    x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1267
1268    ret = pclKeyGetSize(0xFF, "statusHandle/confdefault02", 3, 2);
1269    x_fail_unless(ret == strlen("CONF_DEFAULT_02!"), "Invalid size");
1270
1271 #endif
1272    pclDeinitLibrary();
1273 }
1274 END_TEST
1275
1276
1277
1278 START_TEST(test_GetPath)
1279 {
1280    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1281    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1282    X_TEST_REPORT_REFERENCE("NONE");
1283    X_TEST_REPORT_DESCRIPTION("Test of get path");
1284    X_TEST_REPORT_TYPE(GOOD);
1285
1286    int ret = 0;
1287    char* path = NULL;
1288    const char* thePath = "/Data/mnt-c/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db";
1289    unsigned int pathSize = 0;
1290
1291    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1292
1293    ret = pclInitLibrary(gTheAppId, shutdownReg);
1294    x_fail_unless(ret <= 1, "Failed to init PCL");
1295 #if 1
1296    ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize);
1297
1298    x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
1299    x_fail_unless(pathSize == strlen((char*)path), "Path size not correct");
1300
1301    pclFileReleasePath(ret);
1302 #endif
1303    pclDeinitLibrary();
1304 }
1305 END_TEST
1306
1307
1308
1309 START_TEST(test_InitDeinit)
1310 {
1311    int i = 0, rval = -1;
1312         unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1313
1314    for(i=0; i<5; i++)
1315    {
1316                 // initialize and deinitialize 1. time
1317                 (void)pclInitLibrary(gTheAppId, shutdownReg);
1318                 pclDeinitLibrary();
1319
1320
1321                 // initialize and deinitialize 2. time
1322                 (void)pclInitLibrary(gTheAppId, shutdownReg);
1323                 pclDeinitLibrary();
1324
1325
1326                 // initialize and deinitialize 3. time
1327                 (void)pclInitLibrary(gTheAppId, shutdownReg);
1328                 pclDeinitLibrary();
1329    }
1330
1331
1332    // test multiple init/deinit
1333    pclInitLibrary(gTheAppId, shutdownReg);
1334    pclInitLibrary(gTheAppId, shutdownReg);
1335
1336    pclDeinitLibrary();
1337    pclDeinitLibrary();
1338    pclDeinitLibrary();
1339
1340    // test lifecycle set
1341    pclInitLibrary(gTheAppId, shutdownReg);
1342    rval = pclLifecycleSet(PCL_SHUTDOWN);
1343    x_fail_unless(rval == EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set allowed, but should not");
1344    pclDeinitLibrary();
1345
1346
1347    pclInitLibrary(gTheAppId, PCL_SHUTDOWN_TYPE_NONE);
1348
1349    rval = pclLifecycleSet(PCL_SHUTDOWN);
1350    x_fail_unless(rval != EPERS_SHUTDOWN_NO_PERMIT, "Lifecycle set NOT allowed, but should");
1351
1352
1353    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1354    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1355    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1356    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1357    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1358    rval = pclLifecycleSet(PCL_SHUTDOWN_CANEL);
1359    //EPERS_COMMON
1360
1361    pclDeinitLibrary();
1362
1363 }
1364 END_TEST
1365
1366
1367
1368 START_TEST(test_NegHandle)
1369 {
1370    int handle = -1, ret = 0;
1371    int negativeHandle = -17;
1372    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1373
1374    unsigned char buffer[128] = {0};
1375
1376    (void)pclInitLibrary(gTheAppId, shutdownReg);
1377
1378    handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
1379    x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
1380
1381    ret = pclKeyHandleReadData(negativeHandle, buffer, READ_SIZE);
1382    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1383
1384    ret = pclKeyHandleClose(negativeHandle);
1385    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleClose => negative handle not detected");
1386
1387    ret = pclKeyHandleGetSize(negativeHandle);
1388    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleGetSize => negative handle not detected");
1389
1390    ret = pclKeyHandleReadData(negativeHandle, buffer, 128);
1391    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleReadData => negative handle not detected");
1392
1393    ret = pclKeyHandleRegisterNotifyOnChange(negativeHandle, &myChangeCallback);
1394    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleRegisterNotifyOnChange => negative handle not detected");
1395
1396    ret = pclKeyHandleWriteData(negativeHandle, (unsigned char*)"Whatever", strlen("Whatever"));
1397    x_fail_unless(ret == EPERS_MAXHANDLE, "pclKeyHandleWriteData => negative handle not detected");
1398
1399
1400    // close handle
1401    ret = pclKeyHandleClose(handle);
1402
1403    pclDeinitLibrary();
1404 }
1405 END_TEST
1406
1407
1408
1409 START_TEST(test_utf8_string)
1410 {
1411         int ret = 0, size = 0;
1412    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1413    const char* utf8StringBuffer = "String °^° Ñ text";
1414    unsigned char buffer[128] = {0};
1415
1416    (void)pclInitLibrary(gTheAppId, shutdownReg);
1417
1418    ret = pclKeyReadData(0xFF, "utf8String", 3, 2, buffer, READ_SIZE);
1419    x_fail_unless(ret == strlen(utf8StringBuffer), "Wrong read size");
1420    x_fail_unless(strncmp((char*)buffer, utf8StringBuffer, ret-1) == 0, "Buffer not correctly read => 1");
1421
1422    size = pclKeyGetSize(0xFF, "utf8String", 3, 2);
1423    x_fail_unless(size == strlen(utf8StringBuffer), "Invalid size");
1424
1425    pclDeinitLibrary();
1426 }
1427 END_TEST
1428
1429
1430
1431 START_TEST(test_Notifications)
1432 {
1433         unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1434
1435         (void)pclInitLibrary(gTheAppId, shutdownReg);
1436
1437         pclKeyRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback);
1438         pclKeyUnRegisterNotifyOnChange(0x20, "address/home_address", 1, 1, myChangeCallback);
1439
1440         pclDeinitLibrary();
1441 }
1442 END_TEST
1443
1444
1445
1446 static Suite * persistencyClientLib_suite()
1447 {
1448    Suite * s  = suite_create("Persistency client library");
1449
1450    TCase * tc_persGetData = tcase_create("GetData");
1451    tcase_add_test(tc_persGetData, test_GetData);
1452    tcase_set_timeout(tc_persGetData, 2);
1453
1454    TCase * tc_persSetData = tcase_create("SetData");
1455    tcase_add_test(tc_persSetData, test_SetData);
1456    tcase_set_timeout(tc_persSetData, 2);
1457
1458    TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
1459    tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
1460    tcase_set_timeout(tc_persSetDataNoPRCT, 2);
1461
1462    TCase * tc_persGetDataSize = tcase_create("GetDataSize");
1463    tcase_add_test(tc_persGetDataSize, test_GetDataSize);
1464    tcase_set_timeout(tc_persGetDataSize, 2);
1465
1466    TCase * tc_persDeleteData = tcase_create("DeleteData");
1467    tcase_add_test(tc_persDeleteData, test_DeleteData);
1468    tcase_set_timeout(tc_persDeleteData, 2);
1469
1470    TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
1471    tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
1472    tcase_set_timeout(tc_persGetDataHandle, 2);
1473
1474    TCase * tc_persDataHandle = tcase_create("DataHandle");
1475    tcase_add_test(tc_persDataHandle, test_DataHandle);
1476    tcase_set_timeout(tc_persGetData, 2);
1477
1478    TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
1479    tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
1480    tcase_set_timeout(tc_persDataHandleOpen, 1);
1481
1482    TCase * tc_persDataFile = tcase_create("DataFile");
1483    tcase_add_test(tc_persDataFile, test_DataFile);
1484    tcase_set_timeout(tc_persDataFile, 2);
1485
1486    TCase * tc_persDataFileBackupCreation = tcase_create("DataFileBackupCreation");
1487    tcase_add_test(tc_persDataFileBackupCreation, test_DataFileBackupCreation);
1488    tcase_set_timeout(tc_persDataFileBackupCreation, 1);
1489
1490    TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
1491    tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
1492    tcase_set_timeout(tc_persDataFileRecovery, 2);
1493
1494    TCase * tc_Plugin = tcase_create("Plugin");
1495    tcase_add_test(tc_Plugin, test_Plugin);
1496    tcase_set_timeout(tc_Plugin, 2);
1497
1498    TCase * tc_ReadDefault = tcase_create("ReadDefault");
1499    tcase_add_test(tc_ReadDefault, test_ReadDefault);
1500    tcase_set_timeout(tc_ReadDefault, 2);
1501
1502    TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
1503    tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
1504    tcase_set_timeout(tc_ReadConfDefault, 2);
1505
1506    TCase * tc_GetPath = tcase_create("GetPath");
1507    tcase_add_test(tc_GetPath, test_GetPath);
1508    tcase_set_timeout(tc_GetPath, 2);
1509
1510    TCase * tc_InitDeinit = tcase_create("InitDeinit");
1511    tcase_add_test(tc_InitDeinit, test_InitDeinit);
1512    tcase_set_timeout(tc_InitDeinit, 3);
1513
1514    TCase * tc_NegHandle = tcase_create("NegHandle");
1515    tcase_add_test(tc_NegHandle, test_NegHandle);
1516    tcase_set_timeout(tc_NegHandle, 2);
1517
1518    TCase * tc_utf8_string = tcase_create("UTF-8");
1519    tcase_add_test(tc_utf8_string, test_utf8_string);
1520    tcase_set_timeout(tc_utf8_string, 2);
1521
1522    TCase * tc_Notifications = tcase_create("Notifications");
1523    tcase_add_test(tc_Notifications, test_Notifications);
1524    tcase_set_timeout(tc_Notifications, 2);
1525
1526    suite_add_tcase(s, tc_persSetData);
1527    suite_add_tcase(s, tc_persGetData);
1528    suite_add_tcase(s, tc_persSetDataNoPRCT);
1529    suite_add_tcase(s, tc_persGetDataSize);
1530    suite_add_tcase(s, tc_persDeleteData);
1531    suite_add_tcase(s, tc_persGetDataHandle);
1532    suite_add_tcase(s, tc_persDataHandle);
1533    suite_add_tcase(s, tc_persDataHandleOpen);
1534    suite_add_tcase(s, tc_ReadDefault);
1535    suite_add_tcase(s, tc_ReadConfDefault);
1536
1537    suite_add_tcase(s, tc_persDataFile);
1538    tcase_add_checked_fixture(tc_persDataFile, data_setupBlacklist, data_teardown);
1539
1540    suite_add_tcase(s, tc_persDataFileBackupCreation);
1541    tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown);
1542
1543    suite_add_tcase(s, tc_persDataFileRecovery);
1544    tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown);
1545
1546    suite_add_tcase(s, tc_GetPath);
1547    suite_add_tcase(s, tc_NegHandle);
1548    suite_add_tcase(s, tc_utf8_string);
1549    suite_add_tcase(s, tc_Notifications);
1550    suite_add_tcase(s, tc_Plugin);
1551
1552    suite_add_tcase(s, tc_InitDeinit);
1553
1554    return s;
1555 }
1556
1557
1558 int main(int argc, char *argv[])
1559 {
1560    int nr_failed = 0,
1561           nr_run = 0,
1562                i = 0;
1563    //int fail = 0;
1564
1565    TestResult** tResult;
1566
1567    // assign application name
1568    strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1569    gTheAppId[MaxAppNameLen-1] = '\0';
1570
1571    /// debug log and trace (DLT) setup
1572    DLT_REGISTER_APP("PCLt","tests the persistence client library");
1573
1574 #if 1
1575    Suite * s = persistencyClientLib_suite();
1576    SRunner * sr = srunner_create(s);
1577    srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
1578    srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
1579    srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE*/);
1580
1581    nr_failed = srunner_ntests_failed(sr);
1582    nr_run = srunner_ntests_run(sr);
1583
1584    tResult = srunner_results(sr);
1585    for(i = 0; i< nr_run; i++)
1586    {
1587       (void)tr_rtype(tResult[i]);  // get status of each test
1588       //fail = tr_rtype(tResult[i]);  // get status of each test
1589       //printf("[%d] Fail: %d \n", i, fail);
1590    }
1591
1592    srunner_free(sr);
1593 #endif
1594
1595    // unregister debug log and trace
1596    DLT_UNREGISTER_APP();
1597
1598    dlt_free();
1599
1600    return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;
1601
1602 }
1603