1 /******************************************************************************
4 * Company XS Embedded GmbH
5 *****************************************************************************/
6 /******************************************************************************
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.
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 ******************************************************************************/
32 * @file persistence_client_library_test.c
33 * @ingroup Persistence client library test
34 * @author Ingo Huerner
35 * @brief Test of persistence client library
43 #include <unistd.h> /* exit */
47 #include "../include/persistence_client_library_key.h"
48 #include "../include/persistence_client_library_file.h"
52 #define NUM_OF_FILES 3
55 char* dayOfWeek[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
57 START_TEST (test_persGetData)
60 unsigned char* buffer = NULL;
61 char sysTimeBuffer[128];
62 buffer = malloc(READ_SIZE);
67 locTime = localtime(&t);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
117 START_TEST (test_persGetDataHandle)
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);
127 locTime = localtime(&t);
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);
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);
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);
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);
149 key_handle_close(handleLang);
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);
162 START_TEST(test_persSetData)
165 unsigned char* buffer = NULL;
166 buffer = malloc(READ_SIZE);
167 memset(buffer, 0, READ_SIZE);
176 START_TEST(test_persSetSharedData)
179 unsigned char* buffer = NULL;
180 buffer = malloc(READ_SIZE);
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);
193 START_TEST(test_persGetData_file)
196 unsigned char* buffer = NULL;
197 buffer = malloc(READ_SIZE);
200 memset(buffer, 0, READ_SIZE);
202 ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
203 printf("T E S T Data: %s \n\n", buffer);
212 static Suite * persistencyClientLib_suite()
214 Suite * s = suite_create("Persistency client library");
216 TCase * tc_persGetData = tcase_create("persGetData");
217 tcase_add_test(tc_persGetData, test_persGetData);
219 TCase * tc_persGetDataHandle = tcase_create("persGetDataHandle");
220 tcase_add_test(tc_persGetDataHandle, test_persGetDataHandle);
222 TCase * tc_persSetData = tcase_create("persSetData");
223 tcase_add_test(tc_persSetData, test_persSetData);
225 TCase * tc_persSetSharedData = tcase_create("persSetSharedData");
226 tcase_add_test(tc_persSetSharedData, test_persSetSharedData);
228 TCase * tc_persGetData_file = tcase_create("persGetData_file");
229 tcase_add_test(tc_persGetData_file, test_persGetData_file);
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);
243 int main(int argc, char *argv[])
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);
256 return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE;