add canvas drawImage unit tests
authorCharles Yin <charles.yin@nokia.com>
Thu, 6 Oct 2011 04:08:37 +0000 (14:08 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 6 Oct 2011 08:44:27 +0000 (10:44 +0200)
Change-Id: I772bf58bead4b536cc632983846743e0d576bedd
Reviewed-on: http://codereview.qt-project.org/6100
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Charles Yin <charles.yin@nokia.com>

25 files changed:
src/declarative/items/context2d/qsgcontext2d.cpp
tests/auto/declarative/qsgcanvasitem/data/anim-gr.gif [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/anim-gr.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/anim-poster-gr.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/background.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/broken.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/ggrr-256x256.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/green-16x16.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/green-1x1.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/green-256x256.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/green-2x2.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/green.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/grgr-256x256.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/qt-logo.png [deleted file]
tests/auto/declarative/qsgcanvasitem/data/red-16x16.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/red.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/redtransparent.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/rgrg-256x256.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/rrgg-256x256.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/transparent.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/transparent50.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/tst_canvas.qml
tests/auto/declarative/qsgcanvasitem/data/tst_drawimage.qml
tests/auto/declarative/qsgcanvasitem/data/yellow.png [new file with mode: 0644]
tests/auto/declarative/qsgcanvasitem/data/yellow75.png [new file with mode: 0644]

index ef69eef..91c9b4d 100644 (file)
@@ -2411,7 +2411,7 @@ static v8::Handle<v8::Value> ctx2d_measureText(const v8::Arguments &args)
 
 
   Note:
-  The \a image type can be an Image item, an image url or a \a {QtQuick2::CanvasImageData} object.
+  The \a image type can be an Image or Canvas item, an image url or a \a {QtQuick2::CanvasImageData} object.
   When given as Image item, if the image isn't fully loaded, this method draws nothing.
   When given as url string, the image should be loaded by calling Canvas item's \a QtQuick2::Canvas::loadImage() method first.
   This image been drawing is subject to the current context clip path, even the given \c image is a  {QtQuick2::CanvasImageData} object.
@@ -2437,32 +2437,42 @@ static v8::Handle<v8::Value> ctx2d_drawImage(const v8::Arguments &args)
 
     QImage image;
     if (args[0]->IsString()) {
-        image = r->context->createImage(QUrl(engine->toString(args[0]->ToString())));
+        QUrl url(engine->toString(args[0]->ToString()));
+        if (!url.isValid())
+            V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+
+        image = r->context->createImage(url);
     } else if (args[0]->IsObject()) {
-        QSGImage* imageItem = qobject_cast<QSGImage*>(engine->toQObject(args[0]->ToObject()));
-        QV8Context2DPixelArrayResource *r = v8_resource_cast<QV8Context2DPixelArrayResource>(args[0]->ToObject()->GetInternalField(0)->ToObject());
-        if (r) {
-            image = r->image;
+        QSGImage *imageItem = qobject_cast<QSGImage*>(engine->toQObject(args[0]->ToObject()));
+        QSGCanvasItem *canvas = qobject_cast<QSGCanvasItem*>(engine->toQObject(args[0]->ToObject()));
+
+        QV8Context2DPixelArrayResource *pix = v8_resource_cast<QV8Context2DPixelArrayResource>(args[0]->ToObject()->GetInternalField(0)->ToObject());
+        if (pix) {
+            image = pix->image;
         } else if (imageItem) {
             image = imageItem->pixmap().toImage();
+        } else if (canvas) {
+            image = canvas->toImage();
         } else {
             V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
         }
+    } else {
+        V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
     }
     if (args.Length() == 3) {
         dx = args[1]->NumberValue();
         dy = args[2]->NumberValue();
         sx = 0;
         sy = 0;
-        sw = image.isNull()? -1 : image.width();
-        sh = image.isNull()? -1 : image.height();
+        sw = image.width();
+        sh = image.height();
         dw = sw;
         dh = sh;
     } else if (args.Length() == 5) {
         sx = 0;
         sy = 0;
-        sw = image.isNull()? -1 : image.width();
-        sh = image.isNull()? -1 : image.height();
+        sw = image.width();
+        sh = image.height();
         dx = args[1]->NumberValue();
         dy = args[2]->NumberValue();
         dw = args[3]->NumberValue();
@@ -2490,7 +2500,15 @@ static v8::Handle<v8::Value> ctx2d_drawImage(const v8::Arguments &args)
      || !qIsFinite(dh))
         return args.This();
 
-    r->context->buffer()->drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh);
+    if (!image.isNull()) {
+        if (sx < 0 || sy < 0 || sw == 0 || sh == 0
+         || sx + sw > image.width() || sy + sh > image.height()
+         || sx + sw < 0 || sy + sh < 0) {
+            V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "drawImage(), index size error");
+        }
+
+        r->context->buffer()->drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh);
+    }
 
     return args.This();
 }
diff --git a/tests/auto/declarative/qsgcanvasitem/data/anim-gr.gif b/tests/auto/declarative/qsgcanvasitem/data/anim-gr.gif
new file mode 100644 (file)
index 0000000..45263e0
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/anim-gr.gif differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/anim-gr.png b/tests/auto/declarative/qsgcanvasitem/data/anim-gr.png
new file mode 100644 (file)
index 0000000..925e2ef
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/anim-gr.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/anim-poster-gr.png b/tests/auto/declarative/qsgcanvasitem/data/anim-poster-gr.png
new file mode 100644 (file)
index 0000000..6941207
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/anim-poster-gr.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/background.png b/tests/auto/declarative/qsgcanvasitem/data/background.png
new file mode 100644 (file)
index 0000000..6db6c6b
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/background.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/broken.png b/tests/auto/declarative/qsgcanvasitem/data/broken.png
new file mode 100644 (file)
index 0000000..f258101
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/broken.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/ggrr-256x256.png b/tests/auto/declarative/qsgcanvasitem/data/ggrr-256x256.png
new file mode 100644 (file)
index 0000000..0342e4a
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/ggrr-256x256.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/green-16x16.png b/tests/auto/declarative/qsgcanvasitem/data/green-16x16.png
new file mode 100644 (file)
index 0000000..e19a3ff
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/green-16x16.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/green-1x1.png b/tests/auto/declarative/qsgcanvasitem/data/green-1x1.png
new file mode 100644 (file)
index 0000000..862d1dd
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/green-1x1.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/green-256x256.png b/tests/auto/declarative/qsgcanvasitem/data/green-256x256.png
new file mode 100644 (file)
index 0000000..b06945c
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/green-256x256.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/green-2x2.png b/tests/auto/declarative/qsgcanvasitem/data/green-2x2.png
new file mode 100644 (file)
index 0000000..adc0594
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/green-2x2.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/green.png b/tests/auto/declarative/qsgcanvasitem/data/green.png
new file mode 100644 (file)
index 0000000..28a1faa
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/green.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/grgr-256x256.png b/tests/auto/declarative/qsgcanvasitem/data/grgr-256x256.png
new file mode 100644 (file)
index 0000000..b8c7189
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/grgr-256x256.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png b/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png
deleted file mode 100644 (file)
index 5ab3a1b..0000000
Binary files a/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png and /dev/null differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/red-16x16.png b/tests/auto/declarative/qsgcanvasitem/data/red-16x16.png
new file mode 100644 (file)
index 0000000..9038fef
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/red-16x16.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/red.png b/tests/auto/declarative/qsgcanvasitem/data/red.png
new file mode 100644 (file)
index 0000000..a6e195d
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/red.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/redtransparent.png b/tests/auto/declarative/qsgcanvasitem/data/redtransparent.png
new file mode 100644 (file)
index 0000000..75da08c
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/redtransparent.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/rgrg-256x256.png b/tests/auto/declarative/qsgcanvasitem/data/rgrg-256x256.png
new file mode 100644 (file)
index 0000000..e6fba3d
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/rgrg-256x256.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/rrgg-256x256.png b/tests/auto/declarative/qsgcanvasitem/data/rrgg-256x256.png
new file mode 100644 (file)
index 0000000..7f63515
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/rrgg-256x256.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/transparent.png b/tests/auto/declarative/qsgcanvasitem/data/transparent.png
new file mode 100644 (file)
index 0000000..2b49869
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/transparent.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/transparent50.png b/tests/auto/declarative/qsgcanvasitem/data/transparent50.png
new file mode 100644 (file)
index 0000000..55f8e69
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/transparent50.png differ
index 65649df..b6621d8 100644 (file)
@@ -234,17 +234,17 @@ Rectangle {
            var c = canvas.createObject();
            verify(c);
 
-           c.loadImage("qt-logo.png");
+           c.loadImage("red.png");
            wait(200);
            compare(c.imageLoadedCount, 1);
-           verify(c.isImageLoaded("qt-logo.png"));
-           verify(!c.isImageLoading("qt-logo.png"));
-           verify(!c.isImageError("qt-logo.png"));
-
-           c.unloadImage("qt-logo.png");
-           verify(!c.isImageLoaded("qt-logo.png"));
-           verify(!c.isImageLoading("qt-logo.png"));
-           verify(!c.isImageError("qt-logo.png"));
+           verify(c.isImageLoaded("red.png"));
+           verify(!c.isImageLoading("red.png"));
+           verify(!c.isImageError("red.png"));
+
+           c.unloadImage("red.png");
+           verify(!c.isImageLoaded("red.png"));
+           verify(!c.isImageLoading("red.png"));
+           verify(!c.isImageError("red.png"));
            c.destroy();
 
       }
index 2f10501..3752f52 100644 (file)
@@ -3,32 +3,215 @@ import QtTest 1.0
 import "testhelper.js" as Helper
 Canvas {
    id:canvas; width:100;height:50; renderTarget: Canvas.Image
+   Component.onCompleted: {
+       canvas.loadImage('green.png');
+       canvas.loadImage('red.png');
+       canvas.loadImage('rgrg-256x256.png');
+       canvas.loadImage('ggrr-256x256.png');
+       canvas.loadImage('broken.png');
+   }
+
    TestCase {
        //TODO
        name: "image"; when: windowShown
        function test_3args() {
+           //make sure all images are loaded
+           wait(200);
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           ctx.drawImage('green.png', 0, 0);
+           ctx.drawImage('red.png', -100, 0);
+           ctx.drawImage('red.png', 100, 0);
+           ctx.drawImage('red.png', 0, -50);
+           ctx.drawImage('red.png', 0, 50);
+
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
       }
        function test_5args() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('green.png', 50, 0, 50, 50);
+           ctx.drawImage('red.png', 0, 0, 50, 50);
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 50, 50);
+
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
       }
        function test_9args() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
-      }
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('green.png', 0, 0, 100, 50, 0, 0, 100, 50);
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+           ctx.reset();
+
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('green.png', 0, 0, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, -100, 0, 100, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 100, 0, 100, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 0, -50, 100, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 0, 50, 100, 50);
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('green.png', 1, 1, 1, 1, 0, 0, 100, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, -50, 0, 50, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 100, 0, 50, 50);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 0, -25, 100, 25);
+           ctx.drawImage('red.png', 0, 0, 100, 50, 0, 50, 100, 25);
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('rgrg-256x256.png', 140, 20, 100, 50, 0, 0, 100, 50);
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('rgrg-256x256.png', 0, 0, 256, 256, 0, 0, 100, 50);
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 51, 26);
+           ctx.fillRect(49, 24, 51, 26);
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 20,20, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 80,20, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 20,30, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 80,30, 0,255,0,255,2));
+
+       }
        function test_animated() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           //should animated image be supported at all?
       }
        function test_clip() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.rect(-10, -10, 1, 1);
+           ctx.clip();
+           ctx.drawImage('red.png', 0, 0);
+           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2));
+
+
       }
+       function test_self() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 50, 50);
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(50, 0, 50, 50);
+           ctx.drawImage(canvas, 50, 0);
+
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+           ctx.reset();
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 1, 100, 49);
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 1);
+           ctx.drawImage(canvas, 0, 1);
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 2);
+
+           verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+
+       }
+
+       function test_outsidesource() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           ctx.drawImage('green.png', 10.5, 10.5, 89.5, 39.5, 0, 0, 100, 50);
+           ctx.drawImage('green.png', 5.5, 5.5, -5.5, -5.5, 0, 0, 100, 50);
+           ctx.drawImage('green.png', 100, 50, -5, -5, 0, 0, 100, 50);
+           try { var err = false;
+             ctx.drawImage('red.png', -0.001, 0, 100, 50, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', -0.001, 0, 100, 50, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 0, -0.001, 100, 50, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 0, -0.001, 100, 50, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 0, 0, 100.001, 50, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 0, 0, 100.001, 50, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 0, 0, 100, 50.001, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 0, 0, 100, 50.001, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 50, 0, 50.001, 50, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 50, 0, 50.001, 50, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 0, 0, -5, 5, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 0, 0, -5, 5, 0, 0, 100, 50)"); }
+           try { var err = false;
+             ctx.drawImage('red.png', 0, 0, 5, -5, 0, 0, 100, 50);
+           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 0, 0, 5, -5, 0, 0, 100, 50)"); }
+//           try { var err = false;
+//             ctx.drawImage('red.png', 110, 60, -20, -20, 0, 0, 100, 50);
+//           } catch (e) { if (e.code != DOMException.INDEX_SIZE_ERR) fail("Failed assertion: expected exception of type INDEX_SIZE_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.drawImage('red.png', 110, 60, -20, -20, 0, 0, 100, 50)"); }
+//           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2));
+
+       }
+
+       function test_null() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           try { var err = false;
+             ctx.drawImage(null, 0, 0);
+           } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type TYPE_MISMATCH_ERR: ctx.drawImage(null, 0, 0)"); }
+
+       }
+
        function test_composite() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.globalCompositeOperation = 'destination-over';
+           ctx.drawImage('red.png', 0, 0);
+           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2));
+
       }
        function test_path() {
            var ctx = canvas.getContext('2d');
@@ -37,6 +220,443 @@ Canvas {
        function test_transform() {
            var ctx = canvas.getContext('2d');
            ctx.reset();
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.translate(100, 0);
+           ctx.drawImage('red.png', 0, 0);
+           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2));
+
       }
+
+       function test_imageitem() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+           //TODO
+       }
+
+       function test_imageData() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+           //TODO
+       }
+
+       function test_wrongtype() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           try { var err = false;
+             ctx.drawImage(undefined, 0, 0);
+           } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type TYPE_MISMATCH_ERR: ctx.drawImage(undefined, 0, 0)"); }
+           try { var err = false;
+             ctx.drawImage(0, 0, 0);
+           } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type TYPE_MISMATCH_ERR: ctx.drawImage(0, 0, 0)"); }
+           try { var err = false;
+             ctx.drawImage("", 0, 0);
+           } catch (e) { if (e.code != DOMException.TYPE_MISMATCH_ERR) fail("Failed assertion: expected exception of type TYPE_MISMATCH_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type TYPE_MISMATCH_ERR: ctx.drawImage(\"\", 0, 0)"); }
+       }
+
+       function test_nonfinite() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 50);
+           var red = 'red.png';
+           ctx.drawImage(red, Infinity, 0);
+           ctx.drawImage(red, -Infinity, 0);
+           ctx.drawImage(red, NaN, 0);
+           ctx.drawImage(red, 0, Infinity);
+           ctx.drawImage(red, 0, -Infinity);
+           ctx.drawImage(red, 0, NaN);
+           ctx.drawImage(red, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50);
+           ctx.drawImage(red, -Infinity, 0, 100, 50);
+           ctx.drawImage(red, NaN, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, -Infinity, 100, 50);
+           ctx.drawImage(red, 0, NaN, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, -Infinity, 50);
+           ctx.drawImage(red, 0, 0, NaN, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, -Infinity);
+           ctx.drawImage(red, 0, 0, 100, NaN);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, -Infinity, 0, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, NaN, 0, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, -Infinity, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, NaN, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, -Infinity, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, NaN, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, -Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, NaN, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, -Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, NaN, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, -Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, NaN, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, -Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, NaN, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, 100, -Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, 100, NaN);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, Infinity, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, Infinity, 100, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, Infinity, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, Infinity, 0, 100, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, Infinity, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, Infinity, 100, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, Infinity, 50, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, 0, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, Infinity, 0, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, Infinity, 100, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, 0, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, 0, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, Infinity, 0, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, Infinity, Infinity, 50);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, Infinity, Infinity, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, Infinity, 100, Infinity);
+           ctx.drawImage(red, 0, 0, 100, 50, 0, 0, Infinity, Infinity);
+           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
+
+       }
+
+       function test_negative() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('ggrr-256x256.png', 100, 78, 50, 50, 0, 50, 50, -50);
+           ctx.drawImage('ggrr-256x256.png', 100, 128, 50, -50, 100, 50, -50, -50);
+//           verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255,2));
+
+           ctx.reset();
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('ggrr-256x256.png', 0, 178, 50, -100, 0, 0, 50, 100);
+           ctx.drawImage('ggrr-256x256.png', 0, 78, 50, 100, 50, 100, 50, -100);
+//           verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255,2));
+
+           ctx.reset();
+           ctx.fillStyle = '#f00';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.drawImage('ggrr-256x256.png', 100, 78, -100, 50, 0, 0, 50, 50);
+           ctx.drawImage('ggrr-256x256.png', 100, 128, -100, -50, 50, 0, 50, 50);
+//           verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,1, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 51,48, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255,2));
+//           verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255,2));
+
+       }
+
+       function test_canvas() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+           var canvas2 = Qt.createQmlObject("import QtQuick 2.0; Canvas{renderTarget:Canvas.Image}", canvas);
+           canvas2.width = 100;
+           canvas2.height = 50;
+           var ctx2 = canvas2.getContext('2d');
+           ctx2.fillStyle = '#0f0';
+           ctx2.fillRect(0, 0, 100, 50);
+
+           ctx.fillStyle = '#f00';
+           ctx.drawImage(canvas2, 0, 0);
+
+           //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255,2));
+           //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255,2));
+           //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255,2));
+           //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255,2));
+
+       }
+
+       function test_broken() {
+           var ctx = canvas.getContext('2d');
+           ctx.reset();
+           var img = 'broken.png';
+           verify(!img.complete);
+           ctx.drawImage(img, 0, 0);
+       }
+
+       function test_alpha() {
+           var ctx=canvas.getContext('2d');
+           ctx.reset();
+           ctx.fillStyle = '#0f0';
+           ctx.fillRect(0, 0, 100, 50);
+           ctx.globalAlpha = 0;
+           ctx.drawImage('red.png', 0, 0);
+           verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255, 2));
+
+       }
    }
 }
diff --git a/tests/auto/declarative/qsgcanvasitem/data/yellow.png b/tests/auto/declarative/qsgcanvasitem/data/yellow.png
new file mode 100644 (file)
index 0000000..51e8aaf
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/yellow.png differ
diff --git a/tests/auto/declarative/qsgcanvasitem/data/yellow75.png b/tests/auto/declarative/qsgcanvasitem/data/yellow75.png
new file mode 100644 (file)
index 0000000..2bb82c9
Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/yellow75.png differ