add unittest for save/restore

git-svn-id: http://skia.googlecode.com/svn/trunk@2751 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-28 16:06:04 +00:00
parent 05b6f3a5a9
commit 37f3ae0b9f
2 changed files with 38 additions and 0 deletions

View File

@ -19,6 +19,7 @@
'../tests/BitSetTest.cpp',
'../tests/BlitRowTest.cpp',
'../tests/BlurTest.cpp',
'../tests/CanvasTest.cpp',
'../tests/ClampRangeTest.cpp',
'../tests/ClipCubicTest.cpp',
'../tests/ClipStackTest.cpp',

37
tests/CanvasTest.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
* 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)