Support output to debug window in Windows

This commit is contained in:
Phil Nash 2011-03-21 12:36:58 +00:00
parent 7f52eda048
commit e9e6b90219

View File

@ -17,6 +17,12 @@
#include <iostream> #include <iostream>
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) #if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
#define CATCH_PLATFORM_MAC
#elif defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
#define CATCH_PLATFORM_WINDOWS
#endif
#ifdef CATCH_PLATFORM_MAC
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
@ -80,9 +86,9 @@
inline void BreakIntoDebugger(){} inline void BreakIntoDebugger(){}
#endif #endif
#elif defined(__WIN32__) && defined(_MSC_VER) #elif defined(CATCH_PLATFORM_WINDOWS)
// Thanks to jalfd for the following:
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );
#define BreakIntoDebugger() if (IsDebuggerPresent() ) { __debugbreak(); } #define BreakIntoDebugger() if (IsDebuggerPresent() ) { __debugbreak(); }
#else #else
inline void BreakIntoDebugger(){} inline void BreakIntoDebugger(){}
@ -90,14 +96,12 @@
inline void writeToDebugConsole( const std::string& text ) inline void writeToDebugConsole( const std::string& text )
{ {
// !TBD: Get Windows version working #ifdef CATCH_PLATFORM_WINDOWS
// - need to declare OutputDebugStringA without Windows.h ::OutputDebugStringA( text.c_str() );
//#ifdef _WIN32 #else
// ::OutputDebugStringA( text.c_str() );
//#else
// !TBD: Need a version for Mac/ XCode and other IDEs // !TBD: Need a version for Mac/ XCode and other IDEs
std::cout << text; std::cout << text;
//#endif #endif
} }
#endif // TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED