2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Class implementing the interface to the "testman" Web Service
5 * COPYRIGHT: Copyright 2009-2015 Colin Finck <colin@reactos.org>
10 static const WCHAR szHostname
[] = L
"reactos.org";
11 static const WCHAR szServerFile
[] = L
"sites/all/modules/reactos/testman/webservice/";
14 * Constructs a CWebService object and immediately establishes a connection to the "testman" Web Service.
16 CWebService::CWebService()
18 /* Zero-initialize variables */
20 m_hHTTPRequest
= NULL
;
23 /* Establish an internet connection to the "testman" server */
24 m_hInet
= InternetOpenW(L
"rosautotest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
27 FATAL("InternetOpenW failed\n");
29 m_hHTTP
= InternetConnectW(m_hInet
, szHostname
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
32 FATAL("InternetConnectW failed\n");
36 * Destructs a CWebService object and closes all connections to the Web Service.
38 CWebService::~CWebService()
41 InternetCloseHandle(m_hInet
);
44 InternetCloseHandle(m_hHTTP
);
47 InternetCloseHandle(m_hHTTPRequest
);
54 * Sends data to the Web Service.
57 * A std::string containing all the data, which is going to be submitted as HTTP POST data.
60 * Returns a pointer to a char array containing the data received from the Web Service.
61 * The caller needs to free that pointer.
64 CWebService::DoRequest(const string
& InputData
)
66 const WCHAR szHeaders
[] = L
"Content-Type: application/x-www-form-urlencoded";
68 auto_array_ptr
<char> Data
;
71 /* Post our test results to the web service */
72 m_hHTTPRequest
= HttpOpenRequestW(m_hHTTP
, L
"POST", szServerFile
, NULL
, NULL
, NULL
, INTERNET_FLAG_NO_COOKIES
| INTERNET_FLAG_RELOAD
| INTERNET_FLAG_NO_CACHE_WRITE
, 0);
75 FATAL("HttpOpenRequestW failed\n");
77 Data
.reset(new char[InputData
.size() + 1]);
78 strcpy(Data
, InputData
.c_str());
80 if(!HttpSendRequestW(m_hHTTPRequest
, szHeaders
, wcslen(szHeaders
), Data
, InputData
.size()))
81 FATAL("HttpSendRequestW failed\n");
83 /* Get the response */
84 if(!InternetQueryDataAvailable(m_hHTTPRequest
, &DataLength
, 0, 0))
85 FATAL("InternetQueryDataAvailable failed\n");
87 Data
.reset(new char[DataLength
+ 1]);
89 if(!InternetReadFile(m_hHTTPRequest
, Data
, DataLength
, &DataLength
))
90 FATAL("InternetReadFile failed\n");
94 return Data
.release();
98 * Requests a Test ID from the Web Service for our test run.
101 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
104 CWebService::GetTestID(const char* TestType
)
108 Data
= "action=gettestid";
109 Data
+= Configuration
.GetAuthenticationRequestString();
110 Data
+= Configuration
.GetSystemInfoRequestString();
111 Data
+= "&testtype=";
114 if(!Configuration
.GetComment().empty())
117 Data
+= Configuration
.GetComment();
120 m_TestID
= DoRequest(Data
);
122 /* Verify that this is really a number */
123 if(!IsNumber(m_TestID
))
127 ss
<< "Expected Test ID, but received:" << endl
<< m_TestID
<< endl
;
133 * Gets a Suite ID from the Web Service for this module/test combination.
136 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
139 * Pointer to a CTestInfo object containing information about the test
142 * Returns a pointer to a char array containing the Suite ID received from the Web Service.
143 * The caller needs to free that pointer.
146 CWebService::GetSuiteID(const char* TestType
, CTestInfo
* TestInfo
)
148 auto_array_ptr
<char> SuiteID
;
151 Data
= "action=getsuiteid";
152 Data
+= Configuration
.GetAuthenticationRequestString();
153 Data
+= "&testtype=";
156 Data
+= TestInfo
->Module
;
158 Data
+= TestInfo
->Test
;
160 SuiteID
.reset(DoRequest(Data
));
162 /* Verify that this is really a number */
163 if(!IsNumber(SuiteID
))
167 ss
<< "Expected Suite ID, but received:" << endl
<< SuiteID
<< endl
;
171 return SuiteID
.release();
175 * Interface to other classes for submitting a result of one test
178 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
181 * Pointer to a CTestInfo object containing information about the test
184 CWebService::Submit(const char* TestType
, CTestInfo
* TestInfo
)
186 auto_array_ptr
<char> Response
;
187 auto_array_ptr
<char> SuiteID
;
194 SuiteID
.reset(GetSuiteID(TestType
, TestInfo
));
196 Data
= "action=submit";
197 Data
+= Configuration
.GetAuthenticationRequestString();
198 Data
+= "&testtype=";
205 Data
+= TestInfo
->Log
;
207 Response
.reset(DoRequest(Data
));
209 ss
<< "The server responded:" << endl
<< Response
<< endl
;
212 if(strcmp(Response
, "OK"))
213 EXCEPTION("Aborted!\n");