diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-02-08 07:48:59 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-02-08 09:15:01 +0100 |
commit | 6b00d0576a310796590631d14c54d7d5ea6814ac (patch) | |
tree | 2e11a4454592be39cfeaa68458cae964d8cdef5e /tools | |
parent | 17149f65f03a34e88bb4a10abcd20e6891f5d7ca (diff) |
Improve loplugin:cppunitassertequal for CPPUNIT_ASSERT(a && b)
...by re-enabling the code temporarily #if'ed-out in
a528392e71bc70136021be4e3d83732fccbb885e "Fixed/improved
loplugin:cppunitassertequals" (and which then triggers lots of other
lopglugin:cppunitassertequal CPPUNIT_ASSERT -> CPPUNIT_ASSERT_EQUAL warnings).
For two css::uno::Reference equality comparisons in cppu/qa/test_any.cxx, it
was more straightforward to rewrite them with an explicit call to operator ==
(which silences loplugin:cppunitassertequal) than to adapt them to
CPPUNIT_ASSERT_EQUAL's requirement for arguments of identical types.
In sc/qa/unit/ucalc_pivottable.cxx, ScDPItemData needs toString, which has been
implemented trivially for now, but might want to combine that with the
DEBUG_PIVOT_TABLE-only ScDPItemData::Dump.
Change-Id: Iae6d09cf69bd4e52fe4411bba9e50c48e696291c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110546
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_fract.cxx | 49 | ||||
-rw-r--r-- | tools/qa/cppunit/test_stream.cxx | 12 |
2 files changed, 36 insertions, 25 deletions
diff --git a/tools/qa/cppunit/test_fract.cxx b/tools/qa/cppunit/test_fract.cxx index 897533d645fd..1c3b8ad02986 100644 --- a/tools/qa/cppunit/test_fract.cxx +++ b/tools/qa/cppunit/test_fract.cxx @@ -39,38 +39,45 @@ public: Fraction aFract2( aFract ); aFract2.ReduceInaccurate(8); - CPPUNIT_ASSERT_MESSAGE( "Fraction #2 not 1", - aFract2.GetNumerator() == 1 && - aFract2.GetDenominator() == 1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #2 not 1", + sal_Int32(1), aFract2.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #2 not 1", + sal_Int32(1), aFract2.GetDenominator() ); Fraction aFract3( 0x7AAAAAAA, 0x35555555 ); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 cancellation wrong", - aFract3.GetNumerator() == 0x7AAAAAAA && - aFract3.GetDenominator() == 0x35555555 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 cancellation wrong", + sal_Int32(0x7AAAAAAA), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 cancellation wrong", + sal_Int32(0x35555555), aFract3.GetDenominator() ); aFract3.ReduceInaccurate(30); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 ReduceInaccurate erroneously cut precision", - aFract3.GetNumerator() == 0x7AAAAAAA && - aFract3.GetDenominator() == 0x35555555 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 ReduceInaccurate erroneously cut precision", + sal_Int32(0x7AAAAAAA), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 ReduceInaccurate erroneously cut precision", + sal_Int32(0x35555555), aFract3.GetDenominator() ); aFract3.ReduceInaccurate(29); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 29 bits failed", - aFract3.GetNumerator() == 0x3D555555 && - aFract3.GetDenominator() == 0x1AAAAAAA ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 29 bits failed", + sal_Int32(0x3D555555), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 29 bits failed", + sal_Int32(0x1AAAAAAA), aFract3.GetDenominator() ); aFract3.ReduceInaccurate(9); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 9 bits failed", - aFract3.GetNumerator() == 0x0147 && - aFract3.GetDenominator() == 0x008E ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 9 bits failed", + sal_Int32(0x0147), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 9 bits failed", + sal_Int32(0x008E), aFract3.GetDenominator() ); aFract3.ReduceInaccurate(1); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 1 bit failed", - aFract3.GetNumerator() == 2 && - aFract3.GetDenominator() == 1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 1 bit failed", + sal_Int32(2), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 1 bit failed", + sal_Int32(1), aFract3.GetDenominator() ); aFract3.ReduceInaccurate(0); - CPPUNIT_ASSERT_MESSAGE( "Fraction #3 reduce to 0 bits failed", - aFract3.GetNumerator() == 2 && - aFract3.GetDenominator() == 1 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 0 bits failed", + sal_Int32(2), aFract3.GetNumerator() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fraction #3 reduce to 0 bits failed", + sal_Int32(1), aFract3.GetDenominator() ); } diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx index d8e4d1ef71e1..4672af6c70c9 100644 --- a/tools/qa/cppunit/test_stream.cxx +++ b/tools/qa/cppunit/test_stream.cxx @@ -230,14 +230,16 @@ namespace aMemStream.Seek(0); bRet = aMemStream.ReadLine(aFoo); CPPUNIT_ASSERT(bRet); - CPPUNIT_ASSERT(aFoo.getLength() == 7 && aFoo[3] == 0); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aFoo.getLength()); + CPPUNIT_ASSERT_EQUAL('\0', aFoo[3]); CPPUNIT_ASSERT(aMemStream.good()); std::string sStr(foo, RTL_CONSTASCII_LENGTH(foo)); std::istringstream iss(sStr, std::istringstream::in); std::getline(iss, sStr, '\n'); //embedded null read as expected - CPPUNIT_ASSERT(sStr.size() == 7 && sStr[3] == 0); + CPPUNIT_ASSERT_EQUAL(std::string::size_type(7), sStr.size()); + CPPUNIT_ASSERT_EQUAL('\0', sStr[3]); CPPUNIT_ASSERT(iss.good()); bRet = aMemStream.ReadLine(aFoo); @@ -252,11 +254,13 @@ namespace bRet = aMemStream.ReadLine(aFoo); CPPUNIT_ASSERT(!bRet); CPPUNIT_ASSERT(aFoo.isEmpty()); - CPPUNIT_ASSERT(aMemStream.eof() && !aMemStream.bad()); + CPPUNIT_ASSERT(aMemStream.eof()); + CPPUNIT_ASSERT(!aMemStream.bad()); std::getline(iss, sStr, '\n'); CPPUNIT_ASSERT(sStr.empty()); - CPPUNIT_ASSERT(iss.eof() && !iss.bad()); + CPPUNIT_ASSERT(iss.eof()); + CPPUNIT_ASSERT(!iss.bad()); char bar[] = "foo"; SvMemoryStream aMemStreamB(bar, SAL_N_ELEMENTS(bar)-1, StreamMode::READ); |