Add REPORTF test macro.

This macro replaces:
    SkString str;
    str.printf("Foo test Expected %d got %d", x, y);
    reporter->reportFailed(str);
with the shorter code:
    REPORTF(reporter, ("Foo test Expected %d got %d", x, y));

The new form also appends __FILE__:__LINE__ to the message before calling reportFailed().

BUG=
R=mtklein@google.com

Review URL: https://codereview.chromium.org/132843002

git-svn-id: http://skia.googlecode.com/svn/trunk@13016 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
halcanary@google.com 2014-01-10 14:58:10 +00:00
parent 9acb8cdf20
commit a9325fa237
11 changed files with 95 additions and 120 deletions

View File

@ -21,11 +21,9 @@ static const char* gConfigName[] = {
static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src,
const SkBitmap& dst) {
SkString str;
str.printf("src %s opaque:%d, dst %s opaque:%d",
gConfigName[src.config()], src.isOpaque(),
gConfigName[dst.config()], dst.isOpaque());
reporter->reportFailed(str);
ERRORF(reporter, "src %s opaque:%d, dst %s opaque:%d",
gConfigName[src.config()], src.isOpaque(),
gConfigName[dst.config()], dst.isOpaque());
}
static bool canHaveAlpha(SkBitmap::Config config) {
@ -192,10 +190,7 @@ static void reportCopyVerification(const SkBitmap& bm1, const SkBitmap& bm2,
}
if (!success) {
SkString str;
str.printf("%s [config = %s]",
msg, getSkConfigName(bm1));
reporter->reportFailed(str);
ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1));
}
}
@ -247,20 +242,16 @@ DEF_TEST(BitmapCopy, reporter) {
bool success = srcPremul.copyTo(&dst, gPairs[j].fConfig);
bool expected = gPairs[i].fValid[j] != '0';
if (success != expected) {
SkString str;
str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s",
gConfigName[i], gConfigName[j], boolStr(expected),
boolStr(success));
reporter->reportFailed(str);
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. expected %s "
"returned %s", gConfigName[i], gConfigName[j],
boolStr(expected), boolStr(success));
}
bool canSucceed = srcPremul.canCopyTo(gPairs[j].fConfig);
if (success != canSucceed) {
SkString str;
str.printf("SkBitmap::copyTo from %s to %s. returned %s canCopyTo %s",
gConfigName[i], gConfigName[j], boolStr(success),
boolStr(canSucceed));
reporter->reportFailed(str);
ERRORF(reporter, "SkBitmap::copyTo from %s to %s. returned %s "
"canCopyTo %s", gConfigName[i], gConfigName[j],
boolStr(success), boolStr(canSucceed));
}
if (success) {
@ -345,10 +336,8 @@ DEF_TEST(BitmapCopy, reporter) {
100000000U);
int64_t safeSize = tstSafeSize.computeSafeSize64();
if (safeSize < 0) {
SkString str;
str.printf("getSafeSize64() negative: %s",
getSkConfigName(tstSafeSize));
reporter->reportFailed(str);
ERRORF(reporter, "getSafeSize64() negative: %s",
getSkConfigName(tstSafeSize));
}
bool sizeFail = false;
// Compare against hand-computed values.
@ -380,10 +369,8 @@ DEF_TEST(BitmapCopy, reporter) {
break;
}
if (sizeFail) {
SkString str;
str.printf("computeSafeSize64() wrong size: %s",
getSkConfigName(tstSafeSize));
reporter->reportFailed(str);
ERRORF(reporter, "computeSafeSize64() wrong size: %s",
getSkConfigName(tstSafeSize));
}
int subW = 2;

View File

@ -89,10 +89,8 @@ static bool check_color(const SkBitmap& bm, SkPMColor expect32,
uint32_t bad;
int x = proc(bm.getAddr(0, y), bm.width(), expect, &bad);
if (x >= 0) {
SkString str;
str.printf("BlitRow config=%s [%d %d] expected %x got %x",
gConfigName[bm.config()], x, y, expect, bad);
reporter->reportFailed(str);
ERRORF(reporter, "BlitRow config=%s [%d %d] expected %x got %x",
gConfigName[bm.config()], x, y, expect, bad);
return false;
}
}
@ -252,10 +250,10 @@ static void test_diagonal(skiatest::Reporter* reporter) {
}
if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.getSize())) {
SkString str;
str.printf("Diagonal config=%s bg=0x%x dither=%d alpha=0x%x src=0x%x",
gConfigName[gDstConfig[i]], bgColor, dither, alpha, c);
reporter->reportFailed(str);
ERRORF(reporter, "Diagonal config=%s bg=0x%x dither=%d"
" alpha=0x%x src=0x%x",
gConfigName[gDstConfig[i]], bgColor, dither,
alpha, c);
}
}
}

View File

@ -186,9 +186,7 @@ static void test_files(skiatest::Reporter* reporter) {
{
SkFILEWStream writer(path.c_str());
if (!writer.isValid()) {
SkString msg;
msg.printf("Failed to create tmp file %s\n", path.c_str());
reporter->reportFailed(msg);
ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str());
return;
}
writer.write(s, 26);

View File

@ -10,17 +10,6 @@
#include "SkPath.h"
#include "SkCanvas.h"
static void appendStr(SkString* str, const SkPaint& paint) {
str->appendf(" style[%d] cap[%d] join[%d] antialias[%d]",
paint.getStyle(), paint.getStrokeCap(),
paint.getStrokeJoin(), paint.isAntiAlias());
}
static void appendStr(SkString* str, const SkPath& path) {
str->appendf(" filltype[%d] ptcount[%d]",
path.getFillType(), path.countPoints());
}
#define DIMENSION 32
static void drawAndTest(skiatest::Reporter* reporter, const SkPath& path,
@ -52,16 +41,16 @@ static void drawAndTest(skiatest::Reporter* reporter, const SkPath& path,
bool success = shouldDraw ? (~0U == andValue) : (0 == orValue);
if (!success) {
SkString str;
const char* str;
if (shouldDraw) {
str.set("Path expected to draw everywhere, but didn't. ");
str = "Path expected to draw everywhere, but didn't. ";
} else {
str.set("Path expected to draw nowhere, but did. ");
str = "Path expected to draw nowhere, but did. ";
}
appendStr(&str, paint);
appendStr(&str, path);
reporter->reportFailed(str);
ERRORF(reporter, "%s style[%d] cap[%d] join[%d] antialias[%d]"
" filltype[%d] ptcount[%d]", str, paint.getStyle(),
paint.getStrokeCap(), paint.getStrokeJoin(),
paint.isAntiAlias(), path.getFillType(), path.countPoints());
// uncomment this if you want to step in to see the failure
// canvas.drawPath(path, p);
}

View File

@ -150,21 +150,18 @@ static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* fa
bool success = src.deepCopyTo(&dst, gPairs[j].fConfig);
bool expected = gPairs[i].fValid[j] != '0';
if (success != expected) {
SkString str;
str.printf("SkBitmap::deepCopyTo from %s to %s. expected %s returned %s",
gConfigName[i], gConfigName[j], boolStr(expected),
boolStr(success));
reporter->reportFailed(str);
ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s. "
"expected %s returned %s", gConfigName[i],
gConfigName[j], boolStr(expected),
boolStr(success));
}
bool canSucceed = src.canCopyTo(gPairs[j].fConfig);
if (success != canSucceed) {
SkString str;
str.printf("SkBitmap::deepCopyTo from %s to %s returned %s,"
"but canCopyTo returned %s",
gConfigName[i], gConfigName[j], boolStr(success),
boolStr(canSucceed));
reporter->reportFailed(str);
ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s "
"returned %s, but canCopyTo returned %s",
gConfigName[i], gConfigName[j], boolStr(success),
boolStr(canSucceed));
}
TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, dst);

View File

@ -410,6 +410,23 @@ static inline const char* SkColorType_to_string(SkColorType colorType) {
}
}
static inline const char* options_colorType(
const SkDecodingImageGenerator::Options& opts) {
if (opts.fUseRequestedColorType) {
return SkColorType_to_string(opts.fRequestedColorType);
} else {
return "(none)";
}
}
static inline const char* yn(bool value) {
if (value) {
return "yes";
} else {
return "no";
}
}
/**
* Given either a SkStream or a SkData, try to decode the encoded
* image using the specified options and report errors.
@ -443,13 +460,9 @@ static void test_options(skiatest::Reporter* reporter,
}
// If we get here, it's a failure and we will need more
// information about why it failed.
reporter->reportFailed(SkStringPrintf(
"Bounds decode failed "
"[sampleSize=%d dither=%s colorType=%s %s] %s:%d",
opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"),
(opts.fUseRequestedColorType
? SkColorType_to_string(opts.fRequestedColorType) : "(none)"),
path.c_str(), __FILE__, __LINE__));
ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s "
"colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
options_colorType(opts), path.c_str());
return;
}
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
@ -463,13 +476,9 @@ static void test_options(skiatest::Reporter* reporter,
#endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
SkAutoLockPixels alp(bm);
if (bm.getPixels() == NULL) {
reporter->reportFailed(SkStringPrintf(
"Pixel decode failed "
"[sampleSize=%d dither=%s colorType=%s %s] %s:%d",
opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"),
(opts.fUseRequestedColorType
? SkColorType_to_string(opts.fRequestedColorType) : "(none)"),
path.c_str(), __FILE__, __LINE__));
ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
"colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
options_colorType(opts), path.c_str());
return;
}
@ -496,14 +505,11 @@ static void test_options(skiatest::Reporter* reporter,
}
}
if (pixelErrors != 0) {
reporter->reportFailed(SkStringPrintf(
"Pixel-level mismatch (%d of %d) [sampleSize=%d "
"dither=%s colorType=%s %s] %s:%d",
pixelErrors, kExpectedHeight * kExpectedWidth,
opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"),
(opts.fUseRequestedColorType
? SkColorType_to_string(opts.fRequestedColorType)
: "(none)"), path.c_str(), __FILE__, __LINE__));
ERRORF(reporter, "Pixel-level mismatch (%d of %d) "
"[sampleSize=%d dither=%s colorType=%s %s]",
pixelErrors, kExpectedHeight * kExpectedWidth,
opts.fSampleSize, yn(opts.fDitherImage),
options_colorType(opts), path.c_str());
}
}
}

View File

@ -225,10 +225,8 @@ static bool equal_float_native_skia(float x, uint32_t ni, uint32_t si) {
static void assert_float_equal(skiatest::Reporter* reporter, const char op[],
float x, uint32_t ni, uint32_t si) {
if (!equal_float_native_skia(x, ni, si)) {
SkString desc;
uint32_t xi = SkFloat2Bits(x);
desc.printf("%s float %g bits %x native %x skia %x\n", op, x, xi, ni, si);
reporter->reportFailed(desc);
ERRORF(reporter, "%s float %g bits %x native %x skia %x\n",
op, x, SkFloat2Bits(x), ni, si);
}
}

View File

@ -137,14 +137,11 @@ static bool one_d_pe(const int* array, const unsigned int count,
(estimatedCount <= 2 * computedCount);
if (!isAccurate) {
SkString errorDescription;
errorDescription.printf(
"Curve from %.2f %.2f through %.2f %.2f to %.2f %.2f "
"computes %d, estimates %d\n",
path[0].fX, path[0].fY, path[1].fX, path[1].fY,
path[2].fX, path[2].fY, computedCount, estimatedCount);
ERRORF(reporter, "Curve from %.2f %.2f through %.2f %.2f to "
"%.2f %.2f computes %d, estimates %d\n",
path[0].fX, path[0].fY, path[1].fX, path[1].fY,
path[2].fX, path[2].fY, computedCount, estimatedCount);
numErrors++;
reporter->reportFailed(errorDescription);
}
}

View File

@ -26,9 +26,8 @@ static void check_sort(skiatest::Reporter* reporter, const char label[],
const int array[], const int reference[], int n) {
for (int j = 0; j < n; ++j) {
if (array[j] != reference[j]) {
SkString str;
str.printf("%sSort [%d] failed %d %d", label, n, array[j], reference[j]);
reporter->reportFailed(str);
ERRORF(reporter, "%sSort [%d] failed %d %d",
label, n, array[j], reference[j]);
}
}
}

View File

@ -45,9 +45,7 @@ static void test_filestreams(skiatest::Reporter* reporter, const char* tmpDir) {
{
SkFILEWStream writer(path.c_str());
if (!writer.isValid()) {
SkString msg;
msg.printf("Failed to create tmp file %s\n", path.c_str());
reporter->reportFailed(msg);
ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str());
return;
}

View File

@ -89,23 +89,31 @@ namespace skiatest {
typedef SkTRegistry<Test*(*)(void*)> TestRegistry;
}
#define REPORTER_ASSERT(r, cond) \
do { \
if (!(cond)) { \
SkString desc; \
desc.printf("%s:%d: %s", __FILE__, __LINE__, #cond); \
r->reportFailed(desc); \
} \
#define REPORTER_ASSERT(r, cond) \
do { \
if (!(cond)) { \
SkString desc; \
desc.printf("%s:%d\t%s", __FILE__, __LINE__, #cond); \
r->reportFailed(desc); \
} \
} while(0)
#define REPORTER_ASSERT_MESSAGE(r, cond, message) \
do { \
if (!(cond)) { \
SkString desc; \
desc.printf("%s %s:%d: %s", message, __FILE__, __LINE__, #cond); \
r->reportFailed(desc); \
} \
#define REPORTER_ASSERT_MESSAGE(r, cond, message) \
do { \
if (!(cond)) { \
SkString desc; \
desc.printf("%s:%d\t%s: %s", __FILE__, __LINE__, \
message, #cond); \
r->reportFailed(desc); \
} \
} while(0)
#define ERRORF(reporter, ...) \
do { \
SkString desc; \
desc.printf("%s:%d\t", __FILE__, __LINE__); \
desc.appendf(__VA_ARGS__) ; \
(reporter)->reportFailed(desc); \
} while(0)
#endif