change: single_include: WinCE compatibility.

This commit is contained in:
Vladimir Stepanov 2016-01-08 13:00:46 +01:00
parent f294c98472
commit 784f2ef98f

View File

@ -4423,6 +4423,35 @@ STITCH_CLARA_CLOSE_NAMESPACE
#include <fstream> #include <fstream>
#ifdef _WIN32_WCE
namespace CATCH_WIN_CE
{
time_t time(time_t* p)
{
SYSTEMTIME systime;
GetSystemTime(&systime);
FILETIME ft;
if(!SystemTimeToFileTime(&systime, &ft))
throw std::runtime_error("could not convert local time to file time");
/* convert
1. FILETIME to int64_t
2. 100ns to seconds
3. epoch beginning 1601 to one beginning 1970
4. int64_t to time_t */
LONGLONG t64 = (static_cast<LONGLONG>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
t64 = (t64 + 5000000) / 10000000;
t64 -= 11644473600;
std::time_t res = static_cast<std::time_t>(t64);
// make sure the static cast didn't truncate the result
if(res != t64)
throw std::runtime_error("could not convert t64 to time_t");
if(p)
*p = res;
return res;
}
}
#endif
namespace Catch { namespace Catch {
inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; } inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
@ -4452,7 +4481,12 @@ namespace Catch {
} }
inline void setRngSeed( ConfigData& config, std::string const& seed ) { inline void setRngSeed( ConfigData& config, std::string const& seed ) {
if( seed == "time" ) { if( seed == "time" ) {
config.rngSeed = static_cast<unsigned int>( std::time(0) ); //WinCE compatibility
#ifndef _WIN32_WCE
config.rngSeed = static_cast<unsigned int>( std::time(0) );
#else
config.rngSeed = static_cast<unsigned int>( CATCH_WIN_CE::time(0) );
#endif
} }
else { else {
std::stringstream ss; std::stringstream ss;
@ -6773,7 +6807,7 @@ namespace Catch {
namespace Catch { namespace Catch {
namespace { namespace {
#ifndef _WIN32_WCE
class Win32ColourImpl : public IColourImpl { class Win32ColourImpl : public IColourImpl {
public: public:
Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
@ -6817,7 +6851,8 @@ namespace {
static Win32ColourImpl s_instance; static Win32ColourImpl s_instance;
return &s_instance; return &s_instance;
} }
#else
#endif
} // end anon namespace } // end anon namespace
} // end namespace Catch } // end namespace Catch
@ -6891,9 +6926,14 @@ namespace Catch {
Colour::~Colour(){ if( !m_moved ) use( None ); } Colour::~Colour(){ if( !m_moved ) use( None ); }
void Colour::use( Code _colourCode ) { void Colour::use( Code _colourCode ) {
static IColourImpl* impl = isDebuggerActive() //WinCE compatibility
? NoColourImpl::instance() #ifndef _WIN32_WCE
: platformColourInstance(); static IColourImpl* impl = isDebuggerActive()
? NoColourImpl::instance()
: platformColourInstance();
#else
static IColourImpl* impl = NoColourImpl::instance();
#endif
impl->use( _colourCode ); impl->use( _colourCode );
} }
@ -7679,7 +7719,10 @@ namespace Catch {
} // namespace Catch } // namespace Catch
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#ifndef _WIN32_WCE
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
#else
#endif
namespace Catch { namespace Catch {
bool isDebuggerActive() { bool isDebuggerActive() {
return IsDebuggerPresent() != 0; return IsDebuggerPresent() != 0;
@ -7699,10 +7742,18 @@ namespace Catch {
#endif // Platform #endif // Platform
#ifdef CATCH_PLATFORM_WINDOWS #ifdef CATCH_PLATFORM_WINDOWS
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); #ifndef _WIN32_WCE//WinCE compatibility
extern "C" __declspec(dlliport) void __stdcall OutputDebugStringA( const char* );
#else
#endif
namespace Catch { namespace Catch {
void writeToDebugConsole( std::string const& text ) { void writeToDebugConsole( std::string const& text ) {
#ifndef _WIN32_WCE
::OutputDebugStringA( text.c_str() ); ::OutputDebugStringA( text.c_str() );
#else
USES_CONVERSION;
::OutputDebugString( A2W(text.c_str()) );
#endif
} }
} }
#else #else
@ -10200,4 +10251,3 @@ int main (int argc, char * const argv[]) {
using Catch::Detail::Approx; using Catch::Detail::Approx;
#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED