1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
import QtQuick 2.0
CanvasTestCase {
id:testCase
name: "strokeStyle"
property color anotherColor: "#0000ff"
property color emptyColor
function init_data() { return testData("2d"); }
function test_default(row) {
var canvas = createCanvasObject(row);
tryVerify(function() { return canvas.available; });
var ctx = canvas.getContext('2d');
ctx.reset();
compare(ctx.strokeStyle, "#000000")
ctx.clearRect(0, 0, 1, 1);
compare(ctx.strokeStyle, "#000000")
canvas.destroy()
}
function test_saverestore(row) {
var canvas = createCanvasObject(row);
tryVerify(function() { return canvas.available; });
var ctx = canvas.getContext('2d');
var old = ctx.strokeStyle;
ctx.save();
ctx.strokeStyle = "#ffaaff";
ctx.restore();
compare(ctx.strokeStyle, old);
ctx.strokeStyle = "#ffcc88";
old = ctx.strokeStyle;
ctx.save();
compare(ctx.strokeStyle, old);
ctx.restore();
canvas.destroy()
}
function test_namedColor(row) {
var canvas = createCanvasObject(row);
tryVerify(function() { return canvas.available; });
var ctx = canvas.getContext('2d');
ctx.reset();
ctx.strokeStyle = "red";
ctx.strokeRect(0,0,1,1);
comparePixel(ctx,0,0,255,0,0,255);
ctx.strokeStyle = "black";
ctx.strokeRect(0,0,1,1);
comparePixel(ctx,0,0,0,0,0,255);
ctx.strokeStyle = "white";
ctx.strokeRect(0,0,1,1);
comparePixel(ctx,0,0,255,255,255,255);
canvas.destroy()
}
function test_colorFromObjectToString(row) {
var canvas = createCanvasObject(row);
tryVerify(function() { return canvas.available; });
var ctx = canvas.getContext('2d');
ctx.reset();
ctx.strokeStyle = anotherColor
ctx.strokeStyle = "red";
compare(ctx.strokeStyle, "#ff0000");
ctx.strokeStyle = anotherColor
ctx.strokeStyle = "black";
compare(ctx.strokeStyle, "#000000");
ctx.strokeStyle = "white";
ctx.strokeStyle = anotherColor
compare(ctx.strokeStyle, "#0000ff");
canvas.destroy()
}
function test_withInvalidColor(row) {
var canvas = createCanvasObject(row);
tryVerify(function() { return canvas.available; });
var ctx = canvas.getContext('2d');
ctx.reset();
ctx.strokeStyle = emptyColor
compare(ctx.strokeStyle, "#000000");
ctx.strokeStyle = "red";
compare(ctx.strokeStyle, "#ff0000");
ctx.strokeStyle = emptyColor
compare(ctx.strokeStyle, "#000000");
ctx.strokeStyle = anotherColor;
compare(ctx.strokeStyle, "#0000ff");
canvas.destroy()
}
}
|