1 /******************************************************************************
4 * Company XS Embedded GmbH
5 *****************************************************************************/
6 /******************************************************************************
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ******************************************************************************/
26 * @file persistence_client_library_test.c
27 * @ingroup Persistence client library test
28 * @author Ingo Huerner
29 * @brief Test of persistence client library
37 #include <unistd.h> /* exit */
41 #include "../include/persistence_client_library_key.h"
42 #include "../include/persistence_client_library_file.h"
46 #define NUM_OF_FILES 3
47 #define READ_SIZE 1024
49 char* dayOfWeek[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
53 START_TEST (test_persGetData)
56 unsigned char* buffer = NULL;
57 char sysTimeBuffer[256];
58 buffer = malloc(READ_SIZE);
63 locTime = localtime(&t);
65 snprintf(sysTimeBuffer, 256, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
66 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
69 printf("<-----------------------------------------------\n");
70 memset(buffer, 0, READ_SIZE);
71 ret = key_read_data(0xFF, "/language/country_code", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
72 printf("T E S T Data - country_code: %s | size: %d \n", buffer, ret);
73 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", strlen((char*)buffer)) == 0, "Buffer not correctly read");
75 printf("----------------------------------------------->\n\n");
78 printf("<-----------------------------------------------\n");
79 memset(buffer, 0, READ_SIZE);
80 ret = key_read_data(0xFF, "/pos/last_position", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
81 fail_unless(strncmp((char*)buffer, "+48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
82 printf("T E S T Data - last_position: %s \n", buffer);
83 printf("----------------------------------------------->\n\n");
86 printf("<-----------------------------------------------\n");
87 memset(buffer, 0, READ_SIZE);
88 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"
89 fail_unless(strncmp((char*)buffer, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
90 printf("T E S T Data - current_language: %s \n", buffer);
91 printf("----------------------------------------------->\n\n");
94 printf("<-----------------------------------------------\n");
95 memset(buffer, 0, READ_SIZE);
96 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"
97 printf("T E S T Data - last link: %s \n", buffer);
98 fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", ret-1) == 0, "Buffer not correctly read");
99 printf("T E S T Data - open_document: %s \n", buffer);
100 printf("----------------------------------------------->\n\n");
103 printf("<-----------------------------------------------\n");
104 memset(buffer, 0, READ_SIZE);
105 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"
106 fail_unless(strncmp((char*)buffer, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
107 printf("T E S T Data - home_address: %s \n", buffer);
108 printf("----------------------------------------------->\n\n");
111 printf("<-----------------------------------------------\n");
112 memset(buffer, 0, READ_SIZE);
113 ret = key_read_data(0xFF, "/pos/last satellites", 0, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-1/wt.gvdb" => "/Node/pos/last satellites"
114 fail_unless(strncmp((char*)buffer, "17", ret-1) == 0, "Buffer not correctly read");
115 printf("T E S T Data - last satellites: %s \n", buffer);
116 printf("----------------------------------------------->\n\n");
119 printf("<-----------------------------------------------\n");
120 memset(buffer, 0, READ_SIZE);
121 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"
122 fail_unless(strncmp((char*)buffer, "/last_exit/brooklyn", ret-1) == 0, "Buffer not correctly read");
123 printf("T E S T Data - last link: %s \n", buffer);
124 printf("----------------------------------------------->\n\n");
127 printf("<-----------------------------------------------\n");
128 memset(buffer, 0, READ_SIZE);
129 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"
130 fail_unless(strncmp((char*)buffer, "/last_exit/queens", ret-1) == 0, "Buffer not correctly read");
131 printf("T E S T Data - last link: %s \n", buffer);
132 printf("----------------------------------------------->\n\n");
134 printf("<-----------------------------------------------\n");
135 memset(buffer, 0, READ_SIZE);
136 //ret = key_write_data(0xFF, "/status/open_document", 1, 2, (unsigned char*)sysTimeBuffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
137 printf("T E S T write data /status/open_document: %s \n", sysTimeBuffer);
138 printf("----------------------------------------------->\n\n");
141 printf("<-----------------------------------------------\n");
142 memset(buffer, 0, READ_SIZE);
143 ret = key_read_data(0xFF, "/status/open_document", 1, 2, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
144 printf("T E S T Data /status/open_document: %s \n", buffer);
145 fail_unless(strncmp((char*)buffer, "empty", strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
147 printf("----------------------------------------------->\n\n");
156 START_TEST (test_persGetDataHandle)
158 int ret = 0, handlePos = 0, handleLang = 0, handleStatus = 0, handleHome = 0;
159 unsigned char* buffer = NULL;
160 char sysTimeBuffer[128];
161 buffer = malloc(READ_SIZE);
166 locTime = localtime(&t);
168 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),
169 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
172 memset(buffer, 0, READ_SIZE);
173 handlePos = key_handle_open(0xFF, "/posHandle/last_position", 0, 0);
174 ret = key_handle_read_data(handlePos, buffer, READ_SIZE);
175 fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
176 printf("T E S T handle: %d | Data: %s \n\n", handlePos, buffer);
178 memset(buffer, 0, READ_SIZE);
179 handleLang = key_handle_open(0, "/languageHandle/current_language", 3, 0);
180 ret = key_handle_read_data(handleLang, buffer, READ_SIZE);
181 printf("T E S T handle: %d | Data: %s \n\n", handleLang, buffer);
183 memset(buffer, 0, READ_SIZE);
184 handleStatus = key_handle_open(0xFF, "/statusHandle/open_documen", 3, 2);
185 ret = key_handle_read_data(handleStatus, buffer, READ_SIZE);
186 printf("T E S T handle: %d | Data: %s \n\n", handleStatus, buffer);
189 key_handle_close(handleLang);
191 memset(buffer, 0, READ_SIZE);
192 handleHome = key_handle_open(0x20, "/address/home_address", 4, 0);
193 ret = key_handle_read_data(handleHome, buffer, READ_SIZE);
194 printf("T E S T handle: %d | Data: %s \n\n", handleHome, buffer);
202 START_TEST(test_persSetData)
204 unsigned char* buffer = NULL;
205 buffer = malloc(READ_SIZE);
206 memset(buffer, 0, READ_SIZE);
215 START_TEST(test_persSetSharedData)
218 unsigned char* buffer = NULL;
219 buffer = malloc(READ_SIZE);
222 memset(buffer, 0, READ_SIZE);
223 ret = key_write_data(0x20, "/address/home_address", 4, 0, buffer, READ_SIZE);
224 fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
225 printf("T E S T Data: %s \n\n", buffer);
233 START_TEST(test_persGetData_file)
236 unsigned char* buffer = NULL;
237 buffer = malloc(READ_SIZE);
240 memset(buffer, 0, READ_SIZE);
242 ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
243 fail_unless(ret != -1, "Could not open file");
244 printf("T E S T Data: %s \n\n", buffer);
253 static Suite * persistencyClientLib_suite()
255 Suite * s = suite_create("Persistency client library");
257 TCase * tc_persGetData = tcase_create("persGetData");
258 tcase_add_test(tc_persGetData, test_persGetData);
260 TCase * tc_persGetDataHandle = tcase_create("persGetDataHandle");
261 tcase_add_test(tc_persGetDataHandle, test_persGetDataHandle);
263 TCase * tc_persSetData = tcase_create("persSetData");
264 tcase_add_test(tc_persSetData, test_persSetData);
266 TCase * tc_persSetSharedData = tcase_create("persSetSharedData");
267 tcase_add_test(tc_persSetSharedData, test_persSetSharedData);
269 TCase * tc_persGetData_file = tcase_create("persGetData_file");
270 tcase_add_test(tc_persGetData_file, test_persGetData_file);
272 suite_add_tcase(s, tc_persGetData);
273 /*suite_add_tcase(s, tc_persGetDataHandle);
274 suite_add_tcase(s, tc_persSetData);
275 suite_add_tcase(s, tc_persSetSharedData);
276 suite_add_tcase(s, tc_persGetData_file);
284 int main(int argc, char *argv[])
288 Suite * s = persistencyClientLib_suite();
289 SRunner * sr = srunner_create(s);
290 srunner_run_all(sr, CK_NORMAL);
291 nr_failed = srunner_ntests_failed(sr);
294 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;