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) {
}
if (!success) {
- SkString str;
- str.printf("%s [config = %s]",
- msg, getSkConfigName(bm1));
- reporter->reportFailed(str);
+ ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1));
}
}
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) {
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.
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;
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;
}
}
}
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);
}
}
}
{
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);
#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,
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);
}
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);
}
}
+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.
}
// 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)
#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;
}
}
}
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());
}
}
}
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);
}
}
(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);
}
}
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]);
}
}
}
{
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;
}
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