1 #include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
2 #include <dlt.h> /*Needed for dlt logging*/
4 //!Declare some context for the main program. It's a must have to do this, when you want to log with dlt.
5 DLT_DECLARE_CONTEXT(mainContext);
7 //!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer.
8 DLT_DECLARE_CONTEXT(fileContext);
10 //!Textfile which will be transferred.
12 //!Image which will be transferred.
14 //!Not existing file which will be transferred.
16 //!Not existing file which will be transferred.
18 //!Not existing file which will be transferred.
20 //!Just some variables
21 int i,countPackages, transferResult, dltResult;
23 //!Prints the test result
24 void printTestResultPositiveExpected(const char *function, int result){
27 printf("%s successful\n",function);
31 printf("%s failed\n",function);
36 //!Prints the test result
37 void printTestResultNegativeExpected(const char *function, int result){
40 printf("%s successful\n",function);
44 printf("%s failed\n",function);
49 //!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using dlt_user_log_file_complete.
51 //Just some log to the main context
52 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF1P1 - dlt_user_log_file_complete"),DLT_STRING(file1));
54 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
55 transferResult = dlt_user_log_file_complete(&fileContext,file1,0,20);
56 if(transferResult < 0 )
58 printf("Error: dlt_user_log_file_complete\n");
59 return transferResult;
61 //Just some log to the main context
62 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P1"),DLT_STRING(file1));
64 printTestResultPositiveExpected(__FUNCTION__,transferResult);
66 return transferResult;
69 //!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using single package transfer
71 int total_size, used_size;
73 //Get the information how many packages have the file
74 countPackages = dlt_user_log_file_packagesCount(&fileContext,file1);
75 if(countPackages < 0 )
77 printf("Error: dlt_user_log_file_packagesCount\n");
78 printTestResultPositiveExpected(__FUNCTION__,countPackages);
81 //Just some log to the main context
82 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF1P2 - transfer single package"),DLT_STRING(file1));
84 //Logs the header of the file transfer. For more details see Mainpage.c.
85 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
86 transferResult = dlt_user_log_file_header(&fileContext,file1);
87 if(transferResult >= 0)
89 //Loop to log all packages
90 for(i=1;i<=countPackages;i++)
92 dlt_user_check_buffer(&total_size, &used_size);
93 if((total_size - used_size) < (total_size/2))
95 printf("Error: dlt_user_log_file_data\n");
96 printTestResultPositiveExpected(__FUNCTION__,transferResult);
100 //Logs one single package to the file context
101 transferResult = dlt_user_log_file_data(&fileContext,file1,i,20);
102 if(transferResult < 0)
104 printf("Error: dlt_user_log_file_data\n");
105 printTestResultPositiveExpected(__FUNCTION__,transferResult);
106 return transferResult;
110 //Logs the end of the file transfer. For more details see Mainpage.c
111 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
112 transferResult = dlt_user_log_file_end(&fileContext,file1,0);
113 if(transferResult < 0)
115 printf("Error: dlt_user_log_file_end\n");
116 printTestResultPositiveExpected(__FUNCTION__,transferResult);
117 return transferResult;
122 printf("Error: dlt_user_log_file_header\n");
123 printTestResultPositiveExpected(__FUNCTION__,transferResult);
124 return transferResult;
127 //Just some log to main context
128 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P2 - transfer single package"),DLT_STRING(file1));
129 printTestResultPositiveExpected(__FUNCTION__,transferResult);
132 //!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using dlt_user_log_file_complete.
134 //Just some log to main context
135 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF2P1 - dlt_user_log_file_complete"),DLT_STRING(file2));
137 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
138 transferResult = dlt_user_log_file_complete(&fileContext,file2,0,20);
139 if(transferResult < 0)
141 printf("Error: dlt_user_log_file_complete\n");
142 printTestResultPositiveExpected(__FUNCTION__,transferResult);
143 return transferResult;
145 //Just some log to main context
146 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P1"),DLT_STRING(file2));
147 printTestResultPositiveExpected(__FUNCTION__,transferResult);
148 return transferResult;
151 //!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using single package transfer
153 int total_size, used_size;
155 //Get the information how many packages have the file
156 countPackages = dlt_user_log_file_packagesCount(&fileContext,file2);
157 if(countPackages < 0 )
159 printf("Error: dlt_user_log_file_packagesCount\n");
160 printTestResultPositiveExpected(__FUNCTION__,countPackages);
164 //Just some log to the main context
165 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF2P2 - transfer single package"),DLT_STRING(file2));
167 //Logs the header of the file transfer. For more details see Mainpage.c.
168 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
169 transferResult = dlt_user_log_file_header(&fileContext,file2);
170 if( transferResult >= 0){
172 //Loop to log all packages
173 for(i=1;i<=countPackages;i++)
175 dlt_user_check_buffer(&total_size, &used_size);
176 if((total_size - used_size) < (total_size/2))
178 printf("Error: dlt_user_log_file_data\n");
179 printTestResultPositiveExpected(__FUNCTION__,transferResult);
183 //Logs one single package to the file context
184 transferResult = dlt_user_log_file_data(&fileContext,file2,i,20);
185 if(transferResult < 0)
187 printf("Error: dlt_user_log_file_data\n");
188 printTestResultPositiveExpected(__FUNCTION__,transferResult);
189 return transferResult;
193 //Logs the end of the file transfer. For more details see Mainpage.c
194 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
195 transferResult = dlt_user_log_file_end(&fileContext,file2,0);
196 if(transferResult < 0)
198 printf("Error: dlt_user_log_file_end\n");
199 printTestResultPositiveExpected(__FUNCTION__,transferResult);
200 return transferResult;
205 printf("Error: dlt_user_log_file_header\n");
206 printTestResultPositiveExpected(__FUNCTION__,transferResult);
207 return transferResult;
209 //Just some log to the main context
210 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P2"),DLT_STRING(file2));
211 printTestResultPositiveExpected(__FUNCTION__,transferResult);
215 //!Test the file transfer with the condition that the transferred file does not exist using dlt_user_log_file_complete.
218 //Just some log to the main context
219 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_1));
221 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
222 transferResult = dlt_user_log_file_complete(&fileContext,file3_1,0,20);
223 if(transferResult < 0)
225 //Error expected because file doesn't exist
226 //printf("Error: dlt_user_log_file_complete\n");
227 //Just some log to the main context
228 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_1));
229 printTestResultNegativeExpected(__FUNCTION__,transferResult);
230 return transferResult;
232 printTestResultNegativeExpected(__FUNCTION__,transferResult);
233 return transferResult;
237 //!Test the file transfer with the condition that the transferred file does not exist using single package transfer
240 //Get the information how many packages have the file
241 countPackages = dlt_user_log_file_packagesCount(&fileContext,file3_2);
242 if(countPackages < 0 )
244 //Error expected because file doesn't exist
245 //printf("Error: dlt_user_log_file_packagesCount\n");
246 //Just some log to the main context
247 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_2));
248 printTestResultNegativeExpected(__FUNCTION__,countPackages);
251 //Just some log to the main context
252 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_2));
254 //Logs the header of the file transfer. For more details see Mainpage.c.
255 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
256 transferResult = dlt_user_log_file_header(&fileContext,file3_2);
257 if( transferResult >= 0){
259 //Loop to log all packages
260 for(i=1;i<=countPackages;i++)
262 //Logs one single package to the file context
263 transferResult = dlt_user_log_file_data(&fileContext,file3_2,i,20);
264 if(transferResult < 0)
266 printf("Error: dlt_user_log_file_data\n");
267 printTestResultNegativeExpected(__FUNCTION__,transferResult);
268 return transferResult;
272 //Logs the end of the file transfer. For more details see Mainpage.c
273 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
274 transferResult = dlt_user_log_file_end(&fileContext,file3_2,0);
275 if(transferResult < 0)
277 printf("Error: dlt_user_log_file_end\n");
278 printTestResultNegativeExpected(__FUNCTION__,transferResult);
279 return transferResult;
282 printTestResultNegativeExpected(__FUNCTION__,transferResult);
287 //!Logs some information about the file.
290 //Just some log to the main context
291 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P2"),DLT_STRING(file3_3));
293 //Here's the line where the dlt file file info is called. The method call logs some information to dlt about the file, filesize, file serial number and number of packages
294 transferResult = dlt_user_log_file_infoAbout(&fileContext,file3_3);
295 if(transferResult < 0)
297 //Error expected because file doesn't exist
298 //printf("Error: dlt_user_log_file_infoAbout\n");
299 //Just some log to the main context
300 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P2"),DLT_STRING(file3_3));
301 printTestResultNegativeExpected(__FUNCTION__,transferResult);
302 return transferResult;
304 printTestResultNegativeExpected(__FUNCTION__,transferResult);
308 //!Main program dlt-test-filestransfer starts here
311 //First file contains some text
312 file1 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-file";
313 //Second file is a picture
314 file2 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png";
315 //Third file doesn't exist. Just to test the reaction when the file isn't available.
316 file3_1 = "dlt-test-filetransfer-doesntExist_1";
317 //Third file doesn't exist. Just to test the reaction when the file isn't available.
318 file3_2 = "dlt-test-filetransfer-doesntExist_2";
319 //Third file doesn't exist. Just to test the reaction when the file isn't available.
320 file3_3 = "dlt-test-filetransfer-doesntExist_3";
322 //Register the application at the dlt-daemon
323 dltResult = DLT_REGISTER_APP("FLTR","Test Application filetransfer");
324 // if(dltResult < 0){
325 // printf("Error: DLT_REIGSTER_APP: FLTR\n");
328 //Register the context of the main program at the dlt-daemon
329 dltResult = DLT_REGISTER_CONTEXT(mainContext,"MAIN","Main context for filetransfer test");
330 // if(dltResult < 0){
331 // printf("Error: DLT_REGISTER_CONTEXT: MAIN\n");
334 //Register the context in which the file transfer will be logged at the dlt-daemon
335 dltResult = DLT_REGISTER_CONTEXT(fileContext,"FLTR","Test Context for filetransfer");
336 // if(dltResult < 0){
337 // printf("Error: DLT_REGISTER_CONTEXT:FLTR\n");
341 //More details in corresponding methods
350 //Unregister the context in which the file transfer happened from the dlt-daemon
351 DLT_UNREGISTER_CONTEXT(fileContext);
352 //Unregister the context of the main program from the dlt-daemon
353 DLT_UNREGISTER_CONTEXT(mainContext);
354 //Unregister the app from the dlt-daemon
355 DLT_UNREGISTER_APP();