skia2/tests/BitmapGetColorTest.cpp
tfarina@chromium.org e4fafb146e Use DEFINE_TESTCLASS_SHORT macro in tests.
The three version of DEFINE_TESTCLASS macro is deprecated and thus just
use the simple, short one.

BUG=None
TEST=out/Debug/tests
R=mtklein@google.com, bsalomon@google.com, robertphillips@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12653 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-12 21:11:12 +00:00

49 lines
1.6 KiB
C++

/*
* Copyright 2011 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 "TestClassDef.h"
#include "SkBitmap.h"
#include "SkRect.h"
#include "SkRandom.h"
DEF_TEST(GetColor, reporter) {
static const struct Rec {
SkBitmap::Config fConfig;
SkColor fInColor;
SkColor fOutColor;
} gRec[] = {
// todo: add some tests that involve alpha, so we exercise the
// unpremultiply aspect of getColor()
{ SkBitmap::kA8_Config, 0xFF000000, 0xFF000000 },
{ SkBitmap::kA8_Config, 0, 0 },
{ SkBitmap::kRGB_565_Config, 0xFF00FF00, 0xFF00FF00 },
{ SkBitmap::kRGB_565_Config, 0xFFFF00FF, 0xFFFF00FF },
{ SkBitmap::kARGB_8888_Config, 0xFFFFFFFF, 0xFFFFFFFF },
{ SkBitmap::kARGB_8888_Config, 0, 0 },
{ SkBitmap::kARGB_8888_Config, 0xFF224466, 0xFF224466 },
};
// specify an area that doesn't touch (0,0) and may extend beyond the
// bitmap bounds (to test that we catch that in eraseArea
const SkColor initColor = 0xFF0000FF;
const SkIRect area = { 1, 1, 3, 3 };
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
SkBitmap bm;
uint32_t storage[4];
bm.setConfig(gRec[i].fConfig, 2, 2);
bm.setPixels(storage);
bm.eraseColor(initColor);
bm.eraseArea(area, gRec[i].fInColor);
SkColor c = bm.getColor(1, 1);
REPORTER_ASSERT(reporter, c == gRec[i].fOutColor);
}
}