aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickcanvasitem/data/tst_state.qml
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-05-03 15:21:08 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-04 02:39:23 +0200
commit6318560eca7e3247a63620ce24d2d7e291dd5d84 (patch)
treea4f09da7a81577994d1d34fd9926257dfb136e64 /tests/auto/quick/qquickcanvasitem/data/tst_state.qml
parent9cc306916bf8bd70e79aa67458759985e9a26c0d (diff)
Refactor canvas item unit tests
Change-Id: I99ba84889ce360d2def27834f15af43c2bdf29bc Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickcanvasitem/data/tst_state.qml')
-rw-r--r--tests/auto/quick/qquickcanvasitem/data/tst_state.qml776
1 files changed, 397 insertions, 379 deletions
diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_state.qml b/tests/auto/quick/qquickcanvasitem/data/tst_state.qml
index def312d1e5..1ceb17b31b 100644
--- a/tests/auto/quick/qquickcanvasitem/data/tst_state.qml
+++ b/tests/auto/quick/qquickcanvasitem/data/tst_state.qml
@@ -1,390 +1,408 @@
import QtQuick 2.0
-import QtTest 1.0
-import "testhelper.js" as Helper
-Canvas {
- id:canvas; width:100;height:50; renderTarget: Canvas.Image; renderStrategy:Canvas.Threaded
- TestCase {
- id:testCase
- name: "state"; when: windowShown
- function test_bitmap() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
- ctx.fillStyle = '#f00';
- ctx.fillRect(0, 0, 100, 50);
- ctx.save();
- ctx.fillStyle = '#0f0';
- ctx.fillRect(0, 0, 100, 50);
- ctx.restore();
- verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
- }
- function test_clip() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- ctx.fillStyle = '#f00';
- ctx.fillRect(0, 0, 100, 50);
- ctx.save();
- ctx.rect(0, 0, 1, 1);
- ctx.clip();
- ctx.restore();
- ctx.fillStyle = '#0f0';
- ctx.fillRect(0, 0, 100, 50);
- //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
-
- }
- function test_fillStyle() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
- // Test that restore() undoes any modifications
- var old = ctx.fillStyle;
- ctx.save();
- ctx.fillStyle = "#ff0000";
- ctx.restore();
- compare(ctx.fillStyle, old);
-
- // Also test that save() doesn't modify the values
- ctx.fillStyle = "#ff0000";
- old = ctx.fillStyle;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "#ff0000"
- ctx.save();
- compare(ctx.fillStyle, old);
- ctx.restore();
- }
- function test_font() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.font;
- ctx.save();
- ctx.font = "25px serif";
- ctx.restore();
- compare(ctx.font, old);
-
- // Also test that save() doesn't modify the values
- ctx.font = "25px serif";
- old = ctx.font;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "25px serif"
- ctx.save();
- compare(ctx.font, old);
- ctx.restore();
- }
- function test_globalAlpha() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.globalAlpha;
- ctx.save();
- ctx.globalAlpha = 0.5;
- ctx.restore();
- compare(ctx.globalAlpha, old);
-
- // Also test that save() doesn't modify the values
- ctx.globalAlpha = 0.5;
- old = ctx.globalAlpha;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against 0.5
- ctx.save();
- compare(ctx.globalAlpha, old);
- ctx.restore();
- }
- function test_globalCompositeOperation() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.globalCompositeOperation;
- ctx.save();
- ctx.globalCompositeOperation = "copy";
- ctx.restore();
- compare(ctx.globalCompositeOperation, old);
-
- // Also test that save() doesn't modify the values
- ctx.globalCompositeOperation = "copy";
- old = ctx.globalCompositeOperation;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "copy"
- ctx.save();
- compare(ctx.globalCompositeOperation, old);
- ctx.restore();
- }
- function test_lineCap() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.lineCap;
- ctx.save();
- ctx.lineCap = "round";
- ctx.restore();
- compare(ctx.lineCap, old);
-
- // Also test that save() doesn't modify the values
- ctx.lineCap = "round";
- old = ctx.lineCap;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "round"
- ctx.save();
- compare(ctx.lineCap, old);
- ctx.restore();
- }
- function test_lineJoin() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.lineJoin;
- ctx.save();
- ctx.lineJoin = "round";
- ctx.restore();
- compare(ctx.lineJoin, old);
-
- // Also test that save() doesn't modify the values
- ctx.lineJoin = "round";
- old = ctx.lineJoin;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "round"
- ctx.save();
- compare(ctx.lineJoin, old);
- ctx.restore();
- }
- function test_lineWidth() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.lineJoin;
- ctx.save();
- ctx.lineJoin = "round";
- ctx.restore();
- compare(ctx.lineJoin, old, "ctx.lineJoin", "old");
-
- // Also test that save() doesn't modify the values
- ctx.lineJoin = "round";
- old = ctx.lineJoin;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "round"
- ctx.save();
- compare(ctx.lineJoin, old);
- ctx.restore();
- }
- function test_miterLimit() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.miterLimit;
- ctx.save();
- ctx.miterLimit = 0.5;
- ctx.restore();
- compare(ctx.miterLimit, old);
-
- // Also test that save() doesn't modify the values
- ctx.miterLimit = 0.5;
- old = ctx.miterLimit;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against 0.5
- ctx.save();
- compare(ctx.miterLimit, old);
- ctx.restore();
- }
- function test_path() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- ctx.fillStyle = '#f00';
- ctx.fillRect(0, 0, 100, 50);
- ctx.save();
- ctx.rect(0, 0, 100, 50);
- ctx.restore();
- ctx.fillStyle = '#0f0';
- ctx.fill();
- verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
- }
- function test_shadow() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.shadowBlur;
- ctx.save();
- ctx.shadowBlur = 5;
- ctx.restore();
- compare(ctx.shadowBlur, old);
-
- // Also test that save() doesn't modify the values
- ctx.shadowBlur = 5;
- old = ctx.shadowBlur;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against 5
- ctx.save();
- compare(ctx.shadowBlur, old);
- ctx.restore();
-
- // Test that restore() undoes any modifications
- var old = ctx.shadowColor;
- ctx.save();
- ctx.shadowColor = "#ff0000";
- ctx.restore();
- compare(ctx.shadowColor, old);
-
- // Also test that save() doesn't modify the values
- ctx.shadowColor = "#ff0000";
- old = ctx.shadowColor;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "#ff0000"
- ctx.save();
- compare(ctx.shadowColor, old);
- ctx.restore();
-
- // Test that restore() undoes any modifications
- var old = ctx.shadowOffsetX;
- ctx.save();
- ctx.shadowOffsetX = 5;
- ctx.restore();
- compare(ctx.shadowOffsetX, old);
-
- // Also test that save() doesn't modify the values
- ctx.shadowOffsetX = 5;
- old = ctx.shadowOffsetX;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against 5
- ctx.save();
- compare(ctx.shadowOffsetX, old);
- ctx.restore();
-
- // Test that restore() undoes any modifications
- var old = ctx.shadowOffsetY;
- ctx.save();
- ctx.shadowOffsetY = 5;
- ctx.restore();
- compare(ctx.shadowOffsetY, old);
-
- // Also test that save() doesn't modify the values
- ctx.shadowOffsetY = 5;
- old = ctx.shadowOffsetY;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against 5
- ctx.save();
- compare(ctx.shadowOffsetY, old);
- ctx.restore();
-
- }
- function test_stack() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- ctx.lineWidth = 1;
- ctx.save();
- ctx.lineWidth = 2;
- ctx.save();
- ctx.lineWidth = 3;
- compare(ctx.lineWidth, 3);
- ctx.restore();
- compare(ctx.lineWidth, 2);
- ctx.restore();
- compare(ctx.lineWidth, 1);
-
- var limit = 512;
- for (var i = 1; i < limit; ++i)
- {
- ctx.save();
- ctx.lineWidth = i;
- }
- for (var i = limit-1; i > 0; --i)
- {
- testCase.compare(ctx.lineWidth, i); //strange javascript error here
- ctx.restore();
- }
-
- for (var i = 0; i < 16; ++i)
- ctx.restore();
- ctx.lineWidth = 0.5;
- ctx.restore();
- compare(ctx.lineWidth, 0.5);
-
- }
- function test_strokeStyle() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.strokeStyle;
- ctx.save();
- ctx.strokeStyle = "#ff0000";
- ctx.restore();
- compare(ctx.strokeStyle, old);
-
- // Also test that save() doesn't modify the values
- ctx.strokeStyle = "#ff0000";
- old = ctx.strokeStyle;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "#ff0000"
- ctx.save();
- compare(ctx.strokeStyle, old);
- ctx.restore();
-
+CanvasTestCase {
+ id:testCase
+ name: "state"
+ function init_data() { return testData("2d"); }
+ function test_bitmap(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(0, 0, 100, 50);
+ ctx.save();
+ ctx.fillStyle = '#0f0';
+ ctx.fillRect(0, 0, 100, 50);
+ ctx.restore();
+ comparePixel(ctx, 50,25, 0,255,0,255);
+ canvas.destroy()
+ }
+ function test_clip(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(0, 0, 100, 50);
+ ctx.save();
+ ctx.rect(0, 0, 1, 1);
+ ctx.clip();
+ ctx.restore();
+ ctx.fillStyle = '#0f0';
+ ctx.fillRect(0, 0, 100, 50);
+ //comparePixel(ctx, 50,25, 0,255,0,255);
+ canvas.destroy()
+ }
+ function test_fillStyle(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+ // Test that restore() undoes any modifications
+ var old = ctx.fillStyle;
+ ctx.save();
+ ctx.fillStyle = "#ff0000";
+ ctx.restore();
+ compare(ctx.fillStyle, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.fillStyle = "#ff0000";
+ old = ctx.fillStyle;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "#ff0000"
+ ctx.save();
+ compare(ctx.fillStyle, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_font(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.font;
+ ctx.save();
+ ctx.font = "25px serif";
+ ctx.restore();
+ compare(ctx.font, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.font = "25px serif";
+ old = ctx.font;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "25px serif"
+ ctx.save();
+ compare(ctx.font, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_globalAlpha(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.globalAlpha;
+ ctx.save();
+ ctx.globalAlpha = 0.5;
+ ctx.restore();
+ compare(ctx.globalAlpha, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.globalAlpha = 0.5;
+ old = ctx.globalAlpha;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against 0.5
+ ctx.save();
+ compare(ctx.globalAlpha, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_globalCompositeOperation(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.globalCompositeOperation;
+ ctx.save();
+ ctx.globalCompositeOperation = "copy";
+ ctx.restore();
+ compare(ctx.globalCompositeOperation, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.globalCompositeOperation = "copy";
+ old = ctx.globalCompositeOperation;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "copy"
+ ctx.save();
+ compare(ctx.globalCompositeOperation, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_lineCap(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.lineCap;
+ ctx.save();
+ ctx.lineCap = "round";
+ ctx.restore();
+ compare(ctx.lineCap, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.lineCap = "round";
+ old = ctx.lineCap;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "round"
+ ctx.save();
+ compare(ctx.lineCap, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_lineJoin(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.lineJoin;
+ ctx.save();
+ ctx.lineJoin = "round";
+ ctx.restore();
+ compare(ctx.lineJoin, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.lineJoin = "round";
+ old = ctx.lineJoin;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "round"
+ ctx.save();
+ compare(ctx.lineJoin, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_lineWidth(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.lineJoin;
+ ctx.save();
+ ctx.lineJoin = "round";
+ ctx.restore();
+ compare(ctx.lineJoin, old, "ctx.lineJoin", "old");
+
+ // Also test that save() doesn't modify the values
+ ctx.lineJoin = "round";
+ old = ctx.lineJoin;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "round"
+ ctx.save();
+ compare(ctx.lineJoin, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_miterLimit(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.miterLimit;
+ ctx.save();
+ ctx.miterLimit = 0.5;
+ ctx.restore();
+ compare(ctx.miterLimit, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.miterLimit = 0.5;
+ old = ctx.miterLimit;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against 0.5
+ ctx.save();
+ compare(ctx.miterLimit, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_path(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(0, 0, 100, 50);
+ ctx.save();
+ ctx.rect(0, 0, 100, 50);
+ ctx.restore();
+ ctx.fillStyle = '#0f0';
+ ctx.fill();
+ comparePixel(ctx, 50,25, 0,255,0,255);
+ canvas.destroy()
+ }
+ function test_shadow(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.shadowBlur;
+ ctx.save();
+ ctx.shadowBlur = 5;
+ ctx.restore();
+ compare(ctx.shadowBlur, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.shadowBlur = 5;
+ old = ctx.shadowBlur;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against 5
+ ctx.save();
+ compare(ctx.shadowBlur, old);
+ ctx.restore();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.shadowColor;
+ ctx.save();
+ ctx.shadowColor = "#ff0000";
+ ctx.restore();
+ compare(ctx.shadowColor, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.shadowColor = "#ff0000";
+ old = ctx.shadowColor;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "#ff0000"
+ ctx.save();
+ compare(ctx.shadowColor, old);
+ ctx.restore();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.shadowOffsetX;
+ ctx.save();
+ ctx.shadowOffsetX = 5;
+ ctx.restore();
+ compare(ctx.shadowOffsetX, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.shadowOffsetX = 5;
+ old = ctx.shadowOffsetX;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against 5
+ ctx.save();
+ compare(ctx.shadowOffsetX, old);
+ ctx.restore();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.shadowOffsetY;
+ ctx.save();
+ ctx.shadowOffsetY = 5;
+ ctx.restore();
+ compare(ctx.shadowOffsetY, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.shadowOffsetY = 5;
+ old = ctx.shadowOffsetY;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against 5
+ ctx.save();
+ compare(ctx.shadowOffsetY, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_stack(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ ctx.lineWidth = 1;
+ ctx.save();
+ ctx.lineWidth = 2;
+ ctx.save();
+ ctx.lineWidth = 3;
+ compare(ctx.lineWidth, 3);
+ ctx.restore();
+ compare(ctx.lineWidth, 2);
+ ctx.restore();
+ compare(ctx.lineWidth, 1);
+
+ var limit = 512;
+ for (var i = 1; i < limit; ++i)
+ {
+ ctx.save();
+ ctx.lineWidth = i;
}
-
- function test_text() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- // Test that restore() undoes any modifications
- var old = ctx.textAlign;
- ctx.save();
- ctx.textAlign = "center";
- ctx.restore();
- compare(ctx.textAlign, old);
-
- // Also test that save() doesn't modify the values
- ctx.textAlign = "center";
- old = ctx.textAlign;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "center"
- ctx.save();
- compare(ctx.textAlign, old);
+ for (var i = limit-1; i > 0; --i)
+ {
+ testCase.compare(ctx.lineWidth, i); //strange javascript error here
ctx.restore();
-
- // Test that restore() undoes any modifications
- var old = ctx.textBaseline;
- ctx.save();
- ctx.textBaseline = "bottom";
- ctx.restore();
- compare(ctx.textBaseline, old);
-
- // Also test that save() doesn't modify the values
- ctx.textBaseline = "bottom";
- old = ctx.textBaseline;
- // we're not interested in failures caused by get(set(x)) != x (e.g.
- // from rounding), so compare against 'old' instead of against "bottom"
- ctx.save();
- compare(ctx.textBaseline, old);
- ctx.restore();
-
-
}
- function test_transform() {
- var ctx = canvas.getContext('2d');
- ctx.reset();
-
- ctx.fillStyle = '#0f0';
- ctx.fillRect(0, 0, 100, 50);
- ctx.save();
- ctx.translate(200, 0);
+ for (var i = 0; i < 16; ++i)
ctx.restore();
- ctx.fillStyle = '#f00';
- ctx.fillRect(-200, 0, 100, 50);
- verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
-
-
- }
+ ctx.lineWidth = 0.5;
+ ctx.restore();
+ compare(ctx.lineWidth, 0.5);
+ canvas.destroy()
+ }
+ function test_strokeStyle(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.strokeStyle;
+ ctx.save();
+ ctx.strokeStyle = "#ff0000";
+ ctx.restore();
+ compare(ctx.strokeStyle, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.strokeStyle = "#ff0000";
+ old = ctx.strokeStyle;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "#ff0000"
+ ctx.save();
+ compare(ctx.strokeStyle, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_text(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.textAlign;
+ ctx.save();
+ ctx.textAlign = "center";
+ ctx.restore();
+ compare(ctx.textAlign, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.textAlign = "center";
+ old = ctx.textAlign;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "center"
+ ctx.save();
+ compare(ctx.textAlign, old);
+ ctx.restore();
+
+ // Test that restore() undoes any modifications
+ var old = ctx.textBaseline;
+ ctx.save();
+ ctx.textBaseline = "bottom";
+ ctx.restore();
+ compare(ctx.textBaseline, old);
+
+ // Also test that save() doesn't modify the values
+ ctx.textBaseline = "bottom";
+ old = ctx.textBaseline;
+ // we're not interested in failures caused by get(set(x)) != x (e.g.
+ // from rounding), so compare against 'old' instead of against "bottom"
+ ctx.save();
+ compare(ctx.textBaseline, old);
+ ctx.restore();
+ canvas.destroy()
+ }
+ function test_transform(row) {
+ var canvas = createCanvasObject(row);
+ var ctx = canvas.getContext('2d');
+ ctx.reset();
+
+ ctx.fillStyle = '#0f0';
+ ctx.fillRect(0, 0, 100, 50);
+ ctx.save();
+ ctx.translate(200, 0);
+ ctx.restore();
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(-200, 0, 100, 50);
+ comparePixel(ctx, 50,25, 0,255,0,255);
+ canvas.destroy()
}
}