add unittest for save/restore
git-svn-id: http://skia.googlecode.com/svn/trunk@2751 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
new file mode 100644
index 0000000..7128a22
--- /dev/null
+++ b/tests/CanvasTest.cpp
@@ -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)