From 4808b9249ec168cdfcc49a183294e465aa38a784 Mon Sep 17 00:00:00 2001 From: Bill Hart Date: Sat, 4 Feb 2012 12:11:51 -0700 Subject: [PATCH] Changing if/for/while commands to add braces. This commit clarifies the scope of these statements. This change accounts for Tigris ticket #55. --- .gitignore | 1 + cxxtest/Descriptions.cpp | 18 +++++++---- cxxtest/ErrorFormatter.h | 18 +++++++---- cxxtest/LinkedList.cpp | 57 ++++++++++++++++++++++----------- cxxtest/Mock.h | 15 ++++++--- cxxtest/QtGui.h | 30 ++++++++++++------ cxxtest/RealDescriptions.cpp | 20 +++++++----- cxxtest/StdValueTraits.h | 12 ++++--- cxxtest/TestRunner.h | 12 ++++--- cxxtest/TestSuite.cpp | 41 +++++++++++++++--------- cxxtest/TestSuite.h | 23 +++++++++----- cxxtest/TestTracker.cpp | 3 +- cxxtest/ValueTraits.cpp | 39 +++++++++++++++-------- cxxtest/ValueTraits.h | 19 ++++++----- cxxtest/Win32Gui.h | 61 ++++++++++++++++++++++-------------- cxxtest/X11Gui.h | 33 ++++++++++++------- 16 files changed, 263 insertions(+), 139 deletions(-) diff --git a/.gitignore b/.gitignore index 9ae46f5..66d8f5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ +*.pyc .* guide.epub guide.pdf diff --git a/cxxtest/Descriptions.cpp b/cxxtest/Descriptions.cpp index dc2b88b..98b2bd5 100644 --- a/cxxtest/Descriptions.cpp +++ b/cxxtest/Descriptions.cpp @@ -34,8 +34,9 @@ namespace CxxTest { char *p = numberToString( numTotalTests(), s ); - if ( numTotalTests() <= 1 ) + if ( numTotalTests() <= 1 ) { return s; + } unsigned n = numTotalTests(); unsigned numFactors = 0; @@ -43,23 +44,28 @@ namespace CxxTest 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; } diff --git a/cxxtest/ErrorFormatter.h b/cxxtest/ErrorFormatter.h index 9483976..94bb59e 100644 --- a/cxxtest/ErrorFormatter.h +++ b/cxxtest/ErrorFormatter.h @@ -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() @@ -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; } diff --git a/cxxtest/LinkedList.cpp b/cxxtest/LinkedList.cpp index cb8eb99..3ca8e87 100644 --- a/cxxtest/LinkedList.cpp +++ b/cxxtest/LinkedList.cpp @@ -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; } @@ -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() : @@ -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; + } } } diff --git a/cxxtest/Mock.h b/cxxtest/Mock.h index 2fc85c3..6fd8bcb 100644 --- a/cxxtest/Mock.h +++ b/cxxtest/Mock.h @@ -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(); \ } \ } @@ -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::defaultValue(); \ } \ @@ -177,8 +179,9 @@ namespace dummy_mock_ns {} \ void _Unimplemented_##MOCK::NAME ARGS \ { \ - while ( false ) \ + while ( false ) { \ NAME CALL; \ + } \ __CXXTEST_MOCK_UNIMPLEMENTED( NAME, ARGS ); \ } \ \ @@ -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::defaultValue(); \ } \ @@ -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 ); \ } \ } \ diff --git a/cxxtest/QtGui.h b/cxxtest/QtGui.h index 9abce3d..e98b0b4 100644 --- a/cxxtest/QtGui.h +++ b/cxxtest/QtGui.h @@ -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(); @@ -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]; + } } } @@ -135,10 +139,12 @@ namespace CxxTest createProgressBar(); createStatusBar(); setMainWidget(); - if ( _startMinimized ) + if ( _startMinimized ) { showMinimized(); - else + } + else { showNormal(); + } } void getTotalTests() @@ -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 ); diff --git a/cxxtest/RealDescriptions.cpp b/cxxtest/RealDescriptions.cpp index 91baa9e..eb5099f 100644 --- a/cxxtest/RealDescriptions.cpp +++ b/cxxtest/RealDescriptions.cpp @@ -46,8 +46,9 @@ namespace CxxTest bool RealTestDescription::setUp() { - if ( !suite() ) + if ( !suite() ) { return false; + } for ( GlobalFixture *gf = GlobalFixture::firstGlobalFixture(); gf != 0; gf = gf->nextGlobalFixture() ) { bool ok; @@ -63,7 +64,7 @@ namespace CxxTest _TS_TRY { bool ok = false; _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from setUp()", suite()->setUp(); ok=true ); - if (ok == false) return ok; + if (ok == false) { return ok; } } _TS_CATCH_ABORT( { return false; } ); @@ -72,8 +73,9 @@ namespace CxxTest bool RealTestDescription::tearDown() { - if ( !suite() ) + if ( !suite() ) { return false; + } _TS_TRY { _TSM_ASSERT_THROWS_NOTHING( file(), line(), "Exception thrown from tearDown()", suite()->tearDown() ); @@ -231,8 +233,9 @@ namespace CxxTest unsigned RealWorldDescription::numTotalTests( void ) const { unsigned count = 0; - for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) + for ( const SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) { count += sd->numTests(); + } return count; } @@ -254,17 +257,20 @@ namespace CxxTest void RealWorldDescription::activateAllTests() { suites().activateAll(); - for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) + for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) { sd->activateAllTests(); + } } bool RealWorldDescription::leaveOnly( const char *suiteName, const char *testName ) { for ( SuiteDescription *sd = firstSuite(); sd != 0; sd = sd->next() ) { if ( stringsEqual( sd->suiteName(), suiteName ) ) { - if ( testName ) - if ( !sd->leaveOnly( testName ) ) + if ( testName ) { + if ( !sd->leaveOnly( testName ) ) { return false; + } + } suites().leaveOnly( *sd ); return true; } diff --git a/cxxtest/StdValueTraits.h b/cxxtest/StdValueTraits.h index 2c9060c..e4bc66f 100644 --- a/cxxtest/StdValueTraits.h +++ b/cxxtest/StdValueTraits.h @@ -110,8 +110,9 @@ namespace CxxTest s << "{ "; while ( first != last ) { s << TS_AS_STRING(*first); - if ( ++ first != last ) + if ( ++ first != last ) { s << ", "; + } } s << " }"; } @@ -230,12 +231,15 @@ namespace CxxTest public: ValueTraits( const CXXTEST_STD(complex) &c ) { - if ( !c.imag() ) + if ( !c.imag() ) { *this << TS_AS_STRING(c.real()); - else if ( !c.real() ) + } + else if ( !c.real() ) { *this << "(" << TS_AS_STRING(c.imag()) << " * i)"; - else + } + else { *this << "(" << TS_AS_STRING(c.real()) << " + " << TS_AS_STRING(c.imag()) << " * i)"; + } } }; #endif // _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION diff --git a/cxxtest/TestRunner.h b/cxxtest/TestRunner.h index 17866a6..7fc7757 100644 --- a/cxxtest/TestRunner.h +++ b/cxxtest/TestRunner.h @@ -52,9 +52,11 @@ namespace CxxTest tracker().enterWorld( wd ); if ( wd.setUp() ) { - for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() ) - if ( sd->active() ) + for ( SuiteDescription *sd = wd.firstSuite(); sd; sd = sd->next() ) { + if ( sd->active() ) { runSuite( *sd ); + } + } wd.tearDown(); } @@ -67,9 +69,11 @@ namespace CxxTest tracker().enterSuite( sd ); if ( sd.setUp() ) { - for ( TestDescription *td = sd.firstTest(); td; td = td->next() ) - if ( td->active() ) + for ( TestDescription *td = sd.firstTest(); td; td = td->next() ) { + if ( td->active() ) { runTest( *td ); + } + } sd.tearDown(); } diff --git a/cxxtest/TestSuite.cpp b/cxxtest/TestSuite.cpp index eef2cce..2a5d9c6 100644 --- a/cxxtest/TestSuite.cpp +++ b/cxxtest/TestSuite.cpp @@ -44,8 +44,9 @@ namespace CxxTest void doAbortTest() { # if defined(_CXXTEST_HAVE_EH) - if ( currentAbortTestOnFail ) + if ( currentAbortTestOnFail ) { throw AbortTest(); + } # endif // _CXXTEST_HAVE_EH } @@ -88,28 +89,34 @@ namespace CxxTest void doFailAssert( const char *file, int line, const char *expression, const char *message ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssert( file, line, expression ); TS_ABORT(); } bool sameData( const void *x, const void *y, unsigned size ) { - if ( size == 0 ) + if ( size == 0 ) { return true; + } - if ( x == y ) + if ( x == y ) { return true; + } - if ( !x || !y ) + if ( !x || !y ) { return false; + } const char *cx = (const char *)x; const char *cy = (const char *)y; - while ( size -- ) - if ( *cx++ != *cy++ ) + while ( size -- ) { + if ( *cx++ != *cy++ ) { return false; + } + } return true; } @@ -121,8 +128,9 @@ namespace CxxTest const char *message ) { if ( !sameData( x, y, size ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertSameData( file, line, xExpr, yExpr, sizeExpr, x, y, size ); TS_ABORT(); } @@ -154,7 +162,7 @@ namespace CxxTest while (1) { is1.get(c1); is2.get(c2); - if (!is1 && !is2) return true; + if (!is1 && !is2) { return true; } if (!is1) { explanation << "File '" << file1 << "' ended before file '" << file2 << "' (line " << nline << ")"; explanation << std::endl << "= " << ppprev_line << std::endl << "= " << pprev_line << std::endl << "= " << prev_line << std::endl << "< " << curr_line; @@ -220,8 +228,9 @@ namespace CxxTest #if defined(_CXXTEST_HAVE_STD) std::ostringstream explanation; if ( !sameFiles( file1, file2, explanation ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertSameFiles( file, line, file1, file2, explanation.str().c_str()); TS_ABORT(); } @@ -237,10 +246,12 @@ namespace CxxTest const char *message, const char *exception ) { - if ( exception ) + if ( exception ) { tracker().failedTest( file, line, exception ); - if ( message ) + } + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertThrows( file, line, expr, type, otherThrown ); TS_ABORT(); @@ -250,10 +261,12 @@ namespace CxxTest const char *expression, const char *message, const char *exception ) { - if ( exception ) + if ( exception ) { tracker().failedTest( file, line, exception ); - if ( message ) + } + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertThrowsNot( file, line, expression ); TS_ABORT(); diff --git a/cxxtest/TestSuite.h b/cxxtest/TestSuite.h index eeec0b3..0c7b38f 100644 --- a/cxxtest/TestSuite.h +++ b/cxxtest/TestSuite.h @@ -68,8 +68,9 @@ namespace CxxTest const char *message ) { if ( !equals::test( x, y ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); TS_ABORT(); } @@ -102,8 +103,9 @@ namespace CxxTest const char *message ) { if ( !differs::test( x, y ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertDiffers( file, line, xExpr, yExpr, TS_AS_STRING(x) ); TS_ABORT(); } @@ -124,8 +126,9 @@ namespace CxxTest const char *message ) { if ( !lessThan::test(x, y) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertLessThan( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); TS_ABORT(); } @@ -146,8 +149,9 @@ namespace CxxTest const char *message ) { if ( !lessThanEquals::test( x, y ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertLessThanEquals( file, line, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); TS_ABORT(); } @@ -160,8 +164,9 @@ namespace CxxTest const char *message ) { if ( !p( x ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertPredicate( file, line, pExpr, xExpr, TS_AS_STRING(x) ); TS_ABORT(); } @@ -175,8 +180,9 @@ namespace CxxTest const char *message ) { if ( !r( x, y ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertRelation( file, line, rExpr, xExpr, yExpr, TS_AS_STRING(x), TS_AS_STRING(y) ); TS_ABORT(); } @@ -207,8 +213,9 @@ namespace CxxTest const char *message ) { if ( !delta::test( x, y, d ) ) { - if ( message ) + if ( message ) { tracker().failedTest( file, line, message ); + } tracker().failedAssertDelta( file, line, xExpr, yExpr, dExpr, TS_AS_STRING(x), TS_AS_STRING(y), TS_AS_STRING(d) ); @@ -274,7 +281,7 @@ namespace CxxTest # define TS_FAIL(e) _TS_FAIL( __FILE__, __LINE__, e ) // TS_ASSERT -# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) CxxTest::doFailAssert( (f), (l), #e, (m) ); } +# define ___ETS_ASSERT(f,l,e,m) { if ( !(e) ) { CxxTest::doFailAssert( (f), (l), #e, (m) ); } } # define ___TS_ASSERT(f,l,e,m) { _TS_TRY { ___ETS_ASSERT(f,l,e,m); } __TS_CATCH(f,l) } # define _ETS_ASSERT(f,l,e) ___ETS_ASSERT(f,l,e,0) diff --git a/cxxtest/TestTracker.cpp b/cxxtest/TestTracker.cpp index bb051c4..521b546 100644 --- a/cxxtest/TestTracker.cpp +++ b/cxxtest/TestTracker.cpp @@ -257,8 +257,9 @@ namespace CxxTest { if ( ++ _testFailedAsserts == 1 ) { ++ _failedTests; - if ( ++ _suiteFailedTests == 1 ) + if ( ++ _suiteFailedTests == 1 ) { ++ _failedSuites; + } } } } diff --git a/cxxtest/ValueTraits.cpp b/cxxtest/ValueTraits.cpp index f19b684..8a06652 100644 --- a/cxxtest/ValueTraits.cpp +++ b/cxxtest/ValueTraits.cpp @@ -22,10 +22,12 @@ namespace CxxTest char digitToChar( unsigned digit ) { - if ( digit < 10 ) + if ( digit < 10 ) { return (char)('0' + digit); - if ( digit <= 10 + 'Z' - 'A' ) + } + if ( digit <= 10 + 'Z' - 'A' ) { return (char)('A' + digit - 10); + } return '?'; } @@ -50,9 +52,11 @@ namespace CxxTest bool stringsEqual( const char *s1, const char *s2 ) { char c; - while ( (c = *s1++) == *s2++ ) - if ( c == '\0' ) + while ( (c = *s1++) == *s2++ ) { + if ( c == '\0' ) { return true; + } + } return false; } @@ -93,14 +97,17 @@ namespace CxxTest char *bytesToString( const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s ) { bool truncate = (numBytes > maxBytes); - if ( truncate ) + if ( truncate ) { numBytes = maxBytes; + } s = copyString( s, "{ " ); - for ( unsigned i = 0; i < numBytes; ++ i, ++ bytes ) + for ( unsigned i = 0; i < numBytes; ++ i, ++ bytes ) { s = copyString( copyString( s, byteToHex( *bytes ) ), " " ); - if ( truncate ) + } + if ( truncate ) { s = copyString( s, "..." ); + } return copyString( s, " }" ); } @@ -108,15 +115,17 @@ namespace CxxTest unsigned ValueTraits::requiredDigitsOnLeft( double t ) { unsigned digits = 1; - for ( t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE ) + for ( t = (t < 0.0) ? -t : t; t > 1.0; t /= BASE ) { ++ digits; + } return digits; } char *ValueTraits::doNegative( double &t ) { - if ( t >= 0 ) + if ( t >= 0 ) { return _asString; + } _asString[0] = '-'; t = -t; return _asString + 1; @@ -137,21 +146,25 @@ namespace CxxTest char *s = doNegative( t ); s = doubleToString( t, s ); s = copyString( s, "." ); - for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i ) + for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i ) { s = numberToString( (unsigned)(t *= BASE) % BASE, s ); + } } void ValueTraits::nonFiniteNumber( double t ) { char *s = _asString; - if ( t != t ) + if ( t != t ) { s = copyString( s, "nan" ); + } //else if ( t == 1.0/0.0 ) - else if ( t >= HUGE_VAL ) + else if ( t >= HUGE_VAL ) { s = copyString( s, "-inf" ); - else if ( t <= -HUGE_VAL ) + } + else if ( t <= -HUGE_VAL ) { //else if ( t == -1.0/0.0 ) s = copyString( s, "inf" ); + } } char *ValueTraits::doubleToString( double t, char *s, unsigned skip, unsigned max ) diff --git a/cxxtest/ValueTraits.h b/cxxtest/ValueTraits.h index 9e24cd4..52bc86d 100644 --- a/cxxtest/ValueTraits.h +++ b/cxxtest/ValueTraits.h @@ -168,13 +168,16 @@ namespace CxxTest } N digit = 1; - while ( digit <= (n / base) ) + while ( digit <= (n / base) ) { digit *= base; + } N digitValue; - for ( ; digit >= 1 && skipDigits; n -= digit * digitValue, digit /= base, -- skipDigits ) + for ( ; digit >= 1 && skipDigits; n -= digit * digitValue, digit /= base, -- skipDigits ) { digitValue = (unsigned)(n / digit); - for ( ; digit >= 1 && maxDigits; n -= digit * digitValue, digit /= base, -- maxDigits ) + } + for ( ; digit >= 1 && maxDigits; n -= digit * digitValue, digit /= base, -- maxDigits ) { *s++ = digitToChar( (unsigned)(digitValue = (unsigned)(n / digit)) ); + } *s = '\0'; return s; @@ -329,13 +332,15 @@ namespace CxxTest public: ValueTraits( double t ) { - //if ( ( t != t ) || ( t >= 1.0/0.0 ) || ( t == -1.0/0.0 ) ) - if ( ( t != t ) || ( t >= HUGE_VAL ) || ( t == -HUGE_VAL ) ) + if ( ( t != t ) || ( t >= HUGE_VAL ) || ( t == -HUGE_VAL ) ) { nonFiniteNumber( t ); - else if ( requiredDigitsOnLeft( t ) > MAX_DIGITS_ON_LEFT ) + } + else if ( requiredDigitsOnLeft( t ) > MAX_DIGITS_ON_LEFT ) { hugeNumber( t ); - else + } + else { normalNumber( t ); + } } const char *asString( void ) const { return _asString; } diff --git a/cxxtest/Win32Gui.h b/cxxtest/Win32Gui.h index ec47771..9898d43 100644 --- a/cxxtest/Win32Gui.h +++ b/cxxtest/Win32Gui.h @@ -75,8 +75,9 @@ namespace CxxTest void redBar() { - if ( _startMinimized ) + if ( _startMinimized ) { showMainWindow( SW_SHOWNORMAL ); + } setColor( 255, 0, 0 ); setIcon( IDI_ERROR ); getTotalTests(); @@ -121,12 +122,15 @@ namespace CxxTest for ( int i = 1; i < argc; ++ i ) { - if ( !lstrcmpA( argv[i], "-minimized" ) ) + if ( !lstrcmpA( argv[i], "-minimized" ) ) { _startMinimized = true; - else if ( !lstrcmpA( argv[i], "-keep" ) ) + } + else if ( !lstrcmpA( argv[i], "-keep" ) ) { _keep = true; - else if ( !lstrcmpA( argv[i], "-title" ) && (i + 1 < argc) ) + } + else if ( !lstrcmpA( argv[i], "-title" ) && (i + 1 < argc) ) { _title = argv[++i]; + } } } @@ -196,15 +200,12 @@ namespace CxxTest void initCommonControls() { HMODULE dll = LoadLibraryA( "comctl32.dll" ); - if ( !dll ) - return; + if ( !dll ) { return; } - typedef void (WINAPI *FUNC)( void ); - FUNC func = (FUNC)GetProcAddress( dll, "InitCommonControls" ); - if ( !func ) - return; - - func(); + typedef void (WINAPI *FUNC)( void ); + FUNC func = (FUNC)GetProcAddress( dll, "InitCommonControls" ); + if ( !func ) { return; } + func(); } void createProgressBar() @@ -266,8 +267,9 @@ namespace CxxTest LONG windowWidth = (screenWidth * 4) / 5; LONG windowHeight = screenHeight / 10; LONG minimumHeight = 2 * (GetSystemMetrics( SM_CYCAPTION ) + GetSystemMetrics( SM_CYFRAME )); - if ( windowHeight < minimumHeight ) + if ( windowHeight < minimumHeight ) { windowHeight = minimumHeight; + } SetWindowPos( _mainWindow, HWND_TOP, xCenter - (windowWidth / 2), yCenter - (windowHeight / 2), @@ -276,8 +278,9 @@ namespace CxxTest void getScreenArea( RECT &area ) { - if ( !getScreenAreaWithoutTaskbar( area ) ) + if ( !getScreenAreaWithoutTaskbar( area ) ) { getWholeScreenArea( area ); + } } bool getScreenAreaWithoutTaskbar( RECT &area ) @@ -326,15 +329,18 @@ namespace CxxTest void messageLoop() { MSG message; - while ( BOOL haveMessage = GetMessage( &message, NULL, 0, 0 ) ) - if ( haveMessage != -1 ) + while ( BOOL haveMessage = GetMessage( &message, NULL, 0, 0 ) ) { + if ( haveMessage != -1 ) { DispatchMessage( &message ); + } + } } static LRESULT CALLBACK windowProcedure( HWND window, UINT message, WPARAM wParam, LPARAM lParam ) { - if ( message == WM_CREATE ) + if ( message == WM_CREATE ) { setUp( window, (LPCREATESTRUCT)lParam ); + } Win32Gui *that = (Win32Gui *)GetWindowLong( window, GWL_USERDATA ); return that->handle( window, message, wParam, lParam ); @@ -382,8 +388,9 @@ namespace CxxTest void setStatusParts( LONG width ) { - for ( unsigned i = 0; i < STATUS_TOTAL_PARTS; ++ i ) + for ( unsigned i = 0; i < STATUS_TOTAL_PARTS; ++ i ) { _statusWidths[i] = (width * _statusOffsets[i]) / _statusTotal; + } statusBarMessage( SB_SETPARTS, STATUS_TOTAL_PARTS, _statusWidths ); } @@ -472,20 +479,24 @@ namespace CxxTest unsigned minutes = (total / 60) % 60; unsigned seconds = total % 60; - if ( hours ) + if ( hours ) { wsprintfA( _timeString, "%u:%02u:%02u", hours, minutes, seconds ); - else + } + else { wsprintfA( _timeString, "%02u:%02u", minutes, seconds ); + } setStatusPart( part, _timeString ); } bool keep() { - if ( !_keep ) + if ( !_keep ) { return false; - if ( !_startMinimized ) + } + if ( !_startMinimized ) { return true; + } return (_mainWindow == GetForegroundWindow()); } @@ -513,11 +524,13 @@ namespace CxxTest resizeControls(); const char *tests = (_numTotalTests == 1) ? "test" : "tests"; - if ( tracker().failedTests() ) + if ( tracker().failedTests() ) { wsprintfA( _statusTestsDone, "Failed %u of %s %s", tracker().failedTests(), _strTotalTests, tests ); - else + } + else { wsprintfA( _statusTestsDone, "%s %s passed", _strTotalTests, tests ); + } setStatusPart( STATUS_TESTS_DONE, _statusTestsDone ); } diff --git a/cxxtest/X11Gui.h b/cxxtest/X11Gui.h index 55e70ec..6228cdb 100644 --- a/cxxtest/X11Gui.h +++ b/cxxtest/X11Gui.h @@ -123,20 +123,27 @@ namespace CxxTest _redName = "Red"; for ( int i = 1; i + 1 < argc; ++ i ) { - if ( !strcmp( argv[i], "-title" ) ) + if ( !strcmp( argv[i], "-title" ) ) { _programName = argv[++ i]; - else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) ) + } + else if ( !strcmp( argv[i], "-fn" ) || !strcmp( argv[i], "-font" ) ) { _fontName = argv[++ i]; - else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) ) + } + else if ( !strcmp( argv[i], "-fg" ) || !strcmp( argv[i], "-foreground" ) ) { _foregroundName = argv[++ i]; - else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) ) + } + else if ( !strcmp( argv[i], "-bg" ) || !strcmp( argv[i], "-background" ) ) { _backgroundName = argv[++ i]; - else if ( !strcmp( argv[i], "-green" ) ) + } + else if ( !strcmp( argv[i], "-green" ) ) { _greenName = argv[++ i]; - else if ( !strcmp( argv[i], "-yellow" ) ) + } + else if ( !strcmp( argv[i], "-yellow" ) ) { _yellowName = argv[++ i]; - else if ( !strcmp( argv[i], "-red" ) ) + } + else if ( !strcmp( argv[i], "-red" ) ) { _redName = argv[++ i]; + } } } @@ -172,8 +179,9 @@ namespace CxxTest void createFont() { - if ( !loadFont() ) + if ( !loadFont() ) { useDefaultFont(); + } getFontInfo(); _textHeight = _fontInfo->ascent + _fontInfo->descent; _textDescent = _fontInfo->descent; @@ -181,8 +189,9 @@ namespace CxxTest bool loadFont() { - if ( !_fontName ) + if ( !_fontName ) { return false; + } _fontId = XLoadFont( _display, _fontName ); return (XSetFont( _display, _gc, _fontId ) == Success); } @@ -247,8 +256,9 @@ namespace CxxTest redraw(); XEvent event; - while( XCheckMaskEvent( _display, _eventMask, &event ) ) + while( XCheckMaskEvent( _display, _eventMask, &event ) ) { redraw(); + } } void setWindowName( const char *suiteName, const char *testName ) @@ -290,8 +300,9 @@ namespace CxxTest void drawDividers() { - if(_width / _numTotalTests < 5) + if (_width / _numTotalTests < 5) { return; + } for ( unsigned i = 1; i < _testsDone; ++ i ) { int x = (_width * i) / _numTotalTests; XDrawLine( _display, _window, _gc, x, 0, x, _height);