Reactos
at master 181 lines 4.7 kB view raw
1/* 2 * PROJECT: ReactOS Automatic Testing Utility 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Class implementing the interface to the "testman" Web Service 5 * COPYRIGHT: Copyright 2009-2020 Colin Finck (colin@reactos.org) 6 */ 7 8#include "precomp.h" 9 10static const CHAR szHostname[] = "reactos.org"; 11static const INTERNET_PORT ServerPort = 8443; 12static const CHAR szServerFile[] = "testman/webservice/"; 13 14/** 15 * Constructs a CWebService object and immediately establishes a connection to the "testman" Web Service. 16 */ 17CWebService::CWebService() 18{ 19 /* Zero-initialize variables */ 20 m_TestID = NULL; 21} 22 23/** 24 * Destructs a CWebService object and closes all connections to the Web Service. 25 */ 26CWebService::~CWebService() 27{ 28 if(m_TestID) 29 delete m_TestID; 30} 31 32/** 33* Interface to other classes for finishing this test run 34* 35* @param TestType 36* Constant pointer to a char array containing the test type to be run (i.e. "wine") 37*/ 38void 39CWebService::Finish(const char* TestType) 40{ 41 auto_array_ptr<char> Response; 42 string Data; 43 stringstream ss; 44 45 if (!m_TestID) 46 EXCEPTION("CWebService::Finish was called, but not a single result had been submitted!\n"); 47 48 Data = "action=finish"; 49 Data += Configuration.GetAuthenticationRequestString(); 50 Data += "&testtype="; 51 Data += TestType; 52 Data += "&testid="; 53 Data += m_TestID; 54 55 Response.reset(DoRequest(szHostname, ServerPort, szServerFile, Data)); 56 57 if (strcmp(Response, "OK")) 58 { 59 ss << "When finishing the test run, the server responded:" << endl << Response << endl; 60 SSEXCEPTION; 61 } 62} 63 64/** 65 * Requests a Test ID from the Web Service for our test run. 66 * 67 * @param TestType 68 * Constant pointer to a char array containing the test type to be run (i.e. "wine") 69 */ 70void 71CWebService::GetTestID(const char* TestType) 72{ 73 string Data; 74 75 Data = "action=gettestid"; 76 Data += Configuration.GetAuthenticationRequestString(); 77 Data += Configuration.GetSystemInfoRequestString(); 78 Data += "&testtype="; 79 Data += TestType; 80 81 if(!Configuration.GetComment().empty()) 82 { 83 Data += "&comment="; 84 Data += Configuration.GetComment(); 85 } 86 87 m_TestID = DoRequest(szHostname, ServerPort, szServerFile, Data); 88 89 /* Verify that this is really a number */ 90 if(!IsNumber(m_TestID)) 91 { 92 stringstream ss; 93 94 ss << "Expected Test ID, but received:" << endl << m_TestID << endl; 95 SSEXCEPTION; 96 } 97} 98 99/** 100 * Gets a Suite ID from the Web Service for this module/test combination. 101 * 102 * @param TestType 103 * Constant pointer to a char array containing the test type to be run (i.e. "wine") 104 * 105 * @param TestInfo 106 * Pointer to a CTestInfo object containing information about the test 107 * 108 * @return 109 * Returns a pointer to a char array containing the Suite ID received from the Web Service. 110 * The caller needs to free that pointer. 111 */ 112PCHAR 113CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo) 114{ 115 auto_array_ptr<char> SuiteID; 116 string Data; 117 118 Data = "action=getsuiteid"; 119 Data += Configuration.GetAuthenticationRequestString(); 120 Data += "&testtype="; 121 Data += TestType; 122 Data += "&module="; 123 Data += TestInfo->Module; 124 Data += "&test="; 125 Data += TestInfo->Test; 126 127 SuiteID.reset(DoRequest(szHostname, ServerPort, szServerFile, Data)); 128 129 /* Verify that this is really a number */ 130 if(!IsNumber(SuiteID)) 131 { 132 stringstream ss; 133 134 ss << "Expected Suite ID, but received:" << endl << SuiteID << endl; 135 SSEXCEPTION; 136 } 137 138 return SuiteID.release(); 139} 140 141/** 142 * Interface to other classes for submitting a result of one test 143 * 144 * @param TestType 145 * Constant pointer to a char array containing the test type to be run (i.e. "wine") 146 * 147 * @param TestInfo 148 * Pointer to a CTestInfo object containing information about the test 149 */ 150void 151CWebService::Submit(const char* TestType, CTestInfo* TestInfo) 152{ 153 auto_array_ptr<char> Response; 154 auto_array_ptr<char> SuiteID; 155 string Data; 156 stringstream ss; 157 158 if(!m_TestID) 159 GetTestID(TestType); 160 161 SuiteID.reset(GetSuiteID(TestType, TestInfo)); 162 163 Data = "action=submit"; 164 Data += Configuration.GetAuthenticationRequestString(); 165 Data += "&testtype="; 166 Data += TestType; 167 Data += "&testid="; 168 Data += m_TestID; 169 Data += "&suiteid="; 170 Data += SuiteID; 171 Data += "&log="; 172 Data += EscapeString(TestInfo->Log); 173 174 Response.reset(DoRequest(szHostname, ServerPort, szServerFile, Data)); 175 176 if (strcmp(Response, "OK")) 177 { 178 ss << "When submitting the result, the server responded:" << endl << Response << endl; 179 SSEXCEPTION; 180 } 181}