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>
This commit is contained in:
John Stiles 2021-08-12 10:48:09 -04:00 committed by SkCQ
parent c7829eb316
commit 9765973380
13 changed files with 45 additions and 35 deletions

View File

@ -64,11 +64,10 @@ static const Pair gPairs[] = {
{ 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 @@ static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul,
}
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);

View File

@ -37,14 +37,16 @@ static void testChopCubic(skiatest::Reporter* reporter) {
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[] = {

View File

@ -214,14 +214,12 @@ DEF_TEST(GrMemoryPool, reporter) {
}
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;
}

View File

@ -59,7 +59,7 @@ static void check_allocator_helper(GrTBlockList<C, N>* allocator, int cnt, int p
}
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 @@ static void check_iterator_helper(GrTBlockList<C, N>* allocator,
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]);
}

View File

@ -270,8 +270,7 @@ static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
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));

View File

@ -107,7 +107,7 @@ std::unique_ptr<SkStreamAsset> stream_inflate(skiatest::Reporter* reporter, SkSt
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 @@ DEF_TEST(SkPDF_DeflateWStream, r) {
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));

View File

@ -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 oneOffTests(skiatest::Reporter* reporter) {
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 @@ static const CubicPts selfSet[] = {
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();

View File

@ -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 CubicPts negEpsilonLines[] = {
};
const size_t negEpsilonLines_count = SK_ARRAY_COUNT(negEpsilonLines);
} // namespace PathOpsCubicIntersectionTestData

View File

@ -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 notLines_count;
extern const size_t modEpsilonLines_count;
extern const size_t lessEpsilonLines_count;
extern const size_t negEpsilonLines_count;
} // namespace PathOpsCubicIntersectionTestData

View File

@ -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)

View File

@ -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

View File

@ -121,7 +121,7 @@ void random_test(skiatest::Reporter* reporter) {
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;

View File

@ -154,7 +154,6 @@ public:
{
// 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";