📄 assert.cpp
字号:
//// This file is part of the "More for C++" library//// Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)//// The "More for C++" library is free software; you can redistribute it and/or// modify it under the terms of the license that comes with this package.//// Read "license.txt" for more details.//// THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES// OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#include <cstdio>#include <cstring>#include <more/test/assert.hpp>#include "testexception.hpp"using namespace more::test;////////////////////////////////////////////////////////////////////////////////Assert::~Assert( ){}////////////////////////////////////////////////////////////////////////////////void Assert::fail( const char* pcMessage){ throw TestException( pcMessage );}////////////////////////////////////////////////////////////////////////////////void Assert::assertNull( const void* pObject, const char* pcMessage){ if( pObject != 0 ) { throw TestException( pcMessage ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertNotNull( const void* pObject, const char* pcMessage){ if( pObject == 0 ) { throw TestException( pcMessage ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertCondition( bool bCondition, const char* pcMessage){ if( !bCondition ) { throw TestException( pcMessage ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsChar( char cValue, char cExpected, const char* pcMessage){ if( cValue != cExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %c but was %c)", cExpected, cValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsUnsignedChar( unsigned char cValue, unsigned char cExpected, const char* pcMessage){ if( cValue != cExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %c but was %c)", cExpected, cValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsInt( int nValue, int nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %d but was %d)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsUnsignedInt( unsigned int nValue, unsigned int nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %u but was %u)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsLong( long nValue, long nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %ld but was %ld)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsUnsignedLong( unsigned long nValue, unsigned long nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %lu but was %lu)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsFloat( float nValue, float nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %g but was %g)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsDouble( double nValue, double nExpected, const char* pcMessage){ if( nValue != nExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected %g but was %g)", nExpected, nValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsString( const char* pcValue, const char* pcExpected, const char* pcMessage){ if( strcmp( pcValue, pcExpected) != 0 ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected \"%.511s\" but was \"%.511s\")", pcExpected, pcValue ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////void Assert::assertEqualsPointer( const void* pValue, const void* pExpected, const char* pcMessage){ if( pValue != pExpected ) { char cExplanation[1024]; sprintf( cExplanation, "(Expected another value of the pointer)" ); throw TestException( pcMessage, cExplanation ); }}////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -