mirror of
https://github.com/reactos/reactos.git
synced 2025-07-04 17:41:23 +00:00
[ROSAUTOTEST] Change custom auto_array_ptr to std::unique_ptr
This commit is contained in:
parent
296192685b
commit
9ff3adb7d7
5 changed files with 20 additions and 83 deletions
|
@ -21,6 +21,7 @@ list(APPEND SOURCE
|
||||||
precomp.h)
|
precomp.h)
|
||||||
|
|
||||||
add_executable(rosautotest ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/rosautotestmsg.rc)
|
add_executable(rosautotest ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/rosautotestmsg.rc)
|
||||||
|
set_property(TARGET rosautotest PROPERTY CXX_STANDARD 11)
|
||||||
set_module_type(rosautotest win32cui UNICODE)
|
set_module_type(rosautotest win32cui UNICODE)
|
||||||
add_importlibs(rosautotest advapi32 shell32 user32 wininet msvcrt kernel32 ntdll)
|
add_importlibs(rosautotest advapi32 shell32 user32 wininet msvcrt kernel32 ntdll)
|
||||||
add_pch(rosautotest precomp.h SOURCE)
|
add_pch(rosautotest precomp.h SOURCE)
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
*/
|
*/
|
||||||
CProcess::CProcess(const wstring& CommandLine, LPSTARTUPINFOW StartupInfo)
|
CProcess::CProcess(const wstring& CommandLine, LPSTARTUPINFOW StartupInfo)
|
||||||
{
|
{
|
||||||
auto_array_ptr<WCHAR> CommandLinePtr(new WCHAR[CommandLine.size() + 1]);
|
unique_ptr<WCHAR[]> CommandLinePtr(new WCHAR[CommandLine.size() + 1]);
|
||||||
|
|
||||||
wcscpy(CommandLinePtr, CommandLine.c_str());
|
wcscpy(CommandLinePtr.get(), CommandLine.c_str());
|
||||||
|
|
||||||
if(!CreateProcessW(NULL, CommandLinePtr, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo))
|
if(!CreateProcessW(NULL, CommandLinePtr.get(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo))
|
||||||
TESTEXCEPTION("CreateProcessW failed\n");
|
TESTEXCEPTION("CreateProcessW failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ CWebService::DoRequest(const string& InputData)
|
||||||
{
|
{
|
||||||
const WCHAR szHeaders[] = L"Content-Type: application/x-www-form-urlencoded";
|
const WCHAR szHeaders[] = L"Content-Type: application/x-www-form-urlencoded";
|
||||||
|
|
||||||
auto_array_ptr<char> Data;
|
unique_ptr<char[]> Data;
|
||||||
DWORD DataLength;
|
DWORD DataLength;
|
||||||
|
|
||||||
/* Post our test results to the web service */
|
/* Post our test results to the web service */
|
||||||
|
@ -76,9 +76,9 @@ CWebService::DoRequest(const string& InputData)
|
||||||
FATAL("HttpOpenRequestW failed\n");
|
FATAL("HttpOpenRequestW failed\n");
|
||||||
|
|
||||||
Data.reset(new char[InputData.size() + 1]);
|
Data.reset(new char[InputData.size() + 1]);
|
||||||
strcpy(Data, InputData.c_str());
|
strcpy(Data.get(), InputData.c_str());
|
||||||
|
|
||||||
if(!HttpSendRequestW(m_hHTTPRequest, szHeaders, lstrlenW(szHeaders), Data, (DWORD)InputData.size()))
|
if(!HttpSendRequestW(m_hHTTPRequest, szHeaders, lstrlenW(szHeaders), Data.get(), (DWORD)InputData.size()))
|
||||||
FATAL("HttpSendRequestW failed\n");
|
FATAL("HttpSendRequestW failed\n");
|
||||||
|
|
||||||
/* Get the response */
|
/* Get the response */
|
||||||
|
@ -87,7 +87,7 @@ CWebService::DoRequest(const string& InputData)
|
||||||
|
|
||||||
Data.reset(new char[DataLength + 1]);
|
Data.reset(new char[DataLength + 1]);
|
||||||
|
|
||||||
if(!InternetReadFile(m_hHTTPRequest, Data, DataLength, &DataLength))
|
if(!InternetReadFile(m_hHTTPRequest, Data.get(), DataLength, &DataLength))
|
||||||
FATAL("InternetReadFile failed\n");
|
FATAL("InternetReadFile failed\n");
|
||||||
|
|
||||||
Data[DataLength] = 0;
|
Data[DataLength] = 0;
|
||||||
|
@ -104,7 +104,7 @@ CWebService::DoRequest(const string& InputData)
|
||||||
void
|
void
|
||||||
CWebService::Finish(const char* TestType)
|
CWebService::Finish(const char* TestType)
|
||||||
{
|
{
|
||||||
auto_array_ptr<char> Response;
|
unique_ptr<char[]> Response;
|
||||||
string Data;
|
string Data;
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
|
@ -120,9 +120,9 @@ CWebService::Finish(const char* TestType)
|
||||||
|
|
||||||
Response.reset(DoRequest(Data));
|
Response.reset(DoRequest(Data));
|
||||||
|
|
||||||
if (strcmp(Response, "OK"))
|
if (strcmp(Response.get(), "OK"))
|
||||||
{
|
{
|
||||||
ss << "When finishing the test run, the server responded:" << endl << Response << endl;
|
ss << "When finishing the test run, the server responded:" << endl << Response.get() << endl;
|
||||||
SSEXCEPTION;
|
SSEXCEPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ CWebService::GetTestID(const char* TestType)
|
||||||
PCHAR
|
PCHAR
|
||||||
CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
|
CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
|
||||||
{
|
{
|
||||||
auto_array_ptr<char> SuiteID;
|
unique_ptr<char[]> SuiteID;
|
||||||
string Data;
|
string Data;
|
||||||
|
|
||||||
Data = "action=getsuiteid";
|
Data = "action=getsuiteid";
|
||||||
|
@ -193,11 +193,11 @@ CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
|
||||||
SuiteID.reset(DoRequest(Data));
|
SuiteID.reset(DoRequest(Data));
|
||||||
|
|
||||||
/* Verify that this is really a number */
|
/* Verify that this is really a number */
|
||||||
if(!IsNumber(SuiteID))
|
if(!IsNumber(SuiteID.get()))
|
||||||
{
|
{
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
ss << "Expected Suite ID, but received:" << endl << SuiteID << endl;
|
ss << "Expected Suite ID, but received:" << endl << SuiteID.get() << endl;
|
||||||
SSEXCEPTION;
|
SSEXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,8 +216,8 @@ CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
|
||||||
void
|
void
|
||||||
CWebService::Submit(const char* TestType, CTestInfo* TestInfo)
|
CWebService::Submit(const char* TestType, CTestInfo* TestInfo)
|
||||||
{
|
{
|
||||||
auto_array_ptr<char> Response;
|
unique_ptr<char[]> Response;
|
||||||
auto_array_ptr<char> SuiteID;
|
unique_ptr<char[]> SuiteID;
|
||||||
string Data;
|
string Data;
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
|
||||||
|
@ -233,15 +233,15 @@ CWebService::Submit(const char* TestType, CTestInfo* TestInfo)
|
||||||
Data += "&testid=";
|
Data += "&testid=";
|
||||||
Data += m_TestID;
|
Data += m_TestID;
|
||||||
Data += "&suiteid=";
|
Data += "&suiteid=";
|
||||||
Data += SuiteID;
|
Data += SuiteID.get();
|
||||||
Data += "&log=";
|
Data += "&log=";
|
||||||
Data += EscapeString(TestInfo->Log);
|
Data += EscapeString(TestInfo->Log);
|
||||||
|
|
||||||
Response.reset(DoRequest(Data));
|
Response.reset(DoRequest(Data));
|
||||||
|
|
||||||
if (strcmp(Response, "OK"))
|
if (strcmp(Response.get(), "OK"))
|
||||||
{
|
{
|
||||||
ss << "When submitting the result, the server responded:" << endl << Response << endl;
|
ss << "When submitting the result, the server responded:" << endl << Response.get() << endl;
|
||||||
SSEXCEPTION;
|
SSEXCEPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* PROJECT: ReactOS Automatic Testing Utility
|
|
||||||
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
||||||
* PURPOSE: Template similar to std::auto_ptr for arrays
|
|
||||||
* COPYRIGHT: Copyright 2009 Colin Finck (colin@reactos.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
class auto_array_ptr
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Type* m_Ptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef Type element_type;
|
|
||||||
|
|
||||||
/* Construct an auto_array_ptr from a pointer */
|
|
||||||
explicit auto_array_ptr(Type* Ptr = 0) throw()
|
|
||||||
: m_Ptr(Ptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct an auto_array_ptr from an existing auto_array_ptr */
|
|
||||||
auto_array_ptr(auto_array_ptr<Type>& Right) throw()
|
|
||||||
: m_Ptr(Right.release())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destruct the auto_array_ptr and remove the corresponding array from memory */
|
|
||||||
~auto_array_ptr() throw()
|
|
||||||
{
|
|
||||||
delete[] m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the pointer address */
|
|
||||||
Type* get() const throw()
|
|
||||||
{
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release the pointer */
|
|
||||||
Type* release() throw()
|
|
||||||
{
|
|
||||||
Type* Tmp = m_Ptr;
|
|
||||||
m_Ptr = 0;
|
|
||||||
|
|
||||||
return Tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset to a new pointer */
|
|
||||||
void reset(Type* Ptr = 0) throw()
|
|
||||||
{
|
|
||||||
if(Ptr != m_Ptr)
|
|
||||||
delete[] m_Ptr;
|
|
||||||
|
|
||||||
m_Ptr = Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Simulate all the functionality of real arrays by casting the auto_array_ptr to Type* on demand */
|
|
||||||
operator Type*() const throw()
|
|
||||||
{
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -33,7 +33,7 @@ using namespace std;
|
||||||
#include <reactos/buildno.h>
|
#include <reactos/buildno.h>
|
||||||
|
|
||||||
/* Class includes */
|
/* Class includes */
|
||||||
#include "auto_array_ptr.h"
|
// #include "auto_array_ptr.h"
|
||||||
#include "CConfiguration.h"
|
#include "CConfiguration.h"
|
||||||
#include "CFatalException.h"
|
#include "CFatalException.h"
|
||||||
#include "CInvalidParameterException.h"
|
#include "CInvalidParameterException.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue