0ee9f240dca80c56cf70bd67487dab51bbccf041
[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  * @ingroup        Persistence client library test
14  * @author         Ingo Huerner
15  * @brief          Test of persistence client library
16  * @see            
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <unistd.h>     /* exit */
24 #include <time.h>
25 #include <fcntl.h>
26 #include <sys/mman.h>
27
28 #include <dlt/dlt.h>
29 #include <dlt/dlt_common.h>
30
31
32 #include "persCheck.h"
33
34
35 #include "../include/persistence_client_library_file.h"
36 #include "../include/persistence_client_library_key.h"
37 #include "../include/persistence_client_library.h"
38
39
40 // protected header, should be used only be persistence components
41 // included here for testing purpose
42 #include "../include_protected/persistence_client_library_db_access.h"
43
44
45 #define BUF_SIZE     64
46 #define NUM_OF_FILES 3
47 #define READ_SIZE    1024
48
49 /// application id
50 char gTheAppId[MaxAppNameLen] = {0};
51
52 // definition of weekday
53 char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
54
55
56
57 /**
58  * Test the key value interface using different logicalDB id's, users and seats.
59  * Each resource below has an entry in the resource configuration table where the
60  * storage location (cached or write through) and type (e.g. custom) has been configured.
61  */
62 START_TEST (test_GetData)
63 {
64    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
65    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
66    X_TEST_REPORT_REFERENCE("NONE");
67    X_TEST_REPORT_DESCRIPTION("Test of get data");
68    X_TEST_REPORT_TYPE(GOOD);
69
70    int ret = 0;
71    unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL);
72
73    unsigned char buffer[READ_SIZE] = {0};
74
75    ret = pclInitLibrary(gTheAppId, shutdownReg);
76    x_fail_unless(ret <= 1, "Failed to init PCL");
77
78 #if 1
79    /**
80     * Logical DB ID: 0xFF with user 0 and seat 0
81     *       ==> local value accessible by all users (user 0, seat 0)
82     */
83    ret = pclKeyReadData(0xFF, "pos/last_position",         0, 0, buffer, READ_SIZE);
84    x_fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
85                strlen((char*)buffer)) == 0, "Buffer not correctly read");
86    x_fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
87
88    memset(buffer, 0, READ_SIZE);
89
90    /**
91     * Logical DB ID: 0xFF with user 0 and seat 0
92     *       ==> local value accessible by all users (user 0, seat 0)
93     */
94    ret = pclKeyReadData(0xFF, "language/country_code",         0, 0, buffer, READ_SIZE);
95    x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!",
96                strlen((char*)buffer)) == 0, "Buffer not correctly read");
97    x_fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
98
99    memset(buffer, 0, READ_SIZE);
100
101
102    /**
103     * Logical DB ID: 0 with user 3 and seat 0
104     *       ==> public shared user value (user 3, seat 0)
105     */
106    ret = pclKeyReadData(0,    "language/current_language", 3, 0, buffer, READ_SIZE);
107    x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
108
109    memset(buffer, 0, READ_SIZE);
110
111    /**
112     * Logical DB ID: 0xFF with user 3 and seat 2
113     *       ==> local USER value (user 3, seat 2)
114     */
115    ret = pclKeyReadData(0xFF, "status/open_document",      3, 2, buffer, READ_SIZE);
116    x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
117
118    memset(buffer, 0, READ_SIZE);
119
120    /**
121     * Logical DB ID: 0x20 with user 4 and seat 0
122     *       ==> shared user value accessible by a group (user 4 and seat 0)
123     */
124    ret = pclKeyReadData(0x20, "address/home_address",      4, 0, buffer, READ_SIZE);
125    x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
126
127    memset(buffer, 0, READ_SIZE);
128
129    /**
130     * Logical DB ID: 0xFF with user 0 and seat 0
131     *       ==> local value accessible by ALL USERS (user 0, seat 0)
132     */
133    ret = pclKeyReadData(0xFF, "pos/last_satellites",       0, 0, buffer, READ_SIZE);
134    x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
135
136    memset(buffer, 0, READ_SIZE);
137
138    /**
139     * Logical DB ID: 0x84 with user 4 and seat 0
140     *       ==> shared user value accessible by A GROUP (user 4 and seat 0)
141     */
142    ret = pclKeyReadData(0x84, "links/last_link",           2, 0, buffer, READ_SIZE);
143    x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
144
145    memset(buffer, 0, READ_SIZE);
146
147    /**
148     * Logical DB ID: 0x84 with user 2 and seat 1
149     *       ==> local merge value
150     */
151    ret = pclKeyReadData(0x84, "links/last_link",           2, 1, buffer, READ_SIZE);
152    x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
153 #endif
154    pclDeinitLibrary();
155 }
156 END_TEST
157
158
159
160 /**
161  * Test the key value  h a n d l e  interface using different logicalDB id's, users and seats
162  * Each resource below has an entry in the resource configuration table where
163  * the storage location (cached or write through) and type (e.g. custom) has bee configured.
164  */
165 START_TEST (test_GetDataHandle)
166 {
167    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
168    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
169    X_TEST_REPORT_REFERENCE("NONE");
170    X_TEST_REPORT_DESCRIPTION("Test of get data handle");
171    X_TEST_REPORT_TYPE(GOOD);
172
173    int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0;
174    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
175
176    unsigned char buffer[READ_SIZE] = {0};
177    struct tm *locTime;
178
179    char sysTimeBuffer[128];
180
181    ret = pclInitLibrary(gTheAppId, shutdownReg);
182    x_fail_unless(ret <= 1, "Failed to init PCL");
183 #if 1
184    time_t t = time(0);
185
186    locTime = localtime(&t);
187
188    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),
189                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
190
191
192    // open handle ---------------------------------------------------
193    /**
194     * Logical DB ID: 0xFF with user 0 and seat 0
195     *       ==> local value accessible by ALL USERS (user 0, seat 0)
196     */
197    handle = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
198    x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
199
200    ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
201    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");
202
203    size = pclKeyHandleGetSize(handle);
204    x_fail_unless(size == strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
205    // ---------------------------------------------------------------------------------------------
206
207
208    // open handle ---------------------------------------------------
209    /**
210     * Logical DB ID: 0xFF with user 3 and seat 2
211     *       ==> local USER value (user 3, seat 2)
212     */
213    handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
214    x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
215
216    size = pclKeyHandleWriteData(handle2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
217    x_fail_unless(size == strlen(sysTimeBuffer));
218    // close
219    ret = pclKeyHandleClose(handle2);
220    // ---------------------------------------------------------------------------------------------
221
222
223    // open handle ---------------------------------------------------
224    /**
225     * Logical DB ID: 0xFF with user 0 and seat 0
226     *       ==> local value accessible by ALL USERS (user 0, seat 0)
227     */
228 #if 0 // plugin test case
229    memset(buffer, 0, READ_SIZE);
230    handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
231    printf("H A N D L E: %d\n", handle4);
232    x_fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
233
234    ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
235    x_fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2");
236
237    size = pclKeyHandleGetSize(handle4);
238    x_fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
239
240    ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
241 #endif
242    // ---------------------------------------------------------------------------------------------
243
244
245    // open handle ---------------------------------------------------
246    /**
247     * Logical DB ID: 0xFF with user 3 and seat 2
248     *       ==> local USER value (user 3, seat 2)
249     */
250    handle3 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
251    x_fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document");
252
253    ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE);
254    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3");
255
256    size = pclKeyHandleGetSize(handle3);
257    x_fail_unless(size = strlen(sysTimeBuffer));
258    // ---------------------------------------------------------------------------------------------
259
260
261    // close handle
262    ret = pclKeyHandleClose(handle);
263    ret = pclKeyHandleClose(handle3);
264    ret = pclKeyHandleClose(handle4);
265 #endif
266    pclDeinitLibrary();
267 }
268 END_TEST
269
270
271 /*
272  * Write data to a key using the key interface.
273  * First write data to different keys and after
274  * read the data for verification.
275  */
276 START_TEST(test_SetData)
277 {
278    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
279    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
280    X_TEST_REPORT_REFERENCE("NONE");
281    X_TEST_REPORT_DESCRIPTION("Test of set data");
282    X_TEST_REPORT_TYPE(GOOD);
283
284    int ret = 0;
285    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
286    unsigned char buffer[READ_SIZE]  = {0};
287    char write1[READ_SIZE] = {0};
288    char write2[READ_SIZE] = {0};
289    char sysTimeBuffer[256];
290
291    struct tm *locTime;
292
293    ret = pclInitLibrary(gTheAppId, shutdownReg);
294    x_fail_unless(ret <= 1, "Failed to init PCL");
295 #if 1
296    time_t t = time(0);
297
298    locTime = localtime(&t);
299
300    // write data
301    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),
302                                                                  locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
303
304    /**
305     * Logical DB ID: 0xFF with user 1 and seat 2
306     *       ==> local USER value (user 1, seat 2)
307     * Resource ID: 69
308     */
309
310    ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
311    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
312 #if 1
313    snprintf(write1, 128, "%s %s", "/70",  sysTimeBuffer);
314    /**
315     * Logical DB ID: 0xFF with user 1 and seat 2
316     *       ==> local USER value (user 1, seat 2)
317     * Resource ID: 70
318     */
319    ret = pclKeyWriteData(0xFF, "70", 1, 2, (unsigned char*)write1, strlen(write1));
320    x_fail_unless(ret == strlen(write1), "Wrong write size");
321
322    snprintf(write2, 128, "%s %s", "/key_70",  sysTimeBuffer);
323    /**
324     * Logical DB ID: 0xFF with user 1 and seat 2
325     *       ==> local USER value (user 1, seat 2)
326     * Resource ID: key_70
327     */
328    ret = pclKeyWriteData(0xFF, "key_70", 1, 2, (unsigned char*)write2, strlen(write2));
329    x_fail_unless(ret == strlen(write2), "Wrong write size");
330
331
332    /*******************************************************************************************************************************************/
333    /* used for changed notification testing */
334    /*******************************************************************************************************************************************/
335    /**
336     * Logical DB ID: 0x84 with user 2 and seat 1
337     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
338     *
339     *       ==> used for shared testing
340     */
341    //printf("Write data to trigger change notification\n");
342    ret = pclKeyWriteData(0x84, "links/last_link2",  2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
343    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
344
345    /**
346     * Logical DB ID: 0x84 with user 2 and seat 1
347     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
348     *
349     *       ==> used for shared testing
350     */
351    //printf("Write data to trigger change notification\n");
352    ret = pclKeyWriteData(0x84, "links/last_link3",  3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
353    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
354
355    /**
356     * Logical DB ID: 0x84 with user 2 and seat 1
357     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
358     *
359     *       ==> used for shared testing
360     */
361    //printf("Write data to trigger change notification\n");
362    ret = pclKeyWriteData(0x84, "links/last_link4",  4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data"));
363    x_fail_unless(ret == strlen("Test notify shared data"), "Wrong write size");
364    /*******************************************************************************************************************************************/
365    /*******************************************************************************************************************************************/
366
367
368    /*
369     * now read the data written in the previous steps to the keys
370     * and verify data has been written correctly.
371     */
372    memset(buffer, 0, READ_SIZE);
373
374    ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE);
375    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
376    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
377
378    memset(buffer, 0, READ_SIZE);
379
380    ret = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
381    x_fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
382    x_fail_unless(ret == strlen(write1), "Wrong read size");
383
384    memset(buffer, 0, READ_SIZE);
385
386    ret = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
387    x_fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
388    x_fail_unless(ret == strlen(write2), "Wrong read size");
389 #endif
390 #endif
391    pclDeinitLibrary();
392 }
393 END_TEST
394
395
396
397 /**
398  * Write data to a key using the key interface.
399  * The key is not in the persistence resource table.
400  * The key sill then be stored to the location local and cached.
401  */
402 START_TEST(test_SetDataNoPRCT)
403 {
404    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
405    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
406    X_TEST_REPORT_REFERENCE("NONE");
407    X_TEST_REPORT_DESCRIPTION("Test of set data no PRCT");
408    X_TEST_REPORT_TYPE(GOOD);
409
410    int ret = 0;
411    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
412    unsigned char buffer[READ_SIZE] = {0};
413    struct tm *locTime;
414
415    ret = pclInitLibrary(gTheAppId, shutdownReg);
416    x_fail_unless(ret <= 1, "Failed to init PCL");
417 #if 1
418    time_t t = time(0);
419
420    char sysTimeBuffer[128];
421
422    locTime = localtime(&t);
423
424    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),
425                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
426
427    /**
428     * Logical DB ID: 0xFF with user 1 and seat 2
429     *       ==> local USER value (user 1, seat 2)
430     */
431    ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
432    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size");
433    //printf("Write Buffer : %s\n", sysTimeBuffer);
434
435    // read data again and and verify datat has been written correctly
436    memset(buffer, 0, READ_SIZE);
437
438    ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE);
439    x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
440    x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size");
441    //printf("read buffer  : %s\n", buffer);
442 #endif
443    pclDeinitLibrary();
444 }
445 END_TEST
446
447
448
449 /*
450  * Test the key interface.
451  * Read the size of a key.
452  */
453 START_TEST(test_GetDataSize)
454 {
455    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
456    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
457    X_TEST_REPORT_REFERENCE("NONE");
458    X_TEST_REPORT_DESCRIPTION("Test of get data size");
459    X_TEST_REPORT_TYPE(GOOD);
460
461    int size = 0, ret = 0;
462
463    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
464
465    ret = pclInitLibrary(gTheAppId, shutdownReg);
466    x_fail_unless(ret <= 1, "Failed to init PCL");
467 #if 1
468    /**
469     * Logical DB ID: 0xFF with user 3 and seat 2
470     *       ==> local USER value (user 3, seat 2)
471     */
472    size = pclKeyGetSize(0xFF, "status/open_document", 3, 2);
473    x_fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
474
475
476    /**
477     * Logical DB ID: 0x84 with user 2 and seat 1
478     *       ==> shared user value accessible by A GROUP (user 2 and seat 1)
479     */
480    size = pclKeyGetSize(0x84, "links/last_link", 2, 1);
481    x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
482 #endif
483    pclDeinitLibrary();
484 }
485 END_TEST
486
487
488 /*
489  * Delete a key using the key value interface.
490  * First read a from a key, the delte the key
491  * and then try to read again. The Last read must fail.
492  */
493 START_TEST(test_DeleteData)
494 {
495    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
496    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
497    X_TEST_REPORT_REFERENCE("NONE");
498    X_TEST_REPORT_DESCRIPTION("Test of delete data");
499    X_TEST_REPORT_TYPE(GOOD);
500
501    int rval = 0;
502    unsigned char buffer[READ_SIZE];
503    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
504
505    rval = pclInitLibrary(gTheAppId, shutdownReg);
506    x_fail_unless(rval <= 1, "Failed to init PCL");
507 #if 1
508    // read data from key
509    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
510    x_fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
511
512    // delete key
513    rval = pclKeyDelete(0xFF, "key_70", 1, 2);
514    x_fail_unless(rval == 0, "Failed to delete key");
515
516    // after deleting the key, reading from key must fail now!
517    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
518    x_fail_unless(rval == EPERS_NOKEY, "Read form key key_70 works, but should fail");
519
520
521
522    // read data from key
523    rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
524    x_fail_unless(rval != EPERS_NOKEY, "Read form key 70 fails");
525
526    // delete key
527    rval = pclKeyDelete(0xFF, "70", 1, 2);
528    x_fail_unless(rval == 0, "Failed to delete key");
529
530    // after deleting the key, reading from key must fail now!
531    rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE);
532    x_fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail");
533 #endif
534    pclDeinitLibrary();
535 }
536 END_TEST
537
538
539
540 /*
541  * Test the file interface:
542  * - open file
543  * - read / write
544  * - remove file
545  * - map file
546  * - get size
547  */
548 START_TEST(test_DataFile)
549 {
550    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
551    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
552    X_TEST_REPORT_REFERENCE("NONE");
553    X_TEST_REPORT_DESCRIPTION("Test of data file");
554    X_TEST_REPORT_TYPE(GOOD);
555
556    int fd = 0, i = 0, idx = 0;
557    int size = 0, ret = 0;
558    int writeSize = 16*1024;
559    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
560
561    unsigned char buffer[READ_SIZE] = {0};
562    const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
563    char* writeBuffer;
564    char* fileMap = NULL;
565
566    ret = pclInitLibrary(gTheAppId, shutdownReg);
567    x_fail_unless(ret <= 1, "Failed to init PCL");
568 #if 1
569    writeBuffer = malloc(writeSize);
570
571
572    // fill buffer a sequence
573    for(i = 0; i<(writeSize/8); i++)
574    {
575       writeBuffer[idx++] = 'A';
576       writeBuffer[idx++] = 'B';
577       writeBuffer[idx++] = 'C';
578       writeBuffer[idx++] = ' ';
579       writeBuffer[idx++] = 'D';
580       writeBuffer[idx++] = 'E';
581       writeBuffer[idx++] = 'F';
582       writeBuffer[idx++] = ' ';
583    }
584    // create file
585    fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",
586              O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
587    close(fd);
588
589    // open ------------------------------------------------------------
590    fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
591    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db");
592
593    size = pclFileGetSize(fd);
594    x_fail_unless(size == 68, "Wrong file size");
595
596    size = pclFileReadData(fd, buffer, READ_SIZE);
597    x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db");
598    x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned");      // strlen + 1 ==> inlcude cr/lf
599
600
601    ret = pclFileClose(fd);
602    x_fail_unless(ret == 0, "Failed to close file");
603
604    // open ------------------------------------------------------------
605    fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1);
606    x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db");
607
608    size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer));
609    x_fail_unless(size == strlen(writeBuffer), "Failed to write data");
610
611    ret = pclFileClose(fd);
612    x_fail_unless(ret == 0, "Failed to close file");
613
614
615    // remove ----------------------------------------------------------
616    ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1);
617    x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db");
618
619    fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR);
620    x_fail_unless(fd == -1, "Failed to remove file, file still exists");
621    close(fd);
622
623
624    // map file --------------------------------------------------------
625    fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
626
627    size = pclFileGetSize(fd);
628    pclFileMapData(fileMap, size, 0, fd);
629    x_fail_unless(fileMap != MAP_FAILED, "Failed to map file");
630
631    ret = pclFileUnmapData(fileMap, size);
632    x_fail_unless(ret != -1, "Failed to unmap file");
633
634    // negative test
635    size = pclFileGetSize(1024);
636    x_fail_unless(ret == 0, "Got size, but should not");
637
638    ret = pclFileClose(fd);
639    x_fail_unless(ret == 0, "Failed to close file");
640
641    free(writeBuffer);
642 #endif
643    pclDeinitLibrary();
644 }
645 END_TEST
646
647
648
649
650
651 START_TEST(test_DataFileRecovery)
652 {
653    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
654    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
655    X_TEST_REPORT_REFERENCE("NONE");
656    X_TEST_REPORT_DESCRIPTION("Test of data file recovery");
657    X_TEST_REPORT_TYPE(GOOD);
658
659    int fd_RW = 0, fd_RO = 0;
660    int ret = 0;
661    char* wBuffer = "This is a buffer to write";
662    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
663
664    ret = pclInitLibrary(gTheAppId, shutdownReg);
665    x_fail_unless(ret <= 1, "Failed to init PCL");
666 #if 1
667
668    // test backup creation --------------------------------------------
669    fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
670    x_fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
671
672    fd_RW = pclFileOpen(0xFF, "media/mediaDB_ReadWrite.db", 1, 1);
673    x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
674    pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
675
676    ret = pclFileClose(fd_RW);
677    if(ret == -1)
678
679    ret = pclFileClose(fd_RO);
680    if(ret == -1)
681
682 #endif
683    pclDeinitLibrary();
684 }
685 END_TEST
686
687 /*
688  * The the handle function of the key and file interface.
689  */
690 START_TEST(test_DataHandle)
691 {
692    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
693    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
694    X_TEST_REPORT_REFERENCE("NONE");
695    X_TEST_REPORT_DESCRIPTION("Test of data handle");
696    X_TEST_REPORT_TYPE(GOOD);
697
698    int handle1 = 0, handle2 = 0, size = 0;
699    int handleArray[4] = {0};
700    int ret = 0;
701    unsigned char buffer[READ_SIZE] = {0};
702    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
703
704    ret = pclInitLibrary(gTheAppId, shutdownReg);
705    x_fail_unless(ret <= 1, "Failed to init PCL");
706 #if 1
707    // test file handles
708    handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
709    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
710
711    ret = pclFileClose(handle1);
712    x_fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
713
714    ret = pclFileClose(1024);
715    x_fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
716
717    ret = pclFileClose(17);
718    x_fail_unless(ret == -1, "Could close file, but should not!!");
719
720    // test multiple handles
721    handleArray[0] = pclFileOpen(0xFF, "media/mediaDB_write_01.db", 1, 1);
722    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
723
724    handleArray[1] = pclFileOpen(0xFF, "media/mediaDB_write_02.db", 1, 1);
725    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
726
727    handleArray[2] = pclFileOpen(0xFF, "media/mediaDB_write_03.db", 1, 1);
728    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
729
730    handleArray[3] = pclFileOpen(0xFF, "media/mediaDB_write_04.db", 1, 1);
731    x_fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
732
733    size = pclFileReadData(handleArray[0], buffer, READ_SIZE);
734    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
735          strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
736          == 0, "Buffer not correctly read => mediaDB_write_01.db");
737
738    size = pclFileReadData(handleArray[1], buffer, READ_SIZE);
739    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
740          strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
741          == 0, "Buffer not correctly read => mediaDB_write_02.db");
742
743    size = pclFileReadData(handleArray[2], buffer, READ_SIZE);
744    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
745          strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
746          == 0, "Buffer not correctly read => mediaDB_write_03.db");
747
748    size = pclFileReadData(handleArray[3], buffer, READ_SIZE);
749    x_fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
750          strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
751          == 0, "Buffer not correctly read => mediaDB_write_04.db");
752
753    ret = pclKeyHandleClose(handleArray[0]);
754    x_fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
755
756    ret = pclKeyHandleClose(handleArray[1]);
757    x_fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
758
759    ret = pclKeyHandleClose(handleArray[2]);
760    x_fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
761
762    ret = pclKeyHandleClose(handleArray[3]);
763    x_fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
764
765    // test key handles
766    handle2 = pclKeyHandleOpen(0xFF, "statusHandle/open_document", 3, 2);
767    x_fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
768
769    ret = pclKeyHandleClose(handle2);
770    x_fail_unless(ret != -1, "Failed to close handle!!");
771
772    ret = pclKeyHandleClose(1024);
773    x_fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
774 #endif
775    pclDeinitLibrary();
776 }
777 END_TEST
778
779
780
781 /*
782  * Extended key handle test.
783  * Test have been created after a bug in the key handle function occured.
784  */
785 START_TEST(test_DataHandleOpen)
786 {
787    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
788    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
789    X_TEST_REPORT_REFERENCE("NONE");
790    X_TEST_REPORT_DESCRIPTION("Test of data handle open");
791    X_TEST_REPORT_TYPE(GOOD);
792
793    int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
794    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
795
796    ret = pclInitLibrary(gTheAppId, shutdownReg);
797    x_fail_unless(ret <= 1, "Failed to init PCL");
798 #if 1
799    // open handles ----------------------------------------------------
800    hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
801    x_fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
802
803    hd2 = pclKeyHandleOpen(0xFF, "posHandle/last_position2", 0, 0);
804    x_fail_unless(hd2 == 2, "Failed to open handle ==> /posHandle/last_position2");
805
806    hd3 = pclKeyHandleOpen(0xFF, "posHandle/last_position3", 0, 0);
807    x_fail_unless(hd3 == 3, "Failed to open handle ==> /posHandle/last_position3");
808
809    // close handles ---------------------------------------------------
810    ret = pclKeyHandleClose(hd1);
811    x_fail_unless(ret != -1, "Failed to close handle!!");
812
813    ret = pclKeyHandleClose(hd2);
814    x_fail_unless(ret != -1, "Failed to close handle!!");
815
816    ret = pclKeyHandleClose(hd3);
817    x_fail_unless(ret != -1, "Failed to close handle!!");
818
819    // open handles ----------------------------------------------------
820    hd4 = pclKeyHandleOpen(0xFF, "posHandle/last_position4", 0, 0);
821    x_fail_unless(hd4 == 3, "Failed to open handle ==> /posHandle/last_position4");
822
823    hd5 = pclKeyHandleOpen(0xFF, "posHandle/last_position5", 0, 0);
824    x_fail_unless(hd5 == 2, "Failed to open handle ==> /posHandle/last_position5");
825
826    hd6 = pclKeyHandleOpen(0xFF, "posHandle/last_position6", 0, 0);
827    x_fail_unless(hd6 == 1, "Failed to open handle ==> /posHandle/last_position6");
828
829    hd7 = pclKeyHandleOpen(0xFF, "posHandle/last_position7", 0, 0);
830    x_fail_unless(hd7 == 4, "Failed to open handle ==> /posHandle/last_position7");
831
832    hd8 = pclKeyHandleOpen(0xFF, "posHandle/last_position8", 0, 0);
833    x_fail_unless(hd8 == 5, "Failed to open handle ==> /posHandle/last_position8");
834
835    hd9 = pclKeyHandleOpen(0xFF, "posHandle/last_position9", 0, 0);
836    x_fail_unless(hd9 == 6, "Failed to open handle ==> /posHandle/last_position9");
837
838    // close handles ---------------------------------------------------
839    ret = pclKeyHandleClose(hd4);
840    x_fail_unless(ret != -1, "Failed to close handle!!");
841
842    ret = pclKeyHandleClose(hd5);
843    x_fail_unless(ret != -1, "Failed to close handle!!");
844
845    ret = pclKeyHandleClose(hd6);
846    x_fail_unless(ret != -1, "Failed to close handle!!");
847
848    ret = pclKeyHandleClose(hd7);
849    x_fail_unless(ret != -1, "Failed to close handle!!");
850
851    ret = pclKeyHandleClose(hd8);
852    x_fail_unless(ret != -1, "Failed to close handle!!");
853
854    ret = pclKeyHandleClose(hd9);
855    x_fail_unless(ret != -1, "Failed to close handle!!");
856 #endif
857    pclDeinitLibrary();
858 }
859 END_TEST
860
861
862
863 /**
864  * Test for  i n t e r n a l  structures.
865  * Test the cursor functions.
866  */
867 START_TEST(test_Cursor)
868 {
869    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
870    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
871    X_TEST_REPORT_REFERENCE("NONE");
872    X_TEST_REPORT_DESCRIPTION("Test of cursor");
873    X_TEST_REPORT_TYPE(GOOD);
874
875    int handle = -1, rval = 0, size = 0, handle1 = 0;
876    char bufferKeySrc[READ_SIZE]  = {0};
877    char bufferDataSrc[READ_SIZE] = {0};
878    char bufferKeyDst[READ_SIZE]  = {0};
879    char bufferDataDst[READ_SIZE] = {0};
880    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
881
882    rval = pclInitLibrary(gTheAppId, shutdownReg);
883    x_fail_unless(rval <= 1, "Failed to init PCL");
884 #if 1
885    // create cursor
886    handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
887    x_fail_unless(handle != -1, "Failed to create cursor!!");
888
889    // create cursor
890    handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz");
891    x_fail_unless(handle1 != -1, "Failed to create cursor!!");
892
893    do
894    {
895       memset(bufferKeySrc, 0, READ_SIZE);
896       memset(bufferDataSrc, 0, READ_SIZE);
897       memset(bufferKeyDst, 0, READ_SIZE);
898       memset(bufferDataDst, 0, READ_SIZE);
899
900       // get key
901       rval = pers_db_cursor_get_key(handle, bufferKeySrc, 256);
902       x_fail_unless(rval != -1, "Cursor failed to get key!!");
903       // get data
904       rval = pers_db_cursor_get_data(handle, bufferDataSrc, 256);
905
906       x_fail_unless(rval != -1, "Cursor failed to get data!!");
907       // get size
908       size = pers_db_cursor_get_data_size(handle);
909       x_fail_unless(size != -1, "Cursor failed to get size!!");
910       //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
911
912       // get key
913       rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 256);
914       x_fail_unless(rval != -1, "Cursor failed to get key!!");
915       // get data
916       rval = pers_db_cursor_get_data(handle1, bufferDataDst, 256);
917       x_fail_unless(rval != -1, "Cursor failed to get data!!");
918       // get size
919       size = pers_db_cursor_get_data_size(handle1);
920       x_fail_unless(size != -1, "Cursor failed to get size!!");
921       //printf("  2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
922    }
923    while( (pers_db_cursor_next(handle) == 0) && (pers_db_cursor_next(handle1) == 0) ); // next cursor
924
925    // destory cursor
926    rval = pers_db_cursor_destroy(handle);
927    x_fail_unless(rval != -1, "Failed to destroy cursor!!");
928
929    rval = pers_db_cursor_destroy(handle1);
930    x_fail_unless(rval != -1, "Failed to destroy cursor!!");
931 #endif
932    pclDeinitLibrary();
933 }
934 END_TEST
935
936
937
938 START_TEST(test_Plugin)
939 {
940    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
941    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
942    X_TEST_REPORT_REFERENCE("NONE");
943    X_TEST_REPORT_DESCRIPTION("Test of plugins");
944    X_TEST_REPORT_TYPE(GOOD);
945
946         int ret = 0;
947         unsigned char buffer[READ_SIZE]  = {0};
948
949         unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
950
951    ret = pclInitLibrary(gTheAppId, shutdownReg);
952    x_fail_unless(ret <= 1, "Failed to init PCL");
953 #if 1
954         ret = pclKeyReadData(0xFF, "language/country_code",           0, 0, buffer, READ_SIZE);
955         x_fail_unless(ret != EPERS_NOT_INITIALIZED);
956    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
957                strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
958
959
960         ret = pclKeyReadData(0xFF, "language/country_code_early",     0, 0, buffer, READ_SIZE);
961         x_fail_unless(ret != EPERS_NOT_INITIALIZED);
962         //printf("B U F F E R - early: %s\n", buffer);
963    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
964                strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
965
966         ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
967         x_fail_unless(ret != EPERS_NOT_INITIALIZED);
968         //printf("B U F F E R - emergency: %s\n", buffer);
969    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
970                strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
971
972         ret = pclKeyReadData(0xFF, "language/info",                   0, 0, buffer, READ_SIZE);
973         x_fail_unless(ret != EPERS_NOT_INITIALIZED);
974         //printf("B U F F E R - hwinfo: %s\n", buffer);
975    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
976                strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
977
978    ret = pclKeyReadData(0xFF, "language/country_code_custom3",   0, 0, buffer, READ_SIZE);
979    x_fail_unless(ret != EPERS_NOT_INITIALIZED);
980    //printf("B U F F E R - hwinfo: %s\n", buffer);
981    x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
982                strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
983 #endif
984         pclDeinitLibrary();
985 }
986 END_TEST
987
988
989
990
991
992 START_TEST(test_ReadDefault)
993 {
994    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
995    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
996    X_TEST_REPORT_REFERENCE("NONE");
997    X_TEST_REPORT_DESCRIPTION("Test of read default");
998    X_TEST_REPORT_TYPE(GOOD);
999
1000    int ret = 0;
1001    unsigned char buffer[READ_SIZE]  = {0};
1002
1003    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1004
1005    ret = pclInitLibrary(gTheAppId, shutdownReg);
1006    x_fail_unless(ret <= 1, "Failed to init PCL");
1007 #if 1
1008    ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
1009    x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1010    //printf("B U F F E R: %s\n", buffer);
1011    x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1012
1013    ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
1014    x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1015    //printf("B U F F E R: %s\n", buffer);
1016    x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1017 #endif
1018    pclDeinitLibrary();
1019 }
1020 END_TEST
1021
1022
1023
1024 START_TEST(test_ReadConfDefault)
1025 {
1026    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1027    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1028    X_TEST_REPORT_REFERENCE("NONE");
1029    X_TEST_REPORT_DESCRIPTION("Test of configurable default data");
1030    X_TEST_REPORT_TYPE(GOOD);
1031
1032    int ret = 0;
1033    unsigned char buffer[READ_SIZE]  = {0};
1034
1035    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1036
1037    ret = pclInitLibrary(gTheAppId, shutdownReg);
1038    x_fail_unless(ret <= 1, "Failed to init PCL");
1039 #if 1
1040    ret = pclKeyReadData(0xFF, "statusHandle/confdefault01",     3, 2, buffer, READ_SIZE);
1041    x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1042    x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1043
1044    ret = pclKeyReadData(0xFF, "statusHandle/confdefault02",     3, 2, buffer, READ_SIZE);
1045    x_fail_unless(ret != EPERS_NOT_INITIALIZED);
1046    x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
1047 #endif
1048    pclDeinitLibrary();
1049 }
1050 END_TEST
1051
1052
1053
1054 START_TEST(test_GetPath)
1055 {
1056    X_TEST_REPORT_TEST_NAME("persistence_client_library_test");
1057    X_TEST_REPORT_COMP_NAME("libpersistence_client_library");
1058    X_TEST_REPORT_REFERENCE("NONE");
1059    X_TEST_REPORT_DESCRIPTION("Test of get path");
1060    X_TEST_REPORT_TYPE(GOOD);
1061
1062    int ret = 0;
1063    char* path = NULL;
1064    const char* thePath = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDB_create.db";
1065    unsigned int pathSize = 0;
1066
1067    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
1068
1069    ret = pclInitLibrary(gTheAppId, shutdownReg);
1070    x_fail_unless(ret <= 1, "Failed to init PCL");
1071 #if 1
1072    ret = pclFileCreatePath(0xFF, "media/mediaDB_create.db", 1, 1, &path, &pathSize);
1073    x_fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");
1074    x_fail_unless(pathSize == strlen((char*)path), "Path size not correct");
1075
1076    pclFileReleasePath(ret);
1077 #endif
1078    pclDeinitLibrary();
1079 }
1080 END_TEST
1081
1082
1083 static Suite * persistencyClientLib_suite()
1084 {
1085    Suite * s  = suite_create("Persistency client library");
1086
1087    TCase * tc_persGetData = tcase_create("GetData");
1088    tcase_add_test(tc_persGetData, test_GetData);
1089
1090    TCase * tc_persSetData = tcase_create("SetData");
1091    tcase_add_test(tc_persSetData, test_SetData);
1092
1093    TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
1094    tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
1095
1096    TCase * tc_persGetDataSize = tcase_create("GetDataSize");
1097    tcase_add_test(tc_persGetDataSize, test_GetDataSize);
1098
1099    TCase * tc_persDeleteData = tcase_create("DeleteData");
1100    tcase_add_test(tc_persDeleteData, test_DeleteData);
1101
1102    TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
1103    tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
1104
1105    TCase * tc_persDataHandle = tcase_create("DataHandle");
1106    tcase_add_test(tc_persDataHandle, test_DataHandle);
1107
1108    TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
1109    tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
1110
1111    TCase * tc_persDataFile = tcase_create("DataFile");
1112    tcase_add_test(tc_persDataFile, test_DataFile);
1113
1114    TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
1115    tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
1116
1117    TCase * tc_Cursor = tcase_create("Cursor");
1118    tcase_add_test(tc_Cursor, test_Cursor);
1119
1120    TCase * tc_Plugin = tcase_create("Plugin");
1121    tcase_add_test(tc_Plugin, test_Plugin);
1122
1123    TCase * tc_ReadDefault = tcase_create("ReadDefault");
1124    tcase_add_test(tc_ReadDefault, test_ReadDefault);
1125
1126    TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
1127    tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
1128
1129    TCase * tc_GetPath = tcase_create("GetPath");
1130    tcase_add_test(tc_GetPath, test_GetPath);
1131
1132    suite_add_tcase(s, tc_persSetData);
1133    suite_add_tcase(s, tc_persGetData);
1134    suite_add_tcase(s, tc_persSetDataNoPRCT);
1135    suite_add_tcase(s, tc_persGetDataSize);
1136    suite_add_tcase(s, tc_persDeleteData);
1137    suite_add_tcase(s, tc_persGetDataHandle);
1138    suite_add_tcase(s, tc_persDataHandle);
1139    suite_add_tcase(s, tc_persDataHandleOpen);
1140    suite_add_tcase(s, tc_persDataFile);
1141    suite_add_tcase(s, tc_persDataFileRecovery);
1142    suite_add_tcase(s, tc_Cursor);
1143    suite_add_tcase(s, tc_ReadDefault);
1144    suite_add_tcase(s, tc_ReadConfDefault);
1145    suite_add_tcase(s, tc_GetPath);
1146    //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
1147    return s;
1148 }
1149
1150
1151 int main(int argc, char *argv[])
1152 {
1153    int nr_failed = 0,
1154           nr_run = 0,
1155             fail = 0,
1156                i = 0;
1157
1158    TestResult** tResult;
1159
1160    // assign application name
1161    strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen);
1162    gTheAppId[MaxAppNameLen-1] = '\0';
1163
1164    /// debug log and trace (DLT) setup
1165    DLT_REGISTER_APP("test","tests the persistence client library");
1166
1167 #if 1
1168    Suite * s = persistencyClientLib_suite();
1169    SRunner * sr = srunner_create(s);
1170    srunner_set_xml(sr, "/tmp/persistenceClientLibraryTest.xml");
1171    srunner_set_log(sr, "/tmp/persistenceClientLibraryTest.log");
1172    srunner_run_all(sr, /*CK_NORMAL*/ CK_VERBOSE);
1173
1174    nr_failed = srunner_ntests_failed(sr);
1175    nr_run = srunner_ntests_run(sr);
1176
1177    tResult = srunner_results(sr);
1178    for(i = 0; i< nr_run; i++)
1179    {
1180       fail = tr_rtype(tResult[i]);  // get status of each test
1181       //printf("[%d] Fail: %d \n", i, fail);
1182    }
1183
1184    srunner_free(sr);
1185 #endif
1186
1187    // unregister debug log and trace
1188    DLT_UNREGISTER_APP();
1189
1190    dlt_free();
1191
1192    return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;
1193
1194 }
1195