From 9eaaccc9859b5f271a2cb08a6ede419bfaab3963 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Mon, 1 Apr 2013 05:59:57 +0000 Subject: [PATCH] fix a case that causes a variable not used warning/error git-svn-id: https://zxing.googlecode.com/svn/trunk@2604 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/common/Array.h | 2 ++ .../common/GreyscaleRotatedLuminanceSource.cpp | 2 +- cpp/core/tests/src/common/BitArrayTest.cpp | 8 ++++---- cpp/core/tests/src/common/BitMatrixTest.cpp | 16 ++++++++-------- cpp/core/tests/src/common/BitSourceTest.cpp | 2 +- .../tests/src/common/BlackPointEstimatorTest.cpp | 6 ++++-- cpp/core/tests/src/common/CountedTest.cpp | 8 ++++++-- .../src/common/reedsolomon/ReedSolomonTest.cpp | 6 +++--- .../tests/src/qrcode/FormatInformationTest.cpp | 2 +- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/cpp/core/src/zxing/common/Array.h b/cpp/core/src/zxing/common/Array.h index 78c3c5cfa..a24c3ae68 100644 --- a/cpp/core/src/zxing/common/Array.h +++ b/cpp/core/src/zxing/common/Array.h @@ -129,6 +129,7 @@ public: #endif reset(a); } + /* ArrayRef(const Array &a) : array_(0) { #ifdef DEBUG_COUNTING @@ -136,6 +137,7 @@ public: #endif reset(const_cast *>(&a)); } + */ ArrayRef(const ArrayRef &other) : Counted(), array_(0) { #ifdef DEBUG_COUNTING diff --git a/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp index dd7153fa9..fceca8e89 100644 --- a/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp +++ b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp @@ -30,7 +30,7 @@ using zxing::GreyscaleRotatedLuminanceSource; // rotated. GreyscaleRotatedLuminanceSource:: GreyscaleRotatedLuminanceSource(ArrayRef greyData, - int dataWidth, int /* dataHeight */, + int dataWidth, int dataHeight, int left, int top, int width, int height) : greyData_(greyData), diff --git a/cpp/core/tests/src/common/BitArrayTest.cpp b/cpp/core/tests/src/common/BitArrayTest.cpp index ff143fd22..560d348ea 100644 --- a/cpp/core/tests/src/common/BitArrayTest.cpp +++ b/cpp/core/tests/src/common/BitArrayTest.cpp @@ -66,9 +66,9 @@ void BitArrayTest::testGetArray() { BitArray array(2 * bits); array.set(0); array.set(2 * bits - 1); - vector words(array.getBitArray()); - CPPUNIT_ASSERT_EQUAL(1u, words[0]); - CPPUNIT_ASSERT_EQUAL((1u << (bits - 1)), words[1]); + vector words(array.getBitArray()); + CPPUNIT_ASSERT_EQUAL(1, words[0]); + CPPUNIT_ASSERT_EQUAL((1 << (bits - 1)), words[1]); } void BitArrayTest::testIsRange() { @@ -97,7 +97,7 @@ void BitArrayTest::testIsRange() { // fills the two arrays with identical random bits void BitArrayTest::fillRandom(BitArray& test, BitArray& reference) { srandom(0xDEADBEEFL + test.getSize()); - for(size_t i = 0; i < test.getSize(); ++i) { + for(int i = 0; i < test.getSize(); ++i) { if(random() & 0x1) { test.set(i); reference.set(i); diff --git a/cpp/core/tests/src/common/BitMatrixTest.cpp b/cpp/core/tests/src/common/BitMatrixTest.cpp index c2488a96f..76f77108f 100644 --- a/cpp/core/tests/src/common/BitMatrixTest.cpp +++ b/cpp/core/tests/src/common/BitMatrixTest.cpp @@ -32,18 +32,18 @@ BitMatrixTest::BitMatrixTest() { } void BitMatrixTest::testGetSet() { - size_t bits = numeric_limits::digits; + int bits = numeric_limits::digits; BitMatrix matrix(bits + 1); CPPUNIT_ASSERT_EQUAL(bits + 1, matrix.getDimension()); - for (size_t i = 0; i < bits + 1; i++) { - for (size_t j = 0; j < bits + 1; j++) { + for (int i = 0; i < bits + 1; i++) { + for (int j = 0; j < bits + 1; j++) { if (i * j % 3 == 0) { matrix.set(i, j); } } } - for (size_t i = 0; i < bits + 1; i++) { - for (size_t j = 0; j < bits + 1; j++) { + for (int i = 0; i < bits + 1; i++) { + for (int j = 0; j < bits + 1; j++) { CPPUNIT_ASSERT_EQUAL(i * j % 3 == 0, matrix.get(i, j)); } } @@ -64,9 +64,9 @@ void BitMatrixTest::testGetBits() { BitMatrix matrix(6); matrix.set(0, 0); matrix.set(5, 5); - unsigned int* bits = matrix.getBits(); - CPPUNIT_ASSERT_EQUAL(1u, bits[0]); - CPPUNIT_ASSERT_EQUAL(8u, bits[1]); + ArrayRef bits = matrix.getBits(); + CPPUNIT_ASSERT_EQUAL(1, bits[0]); + CPPUNIT_ASSERT_EQUAL(8, bits[1]); } void BitMatrixTest::testGetRow1() { diff --git a/cpp/core/tests/src/common/BitSourceTest.cpp b/cpp/core/tests/src/common/BitSourceTest.cpp index a7bf0687f..f1996c1c6 100644 --- a/cpp/core/tests/src/common/BitSourceTest.cpp +++ b/cpp/core/tests/src/common/BitSourceTest.cpp @@ -24,7 +24,7 @@ namespace zxing { CPPUNIT_TEST_SUITE_REGISTRATION(BitSourceTest); -typedef unsigned char byte; +typedef char byte; void BitSourceTest::testSource() { byte rawBytes[] = {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5}; diff --git a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp index 1f44cf59a..c4dd5d4a7 100644 --- a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp +++ b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp @@ -29,7 +29,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BlackPointEstimatorTest); void BlackPointEstimatorTest::testBasic() { int histogramRaw[] = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 }; vector histogram(histogramRaw, histogramRaw+16); - size_t point = GlobalHistogramBinarizer::estimate(histogram); + ArrayRef array (new Array(histogram)); + size_t point = GlobalHistogramBinarizer::estimateBlackPoint(array); CPPUNIT_ASSERT_EQUAL((size_t)64, point); } @@ -37,7 +38,8 @@ void BlackPointEstimatorTest::testTooLittleRange() { try { int histogramRaw[] = { 0, 0, 0, 0, 0, 0, 1, 43, 48, 18, 3, 1, 0, 0, 0, 0 }; vector histogram(histogramRaw, histogramRaw+16); - GlobalHistogramBinarizer::estimate(histogram); + ArrayRef array (new Array(histogram)); + GlobalHistogramBinarizer::estimateBlackPoint(array); CPPUNIT_FAIL("Should have thrown an exception"); } catch (IllegalArgumentException ie) { diff --git a/cpp/core/tests/src/common/CountedTest.cpp b/cpp/core/tests/src/common/CountedTest.cpp index c3d587784..57b048994 100644 --- a/cpp/core/tests/src/common/CountedTest.cpp +++ b/cpp/core/tests/src/common/CountedTest.cpp @@ -44,11 +44,15 @@ void CountedTest::test() { CPPUNIT_ASSERT_EQUAL(0, foo.count()); foo.retain(); CPPUNIT_ASSERT_EQUAL(1, foo.count()); + Ref foobar(new Foo); + CPPUNIT_ASSERT_EQUAL(1, foobar->count()); { - Ref fooRef(foo); - CPPUNIT_ASSERT_EQUAL(2, foo.count()); + Ref secondRef(foobar); + CPPUNIT_ASSERT_EQUAL(1, foo.count()); + CPPUNIT_ASSERT_EQUAL(2, foobar->count()); } CPPUNIT_ASSERT_EQUAL(1, foo.count()); + CPPUNIT_ASSERT_EQUAL(1, foobar->count()); } } diff --git a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp index f2cdb9ff2..2a5c053df 100644 --- a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp +++ b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp @@ -69,7 +69,7 @@ void ReedSolomonTest::testNoError() { void ReedSolomonTest::testOneError() { ArrayRef received(new Array(qrCodeTestWithEc_->size())); srandom(0xDEADBEEFL); - for (unsigned i = 0; i < received->size(); i++) { + for (int i = 0; i < received->size(); i++) { *received = *qrCodeTestWithEc_; received[i] = random() % 256; checkQRRSDecode(received); @@ -79,7 +79,7 @@ void ReedSolomonTest::testOneError() { void ReedSolomonTest::testMaxErrors() { ArrayRef received(new Array(qrCodeTestWithEc_->size())); srandom(0xDEADBEEFL); - for (unsigned i = 0; i < qrCodeTest_->size(); i++) { + for (int i = 0; i < qrCodeTest_->size(); i++) { *received = *qrCodeTestWithEc_; corrupt(received, qrCodeCorrectable_); checkQRRSDecode(received); @@ -106,7 +106,7 @@ void ReedSolomonTest::testTooManyErrors() { void ReedSolomonTest::checkQRRSDecode(ArrayRef &received) { int twoS = 2 * qrCodeCorrectable_; qrRSDecoder_->decode(received, twoS); - for (unsigned i = 0; i < qrCodeTest_->size(); i++) { + for (int i = 0; i < qrCodeTest_->size(); i++) { CPPUNIT_ASSERT_EQUAL(qrCodeTest_[i], received[i]); } } diff --git a/cpp/core/tests/src/qrcode/FormatInformationTest.cpp b/cpp/core/tests/src/qrcode/FormatInformationTest.cpp index 0d2935545..1e3973c8a 100644 --- a/cpp/core/tests/src/qrcode/FormatInformationTest.cpp +++ b/cpp/core/tests/src/qrcode/FormatInformationTest.cpp @@ -59,7 +59,7 @@ void FormatInformationTest::testDecode() { // Normal case Ref expected = FormatInformation::decodeFormatInformation(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO); - CPPUNIT_ASSERT_EQUAL((unsigned char) 0x07, expected->getDataMask()); + CPPUNIT_ASSERT_EQUAL((char)0x07, expected->getDataMask()); CPPUNIT_ASSERT_EQUAL(&ErrorCorrectionLevel::Q, &expected->getErrorCorrectionLevel()); // where the code forgot the mask!