aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-10 14:58:10 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-10 14:58:10 +0000
commita9325fa237dde2654bc841c2bb0a05fc3e57696a (patch)
tree3d5952d42ac35f0c9200887215c47dcb14122e41
parent9acb8cdf20423e80d5687ba3c8e11545e3bc8020 (diff)
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
-rw-r--r--tests/BitmapCopyTest.cpp41
-rw-r--r--tests/BlitRowTest.cpp14
-rw-r--r--tests/DataRefTest.cpp4
-rw-r--r--tests/EmptyPathTest.cpp25
-rw-r--r--tests/GpuBitmapCopyTest.cpp19
-rw-r--r--tests/ImageDecodingTest.cpp50
-rw-r--r--tests/MathTest.cpp6
-rw-r--r--tests/PathCoverageTest.cpp11
-rw-r--r--tests/SortTest.cpp5
-rw-r--r--tests/StreamTest.cpp4
-rw-r--r--tests/Test.h36
11 files changed, 95 insertions, 120 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 455fc691e3..d831e5e120 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -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;
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp
index d0518bfb1d..1b0fad0105 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -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);
}
}
}
diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp
index b31bfcdd5c..6a513923ff 100644
--- a/tests/DataRefTest.cpp
+++ b/tests/DataRefTest.cpp
@@ -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);
diff --git a/tests/EmptyPathTest.cpp b/tests/EmptyPathTest.cpp
index fa1fd7f489..39e36808c7 100644
--- a/tests/EmptyPathTest.cpp
+++ b/tests/EmptyPathTest.cpp
@@ -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);
}
diff --git a/tests/GpuBitmapCopyTest.cpp b/tests/GpuBitmapCopyTest.cpp
index 6e1d74dd97..a1434dcf11 100644
--- a/tests/GpuBitmapCopyTest.cpp
+++ b/tests/GpuBitmapCopyTest.cpp
@@ -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);
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index c74bb35ccf..becb8c9dd6 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -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());
}
}
}
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 8cba67dd3d..58dd0c6399 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -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);
}
}
diff --git a/tests/PathCoverageTest.cpp b/tests/PathCoverageTest.cpp
index 25b5fd1c09..c133e9cccc 100644
--- a/tests/PathCoverageTest.cpp
+++ b/tests/PathCoverageTest.cpp
@@ -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);
}
}
diff --git a/tests/SortTest.cpp b/tests/SortTest.cpp
index ceca4097c5..a114f32f76 100644
--- a/tests/SortTest.cpp
+++ b/tests/SortTest.cpp
@@ -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]);
}
}
}
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp
index 16978d59cb..6ac06e5c5c 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -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;
}
diff --git a/tests/Test.h b/tests/Test.h
index 1c89f98e09..ff6b4ac82c 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -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