From 452eecb4436f27e057d4d2df26e3a70020a817b6 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Mon, 6 Jan 2014 12:43:53 +0000 Subject: [PATCH] Convert two more tests to DEF_TEST() macro. Out of three, two were converted. These tests were found with the following command line: $ g grep "public Test" BUG=None TEST=ran tests executable fine. R=mtklein@google.com Review URL: https://codereview.chromium.org/122943004 git-svn-id: http://skia.googlecode.com/svn/trunk@12905 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/ARGBImageEncoderTest.cpp | 26 ++++----------- tests/BitmapHasherTest.cpp | 73 ++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 65 deletions(-) diff --git a/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp index bffcaa4..8157cc7 100644 --- a/tests/ARGBImageEncoderTest.cpp +++ b/tests/ARGBImageEncoderTest.cpp @@ -5,30 +5,20 @@ * found in the LICENSE file. */ -/** Tests for ARGBImageEncoder. */ +#include "SkImageEncoder.h" -#include "Test.h" #include "SkBitmap.h" #include "SkCanvas.h" -#include "SkImageEncoder.h" #include "SkStream.h" - -namespace skiatest { - -class BitmapTransformerTestClass : public Test { -public: - static Test* Factory(void*) { return SkNEW(BitmapTransformerTestClass); } -protected: - virtual void onGetName(SkString* name) SK_OVERRIDE { name->set("ARGBImageEncoder"); } - virtual void onRun(Reporter* reporter) SK_OVERRIDE; -}; +#include "Test.h" +#include "TestClassDef.h" static SkBitmap::Config configs[] = { - SkBitmap::kRGB_565_Config, - SkBitmap::kARGB_8888_Config, + SkBitmap::kRGB_565_Config, + SkBitmap::kARGB_8888_Config, }; -void BitmapTransformerTestClass::onRun(Reporter* reporter) { +DEF_TEST(ARGBImageEncoder, reporter) { // Bytes we expect to get: const int kWidth = 3; const int kHeight = 5; @@ -71,7 +61,3 @@ void BitmapTransformerTestClass::onRun(Reporter* reporter) { REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSize) == 0); } } - -static TestRegistry gReg(BitmapTransformerTestClass::Factory); - -} diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp index d6c9e6a..fe7abde 100644 --- a/tests/BitmapHasherTest.cpp +++ b/tests/BitmapHasherTest.cpp @@ -1,60 +1,43 @@ - /* * Copyright 2013 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include "Test.h" -#include "SkBitmap.h" #include "SkBitmapHasher.h" + +#include "SkBitmap.h" #include "SkColor.h" +#include "Test.h" +#include "TestClassDef.h" // Word size that is large enough to hold results of any checksum type. typedef uint64_t checksum_result; -namespace skiatest { - class BitmapHasherTestClass : public Test { - public: - static Test* Factory(void*) {return SkNEW(BitmapHasherTestClass); } - protected: - virtual void onGetName(SkString* name) { name->set("BitmapHasher"); } - virtual void onRun(Reporter* reporter) { - this->fReporter = reporter; - RunTest(); - } - private: - - // Fill in bitmap with test data. - void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height, - SkColor color) { - bitmap.setConfig(config, width, height); - REPORTER_ASSERT(fReporter, bitmap.allocPixels()); - bitmap.setAlphaType(kOpaque_SkAlphaType); - bitmap.eraseColor(color); - } - - void RunTest() { - // Test SkBitmapHasher - SkBitmap bitmap; - uint64_t digest; - // initial test case - CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE); - REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); - REPORTER_ASSERT(fReporter, digest == 0xfb2903562766ef87ULL); - // same pixel data but different dimensions should yield a different checksum - CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE); - REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); - REPORTER_ASSERT(fReporter, digest == 0xfe04023fb97d0f61ULL); - // same dimensions but different color should yield a different checksum - CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN); - REPORTER_ASSERT(fReporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); - REPORTER_ASSERT(fReporter, digest == 0x2423c51cad6d1edcULL); - } - - Reporter* fReporter; - }; +// Fill in bitmap with test data. +static void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height, + SkColor color, skiatest::Reporter* reporter) { + bitmap.setConfig(config, width, height); + REPORTER_ASSERT(reporter, bitmap.allocPixels()); + bitmap.setAlphaType(kOpaque_SkAlphaType); + bitmap.eraseColor(color); +} - static TestRegistry gReg(BitmapHasherTestClass::Factory); +DEF_TEST(BitmapHasher, reporter) { + // Test SkBitmapHasher + SkBitmap bitmap; + uint64_t digest; + // initial test case + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE, reporter); + REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); + REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL); + // same pixel data but different dimensions should yield a different checksum + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE, reporter); + REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); + REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL); + // same dimensions but different color should yield a different checksum + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN, reporter); + REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest)); + REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL); } -- 2.7.4