Skip to content

Commit

Permalink
Changing if/for/while commands to add braces.
Browse files Browse the repository at this point in the history
This commit clarifies the scope of these statements. This change
accounts for Tigris ticket CxxTest#55.
  • Loading branch information
whart222 committed Feb 4, 2012
1 parent faa0278 commit 4808b92
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__
*.pyc
.*
guide.epub
guide.pdf
18 changes: 12 additions & 6 deletions cxxtest/Descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,38 @@ namespace CxxTest
{
char *p = numberToString( numTotalTests(), s );

if ( numTotalTests() <= 1 )
if ( numTotalTests() <= 1 ) {
return s;
}

unsigned n = numTotalTests();
unsigned numFactors = 0;

for ( unsigned factor = 2; (factor * factor) <= n; factor += (factor == 2) ? 1 : 2 ) {
unsigned power;

for ( power = 0; (n % factor) == 0; n /= factor )
for ( power = 0; (n % factor) == 0; n /= factor ) {
++ power;
}

if ( !power )
if ( !power ) {
continue;
}

p = numberToString( factor, copyString( p, (numFactors == 0) ? " = " : " * " ) );
if ( power > 1 )
if ( power > 1 ) {
p = numberToString( power, copyString( p, "^" ) );
}
++ numFactors;
}

if ( n > 1 ) {
if ( !numFactors )
if ( !numFactors ) {
copyString( p, tracker().failedTests() ? " :(" : tracker().warnings() ? " :|" : " :)" );
else
}
else {
numberToString( n, copyString( p, " * " ) );
}
}
return s;
}
Expand Down
18 changes: 12 additions & 6 deletions cxxtest/ErrorFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,21 @@ namespace CxxTest

void reportTest( void )
{
if( _reported )
if ( _reported ) {
return;
}
(*_o) << "In " << tracker().suite().suiteName() << "::" << tracker().test().testName() << ":" << endl;
_reported = true;
}

void dump( const void *buffer, unsigned size )
{
if ( !buffer )
if ( !buffer ) {
dumpNull();
else
}
else {
dumpBuffer( buffer, size );
}
}

void dumpNull()
Expand All @@ -279,15 +282,18 @@ namespace CxxTest
void dumpBuffer( const void *buffer, unsigned size )
{
unsigned dumpSize = size;
if ( maxDumpSize() && dumpSize > maxDumpSize() )
if ( maxDumpSize() && dumpSize > maxDumpSize() ) {
dumpSize = maxDumpSize();
}

const unsigned char *p = (const unsigned char *)buffer;
(*_o) << " { ";
for ( unsigned i = 0; i < dumpSize; ++ i )
for ( unsigned i = 0; i < dumpSize; ++ i ) {
(*_o) << byteToHex( *p++ ) << " ";
if ( dumpSize < size )
}
if ( dumpSize < size ) {
(*_o) << "... ";
}
(*_o) << "}" << endl;
}

Expand Down
57 changes: 38 additions & 19 deletions cxxtest/LinkedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,36 @@ namespace CxxTest
Link *List::head()
{
Link *l = _head;
while ( l && !l->active() )
while ( l && !l->active() ) {
l = l->next();
}
return l;
}

const Link *List::head() const
{
Link *l = _head;
while ( l && !l->active() )
while ( l && !l->active() ) {
l = l->next();
}
return l;
}

Link *List::tail()
{
Link *l = _tail;
while ( l && !l->active() )
while ( l && !l->active() ) {
l = l->prev();
}
return l;
}

const Link *List::tail() const
{
Link *l = _tail;
while ( l && !l->active() )
while ( l && !l->active() ) {
l = l->prev();
}
return l;
}

Expand All @@ -64,30 +68,35 @@ namespace CxxTest
unsigned List::size() const
{
unsigned count = 0;
for ( const Link *l = head(); l != 0; l = l->next() )
for ( const Link *l = head(); l != 0; l = l->next() ) {
++ count;
}
return count;
}

Link *List::nth( unsigned n )
{
Link *l = head();
while ( n -- )
while ( n -- ) {
l = l->next();
}
return l;
}

void List::activateAll()
{
for ( Link *l = _head; l != 0; l = l->justNext() )
for ( Link *l = _head; l != 0; l = l->justNext() ) {
l->setActive( true );
}
}

void List::leaveOnly( const Link &link )
{
for ( Link *l = head(); l != 0; l = l->next() )
if ( l != &link )
for ( Link *l = head(); l != 0; l = l->next() ) {
if ( l != &link ) {
l->setActive( false );
}
}
}

Link::Link() :
Expand Down Expand Up @@ -124,59 +133,69 @@ namespace CxxTest
Link * Link::next()
{
Link *l = _next;
while ( l && !l->_active )
while ( l && !l->_active ) {
l = l->_next;
}
return l;
}

Link * Link::prev()
{
Link *l = _prev;
while ( l && !l->_active )
while ( l && !l->_active ) {
l = l->_prev;
}
return l;
}

const Link * Link::next() const
{
Link *l = _next;
while ( l && !l->_active )
while ( l && !l->_active ) {
l = l->_next;
}
return l;
}

const Link * Link::prev() const
{
Link *l = _prev;
while ( l && !l->_active )
while ( l && !l->_active ) {
l = l->_prev;
}
return l;
}

void Link::attach( List &l )
{
if ( l._tail )
if ( l._tail ) {
l._tail->_next = this;
}

_prev = l._tail;
_next = 0;

if ( l._head == 0 )
if ( l._head == 0 ) {
l._head = this;
}
l._tail = this;
}

void Link::detach( List &l )
{
if ( _prev )
if ( _prev ) {
_prev->_next = _next;
else
}
else {
l._head = _next;
}

if ( _next )
if ( _next ) {
_next->_prev = _prev;
else
}
else {
l._tail = _prev;
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions cxxtest/Mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ namespace dummy_mock_ns {}
\
Base_##MOCK &Base_##MOCK::current() \
{ \
if ( _list.empty() ) \
if ( _list.empty() ) { \
static _Unimplemented_##MOCK unimplemented; \
} \
return *(Base_##MOCK *)_list.tail(); \
} \
}
Expand All @@ -155,8 +156,9 @@ namespace dummy_mock_ns {}
\
TYPE _Unimplemented_##MOCK::NAME ARGS \
{ \
while ( false ) \
while ( false ) {\
return NAME CALL; \
} \
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
return MockTraits<TYPE>::defaultValue(); \
} \
Expand All @@ -177,8 +179,9 @@ namespace dummy_mock_ns {}
\
void _Unimplemented_##MOCK::NAME ARGS \
{ \
while ( false ) \
while ( false ) { \
NAME CALL; \
} \
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
} \
\
Expand All @@ -193,8 +196,9 @@ namespace dummy_mock_ns {}
namespace CXXTEST_MOCK_NAMESPACE { \
TYPE _Unimplemented_##MOCK::NAME ARGS \
{ \
while ( false ) \
while ( false ) { \
return NAME CALL; \
} \
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
return MockTraits<TYPE>::defaultValue(); \
} \
Expand All @@ -210,8 +214,9 @@ namespace dummy_mock_ns {}
namespace CXXTEST_MOCK_NAMESPACE { \
void _Unimplemented_##MOCK::NAME ARGS \
{ \
while ( false ) \
while ( false ) { \
NAME CALL; \
} \
__CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \
} \
} \
Expand Down
30 changes: 20 additions & 10 deletions cxxtest/QtGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ namespace CxxTest

void redBar()
{
if ( _startMinimized && _mainWindow->isMinimized() )
if ( _startMinimized && _mainWindow->isMinimized() ) {
showNormal();
}
setColor( 255, 0, 0 );
setIcon( QMessageBox::Critical );
getTotalTests();
Expand Down Expand Up @@ -114,12 +115,15 @@ namespace CxxTest

for ( int i = 1; i < argc; ++ i ) {
QString arg( argv[i] );
if ( arg == "-minimized" )
if ( arg == "-minimized" ) {
_startMinimized = true;
else if ( arg == "-keep" )
}
else if ( arg == "-keep" ) {
_keep = true;
else if ( arg == "-title" && (i + 1 < argc) )
}
else if ( arg == "-title" && (i + 1 < argc) ) {
_title = argv[++i];
}
}
}

Expand All @@ -135,10 +139,12 @@ namespace CxxTest
createProgressBar();
createStatusBar();
setMainWidget();
if ( _startMinimized )
if ( _startMinimized ) {
showMinimized();
else
}
else {
showNormal();
}
}

void getTotalTests()
Expand Down Expand Up @@ -255,20 +261,24 @@ namespace CxxTest

bool keep()
{
if ( !_keep )
if ( !_keep ) {
return false;
if ( !_startMinimized )
}
if ( !_startMinimized ) {
return true;
}
return (_mainWindow == _application->activeWindow());
}

void showSummary()
{
QString summary = _strTotalTests + (_numTotalTests == 1 ? " test" : " tests");
if ( tracker().failedTests() )
if ( tracker().failedTests() ) {
summary = "Failed " + asString( tracker().failedTests() ) + " of " + summary;
else
}
else {
summary = summary + " passed";
}

_mainWindow->setCaption( _title + " - " + summary );

Expand Down
Loading

0 comments on commit 4808b92

Please sign in to comment.