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