Initial version of persistence client library on sourceforge (rev. 1281)
[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 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11     * Redistributions of source code must retain the above copyright
12       notice, this list of conditions and the following disclaimer.
13     * Redistributions in binary form must reproduce the above copyright
14       notice, this list of conditions and the following disclaimer in the
15       documentation and/or other materials provided with the distribution.
16     * Neither the name of the <organization> nor the
17       names of its contributors may be used to endorse or promote products
18       derived from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
24 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ******************************************************************************/
31  /**
32  * @file           persistence_client_library_test.c
33  * @ingroup        Persistence client library test
34  * @author         Ingo Huerner
35  * @brief          Test of persistence client library
36  * @see            
37  */
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <errno.h>
43 #include <unistd.h>     /* exit */
44 #include <check.h>
45 #include <time.h>
46
47 #include "../include/persistence_client_library_key.h"
48 #include "../include/persistence_client_library_file.h"
49
50
51 #define BUF_SIZE     64
52 #define NUM_OF_FILES 3
53 #define READ_SIZE    256
54
55 char* dayOfWeek[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
56
57 START_TEST (test_persGetData)
58 {
59    int ret = 0;
60    unsigned char* buffer = NULL;
61    char sysTimeBuffer[128];
62    buffer = malloc(READ_SIZE);
63
64    struct tm *locTime;
65    time_t t = time(0);
66   
67    locTime = localtime(&t);
68
69    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), 
70                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
71    printf("\n\n");
72
73    memset(buffer, 0, READ_SIZE);
74    ret = key_read_data(0xFF, "/pos/last_position",         0, 0, buffer, READ_SIZE);   // "/Data/mnt-c/Appl-1/cached.gvdb"             => "/Node/pos/last position" 
75    printf("T E S T  Data: %s \n\n", buffer);
76
77    memset(buffer, 0, READ_SIZE);
78    ret = key_read_data(0,    "/language/current_language", 3, 0, buffer, READ_SIZE);   // "/Data/mnt-wt/Shared/Public/wt.dconf"        => "/User/3/language/current_language" 
79    printf("T E S T  Data: %s \n\n", buffer);
80
81    memset(buffer, 0, READ_SIZE);
82    ret = key_read_data(0xFF, "/status/open_document",      3, 2, buffer, READ_SIZE);   // "/Data/mnt-c/Appl-1/cached.gvdb"             => "/User/3/Seat/2/status/open_document" 
83    printf("T E S T  Data: %s \n\n", buffer);
84
85    memset(buffer, 0, READ_SIZE);
86    ret = key_read_data(0x20, "/address/home_address",      4, 0, buffer, READ_SIZE);   // "/Data/mnt-c/Shared/Group/20/cached.dconf"   => "/User/4/address/home_address" 
87    printf("T E S T  Data: %s \n\n", buffer);
88
89    memset(buffer, 0, READ_SIZE);
90    ret = key_read_data(0xFF, "/pos/last satellites",       0, 0, buffer, READ_SIZE);   // "/Data/mnt-wt/Appl-1/wt.gvdb"                => "/Node/pos/last satellites" 
91    printf("T E S T  Data: %s \n\n", buffer);
92
93    memset(buffer, 0, READ_SIZE);
94    ret = key_read_data(0x84, "/links/last link",           2, 0, buffer, READ_SIZE);   // "/Data/mnt-wt/Appl-2/wt.gvdb"                => "/84/User/2/links/last link" 
95    printf("T E S T  Data: %s \n\n", buffer);
96
97    memset(buffer, 0, READ_SIZE);
98    ret = key_read_data(0x84, "/links/last link",           2, 1, buffer, READ_SIZE);   // "/Data/mnt-wt/Appl-2/wt.gvdb"                => "/84/User/2/links/last link" 
99    printf("T E S T  Data: %s \n\n", buffer);
100
101    memset(buffer, 0, READ_SIZE);
102    ret = key_write_data(0x84, "/links/last link",          2, 1, sysTimeBuffer, READ_SIZE);   // "/Data/mnt-wt/Appl-2/wt.gvdb"         => "/84/User/2/Seat/1/links/last link" 
103    printf("T E S T  Data: %s \n\n", sysTimeBuffer);
104
105     memset(buffer, 0, READ_SIZE);
106    ret = key_read_data(0x84, "/links/last link",           2, 1, buffer, READ_SIZE);   // "/Data/mnt-wt/Appl-2/wt.gvdb"                => "/84/User/2/Seat/1/links/last link" 
107    printf("T E S T  Data: %s \n\n", buffer);
108
109
110
111    free(buffer);
112 }
113 END_TEST
114
115
116
117 START_TEST (test_persGetDataHandle)
118 {
119    int ret = 0, handlePos = 0, handleLang = 0, handleStatus = 0, handleHome = 0;
120    unsigned char* buffer = NULL;
121    char sysTimeBuffer[128];
122    buffer = malloc(READ_SIZE);
123
124    struct tm *locTime;
125    time_t t = time(0);
126   
127    locTime = localtime(&t);
128
129    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), 
130                                                                   locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
131    printf("\n\n");
132
133    memset(buffer, 0, READ_SIZE);
134    handlePos = key_handle_open(0xFF, "/posHandle/last_position", 0, 0);
135    ret = key_handle_read_data(handlePos, buffer, READ_SIZE);
136    printf("T E S T  handle: %d | Data: %s \n\n", handlePos, buffer);
137
138    memset(buffer, 0, READ_SIZE);
139    handleLang = key_handle_open(0, "/languageHandle/current_language", 3, 0);
140    ret = key_handle_read_data(handleLang, buffer, READ_SIZE);
141    printf("T E S T  handle: %d | Data: %s \n\n", handleLang, buffer);
142
143    memset(buffer, 0, READ_SIZE);
144    handleStatus = key_handle_open(0xFF, "/statusHandle/open_documen", 3, 2);
145    ret = key_handle_read_data(handleStatus, buffer, READ_SIZE);
146    printf("T E S T  handle: %d | Data: %s \n\n", handleStatus, buffer);
147
148    // close handle
149    key_handle_close(handleLang);
150
151    memset(buffer, 0, READ_SIZE);
152    handleHome = key_handle_open(0x20, "/address/home_address", 4, 0);
153    ret = key_handle_read_data(handleHome, buffer, READ_SIZE);
154    printf("T E S T  handle: %d | Data: %s \n\n", handleHome, buffer);
155
156    free(buffer);
157 }
158 END_TEST
159
160
161
162 START_TEST(test_persSetData)
163 {
164    int ret = 0;
165    unsigned char* buffer = NULL;
166    buffer = malloc(READ_SIZE);                            
167    memset(buffer, 0, READ_SIZE);
168
169
170    free(buffer);
171 }
172 END_TEST
173
174
175
176 START_TEST(test_persSetSharedData)
177 {
178    int ret = 0;
179    unsigned char* buffer = NULL;
180    buffer = malloc(READ_SIZE);                            
181
182
183    memset(buffer, 0, READ_SIZE);
184    ret = key_write_data(0x20, "/address/home_address",      4, 0, buffer, READ_SIZE);
185    printf("T E S T  Data: %s \n\n", buffer);
186
187    free(buffer);
188 }
189 END_TEST
190
191
192
193 START_TEST(test_persGetData_file)
194 {
195    int ret = 0;
196    unsigned char* buffer = NULL;
197    buffer = malloc(READ_SIZE);
198
199
200    memset(buffer, 0, READ_SIZE);
201
202    ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
203    printf("T E S T  Data: %s \n\n", buffer);
204
205    free(buffer);
206 }
207 END_TEST
208
209
210
211
212 static Suite * persistencyClientLib_suite()
213 {
214    Suite * s  = suite_create("Persistency client library");
215
216    TCase * tc_persGetData = tcase_create("persGetData");
217    tcase_add_test(tc_persGetData, test_persGetData);
218
219    TCase * tc_persGetDataHandle = tcase_create("persGetDataHandle");
220    tcase_add_test(tc_persGetDataHandle, test_persGetDataHandle);
221
222    TCase * tc_persSetData = tcase_create("persSetData");
223    tcase_add_test(tc_persSetData, test_persSetData);
224
225    TCase * tc_persSetSharedData = tcase_create("persSetSharedData");
226    tcase_add_test(tc_persSetSharedData, test_persSetSharedData);
227
228    TCase * tc_persGetData_file = tcase_create("persGetData_file");
229    tcase_add_test(tc_persGetData_file, test_persGetData_file);
230
231    suite_add_tcase(s, tc_persGetData);
232    suite_add_tcase(s, tc_persGetDataHandle);
233    suite_add_tcase(s, tc_persSetData);
234    suite_add_tcase(s, tc_persSetSharedData);
235    suite_add_tcase(s, tc_persGetData_file);
236
237    return s;
238 }
239
240
241
242
243 int main(int argc, char *argv[])
244 {
245    int nr_failed;
246
247    Suite * s = persistencyClientLib_suite();
248    SRunner * sr = srunner_create(s);
249    srunner_run_all(sr, CK_NORMAL);
250    nr_failed = srunner_ntests_failed(sr);
251    srunner_free(sr);
252
253
254    getchar();
255
256    return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;
257
258 }
259