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[READ_SIZE];
58 memset(buffer, 0, READ_SIZE);
59 ret = key_read_data(0xFF, "/language/country_code", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
60 //printf("T E S T Data - country_code: %s | size: %d \n", buffer, ret);
61 fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", strlen((char*)buffer)) == 0, "Buffer not correctly read");
63 memset(buffer, 0, READ_SIZE);
64 ret = key_read_data(0xFF, "/pos/last_position", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
65 fail_unless(strncmp((char*)buffer, "+48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
66 //printf("T E S T Data - last_position: %s \n", buffer);
68 memset(buffer, 0, READ_SIZE);
69 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"
70 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");
71 //printf("T E S T Data - current_language: %s \n", buffer);
73 memset(buffer, 0, READ_SIZE);
74 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"
75 printf("T E S T Data - last link: %s \n", buffer);
76 fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", ret-1) == 0, "Buffer not correctly read");
77 //printf("T E S T Data - open_document: %s \n", buffer);
79 memset(buffer, 0, READ_SIZE);
80 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"
81 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");
82 //printf("T E S T Data - home_address: %s \n", buffer);
84 memset(buffer, 0, READ_SIZE);
85 ret = key_read_data(0xFF, "/pos/last satellites", 0, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-1/wt.gvdb" => "/Node/pos/last satellites"
86 fail_unless(strncmp((char*)buffer, "17", ret-1) == 0, "Buffer not correctly read");
87 //printf("T E S T Data - last satellites: %s \n", buffer);
89 memset(buffer, 0, READ_SIZE);
90 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"
91 fail_unless(strncmp((char*)buffer, "/last_exit/brooklyn", ret-1) == 0, "Buffer not correctly read");
92 //printf("T E S T Data - last link: %s \n", buffer);
94 memset(buffer, 0, READ_SIZE);
95 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"
96 fail_unless(strncmp((char*)buffer, "/last_exit/queens", ret-1) == 0, "Buffer not correctly read");
97 //printf("T E S T Data - last link: %s \n", buffer);
103 START_TEST (test_persGetDataHandle)
105 int ret = 0, handlePos = 0, handleLang = 0, handleStatus = 0, handleHome = 0;
106 unsigned char* buffer = NULL;
107 char sysTimeBuffer[128];
108 buffer = malloc(READ_SIZE);
113 locTime = localtime(&t);
115 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),
116 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
118 memset(buffer, 0, READ_SIZE);
119 handlePos = key_handle_open(0xFF, "/posHandle/last_position", 0, 0);
120 ret = key_handle_read_data(handlePos, buffer, READ_SIZE);
121 fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
122 printf("T E S T handle: %d | Data: %s \n\n", handlePos, buffer);
124 memset(buffer, 0, READ_SIZE);
125 handleLang = key_handle_open(0, "/languageHandle/current_language", 3, 0);
126 ret = key_handle_read_data(handleLang, buffer, READ_SIZE);
127 printf("T E S T handle: %d | Data: %s \n\n", handleLang, buffer);
129 memset(buffer, 0, READ_SIZE);
130 handleStatus = key_handle_open(0xFF, "/statusHandle/open_documen", 3, 2);
131 ret = key_handle_read_data(handleStatus, buffer, READ_SIZE);
132 printf("T E S T handle: %d | Data: %s \n\n", handleStatus, buffer);
135 key_handle_close(handleLang);
137 memset(buffer, 0, READ_SIZE);
138 handleHome = key_handle_open(0x20, "/address/home_address", 4, 0);
139 ret = key_handle_read_data(handleHome, buffer, READ_SIZE);
140 printf("T E S T handle: %d | Data: %s \n\n", handleHome, buffer);
148 START_TEST(test_persSetData)
151 unsigned char buffer[READ_SIZE];
152 char write1[READ_SIZE];
153 char write2[READ_SIZE];
154 char sysTimeBuffer[256];
159 locTime = localtime(&t);
160 memset(buffer, 0, READ_SIZE);
161 memset(write1, 0, READ_SIZE);
162 memset(write2, 0, READ_SIZE);
165 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),
166 locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
167 ret = key_write_data(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, READ_SIZE);
169 snprintf(write1, 128, "%s %s", "70", sysTimeBuffer);
170 ret = key_write_data(0xFF, "70", 1, 2, (unsigned char*)write1, READ_SIZE);
172 snprintf(write2, 128, "%s %s", "key_70", sysTimeBuffer);
173 ret = key_write_data(0xFF, "key_70", 1, 2, (unsigned char*)write2, READ_SIZE);
176 // read data again and and verify datat has been written correctly
177 memset(buffer, 0, READ_SIZE);
178 ret = key_read_data(0xFF, "69", 1, 2, buffer, READ_SIZE);
179 //printf("T E S T Data 69: %s | read: \"%s\" \n", sysTimeBuffer, buffer);
180 fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
182 memset(buffer, 0, READ_SIZE);
183 ret = key_read_data(0xFF, "70", 1, 2, buffer, READ_SIZE);
184 //printf("T E S T Data 70: %s | read: \"%s\" \n", write1, buffer);
185 fail_unless(strncmp((char*)buffer, write1, strlen(write1)) == 0, "Buffer not correctly read");
187 memset(buffer, 0, READ_SIZE);
188 ret = key_read_data(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
189 //printf("T E S T Data key_70: %s | read: \"%s\" \n", write2, buffer);
190 fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read");
196 START_TEST(test_persSetSharedData)
199 unsigned char* buffer = NULL;
200 buffer = malloc(READ_SIZE);
203 memset(buffer, 0, READ_SIZE);
204 ret = key_write_data(0x20, "/address/home_address", 4, 0, buffer, READ_SIZE);
205 fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
206 printf("T E S T Data: %s \n\n", buffer);
214 START_TEST(test_persGetData_file)
217 unsigned char* buffer = NULL;
218 buffer = malloc(READ_SIZE);
221 memset(buffer, 0, READ_SIZE);
223 ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
224 fail_unless(ret != -1, "Could not open file");
225 printf("T E S T Data: %s \n\n", buffer);
234 static Suite * persistencyClientLib_suite()
236 Suite * s = suite_create("Persistency client library");
238 TCase * tc_persGetData = tcase_create("persGetData");
239 tcase_add_test(tc_persGetData, test_persGetData);
241 TCase * tc_persGetDataHandle = tcase_create("persGetDataHandle");
242 tcase_add_test(tc_persGetDataHandle, test_persGetDataHandle);
244 TCase * tc_persSetData = tcase_create("persSetData");
245 tcase_add_test(tc_persSetData, test_persSetData);
247 TCase * tc_persSetSharedData = tcase_create("persSetSharedData");
248 tcase_add_test(tc_persSetSharedData, test_persSetSharedData);
250 TCase * tc_persGetData_file = tcase_create("persGetData_file");
251 tcase_add_test(tc_persGetData_file, test_persGetData_file);
253 suite_add_tcase(s, tc_persGetData);
254 suite_add_tcase(s, tc_persSetData);
256 // suite_add_tcase(s, tc_persGetDataHandle);
257 // suite_add_tcase(s, tc_persSetSharedData);
258 // suite_add_tcase(s, tc_persGetData_file);
266 int main(int argc, char *argv[])
270 Suite * s = persistencyClientLib_suite();
271 SRunner * sr = srunner_create(s);
272 srunner_run_all(sr, CK_NORMAL);
273 nr_failed = srunner_ntests_failed(sr);
276 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;