提交 b586e277 编写于 作者: A Alexey Milovidov

Removed old files after creating a submodules [#CLICKHOUSE-2].

上级 14d9a91b

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
此差异已折叠。
cmake_minimum_required(VERSION 2.8.0)
# POCO_BUILD_TYPE
# POCO_STATIC
# POCO_UNBUNDLED
# POCO_NO_LOCALE
#
# POCO_ENABLE_{COMPONENT}
# POCO_ENABLE_TESTS
project(Poco)
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/libversion" SHARED_LIBRARY_VERSION)
# Read the version information from the VERSION file
file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PACKAGE_VERSION )
message(STATUS "Poco package version: ${PACKAGE_VERSION}")
string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${PACKAGE_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${PACKAGE_VERSION})
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH ${PACKAGE_VERSION})
set(COMPLETE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(RELEASE_NAME "Unstable-trunk")
set(PROJECT_VERSION ${COMPLETE_VERSION})
# Put the libaries and binaries that get built into directories at the
# top of the build tree rather than in hard-to-find leaf
# directories. This simplifies manual testing and the use of the build
# tree rather than installed Boost libraries.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
# Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
# Append our module directory to CMake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
#################################################################################
# Setup C/C++ compiler options
#################################################################################
if(NOT MSVC_IDE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release" FORCE)
endif()
message(STATUS "Setting Poco build type - ${CMAKE_BUILD_TYPE}")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "")
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
endif ()
# http://www.cmake.org/Wiki/CMake_Useful_Variables :
# CMAKE_BUILD_TYPE
# Choose the type of build. CMake has default flags for these:
#
# * None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
# * Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
# * Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
# * RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
# * MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
# For Debug build types, append a "d" to the library names.
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
# Include some common macros to simpilfy the Poco CMake files
include(PocoMacros)
# Allow enabling and disabling components
option(POCO_ENABLE_XML "Enable the XML" ON)
option(POCO_ENABLE_MONGODB "Enable MongoDB" ON)
option(POCO_ENABLE_PDF "Enable PDF" OFF)
option(POCO_ENABLE_UTIL "Enable Util" ON)
option(POCO_ENABLE_NET "Enable Net" ON)
option(POCO_ENABLE_NETSSL "Enable NetSSL" ON)
option(POCO_ENABLE_NETSSL_WIN "Enable NetSSL Windows" OFF)
option(POCO_ENABLE_CRYPTO "Enable Crypto" ON)
option(POCO_ENABLE_DATA "Enable Data" ON)
option(POCO_ENABLE_DATA_SQLITE "Enable Data SQlite" OFF)
option(POCO_ENABLE_DATA_MYSQL "Enable Data MySQL" OFF)
option(POCO_ENABLE_DATA_ODBC "Enable Data ODBC" ON)
option(POCO_ENABLE_SEVENZIP "Enable SevenZip" OFF)
option(POCO_ENABLE_ZIP "Enable Zip" OFF)
option(POCO_ENABLE_APACHECONNECTOR "Enable ApacheConnector" OFF)
option(POCO_ENABLE_CPPPARSER "Enable C++ parser" OFF)
option(POCO_ENABLE_POCODOC "Enable Poco Documentation Generator" OFF)
option(FORCE_OPENSSL "Force usage of OpenSSL even under windows" OFF)
option(POCO_ENABLE_TESTS
"Set to OFF|ON (default is OFF) to control build of POCO tests & samples" OFF)
option(POCO_STATIC
"Set to OFF|ON (default is ON) to control build of POCO as STATIC library" ON)
option(POCO_UNBUNDLED
"Set to OFF|ON (default is OFF) to control linking dependencies as external" OFF)
# Uncomment from next two lines to force statitc or dynamic library, default is autodetection
if (POCO_STATIC)
add_definitions( -DPOCO_STATIC -DPOCO_NO_AUTOMATIC_LIBS)
set( LIB_MODE STATIC )
message(STATUS "Building static libraries")
else (POCO_STATIC)
set( LIB_MODE SHARED )
message(STATUS "Building dynamic libraries")
endif (POCO_STATIC)
if (POCO_ENABLE_TESTS)
include(CTest)
enable_testing()
message(STATUS "Building with unittests & samples")
else ()
message(STATUS "Building without tests & samples")
endif ()
if (POCO_UNBUNDLED)
add_definitions( -DPOCO_UNBUNDLED)
message(STATUS "Build with using external sqlite, pcre, expat ...")
else ()
message(STATUS "Build with using internal copy of sqlite, pcre, expat, ...")
endif ()
include(CheckTypeSize)
find_package(Cygwin)
# OS Detection
if(WIN32)
add_definitions( -DPOCO_OS_FAMILY_WINDOWS -DUNICODE -D_UNICODE)
#set(SYSLIBS iphlpapi gdi32 odbc32)
endif(WIN32)
if (UNIX AND NOT ANDROID )
add_definitions( -DPOCO_OS_FAMILY_UNIX )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field -Wno-unused-local-typedef -Wno-for-loop-analysis -Wno-unknown-pragmas -Wno-unused-variable")
if (APPLE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable")
# Standard 'must be' defines
if (APPLE)
add_definitions( -DPOCO_HAVE_IPv6 -DPOCO_NO_STAT64)
set(SYSLIBS ${CMAKE_DL_LIBS})
elseif (CMAKE_SYSTEM MATCHES "FreeBSD")
add_definitions(-D__BSD_VISIBLE ) # better #include <sys/cdefs.h>
add_definitions(-D_XOPEN_SOURCE=700 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_IPv6 -DPOCO_HAVE_FD_POLL)
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
else ()
add_definitions(-D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_FD_EPOLL -DPOCO_HAVE_IPv6)
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
endif ()
endif(UNIX AND NOT ANDROID )
if (CMAKE_SYSTEM MATCHES "SunOS")
add_definitions( -DPOCO_OS_FAMILY_UNIX )
# Standard 'must be' defines
add_definitions( -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 )
set(SYSLIBS pthread socket xnet nsl resolv rt ${CMAKE_DL_LIBS})
endif(CMAKE_SYSTEM MATCHES "SunOS")
if (CMAKE_COMPILER_IS_MINGW)
add_definitions(-DWC_NO_BEST_FIT_CHARS=0x400 -DPOCO_WIN32_UTF8)
add_definitions(-D_WIN32 -DMINGW32 -DWINVER=0x500 -DODBCVER=0x0300 -DPOCO_THREAD_STACK_SIZE)
endif (CMAKE_COMPILER_IS_MINGW)
if (CYGWIN)
# add_definitions(-DWC_NO_BEST_FIT_CHARS=0x400 -DPOCO_WIN32_UTF8)
endif (CYGWIN)
# SunPro C++
if (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
add_definitions( -D_BSD_SOURCE -library=stlport4)
endif (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
# iOS
if (IOS)
add_definitions( -DPOCO_HAVE_IPv6 -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_STAT64 -DPOCO_NO_SHAREDLIBS -DPOCO_NO_NET_IFTYPES )
endif (IOS)
#Android
if (ANDROID)
add_definitions( -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY )
endif (ANDROID)
# Collect the built libraries and include dirs, the will be used to create the PocoConfig.cmake file
set (Poco_COMPONENTS "")
if (POCO_ENABLE_TESTS)
add_subdirectory (CppUnit)
endif ()
add_subdirectory (Foundation)
if (POCO_ENABLE_XML)
add_subdirectory (XML)
list (APPEND Poco_COMPONENTS "XML")
endif ()
if (POCO_ENABLE_MONGODB)
add_subdirectory (MongoDB)
list (APPEND Poco_COMPONENTS "MongoDB")
endif ()
if (POCO_ENABLE_PDF)
add_subdirectory (PDF)
list (APPEND Poco_COMPONENTS "PDF")
endif()
if (POCO_ENABLE_UTIL)
add_subdirectory (Util)
list (APPEND Poco_COMPONENTS "Util")
endif ()
if (POCO_ENABLE_NET)
add_subdirectory (Net)
list (APPEND Poco_COMPONENTS "Net")
endif ()
#NetSSL
if(WIN32 AND POCO_ENABLE_NETSSL_WIN)
add_subdirectory(NetSSL_Win)
list(APPEND Poco_COMPONENTS "NetSSL_Win")
endif(WIN32 AND POCO_ENABLE_NETSSL_WIN)
find_package(OpenSSL)
if(OPENSSL_FOUND)
include_directories("${OPENSSL_INCLUDE_DIR}")
if(POCO_ENABLE_NETSSL)
add_subdirectory(NetSSL_OpenSSL)
list(APPEND Poco_COMPONENTS "NetSSL_OpenSSL")
endif()
if(POCO_ENABLE_CRYPTO)
add_subdirectory(Crypto)
list(APPEND Poco_COMPONENTS "Crypto")
endif()
endif(OPENSSL_FOUND)
if(POCO_ENABLE_DATA)
add_subdirectory(Data)
list(APPEND Poco_COMPONENTS "Data")
endif()
if(POCO_ENABLE_SEVENZIP)
add_subdirectory(SevenZip)
list(APPEND Poco_COMPONENTS "SevenZip")
endif()
if(POCO_ENABLE_ZIP)
add_subdirectory(Zip)
list(APPEND Poco_COMPONENTS "Zip")
endif()
find_package(APR)
find_package(Apache2)
if(APRUTIL_FOUND AND APACHE_FOUND)
include_directories( "${APACHE_INCLUDE_DIR}" "${APRUTIL_INCLUDE_DIR}" )
if(POCO_ENABLE_APACHECONNECTOR)
add_subdirectory(ApacheConnector)
list(APPEND Poco_COMPONENTS "ApacheConnector")
endif()
endif(APRUTIL_FOUND AND APACHE_FOUND)
if(POCO_ENABLE_CPPPARSER)
add_subdirectory(CppParser)
list(APPEND Poco_COMPONENTS "CppParser")
endif()
if(POCO_ENABLE_POCODOC)
add_subdirectory(PocoDoc)
list(APPEND Poco_COMPONENTS "PocoDoc")
endif()
#############################################################
# Uninstall stuff see: http://www.vtk.org/Wiki/CMake_FAQ
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
#############################################################
# Enable packaging
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Poco Libraries")
set(CPACK_PACKAGE_VENDOR "Applied Informatics Software Engineering GmbH")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local")
include(CPack)
#############################################################
# cmake config files
configure_file(cmake/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" @ONLY)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake
DESTINATION
"lib/cmake/${PROJECT_NAME}"
COMPONENT
Devel
)
# in tree build settings
#configure_file(PocoBuildTreeSettings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PocoBuildTreeSettings.cmake @ONLY)
message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
message(STATUS "Installation target path: ${CMAKE_INSTALL_PREFIX}")
foreach(component ${Poco_COMPONENTS})
message(STATUS "Building: ${component}")
endforeach()
Guenter Obiltschnig
Alex Fabijanic
Peter Schojer
Ferdinand Beyer
Krzysztof Burghardt
Claus Dabringer
Caleb Epstein
Eran Hammer-Lahav
Chris Johnson
Sergey Kholodilov
Ryan Kraay
Larry Lewis
Andrew J. P. Maclean
Andrew Marlow
Paschal Mushubi
Jiang Shan
David Shawley
Sergey Skorokhodov
Tom Tan
Sergey N. Yatskevich
Marc Chevrier
Philippe Cuvillier
Marian Krivos
Franky Braem
Philip Prindeville
Anton Yabchinskiy
Rangel Reale
Fabrizio Duhem
Patrick White
Mike Naquin
Roger Meier
Mathaus Mendel
Arturo Castro
Adrian Imboden
Matej Knopp
Patrice Tarabbia
Lucas Clemente
Karl Reid
Pascal Bach
Cristian Thiago Moecke
Sergei Nikulov
Aaron Kaluszka
Iyed Bennour
Scott Davis
Kristin Cowalcijk
Yuval Kashtan
Christopher Baker
Scott Davis
Jeff Adams
Martin Osborne
Björn Schramke
--
$Id$
//
// WinTestRunner.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/include/WinTestRunner/WinTestRunner.h#1 $
//
// Application shell for CppUnit's TestRunner dialog.
//
#ifndef WinTestRunner_H_INCLUDED
#define WinTestRunner_H_INCLUDED
#if !defined(POCO_STATIC)
#if defined(WinTestRunner_EXPORTS)
#define WinTestRunner_API __declspec(dllexport)
#else
#define WinTestRunner_API __declspec(dllimport)
#endif
#else
#define WinTestRunner_API
#endif
#include "CppUnit/CppUnit.h"
#include <vector>
#include <afxwin.h>
namespace CppUnit {
class Test;
class WinTestRunner_API WinTestRunner
{
public:
WinTestRunner();
~WinTestRunner();
void run();
void addTest(Test* pTest);
private:
std::vector<Test*> _tests;
};
class WinTestRunner_API WinTestRunnerApp: public CWinApp
/// A simple application class that hosts the TestRunner dialog.
/// Create a subclass and override the TestMain() method.
///
/// WinTestRunnerApp supports a batch mode, which runs the
/// test using the standard text-based TestRunner from CppUnit.
/// To enable batch mode, start the application with the "/b"
/// or "/B" argument. Optionally, a filename may be specified
/// where the test output will be written to: "/b:<path>" or
/// "/B:<path>".
///
/// When run in batch mode, the exit code of the application
/// will denote test success (0) or failure (1).
{
public:
virtual BOOL InitInstance();
virtual void TestMain() = 0;
DECLARE_MESSAGE_MAP()
};
} // namespace CppUnit
#endif // WinTestRunner_H_INCLUDED
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by TestRunner.rc
//
#define IDD_DIALOG_TESTRUNNER 129
#define IDC_LIST 1000
#define ID_RUN 1001
#define ID_STOP 1002
#define IDC_PROGRESS 1003
#define IDC_INDICATOR 1004
#define IDC_COMBO_TEST 1005
#define IDC_STATIC_RUNS 1007
#define IDC_STATIC_ERRORS 1008
#define IDC_STATIC_FAILURES 1009
#define IDC_EDIT_TIME 1010
#define IDC_CHK_AUTORUN 1013
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 131
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1014
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif\r\n"
"#include ""..\\res\\WinTestRunner.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "CppUnit WinTestRunner DLL"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "WinTestRunner"
VALUE "LegalCopyright", "Copyright (c) 2005"
VALUE "OriginalFilename", "TestRunner.dll"
VALUE "ProductName", "CppUnit WinTestRunner Dynamic Link Library"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG_TESTRUNNER DIALOGEX 0, 0, 512, 300
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "CppUnit WinTestRunner"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
COMBOBOX IDC_COMBO_TEST,7,20,424,273,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "Run",ID_RUN,455,7,50,14
DEFPUSHBUTTON "Stop",ID_STOP,455,24,50,14
CONTROL "List1",IDC_LIST,"SysListView32",LVS_REPORT | WS_BORDER |
WS_TABSTOP,7,110,498,160
PUSHBUTTON "Close",IDOK,455,279,50,14
LTEXT "Test Name:",IDC_STATIC,7,9,179,9
LTEXT "Progress:",IDC_STATIC,7,55,49,9
LTEXT "Errors and Failures:",IDC_STATIC,7,99,67,9
LTEXT "Runs:",IDC_STATIC,457,54,26,10
LTEXT "Failures:",IDC_STATIC,457,80,26,10
LTEXT "Errors:",IDC_STATIC,457,67,26,10
RTEXT "0",IDC_STATIC_RUNS,487,54,16,10
RTEXT "0",IDC_STATIC_ERRORS,487,67,16,10
RTEXT "0",IDC_STATIC_FAILURES,487,80,16,10
EDITTEXT IDC_EDIT_TIME,7,281,440,12,ES_AUTOHSCROLL | ES_READONLY |
NOT WS_BORDER
LTEXT "",IDC_PROGRESS,7,67,424,20,SS_SUNKEN | NOT WS_VISIBLE
CONTROL "Auto Run",IDC_CHK_AUTORUN,"Button",BS_AUTOCHECKBOX |
BS_LEFTTEXT | WS_TABSTOP,383,38,46,10
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG_TESTRUNNER, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 505
TOPMARGIN, 7
BOTTOMMARGIN, 293
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
//
// ActiveTest.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.cpp#1 $
//
#include <afxwin.h>
#include "ActiveTest.h"
namespace CppUnit {
// Spawn a thread to a test
void ActiveTest::run(TestResult* result)
{
CWinThread* thread;
setTestResult(result);
_runCompleted.ResetEvent();
thread = AfxBeginThread(threadFunction, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
DuplicateHandle(GetCurrentProcess(), thread->m_hThread, GetCurrentProcess(), &_threadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
thread->ResumeThread();
}
// Simple execution thread. Assuming that an ActiveTest instance
// only creates one of these at a time.
UINT ActiveTest::threadFunction(LPVOID thisInstance)
{
ActiveTest* test = (ActiveTest*) thisInstance;
test->run();
test->_runCompleted.SetEvent();
return 0;
}
} // namespace CppUnit
//
// ActiveTest.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.h#1 $
//
#ifndef ActiveTest_INCLUDED
#define ActiveTest_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestDecorator.h"
#include <afxmt.h>
namespace CppUnit {
/* A Microsoft-specific active test
*
* An active test manages its own
* thread of execution. This one
* is very simple and only sufficient
* for the limited use we put it through
* in the TestRunner. It spawns a thread
* on run (TestResult *) and signals
* completion of the test.
*
* We assume that only one thread
* will be active at once for each
* instance.
*
*/
class ActiveTest: public TestDecorator
{
public:
ActiveTest(Test* test);
~ActiveTest();
void run(TestResult* result);
protected:
HANDLE _threadHandle;
CEvent _runCompleted;
TestResult* _currentTestResult;
void run ();
void setTestResult(TestResult* result);
static UINT threadFunction(LPVOID thisInstance);
};
// Construct the active test
inline ActiveTest::ActiveTest(Test *test): TestDecorator(test)
{
_currentTestResult = NULL;
_threadHandle = INVALID_HANDLE_VALUE;
}
// Pend until the test has completed
inline ActiveTest::~ActiveTest()
{
CSingleLock(&_runCompleted, TRUE);
CloseHandle(_threadHandle);
}
// Set the test result that we are to run
inline void ActiveTest::setTestResult(TestResult* result)
{
_currentTestResult = result;
}
// Run our test result
inline void ActiveTest::run()
{
TestDecorator::run(_currentTestResult);
}
} // namespace CppUnit
#endif // ActiveTest_INCLUDED
//
// DLLMain.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/DLLMain.cpp#1 $
//
#include <afxwin.h>
#include <afxdllx.h>
static AFX_EXTENSION_MODULE TestRunnerDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("WinTestRunner.DLL Initializing\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(TestRunnerDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(TestRunnerDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("WinTestRunner.DLL Terminating\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(TestRunnerDLL);
}
return 1; // ok
}
//
// GUITestResult.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.cpp#1 $
//
#include "TestRunnerDlg.h"
#include "GUITestResult.h"
namespace CppUnit {
void GUITestResult::addError(Test *test, CppUnitException *e)
{
ExclusiveZone zone(_syncObject);
TestResult::addError(test, e);
_runner->addError(this, test, e);
}
void GUITestResult::addFailure(Test *test, CppUnitException *e)
{
ExclusiveZone zone(_syncObject);
TestResult::addFailure(test, e);
_runner->addFailure(this, test, e);
}
void GUITestResult::startTest(Test *test)
{
ExclusiveZone zone(_syncObject);
TestResult::startTest(test);
_runner->startTest(test);
}
void GUITestResult::endTest(Test *test)
{
ExclusiveZone zone(_syncObject);
TestResult::endTest(test);
_runner->endTest(this, test);
}
} // namespace CppUnit
//
// GUITestResult.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.h#1 $
//
#ifndef GuiTestResult_INCLUDED
#define GuiTestResult_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestResult.h"
#include <afxmt.h>
namespace CppUnit {
class TestRunnerDlg;
class GUITestResult: public TestResult
{
public:
GUITestResult(TestRunnerDlg* runner);
~GUITestResult();
void addError(Test* test, CppUnitException* e);
void addFailure(Test* test, CppUnitException* e);
void startTest(Test* test);
void endTest(Test* test);
void stop();
protected:
class LightweightSynchronizationObject: public TestResult::SynchronizationObject
{
public:
void lock()
{
_syncObject.Lock();
}
void unlock()
{
_syncObject.Unlock();
}
private:
CCriticalSection _syncObject;
};
private:
TestRunnerDlg *_runner;
};
// Construct with lightweight synchronization
inline GUITestResult::GUITestResult(TestRunnerDlg* runner): _runner(runner)
{
setSynchronizationObject(new LightweightSynchronizationObject());
}
// Destructor
inline GUITestResult::~GUITestResult()
{
}
// Override without protection to prevent deadlock
inline void GUITestResult::stop()
{
_stop = true;
}
} // namespace CppUnit
#endif // GuiTestResult_INCLUDED
//
// ProgressBar.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.cpp#1 $
//
#include "ProgressBar.h"
namespace CppUnit {
// Paint the progress bar in response to a paint message
void ProgressBar::paint(CDC& dc)
{
paintBackground (dc);
paintStatus (dc);
}
// Paint the background of the progress bar region
void ProgressBar::paintBackground (CDC& dc)
{
CBrush brshBackground;
CPen penGray (PS_SOLID, 1, RGB (128, 128, 128));
CPen penWhite (PS_SOLID, 1, RGB (255, 255, 255));
VERIFY (brshBackground.CreateSolidBrush (::GetSysColor (COLOR_BTNFACE)));
dc.FillRect (_bounds, &brshBackground);
CPen *pOldPen;
pOldPen = dc.SelectObject (&penGray);
{
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (&penWhite);
{
dc.MoveTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
dc.MoveTo (_bounds.left, _bounds.top + _bounds.Height () -1);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (pOldPen);
}
// Paint the actual status of the progress bar
void ProgressBar::paintStatus (CDC& dc)
{
if (_progress <= 0)
return;
CBrush brshStatus;
CRect rect (_bounds.left, _bounds.top,
_bounds.left + _progressX, _bounds.bottom);
COLORREF statusColor = getStatusColor ();
VERIFY (brshStatus.CreateSolidBrush (statusColor));
rect.DeflateRect (1, 1);
dc.FillRect (rect, &brshStatus);
}
// Paint the current step
void ProgressBar::paintStep (int startX, int endX)
{
// kludge: painting the whole region on each step
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
// Setup the progress bar for execution over a total number of steps
void ProgressBar::start (int total)
{
_total = total;
reset ();
}
// Take one step, indicating whether it was a successful step
void ProgressBar::step (bool successful)
{
_progress++;
int x = _progressX;
_progressX = scale (_progress);
if (!_error && !successful)
{
_error = true;
x = 1;
}
paintStep (x, _progressX);
}
// Map from steps to display units
int ProgressBar::scale (int value)
{
if (_total > 0)
return max (1, value * (_bounds.Width () - 1) / _total);
return value;
}
// Reset the progress bar
void ProgressBar::reset ()
{
_progressX = 1;
_progress = 0;
_error = false;
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
} // namespace CppUnit
//
// ProgressBar.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.h#1 $
//
#ifndef ProgressBar_INCLUDED
#define ProgressBar_INCLUDED
#include "CppUnit/CppUnit.h"
#include <afxwin.h>
namespace CppUnit {
/* A Simple ProgressBar for test execution display
*/
class ProgressBar
{
public:
ProgressBar(CWnd* baseWindow, CRect& bounds);
void step(bool successful);
void paint(CDC& dc);
int scale(int value);
void reset();
void start(int total);
protected:
void paintBackground(CDC& dc);
void paintStatus(CDC& dc);
COLORREF getStatusColor();
void paintStep(int startX, int endX);
CWnd* _baseWindow;
CRect _bounds;
bool _error;
int _total;
int _progress;
int _progressX;
};
// Construct a ProgressBar
inline ProgressBar::ProgressBar(CWnd* baseWindow, CRect& bounds):
_baseWindow(baseWindow),
_bounds(bounds),
_error(false),
_total(0),
_progress(0),
_progressX(0)
{
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
baseWindow->GetWindowInfo(&wi);
_bounds.OffsetRect(-wi.rcClient.left, -wi.rcClient.top);
}
// Get the current color
inline COLORREF ProgressBar::getStatusColor()
{
return _error ? RGB(255, 0, 0) : RGB(0, 255, 0);
}
} // namespace CppUnit
#endif // ProgressBar_INCLUDED
#ifndef SYNCHRONIZEDTESTRESULTDECORATOR_H
#define SYNCHRONIZEDTESTRESULTDECORATOR_H
#include <afxmt.h>
#include "TestResultDecorator.h"
class SynchronizedTestResult : public TestResultDecorator
{
public:
SynchronizedTestResult (TestResult *result);
~SynchronizedTestResult ();
bool shouldStop ();
void addError (Test *test, CppUnitException *e);
void addFailure (Test *test, CppUnitException *e);
void startTest (Test *test);
void endTest (Test *test);
int runTests ();
int testErrors ();
int testFailures ();
bool wasSuccessful ();
void stop ();
vector<TestFailure *>& errors ();
vector<TestFailure *>& failures ();
private:
CCriticalSection m_criticalSection;
};
// Constructor
inline SynchronizedTestResult::SynchronizedTestResult (TestResult *result)
: TestResultDecorator (result) {}
// Destructor
inline SynchronizedTestResult::~SynchronizedTestResult ()
{}
// Returns whether the test should stop
inline bool SynchronizedTestResult::shouldStop ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->shouldStop (); }
// Adds an error to the list of errors. The passed in exception
// caused the error
inline void SynchronizedTestResult::addError (Test *test, CppUnitException *e)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addError (test, e); }
// Adds a failure to the list of failures. The passed in exception
// caused the failure.
inline void SynchronizedTestResult::addFailure (Test *test, CppUnitException *e)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addFailure (test, e); }
// Informs the result that a test will be started.
inline void SynchronizedTestResult::startTest (Test *test)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->startTest (test); }
// Informs the result that a test was completed.
inline void SynchronizedTestResult::endTest (Test *test)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->endTest (test); }
// Gets the number of run tests.
inline int SynchronizedTestResult::runTests ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->runTests (); }
// Gets the number of detected errors.
inline int SynchronizedTestResult::testErrors ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testErrors (); }
// Gets the number of detected failures.
inline int SynchronizedTestResult::testFailures ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testFailures (); }
// Returns whether the entire test was successful or not.
inline bool SynchronizedTestResult::wasSuccessful ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->wasSuccessful (); }
// Marks that the test run should stop.
inline void SynchronizedTestResult::stop ()
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->stop (); }
// Returns a vector of the errors.
inline vector<TestFailure *>& SynchronizedTestResult::errors ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->errors (); }
// Returns a vector of the failures.
inline vector<TestFailure *>& SynchronizedTestResult::failures ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->failures (); }
#endif
#ifndef CPP_UNIT_TESTRESULTDECORATOR_H
#define CPP_UNIT_TESTRESULTDECORATOR_H
#include "TestResult.h"
class TestResultDecorator
{
public:
TestResultDecorator (TestResult *result);
virtual ~TestResultDecorator ();
virtual bool shouldStop ();
virtual void addError (Test *test, CppUnitException *e);
virtual void addFailure (Test *test, CppUnitException *e);
virtual void startTest (Test *test);
virtual void endTest (Test *test);
virtual int runTests ();
virtual int testErrors ();
virtual int testFailures ();
virtual bool wasSuccessful ();
virtual void stop ();
vector<TestFailure *>& errors ();
vector<TestFailure *>& failures ();
protected:
TestResult *m_result;
};
inline TestResultDecorator::TestResultDecorator (TestResult *result)
: m_result (result) {}
inline TestResultDecorator::~TestResultDecorator ()
{}
// Returns whether the test should stop
inline bool TestResultDecorator::shouldStop ()
{ return m_result->shouldStop (); }
// Adds an error to the list of errors. The passed in exception
// caused the error
inline void TestResultDecorator::addError (Test *test, CppUnitException *e)
{ m_result->addError (test, e); }
// Adds a failure to the list of failures. The passed in exception
// caused the failure.
inline void TestResultDecorator::addFailure (Test *test, CppUnitException *e)
{ m_result->addFailure (test, e); }
// Informs the result that a test will be started.
inline void TestResultDecorator::startTest (Test *test)
{ m_result->startTest (test); }
// Informs the result that a test was completed.
inline void TestResultDecorator::endTest (Test *test)
{ m_result->endTest (test); }
// Gets the number of run tests.
inline int TestResultDecorator::runTests ()
{ return m_result->runTests (); }
// Gets the number of detected errors.
inline int TestResultDecorator::testErrors ()
{ return m_result->testErrors (); }
// Gets the number of detected failures.
inline int TestResultDecorator::testFailures ()
{ return m_result->testFailures (); }
// Returns whether the entire test was successful or not.
inline bool TestResultDecorator::wasSuccessful ()
{ return m_result->wasSuccessful (); }
// Marks that the test run should stop.
inline void TestResultDecorator::stop ()
{ m_result->stop (); }
// Returns a vector of the errors.
inline vector<TestFailure *>& TestResultDecorator::errors ()
{ return m_result->errors (); }
// Returns a vector of the failures.
inline vector<TestFailure *>& TestResultDecorator::failures ()
{ return m_result->failures (); }
#endif
//
// TestRunnerDlg.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.cpp#1 $
//
#include <afxwin.h>
#include <afxext.h>
#include <afxcmn.h>
#include <mmsystem.h>
#include "TestRunnerDlg.h"
#include "ActiveTest.h"
#include "GUITestResult.h"
#include "ProgressBar.h"
#include "CppUnit/TestSuite.h"
#include "TestRunnerDlg.h"
namespace CppUnit {
TestRunnerDlg::TestRunnerDlg(CWnd* pParent): CDialog(TestRunnerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(TestRunnerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
_testsProgress = 0;
_selectedTest = 0;
_currentTest = 0;
}
void TestRunnerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TestRunnerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TestRunnerDlg, CDialog)
//{{AFX_MSG_MAP(TestRunnerDlg)
ON_BN_CLICKED(ID_RUN, OnRun)
ON_BN_CLICKED(ID_STOP, OnStop)
ON_CBN_SELCHANGE(IDC_COMBO_TEST, OnSelchangeComboTest)
ON_BN_CLICKED(IDC_CHK_AUTORUN, OnBnClickedAutorun)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL TestRunnerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
CComboBox *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
ASSERT (listCtrl);
ASSERT (comboBox);
CString title;
GetWindowText(title);
#if defined(_DEBUG)
title.Append(" [debug]");
#else
title.Append(" [release]");
#endif
SetWindowText(title);
listCtrl->InsertColumn (0,"Type", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("Type"), 1);
listCtrl->InsertColumn (1,"Name", LVCFMT_LEFT, 16 * listCtrl->GetStringWidth ("X"), 2);
listCtrl->InsertColumn (2,"Failed Condition", LVCFMT_LEFT, 24 * listCtrl->GetStringWidth ("M"), 3);
listCtrl->InsertColumn (3,"Line", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("0000"), 4);
listCtrl->InsertColumn (4,"File Name", LVCFMT_LEFT, 36 * listCtrl->GetStringWidth ("M"), 5);
int numberOfCases = 0;
CWinApp* pApp = AfxGetApp();
CString lastTestCS = pApp->GetProfileString("Tests", "lastTest");
std::string lastTest((LPCSTR) lastTestCS);
int sel = -1;
for (std::vector<TestInfo>::iterator it = _tests.begin (); it != _tests.end (); ++it)
{
std::string cbName(it->level*4, ' ');
cbName.append(it->pTest->toString());
comboBox->AddString (cbName.c_str ());
if (sel < 0)
{
if (lastTest.empty() || lastTest == it->pTest->toString())
{
_selectedTest = it->pTest;
sel = numberOfCases;
}
}
numberOfCases++;
}
if (numberOfCases > 0)
{
if (sel < 0)
{
_selectedTest = _tests[0].pTest;
sel = 0;
}
comboBox->SetCurSel (sel);
}
else
{
beRunDisabled ();
}
CWnd *pProgress = GetDlgItem(IDC_PROGRESS);
CRect rect;
pProgress->GetWindowRect(&rect);
_testsProgress = new ProgressBar (this, rect);
CButton* autoRunBtn = (CButton*) GetDlgItem(IDC_CHK_AUTORUN);
autoRunBtn->SetCheck(pApp->GetProfileInt("Tests", "autoRun", BST_UNCHECKED));
reset ();
if (autoRunBtn->GetCheck() == BST_CHECKED)
{
OnRun();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
TestRunnerDlg::~TestRunnerDlg ()
{
freeState ();
delete _testsProgress;
}
void TestRunnerDlg::OnRun()
{
if (_selectedTest == 0)
return;
freeState ();
reset ();
beRunning ();
int numberOfTests = _selectedTest->countTestCases ();
_testsProgress->start (numberOfTests);
_result = new GUITestResult ((TestRunnerDlg *)this);
_activeTest = new ActiveTest (_selectedTest);
_testStartTime = timeGetTime ();
_activeTest->run (_result);
_testEndTime = timeGetTime ();
}
void TestRunnerDlg::addListEntry(const std::string& type, TestResult *result, Test *test, CppUnitException *e)
{
char stage [80];
LV_ITEM lvi;
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
int currentEntry = result->testErrors () + result->testFailures () -1;
sprintf (stage, "%s", type.c_str ());
lvi.mask = LVIF_TEXT;
lvi.iItem = currentEntry;
lvi.iSubItem = 0;
lvi.pszText = stage;
lvi.iImage = 0;
lvi.stateMask = 0;
lvi.state = 0;
listCtrl->InsertItem (&lvi);
// Set class string
listCtrl->SetItemText (currentEntry, 1, test->toString ().c_str ());
// Set the asserted text
listCtrl->SetItemText(currentEntry, 2, e->what ());
// Set the line number
if (e->lineNumber () == CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
sprintf (stage, "<unknown>");
else
sprintf (stage, "%ld", e->lineNumber ());
listCtrl->SetItemText(currentEntry, 3, stage);
// Set the file name
listCtrl->SetItemText(currentEntry, 4, e->fileName ().c_str ());
listCtrl->RedrawItems (currentEntry, currentEntry);
listCtrl->UpdateWindow ();
}
void TestRunnerDlg::addError (TestResult *result, Test *test, CppUnitException *e)
{
addListEntry ("Error", result, test, e);
_errors++;
_currentTest = 0;
updateCountsDisplay ();
}
void TestRunnerDlg::addFailure (TestResult *result, Test *test, CppUnitException *e)
{
addListEntry ("Failure", result, test, e);
_failures++;
_currentTest = 0;
updateCountsDisplay ();
}
void TestRunnerDlg::startTest(Test* test)
{
_currentTest = test;
updateCountsDisplay();
}
void TestRunnerDlg::endTest (TestResult *result, Test *test)
{
if (_selectedTest == 0)
return;
_currentTest = 0;
_testsRun++;
updateCountsDisplay ();
_testsProgress->step (_failures == 0 && _errors == 0);
_testEndTime = timeGetTime ();
updateCountsDisplay ();
if (_testsRun >= _selectedTest->countTestCases ())
beIdle ();
}
void TestRunnerDlg::beRunning ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
runButton->EnableWindow (FALSE);
closeButton->EnableWindow (FALSE);
}
void TestRunnerDlg::beIdle ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
runButton->EnableWindow (TRUE);
closeButton->EnableWindow (TRUE);
}
void TestRunnerDlg::beRunDisabled ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
CButton *stopButton = (CButton *)GetDlgItem (ID_STOP);
runButton->EnableWindow (FALSE);
stopButton->EnableWindow (FALSE);
closeButton->EnableWindow (TRUE);
}
void TestRunnerDlg::freeState ()
{
delete _activeTest;
delete _result;
}
void TestRunnerDlg::reset ()
{
_testsRun = 0;
_errors = 0;
_failures = 0;
_testEndTime = _testStartTime;
updateCountsDisplay ();
_activeTest = 0;
_result = 0;
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
listCtrl->DeleteAllItems ();
_testsProgress->reset ();
}
void TestRunnerDlg::updateCountsDisplay ()
{
CStatic *statTestsRun = (CStatic *)GetDlgItem (IDC_STATIC_RUNS);
CStatic *statErrors = (CStatic *)GetDlgItem (IDC_STATIC_ERRORS);
CStatic *statFailures = (CStatic *)GetDlgItem (IDC_STATIC_FAILURES);
CEdit *editTime = (CEdit *)GetDlgItem (IDC_EDIT_TIME);
CString argumentString;
argumentString.Format ("%d", _testsRun);
statTestsRun ->SetWindowText (argumentString);
argumentString.Format ("%d", _errors);
statErrors ->SetWindowText (argumentString);
argumentString.Format ("%d", _failures);
statFailures ->SetWindowText (argumentString);
if (_currentTest)
argumentString.Format ("Execution Time: %3.3lf seconds, Current Test: %s", (_testEndTime - _testStartTime) / 1000.0, _currentTest->toString().c_str());
else
argumentString.Format ("Execution Time: %3.3lf seconds", (_testEndTime - _testStartTime) / 1000.0);
editTime ->SetWindowText (argumentString);
}
void TestRunnerDlg::OnStop()
{
if (_result)
_result->stop ();
beIdle ();
}
void TestRunnerDlg::OnOK()
{
if (_result)
_result->stop ();
CDialog::OnOK ();
}
void TestRunnerDlg::OnSelchangeComboTest()
{
CComboBox *testsSelection = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
int currentSelection = testsSelection->GetCurSel ();
if (currentSelection >= 0 && currentSelection < _tests.size ())
{
_selectedTest = (_tests.begin () + currentSelection)->pTest;
beIdle ();
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileString("Tests", "lastTest", _selectedTest->toString().c_str());
}
else
{
_selectedTest = 0;
beRunDisabled ();
}
freeState ();
reset ();
}
void TestRunnerDlg::OnBnClickedAutorun()
{
CButton *autoRunBtn = (CButton *)GetDlgItem (IDC_CHK_AUTORUN);
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt("Tests", "autoRun", autoRunBtn->GetCheck());
}
void TestRunnerDlg::OnPaint()
{
CPaintDC dc (this);
_testsProgress->paint (dc);
}
void TestRunnerDlg::setTests(const std::vector<Test*>& tests)
{
_tests.clear();
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
{
addTest(*it, 0);
}
}
void TestRunnerDlg::addTest(Test* pTest, int level)
{
TestInfo ti;
ti.pTest = pTest;
ti.level = level;
_tests.push_back(ti);
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
if (pSuite)
{
const std::vector<Test*>& tests = pSuite->tests();
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
{
addTest(*it, level + 1);
}
}
}
} // namespace CppUnit
//
// TestRunnerDlg.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.h#1 $
//
#ifndef TestRunnerDlg_INCLUDED
#define TestRunnerDlg_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/CppUnitException.h"
#include "ActiveTest.h"
#include <vector>
#include "../res/Resource.h"
#include <afxwin.h>
#include "afxwin.h"
namespace CppUnit {
class ProgressBar;
class TestRunnerDlg: public CDialog
{
public:
TestRunnerDlg(CWnd* pParent = NULL);
~TestRunnerDlg();
void setTests(const std::vector<Test*>& tests);
void addError(TestResult* result, Test* test, CppUnitException* e);
void addFailure(TestResult* result, Test* test, CppUnitException* e);
void startTest(Test* test);
void endTest(TestResult* result, Test* test);
//{{AFX_DATA(TestRunnerDlg)
enum { IDD = IDD_DIALOG_TESTRUNNER };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
//{{AFX_VIRTUAL(TestRunnerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(TestRunnerDlg)
virtual BOOL OnInitDialog();
afx_msg void OnRun();
afx_msg void OnStop();
virtual void OnOK();
afx_msg void OnSelchangeComboTest();
afx_msg void OnBnClickedAutorun();
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
void addListEntry(const std::string& type, TestResult* result, Test* test, CppUnitException* e);
void beIdle();
void beRunning();
void beRunDisabled();
void reset();
void freeState();
void updateCountsDisplay();
void addTest(Test* pTest, int level);
struct TestInfo
{
Test* pTest;
int level;
};
std::vector<TestInfo> _tests;
ProgressBar* _testsProgress;
Test* _selectedTest;
ActiveTest* _activeTest;
TestResult* _result;
int _testsRun;
int _errors;
int _failures;
DWORD _testStartTime;
DWORD _testEndTime;
Test* _currentTest;
};
} // namespace CppUnit
#endif // TestRunnerDlg_INCLUDED
//
// WinTestRunner.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/WinTestRunner.cpp#1 $
//
#include "WinTestRunner/WinTestRunner.h"
#include "TestRunnerDlg.h"
#include "CppUnit/TestRunner.h"
#include <fstream>
namespace CppUnit {
WinTestRunner::WinTestRunner()
{
}
WinTestRunner::~WinTestRunner()
{
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
delete *it;
}
void WinTestRunner::run()
{
// Note: The following code is some evil hack to
// add batch capability to the MFC based WinTestRunner.
std::string cmdLine(AfxGetApp()->m_lpCmdLine);
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
{
TestRunner runner;
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
runner.addTest((*it)->toString(), *it);
_tests.clear();
std::vector<std::string> args;
args.push_back("WinTestRunner");
args.push_back("-all");
bool success = runner.run(args);
ExitProcess(success ? 0 : 1);
}
else
{
// We're running in interactive mode.
TestRunnerDlg dlg;
dlg.setTests(_tests);
dlg.DoModal();
}
}
void WinTestRunner::addTest(Test* pTest)
{
_tests.push_back(pTest);
}
BEGIN_MESSAGE_MAP(WinTestRunnerApp, CWinApp)
END_MESSAGE_MAP()
BOOL WinTestRunnerApp::InitInstance()
{
std::string cmdLine(AfxGetApp()->m_lpCmdLine);
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
{
// We're running in batch mode.
std::string outPath;
if (cmdLine.size() > 4 && cmdLine[2] == ':')
{
outPath = cmdLine.substr(3);
}
else
{
char buffer[1024];
GetModuleFileName(NULL, buffer, sizeof(buffer));
outPath = buffer;
outPath += ".out";
}
freopen(outPath.c_str(), "w", stdout);
freopen(outPath.c_str(), "w", stderr);
TestMain();
}
else
{
AllocConsole();
SetConsoleTitle("CppUnit WinTestRunner Console");
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
freopen("CONIN$", "r", stdin);
TestMain();
FreeConsole();
}
return FALSE;
}
void WinTestRunnerApp::TestMain()
{
}
} // namespace CppUnit
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>CppUnit 1.5</TITLE>
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080">
<P><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"></P>
<H1>CppUnit 1.5</H1>
<P>Last Revision: 12/15/99 - Michael Feathers (mfeathers@acm.org) - written in standard C++, tested under Microsoft Visual C++ 6.0</P>
<P><HR></P>
<H3>Background</H3>
<P>CppUnit is a simple unit test framework for C++. It is a port from JUnit, a testing framework for Java, developed by Kent Beck and Erich Gamma. </P>
<H3>Contents</H3>
<PRE>README.html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this file
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the source code
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; framework&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the testing framework
&#9;&#9;extensions&#9;some framework extension classes
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textui&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a command line interface to run tests
&nbsp;&nbsp;&nbsp;&nbsp;ms&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; code for a Microsoft specific TestRunner
&nbsp;&nbsp;&nbsp;&nbsp;samples&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; some example test cases and extensions to the framework
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; multicaster&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a sample illustrating a publish/subscribe
&#9;&#9;&#9;&#9;multicaster under test
&nbsp;&nbsp;&nbsp; doc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; documentation</PRE>
<H3>Installation</H3>
<P>To use the test framework, create a makefile or load all files in test\framework into your IDE. In this incarnation of CppUnit, all includes assume the current directory first. A makefile or project can be used to resolve the dependencies. </P>
<P>The directory test\textui contains a simple command line example that uses the framework.</P>
<H3>Documentation</H3>
<P>CppUnit comes with the following documentation: </P>
<UL>
<LI>a cookbook: doc\cookbook.htm </LI>
<LI>this file </LI></UL>
<H3>Samples</H3>
<P>You can find several sample test cases in the samples directory: </P>
<UL>
<LI>ExampleTestCase - some simple tests </LI>
<LI>Multicaster - test cases for a sample publish/subscribe multicaster class </LI></UL>
<P>Also, the wiki page <a HREF="http://c2.com/cgi/wiki?ClassHierarchyTestingInCppUnit">http://c2.com/cgi/wiki?ClassHierarchyTestingInCppUnit</a> shows how to automatically apply tests of classes to the classes' subclasses.</P>
<H3>Extensions</H3>
<P>You can find several classes that illustrate framework extensions in the extensions directory: </P>
<UL>
<LI>TestDecorator - A Decorator for Test. You can use it as the base class for decorators that extend test cases. </LI>
<LI>TestSetup - A Decorator that can be used to set up and tear down additional fixture state. Subclass TestSetup and insert it into your tests when you want to set up additional state once before the test is run. </LI>
<LI>Orthodox - a template class which can be used to verify operations on an arbitrary class.</LI></UL>
<H3>Notes</H3>
<P>Porting this framework has been fun. I've tried to maintain the spirit and utility of JUnit in a C++ environment. Naturally, the move from Java to standard C++ forces out several nice JUnit features:</P>
<OL>
<LI>Platform independent GUI.</LI>
<LI>Stack traces of test failures</LI>
<LI>Active (threaded) tests</LI>
<LI>Direct invocation of test cases via reflection</LI>
<LI>Run-time loading of new tests</LI></OL>
<P>In addition, the lack of garbage collection in C++ requires some careful use of the framework classes. In particular, TestSuites are composites that manage the lifetime of any tests added to them. Holding onto a TestResult past the lifetime of the tests which filled it is a bad idea. This is because TestResults hold TestFailures and TestFailures hold pointers to the Tests that generated them.</P>
<P>On the plus side, we can use the C++ macro preprocessor to get the exact line at which a failure occurs, along with the actual text inside the assert () call that detected the failure. The features of C++ that enable this are the __LINE__ and __FILE__ preprocessor definitions, along with the <I>stringizing</I> operator. If you find that generating this much literal text bulks up your test executables, you can use the CPP_UNIT_SOURCEANNOT define to disable that portion of the reporting.</P>
<P>Note: If you use the C++ macro "assert ()" in your code, or include assert.h, you may have a name clash with CppUnit's assert macro. This can be remedied by changing the name of the macro to "cu_assert ()" in TestCase.h.</P>
<P>I'd like to thank Kent Beck and Erich Gamma for the inspiration, design, and a wonderful cookbook that was easily/shamelessly mutated to describe CppUnit. Double thanks to Erich for thinking up a way to implement TestCaller. Additional thanks to Kent, Ward Cunningham, Ron Jeffries, Martin Fowler, and several other netizens of the WikiWikiWeb. I don't think any other bunch of people could have convinced me that rapid development with unit tests can be both effective and easy.</P>
<P>Thanks also to Fred Huls for mentioning the idea of template-based testing. The <EM>orthodox</EM> template class demonstrates only a small part of what can be done with templated test cases.</P>
<H3>History Of Changes</H3>
<P>1.2 -- Added the TestCaller template class. There is now no need to use the CPP_UNIT_TESTCASEDISPATCH macro unless you are using a C++ compiler which does not support templates well. CPP_UNIT_TESTCASEDISPATCH remains in TestCase.h for backward compatibility. I've also kept the use of the macro in the Multicaster sample to leave in an example.</P>
<P>1.3 -- Retired the CPP_UNIT_TESTCASEDISPATCH macro and cleaned up the include structure. Fixed bug in the textui version.</P>
<P>1.4 -- Removed using directives for std in CppUnit headers. Merged the old AssertionFailedError into CppUnitException. Fixed a memory leak in the TestRunner class of the MS GUI TestRunner. Removed CppUnit.h file. Now headers for each class must be included directly.</P></BODY></HTML>
<P>1.5 -- Upgraded projects from VC++ 5.0 to 6.0.</P></BODY></HTML>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>CppUnit Cookbook</TITLE>
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080">
<P><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"></P>
<H1>CppUnit Cookbook</H1>
<P>Here is a short cookbook to help you get started. </P>
<H2>Simple Test Case</H2>
<P>You want to know whether your code is working. How do you do it? There are many ways. Stepping through a debugger or littering your code with stream output calls are two of the simpler ways, but they both have drawbacks. Stepping through your code is a good idea, but it is not automatic. You have to do it every time you make changes. Streaming out text is also fine, but it makes code ugly and it generates far more information than you need most of the time.</P>
<P>Tests in CppUnit can be run automatically. They are easy to set up and once you have written them, they are always there to help you keep confidence in the quality of your code.</P>
<P>To make a simple test, here is what you do:</P>
<P>Subclass the TestCase class. Override the method "runTest ()". When you want to check a value, call "assert (bool)" and pass in an expression that is true if the test succeeds. </P>
<P>For example, to test the equality comparison for a Complex number class, write:</P>
<TT><PRE>&#9;class ComplexNumberTest : public TestCase {&nbsp;
&#9;public:
ComplexNumberTest (string name) : TestCase (name) {}
void runTest () {
assert (Complex (10, 1) == Complex (10, 1));
assert (!(Complex (1, 1) == Complex (2, 2)));
}
};</PRE>
</TT><P>That was a very simple test. Ordinarily, you'll have many little test cases that you'll want to run on the same set of objects. To do this, use a fixture.</P>
<P>&nbsp;</P>
<H2>Fixture</H2>
<P>A fixture is a known set of objects that serves as a base for a set of test cases. Fixtures come in very handy when you are testing as you develop. Let's try out this style of development and learn about fixtures along the away. Suppose that we are really developing a complex number class. Let's start by defining a empty class named Complex.</P>
<TT><PRE>&#9;class Complex {};&nbsp;</PRE>
</TT><P>Now create an instance of ComplexNumberTest above, compile the code and see what happens. The first thing we notice is a few compiler errors. The test uses operator==, but it is not defined. Let's fix that.</P>
<TT><PRE>&#9;bool operator== (const Complex&amp; a, const Complex&amp; b) { return true; }</PRE>
</TT><P>Now compile the test, and run it. This time it compiles but the test fails. We need a bit more to get an operator== working correctly, so we revisit the code.</P>
<TT><PRE>&#9;class Complex {&nbsp;
friend bool operator== (const Complex&amp; a, const Complex&amp; b);
double real, imaginary;
public:
Complex () {
real = imaginary = 0.0;
}
};
bool operator== (const Complex&amp; a, const Complex&amp; b)
{ return eq(a.real,b.real) &amp;&amp; eq(a.imaginary,b.imaginary); }</PRE>
</TT><P>If we compile now and run our test it will pass. </P>
<P>Now we are ready to add new operations and new tests. At this point a fixture would be handy. We would probably be better off when doing our tests if we decided to instantiate three or four complex numbers and reuse them across our tests. </P>
<P>Here is how we do it:</P>
<OL>
<LI>Add member variables for each part of the fixture </LI>
<LI>Override "setUp ()" to initialize the variables </LI>
<LI>Override "tearDown ()" to release any permanent resources you allocated in "setUp ()"</LI></OL>
<TT><PRE>&#9;class ComplexNumberTest : public TestCase {
&#9;private:
Complex &#9;*m_10_1, *m_1_1; *m_11_2;
&#9;protected:
&#9;void&#9;&#9;setUp () {
&#9;&#9;&#9; m_10_1 = new Complex (10, 1);
&#9;&#9;&#9; m_1_1 = new Complex (1, 1);
&#9;&#9;&#9; m_11_2 = new Complex (11, 2);
}
&#9;void&#9;&#9;tearDown () {
&#9;&#9;&#9; delete m_10_1, delete m_1_1, delete m_11_2;
&#9;&#9;&#9;}
&#9;};</PRE>
</TT><P>Once we have this fixture, we can add the complex addition test case any any others that we need over the course of our development.</P>
<P>&nbsp;</P>
<H2>Test Case</H2>
<P>How do you write and invoke individual tests using a fixture? </P>
<P>There are two steps to this process:</P>
<OL>
<LI>Write the test case as a method in the fixture class</LI>
<LI>Create a TestCaller which runs that particular method</LI></OL>
<P>Here is our test case class with a few extra case methods:</P>
<TT><PRE>&#9;class ComplexNumberTest : public TestCase {
&#9;private:
Complex &#9;*m_10_1, *m_1_1; *m_11_2;
&#9;protected:
&#9;void&#9;&#9;setUp () {
&#9;&#9;&#9; m_10_1 = new Complex (10, 1);
&#9;&#9;&#9; m_1_1 = new Complex (1, 1);
&#9;&#9;&#9; m_11_2 = new Complex (11, 2);
}
&#9;void&#9;&#9;tearDown () {
&#9;&#9;&#9; delete m_10_1, delete m_1_1, delete m_11_2;
&#9;&#9;&#9;}
&#9;void&#9;&#9;testEquality () {
&#9;&#9;&#9; assert (*m_10_1 == *m_10_1);
&#9;&#9;&#9; assert (!(*m_10_1 == *m_11_2));
&#9;&#9;&#9;}
&#9;void&#9;&#9;testAddition () {
&#9;&#9;&#9; assert (*m_10_1 + *m_1_1 == *m_11_2);
&#9;}
&#9;};</PRE>
</TT><P>Create and run instances for each test case like this:</P>
<TT><PRE>&#9;test = new TestCaller&lt;ComplexNumberTest&gt;("testEquality", ComplexNumberTest::testEquality);
test->run (); </PRE>
</TT><P>The second argument to the test caller constructor is the address of a method on ComplexNumberTest. When the test caller is run, that specific method will be run.</P>
<P>Once you have several tests, organize them into a suite.</P>
<P>&nbsp;</P>
<H2>Suite</H2>
<P>How do you set up your tests so that you can run them all at once?<BR>
<BR>
CppUnit provides a TestSuite class that runs any number of TestCases together. For example, to run a single test case, you execute:</P>
<TT><PRE>&#9;TestResult result;
&#9;TestCaller&lt;ComplexNumberTest&gt; test ("testAddition", ComplexNumberTest::testAddition);
&#9;Test.run (&amp;result);</PRE>
</TT><P>&nbsp;</P>
<P>To create a suite of two or more tests, you do the following:</P>
<TT><PRE>&#9;TestSuite suite;
&#9;TestResult result;
&#9;suite.addTest (new TestCaller&lt;ComplexNumberTest&gt;("testEquality", ComplexNumberTest::testEquality));
&#9;suite.addTest (new TestCaller&lt;ComplexNumberTest&gt;("testAddition", ComplexNumberTest::testAddition));
&#9;suite.run (&amp;result);
</PRE>
</TT><P>TestSuites don't only have to contain callers for TestCases. They can contain any object that implements the Test interface. For example, you can create a TestSuite in your code and I can create one in mine, and we can run them together by creating a TestSuite that contains both: </P>
<TT><PRE>&#9;TestSuite suite;
&#9;suite.addTest (ComplexNumberTest.suite ());
&#9;suite.addTest (SurrealNumberTest.suite ());
&#9;suite.run (&amp;result);</PRE>
</TT><P>&nbsp;</P>
<H2>TestRunner</H2>
<P>How do you run your tests and collect their results? </P>
<P>Once you have a test suite, you'll want to run it. CppUnit provides tools to define the suite to be run and to display its results. You make your suite accessible to a TestRunner program with a static method <I>suite</I> that returns a test suite. <BR>
For example, to make a ComplexNumberTest suite available to a TestRunner, add the following code to ComplexNumberTest: </P>
<TT><PRE>&#9;public: static Test *suite () {
&#9; TestSuite *suiteOfTests = new TestSuite;
&#9; suiteOfTests-&gt;addTest (new TestCaller&lt;ComplexNumberTest&gt;("testEquality", testEquality));
&#9; suiteOfTests-&gt;addTest (new TestCaller&lt;ComplexNumberTest&gt;("testAddition", testAddition));
return suiteOfTests;
&#9;}</PRE>
</TT><P>CppUnit provides both a textual version of a TestRunner tool, and a Micosoft Visual C++ 5.0 graphical version. If you are running on another platform, take a look at the graphical version. It is easy to port.</P>
<P>To use the text version, include the header file for the test in TestRunner.cpp:</P>
<TT><PRE>&#9;#include "ExampleTestCase.h"
&#9;#include "ComplexNumberTest.h"</PRE>
</TT><P>And add a call to "addTest (string, Test *) in the "main ()" function:</P>
<TT><PRE>&#9;int main (int ac, char **av) {
&#9; TestRunner runner;
&#9; runner.addTest (ExampleTestCase::suite ());
&#9; runner.addTest (ComplexNumberTest::suite ());
&#9; runner.run ();
&#9; return 0;
&#9;}</PRE>
</TT><P>The TestRunner will run the tests. If all the tests pass, you'll get an informative message. If any fail, you'll get the following information:</P>
<OL>
<LI>The name of the test case that failed</LI>
<LI>The name of the source file that contains the test</LI>
<LI>The line number where the failure occurred</LI>
<LI>All of the text inside the call to assert which detected the failure</LI></OL>
<P>CppUnit distinguishes between <I>failures</I> and <I>errors</I>. A failure is anticipated and checked for with assertions. Errors are unanticipated problems like division by zero and other exceptions thrown by the C++ runtime or your code.</P>
<P>If you are running MS Developer's Studio, you can build the GUI version rather easily. There are three projects: culib, TestRunner, and HostApp. They make a static library for the framework, a dialog based TestRunner in a DLL and an example Hosting application, respectively. To incorporate a TestRunner in an application you are developing, link with the static library and the TestRunner DLL. Note that the TestRunner DLL must be in the home directory of your application, the system directory or the path. In your application, create an instance of TestRunnerDlg whenever you want to run tests. Pass tests you want to run to the dialog object and then execute.</P>
<P>Here is a screen shot of the TestRunner in use:</P>
<P><IMG SRC="test.gif" WIDTH=574 HEIGHT=351></P>
<P>&nbsp;</P>
<P>More notes about the implementation of CppUnit can be found in README.HTML.</P>
<P>&nbsp;</P>
<P>&nbsp;</P></BODY>
</HTML>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>License Agreement</TITLE>
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080">
<P>Permission to reproduce and create derivative works from the Software ("Software Derivative Works") is hereby granted to you under the copyright of Michael Feathers.&nbsp; Michael Feathers also grants you the right to distribute the Software and Software Derivative Works. </P>
<P>Michael Feathers licenses the Software to you on an "AS IS" basis, without warranty of any kind. Michael Feathers HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.&nbsp; You are solely responsible for determining the appropriateness of using the Software and assume all risks associated with the use and distribution of this Software, including but not limited to the risks of program errors, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.&nbsp; MICHAEL FEATHERS WILL NOT BE LIABLE FOR ANY DIRECT DAMAGES OR FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF MICHAEL FEATHERS HAD BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&nbsp; Michael Feathers will not be liable for the loss of, or damage to, your records or data, or any damages claimed by you based on a third party claim. </P>
<P>You agree to distribute the Software and any Software Derivatives under a license agreement that: 1) is sufficient to notify all licensees of the Software and Software Derivatives that Michael Feathers assumes no liability for any claim that may arise regarding the Software or Software Derivatives, and 2) that disclaims all warranties, both express and implied, from Michael Feathers regarding the Software and Software Derivatives.&nbsp; (If you include this Agreement with any distribution of the Software and Software Derivatives you will have meet this requirement).&nbsp; You agree that you will not delete any copyright notices in the Software. </P>
<P>This Agreement is the exclusive statement of your rights in the Software as provided by Michael Feathers.&nbsp; Except for the licenses granted to you in the second paragraph above, no other licenses are granted hereunder, by estoppel, implication or otherwise. <BR>
&nbsp; </P></BODY>
</HTML>
//
// CppUnit.h
//
// $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnit.h#1 $
//
#ifndef CppUnit_CppUnit_INCLUDED
#define CppUnit_CppUnit_INCLUDED
//
// Ensure that POCO_DLL is default unless POCO_STATIC is defined
//
#if defined(_WIN32) && defined(_DLL)
#if !defined(POCO_DLL) && !defined(POCO_STATIC)
#define POCO_DLL
#endif
#endif
//
// The following block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the CppUnit_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// CppUnit_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(CppUnit_EXPORTS)
#define CppUnit_API __declspec(dllexport)
#else
#define CppUnit_API __declspec(dllimport)
#endif
#endif
#if !defined(CppUnit_API)
#if defined (__GNUC__) && (__GNUC__ >= 4)
#define CppUnit_API __attribute__ ((visibility ("default")))
#else
#define CppUnit_API
#endif
#endif
// Turn off some annoying warnings
#ifdef _MSC_VER
#pragma warning(disable:4786) // identifier truncation warning
#pragma warning(disable:4503) // decorated name length exceeded - mainly a problem with STLPort
#pragma warning(disable:4018) // signed/unsigned comparison
#pragma warning(disable:4284) // return type for operator -> is not UDT
#pragma warning(disable:4251) // ... needs to have dll-interface warning
#pragma warning(disable:4273)
#pragma warning(disable:4275) // ... non dll-interface class used as base for dll-interface class
#endif
#endif // CppUnit_CppUnit_INCLUDED
//
// CppUnitException.h
//
// $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnitException.h#1 $
//
#ifndef CppUnit_CppUnitException_INCLUDED
#define CppUnit_CppUnitException_INCLUDED
#include "CppUnit/CppUnit.h"
#include <exception>
#include <string>
namespace CppUnit {
class CppUnit_API CppUnitException: public std::exception
/// CppUnitException is an exception that serves
/// descriptive strings through its what() method
{
public:
CppUnitException(const std::string& message = "",
long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,
const std::string& fileName = CPPUNIT_UNKNOWNFILENAME);
CppUnitException(const std::string& message,
long lineNumber,
long data1lineNumber,
const std::string& fileName);
CppUnitException(const std::string& message,
long lineNumber,
long data1lineNumber,
long data2lineNumber,
const std::string& fileName);
CppUnitException(const CppUnitException& other);
virtual ~CppUnitException() throw();
CppUnitException& operator = (const CppUnitException& other);
const char* what() const throw ();
long lineNumber() const;
long data1LineNumber() const;
long data2LineNumber() const;
const std::string& fileName() const;
static const std::string CPPUNIT_UNKNOWNFILENAME;
static const int CPPUNIT_UNKNOWNLINENUMBER;
private:
std::string _message;
long _lineNumber;
long _data1lineNumber;
long _data2lineNumber;
std::string _fileName;
};
inline CppUnitException::CppUnitException(const CppUnitException& other): exception (other)
{
_message = other._message;
_lineNumber = other._lineNumber;
_data1lineNumber = other._data1lineNumber;
_data2lineNumber = other._data2lineNumber;
_fileName = other._fileName;
}
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
{
}
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
{
}
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(data2lineNumber), _fileName(fileName)
{
}
inline CppUnitException::~CppUnitException () throw()
{
}
inline CppUnitException& CppUnitException::operator = (const CppUnitException& other)
{
exception::operator= (other);
if (&other != this)
{
_message = other._message;
_lineNumber = other._lineNumber;
_data1lineNumber = other._data1lineNumber;
_data2lineNumber = other._data2lineNumber;
_fileName = other._fileName;
}
return *this;
}
inline const char* CppUnitException::what() const throw ()
{
return _message.c_str();
}
inline long CppUnitException::lineNumber() const
{
return _lineNumber;
}
inline long CppUnitException::data1LineNumber() const
{
return _data1lineNumber;
}
inline long CppUnitException::data2LineNumber() const
{
return _data2lineNumber;
}
// The file in which the error occurred
inline const std::string& CppUnitException::fileName() const
{
return _fileName;
}
} // namespace CppUnit
#endif // CppUnit_CppUnitException_INCLUDED
//
// Guards.h
//
// $Id: //poco/1.4/CppUnit/include/CppUnit/Guards.h#1 $
//
#ifndef CppUnit_Guards_INCLUDED
#define CppUnit_Guards_INCLUDED
// Prevent copy construction and assignment for a class
#define REFERENCEOBJECT(className) \
private: \
className(const className& other); \
className& operator = (const className& other);
#endif // CppUnit_Guards_INCLUDED
//
// Orthodox.h
//
// $Id: //poco/1.4/CppUnit/include/CppUnit/Orthodox.h#1 $
//
#ifndef CppUnit_Orthodox_INCLUDED
#define CppUnit_Orthodox_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestCase.h"
namespace CppUnit {
/*
* Orthodox performs a simple set of tests on an arbitary
* class to make sure that it supports at least the
* following operations:
*
* default construction - constructor
* equality/inequality - operator== && operator!=
* assignment - operator=
* negation - operator!
* safe passage - copy construction
*
* If operations for each of these are not declared
* the template will not instantiate. If it does
* instantiate, tests are performed to make sure
* that the operations have correct semantics.
*
* Adding an orthodox test to a suite is very
* easy:
*
* public: Test *suite () {
* TestSuite *suiteOfTests = new TestSuite;
* suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
* suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
* return suiteOfTests;
* }
*
* Templated test cases be very useful when you are want to
* make sure that a group of classes have the same form.
*
* see TestSuite
*/
template <class ClassUnderTest>
class Orthodox: public TestCase
{
public:
Orthodox(): TestCase("Orthodox")
{
}
protected:
ClassUnderTest call(ClassUnderTest object);
void runTest ();
};
// Run an orthodoxy test
template <class ClassUnderTest>
void Orthodox<ClassUnderTest>::runTest()
{
// make sure we have a default constructor
ClassUnderTest a, b, c;
// make sure we have an equality operator
assert (a == b);
// check the inverse
b.operator= (a.operator! ());
assert (a != b);
// double inversion
b = !!a;
assert (a == b);
// invert again
b = !a;
// check calls
c = a;
assert (c == call (a));
c = b;
assert (c == call (b));
}
// Exercise a call
template <class ClassUnderTest>
ClassUnderTest Orthodox<ClassUnderTest>::call(ClassUnderTest object)
{
return object;
}
} // namespace CppUnit
#endif // CppUnit_Orthodox_INCLUDED
//
// CppUnitException.cpp
//
// $Id: //poco/1.4/CppUnit/src/CppUnitException.cpp#1 $
//
#include "CppUnit/CppUnitException.h"
namespace CppUnit {
const std::string CppUnitException::CPPUNIT_UNKNOWNFILENAME = "<unknown>";
const int CppUnitException::CPPUNIT_UNKNOWNLINENUMBER = -1;
} // namespace CppUnit
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
include(CMakeFindDependencyMacro)
find_dependency(PocoFoundation)
include("${CMAKE_CURRENT_LIST_DIR}/PocoCryptoTargets.cmake")
set(SAMPLE_NAME "genrsakey")
set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS)
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
target_link_libraries( ${SAMPLE_NAME} PocoCrypto PocoUtil PocoXML PocoFoundation )
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册