Fix cases of variable shadowing in /tests/.
If we manage to fix all the existing cases of variable shadowing, we
could enable -Wshadow.
Change-Id: Ib8b92275c5da71c4ee48540d434f3afdc45f4067
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438819
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Florin Malita <fmalita@google.com>
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index e98597f..3f7f3d8 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -64,11 +64,10 @@
{ kRGBA_F16_SkColorType, "0101011" },
};
-static const int W = 20;
-static const int H = 33;
-
static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
SkColorType ct) {
+ const int W = 20;
+ const int H = 33;
sk_sp<SkColorSpace> colorSpace = nullptr;
if (kRGBA_F16_SkColorType == ct) {
colorSpace = SkColorSpace::MakeSRGB();
@@ -81,6 +80,7 @@
}
DEF_TEST(BitmapCopy_extractSubset, reporter) {
+ const int W = 20;
for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
SkBitmap srcOpaque, srcPremul;
setup_src_bitmaps(&srcOpaque, &srcPremul, gPairs[i].fColorType);
diff --git a/tests/GeometryTest.cpp b/tests/GeometryTest.cpp
index 3daf47b..6ea9436 100644
--- a/tests/GeometryTest.cpp
+++ b/tests/GeometryTest.cpp
@@ -37,14 +37,16 @@
REPORTER_ASSERT(reporter, count);
}
// Make sure src and dst can be the same pointer.
- SkPoint pts[7];
- for (int i = 0; i < 7; ++i) {
- pts[i].set(i, i);
- }
- SkChopCubicAt(pts, pts, .5f);
- for (int i = 0; i < 7; ++i) {
- REPORTER_ASSERT(reporter, pts[i].fX == pts[i].fY);
- REPORTER_ASSERT(reporter, pts[i].fX == i * .5f);
+ {
+ SkPoint pts[7];
+ for (int i = 0; i < 7; ++i) {
+ pts[i].set(i, i);
+ }
+ SkChopCubicAt(pts, pts, .5f);
+ for (int i = 0; i < 7; ++i) {
+ REPORTER_ASSERT(reporter, pts[i].fX == pts[i].fY);
+ REPORTER_ASSERT(reporter, pts[i].fX == i * .5f);
+ }
}
static const float chopTs[] = {
diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp
index 1dd1c73..6424161 100644
--- a/tests/GrMemoryPoolTest.cpp
+++ b/tests/GrMemoryPoolTest.cpp
@@ -214,14 +214,12 @@
}
if (0 == i % kCheckPeriod) {
A::ValidatePool();
- for (int r = 0; r < instanceRecs.count(); ++r) {
- Rec& rec = instanceRecs[r];
+ for (Rec& rec : instanceRecs) {
REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec.fValue));
}
}
}
- for (int i = 0; i < instanceRecs.count(); ++i) {
- Rec& rec = instanceRecs[i];
+ for (Rec& rec : instanceRecs) {
REPORTER_ASSERT(reporter, rec.fInstance->checkValues(rec.fValue));
delete rec.fInstance;
}
diff --git a/tests/GrTBlockListTest.cpp b/tests/GrTBlockListTest.cpp
index dd2cfab..aa16338 100644
--- a/tests/GrTBlockListTest.cpp
+++ b/tests/GrTBlockListTest.cpp
@@ -59,7 +59,7 @@
}
if (popCnt > 0) {
- for (int i = 0; i < popCnt; ++i) {
+ for (i = 0; i < popCnt; ++i) {
allocator->pop_back();
}
check_allocator_helper(allocator, cnt - popCnt, 0, reporter);
@@ -105,7 +105,7 @@
REPORTER_ASSERT(reporter, i == -1);
// Also test random access
- for (int i = 0; i < allocator->count(); ++i) {
+ for (i = 0; i < allocator->count(); ++i) {
REPORTER_ASSERT(reporter, (uintptr_t) &allocator->item(i) == (uintptr_t) expected[i]);
REPORTER_ASSERT(reporter, (uintptr_t) &cAlloc->item(i) == (uintptr_t) expected[i]);
}
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 51c7687..562aa5c 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -270,8 +270,7 @@
REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
- SkScalar scales[2];
- bool success = mat.getMinMaxScales(scales);
+ success = mat.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
diff --git a/tests/PDFDeflateWStreamTest.cpp b/tests/PDFDeflateWStreamTest.cpp
index 29a6b85..89aa94a 100644
--- a/tests/PDFDeflateWStreamTest.cpp
+++ b/tests/PDFDeflateWStreamTest.cpp
@@ -107,7 +107,7 @@
DEF_TEST(SkPDF_DeflateWStream, r) {
SkRandom random(123456);
- for (int i = 0; i < 50; ++i) {
+ for (int loop = 0; loop < 50; ++loop) {
uint32_t size = random.nextULessThan(10000);
SkAutoTMalloc<uint8_t> buffer(size);
for (uint32_t j = 0; j < size; ++j) {
@@ -137,22 +137,20 @@
return;
}
if (decompressed->getLength() != size) {
- ERRORF(r, "Decompression failed to get right size [%d]."
- " %u != %u", i, (unsigned)(decompressed->getLength()),
- (unsigned)size);
- SkString s = SkStringPrintf("/tmp/deftst_compressed_%d", i);
+ ERRORF(r, "Decompression failed to get right size [%d]. %u != %u",
+ loop, (unsigned)(decompressed->getLength()), (unsigned)size);
+ SkString s = SkStringPrintf("/tmp/deftst_compressed_%d", loop);
SkFILEWStream o(s.c_str());
o.writeStream(compressed.get(), compressed->getLength());
compressed->rewind();
- s = SkStringPrintf("/tmp/deftst_input_%d", i);
+ s = SkStringPrintf("/tmp/deftst_input_%d", loop);
SkFILEWStream o2(s.c_str());
o2.write(&buffer[0], size);
continue;
}
- uint32_t minLength = std::min(size,
- (uint32_t)(decompressed->getLength()));
+ uint32_t minLength = std::min(size, (uint32_t)(decompressed->getLength()));
for (uint32_t i = 0; i < minLength; ++i) {
uint8_t c;
SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t));
diff --git a/tests/PathOpsCubicIntersectionTest.cpp b/tests/PathOpsCubicIntersectionTest.cpp
index 6892a9d..0248f41 100644
--- a/tests/PathOpsCubicIntersectionTest.cpp
+++ b/tests/PathOpsCubicIntersectionTest.cpp
@@ -14,10 +14,12 @@
#include <stdlib.h>
-const int firstCubicIntersectionTest = 9;
+using namespace PathOpsCubicIntersectionTestData;
+
+static constexpr int kFirstCubicIntersectionTest = 9;
static void standardTestCases(skiatest::Reporter* reporter) {
- for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) {
+ for (size_t index = kFirstCubicIntersectionTest; index < tests_count; ++index) {
int iIndex = static_cast<int>(index);
const CubicPts& cubic1 = tests[index][0];
const CubicPts& cubic2 = tests[index][1];
@@ -467,11 +469,11 @@
static void CubicIntersection_RandTest(skiatest::Reporter* reporter) {
srand(0);
- const int tests = 10000000;
+ const int kNumTests = 10000000;
#if !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_ANDROID)
unsigned seed = 0;
#endif
- for (int test = 0; test < tests; ++test) {
+ for (int test = 0; test < kNumTests; ++test) {
CubicPts cubic1, cubic2;
for (int i = 0; i < 4; ++i) {
cubic1.fPts[i].fX = static_cast<double>(SK_RAND(seed)) / RAND_MAX * 100;
@@ -637,8 +639,8 @@
int selfSetCount = (int) SK_ARRAY_COUNT(selfSet);
-static void selfOneOff(skiatest::Reporter* reporter, int index) {
- const CubicPts& cubic = selfSet[index];
+static void selfOneOff(skiatest::Reporter* reporter, int setIdx) {
+ const CubicPts& cubic = selfSet[setIdx];
SkPoint c[4];
for (int i = 0; i < 4; ++i) {
c[i] = cubic.fPts[i].asSkPoint();
diff --git a/tests/PathOpsCubicIntersectionTestData.cpp b/tests/PathOpsCubicIntersectionTestData.cpp
index 55eda4c..7641fd7 100644
--- a/tests/PathOpsCubicIntersectionTestData.cpp
+++ b/tests/PathOpsCubicIntersectionTestData.cpp
@@ -9,6 +9,8 @@
#include <limits>
+namespace PathOpsCubicIntersectionTestData {
+
static const double D = FLT_EPSILON / 2;
static const double G = FLT_EPSILON / 3;
static const double N = -FLT_EPSILON / 2;
@@ -273,3 +275,5 @@
};
const size_t negEpsilonLines_count = SK_ARRAY_COUNT(negEpsilonLines);
+
+} // namespace PathOpsCubicIntersectionTestData
diff --git a/tests/PathOpsCubicIntersectionTestData.h b/tests/PathOpsCubicIntersectionTestData.h
index e70b907..69e8c83 100644
--- a/tests/PathOpsCubicIntersectionTestData.h
+++ b/tests/PathOpsCubicIntersectionTestData.h
@@ -6,6 +6,8 @@
*/
#include "tests/PathOpsTestCommon.h"
+namespace PathOpsCubicIntersectionTestData {
+
extern const CubicPts pointDegenerates[];
extern const CubicPts notPointDegenerates[];
extern const CubicPts tests[][2];
@@ -26,3 +28,5 @@
extern const size_t modEpsilonLines_count;
extern const size_t lessEpsilonLines_count;
extern const size_t negEpsilonLines_count;
+
+} // namespace PathOpsCubicIntersectionTestData
diff --git a/tests/PathOpsCubicReduceOrderTest.cpp b/tests/PathOpsCubicReduceOrderTest.cpp
index b3d4ef9..9a1a6a1 100644
--- a/tests/PathOpsCubicReduceOrderTest.cpp
+++ b/tests/PathOpsCubicReduceOrderTest.cpp
@@ -12,6 +12,8 @@
#include "tests/PathOpsTestCommon.h"
#include "tests/Test.h"
+using namespace PathOpsCubicIntersectionTestData;
+
#if 0 // disable test until stroke reduction is supported
static bool controls_inside(const SkDCubic& cubic) {
return between(cubic[0].fX, cubic[1].fX, cubic[3].fX)
diff --git a/tests/StrokerTest.cpp b/tests/StrokerTest.cpp
index 9f902bb..0ea2fcc 100644
--- a/tests/StrokerTest.cpp
+++ b/tests/StrokerTest.cpp
@@ -17,6 +17,8 @@
#include "tests/Test.h"
#include "tools/flags/CommandLineFlags.h"
+using namespace PathOpsCubicIntersectionTestData;
+
static DEFINE_bool(timeout, true, "run until alloted time expires");
#define MS_TEST_DURATION 10
diff --git a/tests/TDPQueueTest.cpp b/tests/TDPQueueTest.cpp
index f4798a6..290ddfa 100644
--- a/tests/TDPQueueTest.cpp
+++ b/tests/TDPQueueTest.cpp
@@ -121,7 +121,7 @@
unsigned action = random.nextULessThan(3);
switch (action) {
case 0: { // pop the top,
- Mock* top = pq.peek();
+ top = pq.peek();
REPORTER_ASSERT(reporter, array.begin() <= top && top < array.end());
pq.pop();
*top = kSentinel;
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index 9792d0b..51ab346 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -154,7 +154,6 @@
{
// Exercise the empty bounds path, and ensure that RunRecord-aligned pos buffers
// don't trigger asserts (http://crbug.com/542643).
- SkFont font;
font.setSize(0);
const char* txt = "BOOO";