ofdbus/dbus/tsrc/testapps/exes1/src/dbus_simultaneous_connections.c
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include<stdio.h> 
       
    20 #include <dbus/dbus.h>
       
    21 #include <stdlib.h>
       
    22 #include <string.h>
       
    23 #include <fcntl.h>
       
    24 #include <unistd.h>
       
    25 #include <sys/stat.h>
       
    26 
       
    27 #define LOG_FILE "c:\\logs\\dbus_simultaneous_connections_log1.txt"
       
    28 #include "std_log_result.h"
       
    29 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    30 
       
    31 int make_fifo(char* fifopath)
       
    32 {
       
    33 	int err =0;
       
    34 	err = mkfifo (fifopath, 0666);
       
    35 	   if(err != 0)
       
    36 	   {
       
    37 	       // probably file already exists, delete the file
       
    38 	       unlink(fifopath); 
       
    39 	       // try once more..
       
    40 	       err = mkfifo (fifopath, 0666);
       
    41 	       if(err != 0)
       
    42 	       {
       
    43 	            return 1;
       
    44 	       }
       
    45 	   }
       
    46 	   return 0;
       
    47 }
       
    48 
       
    49 int read_fifo(char* fifopath, char* str)
       
    50 {
       
    51 	int fd = open(fifopath, O_RDONLY);
       
    52 	int err;
       
    53 	char buf[180];
       
    54 	
       
    55 	if(fd > 0)
       
    56 	{
       
    57 		err = read (fd, buf, 80);
       
    58 		close(fd);
       
    59 	}
       
    60 	else
       
    61 		{
       
    62 		return 1;
       
    63 		}
       
    64 	unlink(fifopath);
       
    65 	if(strcmp(buf, "done"))
       
    66 	{
       
    67 		strcpy(str, buf);
       
    68 		return 1;
       
    69 	}
       
    70 	
       
    71 	return 0;
       
    72 }
       
    73 
       
    74 void create_xml(int result)
       
    75 {
       
    76 	if(result)
       
    77 		assert_failed = 1;
       
    78 	
       
    79 	testResultXml("dbus_simultaneous_connections");
       
    80 	close_log_file();
       
    81 }
       
    82 
       
    83 int main()
       
    84 {
       
    85 
       
    86 	
       
    87 	FILE* fp[3];
       
    88 	int cnt;
       
    89 	char buf[180];
       
    90 	char res[80];
       
    91 	
       
    92 #if defined(__WINSCW__) || defined(__WINS__)
       
    93 	char* exe_names[] = { 	"z:\\sys\\bin\\get_connection_1.exe",
       
    94 							"z:\\sys\\bin\\get_connection_2.exe",
       
    95 							"z:\\sys\\bin\\get_connection_3.exe"
       
    96 						};
       
    97 #else
       
    98 	char* exe_names[] = { 	"c:\\sys\\bin\\get_connection_1.exe",
       
    99 							"c:\\sys\\bin\\get_connection_2.exe",
       
   100 							"c:\\sys\\bin\\get_connection_3.exe"
       
   101 						};
       
   102 #endif
       
   103 	
       
   104 	char* fifopath[3] = {	"C:\\mkfifo001.file",
       
   105 								"C:\\mkfifo002.file",
       
   106 								"C:\\mkfifo003.file"};
       
   107 	for(cnt=0; cnt<3; cnt++)
       
   108 	{
       
   109 		if(make_fifo(fifopath[cnt]))
       
   110 			{
       
   111 			std_log(LOG_FILENAME_LINE,"Failed to open FIFO for %d count", cnt);
       
   112 			create_xml(1);
       
   113 			return 1;
       
   114 			}
       
   115 	}
       
   116 	
       
   117 
       
   118 	
       
   119 	
       
   120 	for(cnt=0; cnt<3; cnt++)
       
   121 		{
       
   122 			fp[cnt] = popen(exe_names[cnt], "r");
       
   123 			if(!fp[cnt])
       
   124 				{
       
   125 				std_log(LOG_FILENAME_LINE,"Failed to open %d th EXE", cnt);
       
   126 				create_xml(1);
       
   127 				return 1;
       
   128 				}
       
   129 		}
       
   130 	
       
   131 	for(cnt=0; cnt<3; cnt++)
       
   132 	{
       
   133 		if(read_fifo(fifopath[cnt], res))
       
   134 			{
       
   135 			std_log(LOG_FILENAME_LINE,"Failed to read FIFO for %d exe and %s", cnt, res);
       
   136 			create_xml(1);
       
   137 			return 1;
       
   138 			}
       
   139 	}	
       
   140 	
       
   141 	std_log(LOG_FILENAME_LINE,"Test Successful");
       
   142 	create_xml(0);
       
   143 	return 0;
       
   144 }