skia2/tests/CanvasTest.cpp
reed@google.com 37f3ae0b9f add unittest for save/restore
git-svn-id: http://skia.googlecode.com/svn/trunk@2751 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-11-28 16:06:04 +00:00

38 lines
993 B
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 "SkBitmap.h"
#include "SkCanvas.h"
static void TestCanvas(skiatest::Reporter* reporter) {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
bm.allocPixels();
SkCanvas canvas(bm);
int n;
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
n = canvas.save();
REPORTER_ASSERT(reporter, 1 == n);
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
canvas.save();
canvas.save();
REPORTER_ASSERT(reporter, 4 == canvas.getSaveCount());
canvas.restoreToCount(2);
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
// should this pin to 1, or be a no-op, or crash?
canvas.restoreToCount(0);
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("Canvas", TestCanvasClass, TestCanvas)