31
|
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_bus_request_name0_log1.txt"
|
|
28 |
#include "std_log_result.h"
|
|
29 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
|
30 |
|
|
31 |
int CheckConnection(DBusConnection* conn, DBusError* error)
|
|
32 |
{
|
|
33 |
if(!conn)
|
|
34 |
{
|
|
35 |
std_log(LOG_FILENAME_LINE,"Failed to get connection with error :: %s\n%s", error->name, error->message);
|
|
36 |
|
|
37 |
dbus_error_free(error);
|
|
38 |
return FALSE;
|
|
39 |
}
|
|
40 |
|
|
41 |
return TRUE;
|
|
42 |
}
|
|
43 |
|
|
44 |
void create_xml(int result)
|
|
45 |
{
|
|
46 |
if(result)
|
|
47 |
assert_failed = 1;
|
|
48 |
|
|
49 |
testResultXml("dbus_bus_request_name0");
|
|
50 |
close_log_file();
|
|
51 |
}
|
|
52 |
|
|
53 |
int main()
|
|
54 |
{
|
|
55 |
|
|
56 |
DBusConnection* connection;
|
|
57 |
DBusError error;
|
|
58 |
DBusError error1;
|
|
59 |
int result;
|
|
60 |
|
|
61 |
FILE* fp;
|
|
62 |
char buf[20];
|
|
63 |
const char* fifopath = "C:\\mkfifo2.file";
|
|
64 |
int err;
|
|
65 |
int fd;
|
|
66 |
|
|
67 |
dbus_error_init(&error);
|
|
68 |
dbus_error_init(&error1);
|
|
69 |
connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
|
|
70 |
if(!CheckConnection(connection, &error))
|
|
71 |
{
|
|
72 |
std_log(LOG_FILENAME_LINE,"Failed to Open the connection with Error :: %s", error.name);
|
|
73 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
|
74 |
create_xml(1);
|
|
75 |
return 1;
|
|
76 |
}
|
|
77 |
|
|
78 |
result = dbus_bus_request_name(connection, "Test.Method.Call", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error1);
|
|
79 |
if(result == -1)
|
|
80 |
std_log(LOG_FILENAME_LINE,"Error Set :: %s\n%s", error1.name,error1.message);
|
|
81 |
if(result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
|
|
82 |
{
|
|
83 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
|
84 |
create_xml(1);
|
|
85 |
return 1;
|
|
86 |
}
|
|
87 |
|
|
88 |
result = dbus_bus_request_name(connection, "Test.Method.Call2", DBUS_NAME_FLAG_REPLACE_EXISTING, &error1);
|
|
89 |
if(result == -1)
|
|
90 |
std_log(LOG_FILENAME_LINE,"Error Set :: %s\n%s", error1.name,error1.message);
|
|
91 |
if(result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
|
|
92 |
{
|
|
93 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
|
94 |
create_xml(1);
|
|
95 |
return 1;
|
|
96 |
}
|
|
97 |
|
|
98 |
result = dbus_bus_request_name(connection, "Test.Method.Call2", DBUS_NAME_FLAG_REPLACE_EXISTING, &error1);
|
|
99 |
if(result == -1)
|
|
100 |
std_log(LOG_FILENAME_LINE,"Error Set :: %s\n%s", error1.name,error1.message);
|
|
101 |
if(result != DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER )
|
|
102 |
{
|
|
103 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
|
104 |
create_xml(1);
|
|
105 |
return 1;
|
|
106 |
}
|
|
107 |
|
|
108 |
//for FIFO
|
|
109 |
|
|
110 |
err = mkfifo (fifopath, 0666);
|
|
111 |
if(err != 0)
|
|
112 |
{
|
|
113 |
// probably file already exists, delete the file
|
|
114 |
unlink(fifopath);
|
|
115 |
// try once more..
|
|
116 |
err = mkfifo (fifopath, 0666);
|
|
117 |
if(err != 0)
|
|
118 |
{
|
|
119 |
return 1;
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
#if defined(__WINSCW__) || defined(__WINS__)
|
|
124 |
fp = popen("z:\\sys\\bin\\request_name.exe","r");
|
|
125 |
#else
|
|
126 |
fp = popen("c:\\sys\\bin\\request_name.exe","r");
|
|
127 |
#endif
|
|
128 |
if(!fp)
|
|
129 |
{
|
|
130 |
std_log(LOG_FILENAME_LINE,"fp is NULL.");
|
|
131 |
create_xml(1);
|
|
132 |
return 1;
|
|
133 |
}
|
|
134 |
|
|
135 |
fd = open(fifopath, O_RDONLY);
|
|
136 |
if(fd > 0)
|
|
137 |
{
|
|
138 |
err = read (fd, buf, 20);
|
|
139 |
if(!strcmp("Error Occured", buf))
|
|
140 |
{
|
|
141 |
std_log(LOG_FILENAME_LINE,"Error while requesting name in request_name.exe.");
|
|
142 |
create_xml(1);
|
|
143 |
return 1;
|
|
144 |
}
|
|
145 |
close(fd);
|
|
146 |
}
|
|
147 |
else
|
|
148 |
{
|
|
149 |
std_log(LOG_FILENAME_LINE,"Error in FIFO open().");
|
|
150 |
create_xml(1);
|
|
151 |
return 1;
|
|
152 |
}
|
|
153 |
unlink(fifopath);
|
|
154 |
if(strcmp("done", buf))
|
|
155 |
{
|
|
156 |
create_xml(1);
|
|
157 |
return 1;
|
|
158 |
}
|
|
159 |
result = dbus_bus_request_name(connection, "Test.Method.Call3", DBUS_NAME_FLAG_DO_NOT_QUEUE , &error1);
|
|
160 |
if(result == -1)
|
|
161 |
std_log(LOG_FILENAME_LINE,"Error Set :: %s\n%s", error1.name,error1.message);
|
|
162 |
if(result != DBUS_REQUEST_NAME_REPLY_EXISTS )
|
|
163 |
{
|
|
164 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
|
165 |
create_xml(1);
|
|
166 |
return 1;
|
|
167 |
}
|
|
168 |
|
|
169 |
dbus_connection_close(connection);
|
|
170 |
dbus_connection_unref(connection);
|
|
171 |
dbus_shutdown();
|
|
172 |
|
|
173 |
std_log(LOG_FILENAME_LINE,"Test Successful");
|
|
174 |
create_xml(0);
|
|
175 |
return 0;
|
|
176 |
|
|
177 |
}
|