Core Library
Classes | Typedefs | Enumerations | Functions | Variables
Core Namespace Reference

The Core Library namespace. More...

Classes

class  AnsiToWide
 The class used to do the conversion from ANSI to Wide via the X2Y() macros. More...
class  WideToAnsi
 The class used to do the conversion from Wide to ANSI via the X2Y() macros. More...
class  ArrayPtr
 An array smart-pointer for use within a limited scope. More...
class  BadLogicException
 The exception type thrown for errors that are the result of incorrect program logic. More...
class  CmdLineException
 The type of exception thrown for errors parsing the command line. More...
class  CmdLineParser
 A command line parser. More...
struct  CmdLineSwitch
 The definition of a command line switch. More...
class  ConfigurationException
 The exception type thrown for configuration errors. More...
struct  STATIC_ASSERT_CHECK< true >
 The STATIC_ASSERT template matching valid assertions. More...
class  Exception
 The base class for all exception types. More...
class  FileSystemException
 The type of exception thrown when an error involving the file-system is encountered. More...
class  InvalidArgException
 The type of exception thrown when an invalid argument is passed to a function. More...
class  LeakReporter
 The static object that uses it's dtor to report any memory leaks. More...
class  NotCopyable
 Base class used to disable copying of the derived class. More...
class  NotImplException
 The exception type thrown for features that have not been implemented. More...
class  NullPtrException
 The type of exception thrown when an attempt is made to dereference a null pointer. More...
class  ParseException
 The type of exception thrown for parsing errors. More...
class  RefCntPtr
 The smart-pointer type for use with types that contain their own reference counting mechanism, e.g. More...
class  RefCounted
 The class used to provide internal reference counting. More...
class  RuntimeException
 The exception type thrown for unclassified runtime errors. More...
class  Scoped
 A class for temporarily managing the lifetime of resources that require a custom destroy function. More...
class  SharedPtr
 A reference counted smart pointer. More...
class  SmartPtr
 The base class for all smart-pointer types. More...
struct  FormatTraits
 Traits to invoke the underlying formatting and parsing functions for the specified template type. More...
struct  FormatTraits< int >
 Formatting and parsing functions for handling int's. More...
struct  FormatTraits< uint >
 Formatting and parsing functions for handling unsigned int's. More...
struct  FormatTraits< longlong >
 Formatting and parsing functions for handling long long int's. More...
struct  FormatTraits< ulonglong >
 Formatting and parsing functions for handling unsigned long long int's. More...
class  TextFileIterator
 The iterator type used to read lines of text from a file. More...
class  Tokeniser
 A class to split a string into separate tokens. More...
class  UniquePtr
 A smart-pointer for use within a limited scope. More...
struct  TestSetComparator
 Comparison functor for matching test sets against by test set name. More...

Typedefs

typedef std::map< tstring,
TestSetFn
TestSets
 A collection of test sets.
typedef std::vector< tstringTestCaseNames
 A collection of test case names.
typedef std::set< tstringTestSetFilters
 A collection of test suite names.
typedef void(* TestSetFn )()
 The Test Set run function type.
typedef void(* TestCaseSetUpFn )()
 The test case SetUp function type.
typedef void(* TestCaseTearDownFn )()
 The test case TearDown function type.

Enumerations

enum  SwitchID { HELP = 0, VERBOSE = 1, QUIET = 2 }
 The test runner command line switch IDs. More...
enum  TestResult { UNKNOWN = 1, SUCCEEDED = 2, FAILED = 3 }
 Test case result state. More...

Functions

template<typename T >
bool exists (const std::vector< T > &container, T value)
 Search to see if the value exists within the container.
template<typename T >
void deepCopy (const std::vector< Core::SharedPtr< T > > &input, std::vector< Core::SharedPtr< T > > &output)
 Perform a deep copy of the container.
void ansiToWide (const char *pszBegin, const char *pszEnd, wchar_t *pszDst)
 Convert a string from ANSI to Wide.
std::wstring ansiToWide (const char *pszBegin, const char *pszEnd)
 Convert a string from ANSI to Wide.
void wideToAnsi (const wchar_t *pszBegin, const wchar_t *pszEnd, char *pszDst)
 Convert a string from Wide to ANSI.
std::string wideToAnsi (const wchar_t *pszBegin, const wchar_t *pszEnd)
 Convert a string from Wide to ANSI.
std::wstring ansiToWide (const char *psz)
 Convert a string from ANSI to Wide.
std::wstring ansiToWide (const std::string &str)
 Convert a string from ANSI to Wide.
std::string wideToAnsi (const wchar_t *psz)
 Convert a string from Wide to ANSI.
std::string wideToAnsi (const std::wstring &str)
 Convert a string from Wide to ANSI.
template<typename T >
T ** attachTo (ArrayPtr< T > &ptr)
 Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.
void assertFail (const char *pszExpression, const char *pszFile, uint nLine)
 The function invoked when an ASSERT fails.
void traceEx (const tchar *pszFormat,...)
 Function to write a message to the debugger output.
void debugWrite (const tchar *pszFormat,...)
 Write a message to the debugger stream in both Debug and Release builds.
void enableLeakReporting (bool bEnable)
 Enable or disable memory leak reporting.
tstring getTempFolder ()
 Get the folder to use for temporary files.
tstring combinePaths (const tstring &lhs, const tstring &rhs)
 Combine two paths into a single path.
bool pathExists (const tstring &path)
 Query if the path points to a file or folder that exists.
static void localFree (tchar *buffer)
 Wrapper to invoke LocalFree on the buffer pointer.
static tstring formatWin32ErrorMessage (DWORD errorCode)
 Convert the WIN32 error code into a text message.
void deleteFile (const tstring &path, bool ignoreErrors)
 Delete the specified file.
long atomicIncrement (volatile long &value)
 Thread-safe function for incrementing the value by one.
long atomicDecrement (volatile long &value)
 Thread-safe function for decrementing the value by one.
template<typename T >
T ** attachTo (RefCntPtr< T > &ptr)
 Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.
template<typename P , typename U >
RefCntPtr< P > static_ptr_cast (const RefCntPtr< U > &oPtr)
 A variant of static_cast<> that can be used to create a RefCntPtr of the derived ptr type from the base ptr type.
template<typename P , typename U >
RefCntPtr< P > dynamic_ptr_cast (const RefCntPtr< U > &oPtr)
 A variant of dynamic_cast<> that can be used to create a RefCntPtr of the derived ptr type from the base ptr type.
template<typename T >
T * attachTo (Scoped< T > &guard)
 Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.
template<typename P , typename U >
SharedPtr< P > static_ptr_cast (const SharedPtr< U > &oPointer)
 A variant of static_cast<> that can be used to create a SharedPtr of the derived ptr type from the base ptr type.
template<typename P , typename U >
SharedPtr< P > dynamic_ptr_cast (const SharedPtr< U > &oPointer)
 A variant of dynamic_cast<> that can be used to create a SharedPtr of the derived ptr type from the base ptr type.
template<typename T , typename U >
bool operator== (const SmartPtr< T > &oLHS, const SmartPtr< U > &oRHS)
 SmartPtr<T> equality operator.
template<typename T , typename U >
bool operator!= (const SmartPtr< T > &oLHS, const SmartPtr< U > &oRHS)
 SmartPtr<T> inequality operator.
tstring fmtEx (const tchar *pszFormat, va_list args)
 Format the string ala printf.
tstring fmt (const tchar *pszFormat,...)
 Format the string ala printf.
template<typename T , typename Traits >
tstring formatInteger (const T &value)
 Generic function for parsing integers.
template<>
tstring format (const bool &value)
 Format a boolean value into a string.
template<>
tstring format (const int &value)
 Format a signed integer value into a string.
template<>
tstring format (const uint &value)
 Format an unsigned integer value into a string.
template<>
tstring format (const longlong &value)
 Format a signed long long integer value into a string.
template<>
tstring format (const ulonglong &value)
 Format a unsigned long long integer value into a string.
template<typename T , typename Traits >
parseInteger (const tstring &buffer)
 Generic function for parsing integers.
template<>
bool parse (const tstring &buffer)
 Parse a boolean value from a string.
void makeUpper (tstring &string)
 Convert a string to upper case.
tstring createUpper (tstring string)
 Create an upper case version of a string.
void makeLower (tstring &string)
 Convert a string to lower case.
tstring createLower (tstring string)
 Create a lower case version of a string.
void trimLeft (tstring &string)
 Trim any leading whitespace from the string.
void trimRight (tstring &string)
 Trim any trailing whitespace from the string.
void trim (tstring &string)
 Trim any leading or trailing whitespace from the string.
tstring trimCopy (tstring string)
 Trim any leading or trailing whitespace from a copy of the string.
template<typename First , typename Last >
First skipWhitespace (First first, Last last)
 Skip any leading whitespace.
template<typename T >
tstring format (const T &value)
 Format a value into a string.
template<typename T >
parse (const tstring &buffer)
 Parse a boolean value from a string.
bool operator== (const TextFileIterator &lhs, const TextFileIterator &rhs)
 Compare two iterators for equivalence.
bool operator!= (const TextFileIterator &lhs, const TextFileIterator &rhs)
 Compare two iterators for difference.
template<typename CharT >
size_t numBytes (size_t nChars)
 Calculate the number of bytes required to represent a string of the given number of characters.
size_t numBytes (const char *psz)
 Calculate the number of bytes required to represent the string.
size_t numBytes (const wchar_t *psz)
 Calculate the number of bytes required to represent the string.
template<typename T >
T ** attachTo (UniquePtr< T > &ptr)
 Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.
static void showUsage (const tchar *process, const Core::CmdLineParser &parser)
 Display the program options syntax.
bool parseCmdLine (int argc, tchar *argv[], TestSetFilters &filters)
 Parse the command line.
static TestSetsgetTestSetCollection ()
 Get the collection of test sets.
bool registerTestSet (const tchar *name, TestSetFn runner)
 Register a test set runner function.
bool runTestSets (const TestSetFilters &filters)
 Run the self-registering test sets.
void onStartTestSet (const tchar *name)
 Start the test set.
void onEndTestSet ()
 End the test set.
void defineTestCaseSetup (TestCaseSetUpFn setup)
 Define the test case setup function.
void defineTestCaseTearDown (TestCaseTearDownFn teardown)
 Define the test case teardown function.
bool onStartTestCase (const tchar *name)
 Start a new test case.
void onEndTestCase ()
 End a test case.
static const char * getFileName (const char *path)
 Get just the filename from the path.
void processAssertResult (const char *file, size_t line, const tchar *expression, bool passed)
 Write the assert result to stdout.
void processTestException (const char *file, size_t line, const tchar *error)
 Process an unexpected exception running a test case.
void processSetupTeardownException (const tchar *function, const tchar *error)
 Process an unexpected exception during setup or teardown.
void setTestRunFinalStatus (bool successful)
 Set how the test run completed.
void writeTestsSummary ()
 Write the summary of the test results to the debugger stream and stdout.
int getTestProcessResult ()
 Get the test process result code.

Variables

const tchar FOLDER_SEPARATOR = TXT('\\')
static bool g_bReportLeaks = false
 The flag used to signal whether to dump leaks or not.
class Core::LeakReporter g_oReporter
static const size_t npos = static_cast<size_t>(-1)
 A general purpose equivalent to basic_string::npos.
static bool s_successful = false
 The overall state of the test run.
static uint s_numPassed = 0
 The number of tests that passed.
static uint s_numFailed = 0
 The number of tests that failed.
static uint s_numUnknown = 0
 The number of tests that were indeterminate.
static bool s_verbose = false
 Is verbose mode enabled?
static bool s_quiet = false
 Is quiet mode enabled?
static TestResult s_currentResult = UNKNOWN
 Current test case status.
static tstring s_currentTestSet
 The name of the executing test set.
static tstring s_currentTestCase
 The name of the executing test case.
static TestCaseNames s_failures
 The list of failed test cases for the set.
static TestCaseSetUpFn s_setup
 The test case SetUp function.
static TestCaseTearDownFn s_teardown
 The test case TearDown function.
static TestCaseNames s_executed
 The list of test cases executed.
static Core::CmdLineSwitch s_switches []
 Parse the command line.
static size_t s_switchCount = ARRAY_SIZE(s_switches)

Detailed Description

The Core Library namespace.


Typedef Documentation

typedef std::map<tstring, TestSetFn> Core::TestSets

A collection of test sets.

typedef std::vector<tstring> Core::TestCaseNames

A collection of test case names.

typedef std::set<tstring> Core::TestSetFilters

A collection of test suite names.

typedef void(* Core::TestSetFn)()

The Test Set run function type.

typedef void(* Core::TestCaseSetUpFn)()

The test case SetUp function type.

typedef void(* Core::TestCaseTearDownFn)()

The test case TearDown function type.


Enumeration Type Documentation

The test runner command line switch IDs.

Enumerator:
HELP 

Show command line usage.

VERBOSE 

Verbose output of each test case.

QUIET 

Minimal output of each test case.

Test case result state.

Enumerator:
UNKNOWN 
SUCCEEDED 

Test result undetermined.

FAILED 

Test definitely succeeded.


Function Documentation

template<typename T >
bool Core::exists ( const std::vector< T > &  container,
value 
) [inline]

Search to see if the value exists within the container.

template<typename T >
void Core::deepCopy ( const std::vector< Core::SharedPtr< T > > &  input,
std::vector< Core::SharedPtr< T > > &  output 
) [inline]

Perform a deep copy of the container.

void Core::ansiToWide ( const char *  pszBegin,
const char *  pszEnd,
wchar_t *  pszDst 
)

Convert a string from ANSI to Wide.

std::wstring Core::ansiToWide ( const char *  pszBegin,
const char *  pszEnd 
)

Convert a string from ANSI to Wide.

void Core::wideToAnsi ( const wchar_t *  pszBegin,
const wchar_t *  pszEnd,
char *  pszDst 
)

Convert a string from Wide to ANSI.

std::string Core::wideToAnsi ( const wchar_t *  pszBegin,
const wchar_t *  pszEnd 
)

Convert a string from Wide to ANSI.

std::wstring Core::ansiToWide ( const char *  psz) [inline]

Convert a string from ANSI to Wide.

std::wstring Core::ansiToWide ( const std::string &  str) [inline]

Convert a string from ANSI to Wide.

std::string Core::wideToAnsi ( const wchar_t *  psz) [inline]

Convert a string from Wide to ANSI.

std::string Core::wideToAnsi ( const std::wstring &  str) [inline]

Convert a string from Wide to ANSI.

template<typename T >
T ** Core::attachTo ( ArrayPtr< T > &  ptr) [inline]

Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.

Allow attachment via an output parameter.

e.g. LoadTypeLib(..., attachTo(p)).

void Core::assertFail ( const char *  pszExpression,
const char *  pszFile,
uint  nLine 
)

The function invoked when an ASSERT fails.

It displays a message box with details about why and where the assert failed. If asked it will also cause an INT 3 to kick in the debugger.

void Core::traceEx ( const tchar pszFormat,
  ... 
)

Function to write a message to the debugger output.

This is a printf() style function for outputing debugging messages. It uses vsprintf() and so is restricted to the types it can handle.

void Core::debugWrite ( const tchar pszFormat,
  ... 
)

Write a message to the debugger stream in both Debug and Release builds.

Unlike TraceEx() this goes directly to OutputDebugString().

void Core::enableLeakReporting ( bool  bEnable)

Enable or disable memory leak reporting.

NB: This function is available in all builds, but does nothing in Release.

Get the folder to use for temporary files.

tstring Core::combinePaths ( const tstring lhs,
const tstring rhs 
)

Combine two paths into a single path.

bool Core::pathExists ( const tstring path)

Query if the path points to a file or folder that exists.

static void Core::localFree ( tchar buffer) [static]

Wrapper to invoke LocalFree on the buffer pointer.

static tstring Core::formatWin32ErrorMessage ( DWORD  errorCode) [static]

Convert the WIN32 error code into a text message.

void Core::deleteFile ( const tstring path,
bool  ignoreErrors 
)

Delete the specified file.

long Core::atomicIncrement ( volatile long &  value) [inline]

Thread-safe function for incrementing the value by one.

long Core::atomicDecrement ( volatile long &  value) [inline]

Thread-safe function for decrementing the value by one.

template<typename T >
T ** Core::attachTo ( RefCntPtr< T > &  ptr) [inline]

Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.

Allow attachment via an output parameter.

e.g. LoadTypeLib(..., attachTo(p)).

template<typename P , typename U >
RefCntPtr<P> Core::static_ptr_cast ( const RefCntPtr< U > &  oPtr) [inline]

A variant of static_cast<> that can be used to create a RefCntPtr of the derived ptr type from the base ptr type.

Allow member access for the static_cast like function.

template<typename P , typename U >
RefCntPtr<P> Core::dynamic_ptr_cast ( const RefCntPtr< U > &  oPtr) [inline]

A variant of dynamic_cast<> that can be used to create a RefCntPtr of the derived ptr type from the base ptr type.

Allow member access for the dynamic_cast like function.

template<typename T >
T * Core::attachTo ( Scoped< T > &  guard) [inline]

Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.

Allow attachment via an output parameter.

e.g. LoadTypeLib(..., attachTo(p)).

template<typename P , typename U >
SharedPtr<P> Core::static_ptr_cast ( const SharedPtr< U > &  oPointer) [inline]

A variant of static_cast<> that can be used to create a SharedPtr of the derived ptr type from the base ptr type.

Allow member access for the static_cast like function.

template<typename P , typename U >
SharedPtr<P> Core::dynamic_ptr_cast ( const SharedPtr< U > &  oPointer) [inline]

A variant of dynamic_cast<> that can be used to create a SharedPtr of the derived ptr type from the base ptr type.

Allow member access for the dynamic_cast like function.

template<typename T , typename U >
bool Core::operator== ( const SmartPtr< T > &  oLHS,
const SmartPtr< U > &  oRHS 
) [inline]

SmartPtr<T> equality operator.

Compare two SmartPtr's for equality.

template<typename T , typename U >
bool Core::operator!= ( const SmartPtr< T > &  oLHS,
const SmartPtr< U > &  oRHS 
) [inline]

SmartPtr<T> inequality operator.

Compare two SmartPtr's for inequality.

tstring Core::fmtEx ( const tchar pszFormat,
va_list  args 
)

Format the string ala printf.

This function is used internally as the underlying function used for all var args string formatting.

tstring Core::fmt ( const tchar pszFormat,
  ... 
)

Format the string ala printf.

template<typename T , typename Traits >
tstring Core::formatInteger ( const T &  value)

Generic function for parsing integers.

template<>
tstring Core::format ( const bool &  value)

Format a boolean value into a string.

template<>
tstring Core::format ( const int &  value)

Format a signed integer value into a string.

template<>
tstring Core::format ( const uint value)

Format an unsigned integer value into a string.

template<>
tstring Core::format ( const longlong value)

Format a signed long long integer value into a string.

template<>
tstring Core::format ( const ulonglong value)

Format a unsigned long long integer value into a string.

template<typename T , typename Traits >
T Core::parseInteger ( const tstring buffer)

Generic function for parsing integers.

template<>
ulonglong Core::parse ( const tstring buffer)

Parse a boolean value from a string.

void Core::makeUpper ( tstring string)

Convert a string to upper case.

Create an upper case version of a string.

void Core::makeLower ( tstring string)

Convert a string to lower case.

Create a lower case version of a string.

void Core::trimLeft ( tstring string)

Trim any leading whitespace from the string.

void Core::trimRight ( tstring string)

Trim any trailing whitespace from the string.

void Core::trim ( tstring string)

Trim any leading or trailing whitespace from the string.

Trim any leading or trailing whitespace from a copy of the string.

template<typename First , typename Last >
First Core::skipWhitespace ( First  first,
Last  last 
)

Skip any leading whitespace.

template<typename T >
tstring Core::format ( const T &  value)

Format a value into a string.

template<typename T >
T Core::parse ( const tstring buffer)

Parse a boolean value from a string.

bool Core::operator== ( const TextFileIterator &  lhs,
const TextFileIterator &  rhs 
) [inline]

Compare two iterators for equivalence.

bool Core::operator!= ( const TextFileIterator &  lhs,
const TextFileIterator &  rhs 
) [inline]

Compare two iterators for difference.

template<typename CharT >
size_t Core::numBytes ( size_t  nChars) [inline]

Calculate the number of bytes required to represent a string of the given number of characters.

size_t Core::numBytes ( const char *  psz) [inline]

Calculate the number of bytes required to represent the string.

size_t Core::numBytes ( const wchar_t *  psz) [inline]

Calculate the number of bytes required to represent the string.

template<typename T >
T ** Core::attachTo ( UniquePtr< T > &  ptr) [inline]

Helper function to gain access to the internal member so that it can be passed as an output parameter, without overloading the & operator.

Allow attachment via an output parameter.

e.g. LoadTypeLib(..., attachTo(p)).

static void Core::showUsage ( const tchar process,
const Core::CmdLineParser parser 
) [static]

Display the program options syntax.

bool Core::parseCmdLine ( int  argc,
tchar argv[],
TestSetFilters &  filters 
)

Parse the command line.

This extracts the list of test cases to run.

static TestSets& Core::getTestSetCollection ( ) [static]

Get the collection of test sets.

This is accessed via a special function to workaround the indeterminate initialisation order of the self-registering test sets and this collection.

bool Core::registerTestSet ( const tchar name,
TestSetFn  runner 
)

Register a test set runner function.

bool Core::runTestSets ( const TestSetFilters &  filters)

Run the self-registering test sets.

void Core::onStartTestSet ( const tchar name)

Start the test set.

End the test set.

void Core::defineTestCaseSetup ( TestCaseSetUpFn  setup)

Define the test case setup function.

void Core::defineTestCaseTearDown ( TestCaseTearDownFn  teardown)

Define the test case teardown function.

bool Core::onStartTestCase ( const tchar name)

Start a new test case.

End a test case.

static const char* Core::getFileName ( const char *  path) [static]

Get just the filename from the path.

void Core::processAssertResult ( const char *  file,
size_t  line,
const tchar expression,
bool  passed 
)

Write the assert result to stdout.

void Core::processTestException ( const char *  file,
size_t  line,
const tchar error 
)

Process an unexpected exception running a test case.

void Core::processSetupTeardownException ( const tchar function,
const tchar error 
)

Process an unexpected exception during setup or teardown.

void Core::setTestRunFinalStatus ( bool  successful)

Set how the test run completed.

Write the summary of the test results to the debugger stream and stdout.

Get the test process result code.


Variable Documentation

bool Core::g_bReportLeaks = false [static]

The flag used to signal whether to dump leaks or not.

const size_t Core::npos = static_cast<size_t>(-1) [static]

A general purpose equivalent to basic_string::npos.

bool Core::s_successful = false [static]

The overall state of the test run.

uint Core::s_numPassed = 0 [static]

The number of tests that passed.

uint Core::s_numFailed = 0 [static]

The number of tests that failed.

uint Core::s_numUnknown = 0 [static]

The number of tests that were indeterminate.

bool Core::s_verbose = false [static]

Is verbose mode enabled?

bool Core::s_quiet = false [static]

Is quiet mode enabled?

Current test case status.

The name of the executing test set.

The name of the executing test case.

The list of failed test cases for the set.

The test case SetUp function.

The test case TearDown function.

The list of test cases executed.

Initial value:
{
    { HELP,     TXT("?"),   NULL,           Core::CmdLineSwitch::ONCE,  Core::CmdLineSwitch::NONE,  NULL,   TXT("Display command line usage")       },
    { HELP,     TXT("h"),   TXT("help"),    Core::CmdLineSwitch::ONCE,  Core::CmdLineSwitch::NONE,  NULL,   TXT("Display command line usage")       },
    { VERBOSE,  TXT("v"),   TXT("verbose"), Core::CmdLineSwitch::ONCE,  Core::CmdLineSwitch::NONE,  NULL,   TXT("Verbose output of each test case") },
    { QUIET,    TXT("q"),   TXT("quiet"),   Core::CmdLineSwitch::ONCE,  Core::CmdLineSwitch::NONE,  NULL,   TXT("Minimal output of each test case") },
}

Parse the command line.

This extracts the list of test cases to run.