summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorChristian Muck <christian.muck@bmw.de>2012-01-13 10:36:49 +0100
committerChristian Muck <christian.muck@bmw.de>2012-01-13 10:36:49 +0100
commit3d3de8d77645d2b7186dc58830d4cb94a3bcb0da (patch)
treed6cbcb898c4954051fafa014702455410b0c06ab /src/tests
parentb512a5a86504ce52371f0ff01bd13fb903d156ad (diff)
downloadDLT-daemon-3d3de8d77645d2b7186dc58830d4cb94a3bcb0da.tar.gz
Updated filetransfer documentation, lib and test application
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dlt-test-filetransfer.c216
1 files changed, 101 insertions, 115 deletions
diff --git a/src/tests/dlt-test-filetransfer.c b/src/tests/dlt-test-filetransfer.c
index 75b77d2..cf52920 100644
--- a/src/tests/dlt-test-filetransfer.c
+++ b/src/tests/dlt-test-filetransfer.c
@@ -1,5 +1,5 @@
#include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
-#include <dlt.h> /*Needed for dlt logging*/
+#include <dlt.h> /*Needed for dlt logging*/
//!Declare some context for the main program. It's a must have to do this, when you want to log with dlt.
DLT_DECLARE_CONTEXT(mainContext);
@@ -20,116 +20,34 @@ char *file3_3;
//!Just some variables
int i,countPackages, transferResult, dltResult;
-extern int testF1P1();
-extern int testF1P2();
-extern int testF2P1();
-extern int testF2P2();
-extern int testF3P1();
-extern int testF3P2();
-extern int testF3P3();
+//!Prints the test result
+void printTestResultPositiveExpected(const char *function, int result){
-//!Main program dlt-test-filestransfer starts here
-int main(void)
-{
- //First file contains some text
- file1 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-file";
- //Second file is a picture
- file2 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png";
- //Third file doesn't exist. Just to test the reaction when the file isn't available.
- file3_1 = "dlt-test-filetransfer-doesntExist_1";
- //Third file doesn't exist. Just to test the reaction when the file isn't available.
- file3_2 = "dlt-test-filetransfer-doesntExist_2";
- //Third file doesn't exist. Just to test the reaction when the file isn't available.
- file3_3 = "dlt-test-filetransfer-doesntExist_3";
-
- //Register the application at the dlt-daemon
- dltResult = DLT_REGISTER_APP("FLTR","Test Application filetransfer");
- if(dltResult < 0){
- printf("Error: DLT_REIGSTER_APP: FLTR\n");
- return -1;
+ if(result >= 0){
+ printf("%s successful\n",function);
}
- //Register the context of the main program at the dlt-daemon
- dltResult = DLT_REGISTER_CONTEXT(mainContext,"MAIN","Main context for filetransfer test");
- if(dltResult < 0){
- printf("Error: DLT_REGISTER_CONTEXT: MAIN\n");
- return -1;
+ else
+ {
+ printf("%s failed\n",function);
}
- //Register the context in which the file transfer will be logged at the dlt-daemon
- dltResult = DLT_REGISTER_CONTEXT(fileContext,"FLTR","Test Context for filetransfer");
- if(dltResult < 0){
- printf("Error: DLT_REGISTER_CONTEXT:FLTR\n");
- return -1;
+
+}
+
+//!Prints the test result
+void printTestResultNegativeExpected(const char *function, int result){
+
+ if(result < 0){
+ printf("%s successful\n",function);
+ }
+ else
+ {
+ printf("%s failed\n",function);
}
- //More details in corresponding methods
- if(testF1P1() >= 0){
- printf("testF1P1 successful\n");
- }
- else
- {
- printf("testF1P1 failed\n");
- }
-
- if(testF1P2() >= 0){
- printf("testF1P2 successful\n");
- }
- else
- {
- printf("testF1P2 failed\n");
- }
-
- if(testF2P1() >= 0){
- printf("testF2P1 successful\n");
- }
- else
- {
- printf("testF2P1 failed\n");
- }
-
- if(testF2P2() >= 0){
- printf("testF2P2 successful\n");
- }
- else
- {
- printf("testF2P2 failed\n");
- }
-
- if(testF3P1() < 0){
- printf("testF3P1 successful\n");
- }
- else
- {
- printf("testF3P1 failed\n");
- }
-
- if(testF3P2() < 0){
- printf("testF3P2 successful\n");
- }
- else
- {
- printf("testF3P2 failed\n");
- }
-
- if(testF3P3() < 0 ){
- printf("testF3P3 successful\n");
- }
- else
- {
- printf("testF3P3 failed\n");
- }
-
- //Unregister the context in which the file transfer happened from the dlt-daemon
- DLT_UNREGISTER_CONTEXT(fileContext);
- //Unregister the context of the main program from the dlt-daemon
- DLT_UNREGISTER_CONTEXT(mainContext);
- //Unregister the app from the dlt-daemon
- DLT_UNREGISTER_APP();
-
- return(0);
}
//!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using dlt_user_log_file_complete.
-int testF1P1(){
+int testFile1Run1(){
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF1P1 - dlt_user_log_file_complete"),DLT_STRING(file1));
@@ -143,17 +61,20 @@ int testF1P1(){
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P1"),DLT_STRING(file1));
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
+
return transferResult;
}
//!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using single package transfer
-int testF1P2(){
+int testFile1Run2(){
//Get the information how many packages have the file
countPackages = dlt_user_log_file_packagesCount(&fileContext,file1);
if(countPackages < 0 )
{
printf("Error: dlt_user_log_file_packagesCount\n");
+ printTestResultPositiveExpected(__FUNCTION__,countPackages);
return -1;
}
//Just some log to the main context
@@ -172,6 +93,7 @@ int testF1P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_data\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
@@ -182,22 +104,24 @@ int testF1P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_end\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
else
{
printf("Error: dlt_user_log_file_header\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
//Just some log to main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P2 - transfer single package"),DLT_STRING(file1));
-
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return 0;
}
//!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using dlt_user_log_file_complete.
-int testF2P1(){
+int testFile2Run1(){
//Just some log to main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF2P1 - dlt_user_log_file_complete"),DLT_STRING(file2));
@@ -206,22 +130,24 @@ int testF2P1(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_complete\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
//Just some log to main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P1"),DLT_STRING(file2));
-
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
//!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using single package transfer
-int testF2P2(){
+int testFile2Run2(){
//Get the information how many packages have the file
countPackages = dlt_user_log_file_packagesCount(&fileContext,file2);
if(countPackages < 0 )
{
printf("Error: dlt_user_log_file_packagesCount\n");
+ printTestResultPositiveExpected(__FUNCTION__,countPackages);
return -1;
}
@@ -241,6 +167,7 @@ int testF2P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_data\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
@@ -251,22 +178,24 @@ int testF2P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_end\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
else
{
printf("Error: dlt_user_log_file_header\n");
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return transferResult;
}
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P2"),DLT_STRING(file2));
-
+ printTestResultPositiveExpected(__FUNCTION__,transferResult);
return 0;
}
//!Test the file transfer with the condition that the transferred file does not exist using dlt_user_log_file_complete.
-int testF3P1(){
+int testFile3Run1(){
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_1));
@@ -279,14 +208,16 @@ int testF3P1(){
//printf("Error: dlt_user_log_file_complete\n");
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_1));
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return transferResult;
}
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return transferResult;
}
//!Test the file transfer with the condition that the transferred file does not exist using single package transfer
-int testF3P2(){
+int testFile3Run2(){
//Get the information how many packages have the file
countPackages = dlt_user_log_file_packagesCount(&fileContext,file3_2);
@@ -296,6 +227,7 @@ int testF3P2(){
//printf("Error: dlt_user_log_file_packagesCount\n");
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_2));
+ printTestResultNegativeExpected(__FUNCTION__,countPackages);
return -1;
}
//Just some log to the main context
@@ -314,6 +246,7 @@ int testF3P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_data\n");
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
@@ -324,16 +257,17 @@ int testF3P2(){
if(transferResult < 0)
{
printf("Error: dlt_user_log_file_end\n");
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return transferResult;
}
}
-
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return 0;
}
//!Logs some information about the file.
-int testF3P3(){
+int testFile3Run3(){
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P2"),DLT_STRING(file3_3));
@@ -346,9 +280,61 @@ int testF3P3(){
//printf("Error: dlt_user_log_file_infoAbout\n");
//Just some log to the main context
DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P2"),DLT_STRING(file3_3));
-
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return transferResult;
}
-
+ printTestResultNegativeExpected(__FUNCTION__,transferResult);
return 0;
}
+
+//!Main program dlt-test-filestransfer starts here
+int main(void)
+{
+ //First file contains some text
+ file1 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-file";
+ //Second file is a picture
+ file2 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png";
+ //Third file doesn't exist. Just to test the reaction when the file isn't available.
+ file3_1 = "dlt-test-filetransfer-doesntExist_1";
+ //Third file doesn't exist. Just to test the reaction when the file isn't available.
+ file3_2 = "dlt-test-filetransfer-doesntExist_2";
+ //Third file doesn't exist. Just to test the reaction when the file isn't available.
+ file3_3 = "dlt-test-filetransfer-doesntExist_3";
+
+ //Register the application at the dlt-daemon
+ dltResult = DLT_REGISTER_APP("FLTR","Test Application filetransfer");
+ if(dltResult < 0){
+ printf("Error: DLT_REIGSTER_APP: FLTR\n");
+ return -1;
+ }
+ //Register the context of the main program at the dlt-daemon
+ dltResult = DLT_REGISTER_CONTEXT(mainContext,"MAIN","Main context for filetransfer test");
+ if(dltResult < 0){
+ printf("Error: DLT_REGISTER_CONTEXT: MAIN\n");
+ return -1;
+ }
+ //Register the context in which the file transfer will be logged at the dlt-daemon
+ dltResult = DLT_REGISTER_CONTEXT(fileContext,"FLTR","Test Context for filetransfer");
+ if(dltResult < 0){
+ printf("Error: DLT_REGISTER_CONTEXT:FLTR\n");
+ return -1;
+ }
+
+ //More details in corresponding methods
+ testFile1Run1();
+ testFile1Run2();
+ testFile2Run1();
+ testFile2Run2();
+ testFile3Run1();
+ testFile3Run2();
+ testFile3Run3();
+
+ //Unregister the context in which the file transfer happened from the dlt-daemon
+ DLT_UNREGISTER_CONTEXT(fileContext);
+ //Unregister the context of the main program from the dlt-daemon
+ DLT_UNREGISTER_CONTEXT(mainContext);
+ //Unregister the app from the dlt-daemon
+ DLT_UNREGISTER_APP();
+
+ return(0);
+}