From: Charles Yin Date: Tue, 4 Oct 2011 07:12:12 +0000 (+1000) Subject: Add more unit tests for qsgcanvasitem and fix unstable tests X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fdc87143eb9eff98938b6a086c3e81432be08e4d;p=konrad%2Fqtdeclarative.git Add more unit tests for qsgcanvasitem and fix unstable tests Change-Id:I5fc11a5874d55ad423dc1fb9c3e1b75a38003465 Reviewed-on: http://codereview.qt-project.org/5962 Reviewed-by: Qt Sanity Bot Reviewed-by: Charles Yin --- diff --git a/src/declarative/items/context2d/qsgcanvasitem.cpp b/src/declarative/items/context2d/qsgcanvasitem.cpp index 50cbc7e..6b0b438 100644 --- a/src/declarative/items/context2d/qsgcanvasitem.cpp +++ b/src/declarative/items/context2d/qsgcanvasitem.cpp @@ -85,7 +85,7 @@ QSGCanvasItemPrivate::QSGCanvasItemPrivate() , hasTileSize(false) , hasCanvasWindow(false) , componentCompleted(false) - , renderTarget(QSGCanvasItem::Image) + , renderTarget(QSGCanvasItem::FramebufferObject) { } @@ -512,7 +512,9 @@ void QSGCanvasItem::createContext() QDeclarativeV8Handle QSGCanvasItem::getContext(const QString &contextId) { Q_D(QSGCanvasItem); - Q_UNUSED(contextId); + + if (contextId.toLower() != QLatin1String("2d")) + return QDeclarativeV8Handle::fromHandle(v8::Undefined()); if (!d->context) createContext(); @@ -552,7 +554,9 @@ void QSGCanvasItem::markDirty(const QRectF& region) */ bool QSGCanvasItem::save(const QString &filename) const { - return toImage().save(filename); + Q_D(const QSGCanvasItem); + QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename)); + return toImage().save(url.toLocalFile()); } QImage QSGCanvasItem::loadedImage(const QUrl& url) @@ -683,24 +687,25 @@ QString QSGCanvasItem::toDataURL(const QString& mimeType) const QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - QString mime = mimeType; + QString mime = mimeType.toLower(); QString type; - if (mimeType == QLatin1Literal("image/bmp")) + if (mime == QLatin1Literal("image/png")) { + type = QLatin1Literal("PNG"); + } else if (mime == QLatin1Literal("image/bmp")) type = QLatin1Literal("BMP"); - else if (mimeType == QLatin1Literal("image/jpeg")) + else if (mime == QLatin1Literal("image/jpeg")) type = QLatin1Literal("JPEG"); - else if (mimeType == QLatin1Literal("image/x-portable-pixmap")) + else if (mime == QLatin1Literal("image/x-portable-pixmap")) type = QLatin1Literal("PPM"); - else if (mimeType == QLatin1Literal("image/tiff")) + else if (mime == QLatin1Literal("image/tiff")) type = QLatin1Literal("TIFF"); - else if (mimeType == QLatin1Literal("image/xbm")) + else if (mime == QLatin1Literal("image/xbm")) type = QLatin1Literal("XBM"); - else if (mimeType == QLatin1Literal("image/xpm")) + else if (mime == QLatin1Literal("image/xpm")) type = QLatin1Literal("XPM"); - else { - type = QLatin1Literal("PNG"); - mime = QLatin1Literal("image/png"); - } + else + return QLatin1Literal("data:,"); + image.save(&buffer, type.toAscii()); buffer.close(); QString dataUrl = QLatin1Literal("data:%1;base64,%2"); diff --git a/src/declarative/items/context2d/qsgcontext2d.cpp b/src/declarative/items/context2d/qsgcontext2d.cpp index cfcfb06..ef69eef 100644 --- a/src/declarative/items/context2d/qsgcontext2d.cpp +++ b/src/declarative/items/context2d/qsgcontext2d.cpp @@ -59,6 +59,9 @@ #include "qv8engine_p.h" #include "qdeclarativeengine.h" +#include "qv8domerrors_p.h" +#include + QT_BEGIN_NAMESPACE /*! \qmlclass Context2D QSGContext2D @@ -102,78 +105,69 @@ static const double Q_PI = 3.14159265358979323846; // pi #define CHECK_CONTEXT_SETTER(r) if (!r || !r->context || !r->context->buffer()) \ V8THROW_ERROR_SETTER("Not a Context2D object"); #define qClamp(val, min, max) qMin(qMax(val, min), max) - -QColor qt_color_from_string(const QString& name) +#define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9)) +QColor qt_color_from_string(v8::Local name) { + v8::String::AsciiValue str(name); + + char *p = *str; + int len = str.length(); //rgb/hsl color string has at least 7 characters - if (name.isEmpty() || name.size() > 255 || name.size() <= 7) - return QColor(name); + if (!p || len > 255 || len <= 7) + return QColor(p); else { - const char* data = name.toLatin1().constData(); - bool isRgb = false, isHsl = false, hasAlpha = false; + bool isRgb(false), isHsl(false), hasAlpha(false); - int pos = 0; - while (isspace(data[pos])) pos++; - - if (strncmp(&(data[pos]), "rgb", 3) == 0) + while (isspace(*p)) p++; + if (strncmp(p, "rgb", 3) == 0) isRgb = true; - else if (strncmp(&(data[pos]), "hsl", 3) == 0) + else if (strncmp(p, "hsl", 3) == 0) isHsl = true; else - return QColor(name); - pos+=3; - if (data[pos] == 'a') - hasAlpha = true; + return QColor(p); - int rh, gs, bl, alpha = 255; + p+=3; //skip "rgb" or "hsl" + hasAlpha = (*p == 'a') ? true : false; + + ++p; //skip "(" - const int len = name.size(); - while (pos < len && (data[pos] != '(' || isspace(data[pos]))) pos++; - if (pos >= len) return QColor(); + if (hasAlpha) ++p; //skip "a" + + int rh, gs, bl, alpha = 255; //red - while (pos < len && !isdigit(data[pos])) pos++; - if (pos >= len) return QColor(); - rh = atoi(&(data[pos])); - while (pos < len && ((data[pos] != ',' && data[pos] != '%') || isspace(data[pos]))) pos++; - if (data[pos] == '%') { + while (isspace(*p)) p++; + rh = strtol(p, &p, 10); + if (*p == '%') { rh = qRound(rh/100.0 * 255); - pos++; + ++p; } + if (*p++ != ',') return QColor(); + //green - while (pos < len && !isdigit(data[pos])) pos++; - if (pos >= len) return QColor(); - gs = atoi(&(data[pos])); - while (pos < len && ((data[pos] != ',' && data[pos] != '%') || isspace(data[pos]))) pos++; - if (data[pos] == '%') { + while (isspace(*p)) p++; + gs = strtol(p, &p, 10); + if (*p == '%') { gs = qRound(gs/100.0 * 255); - pos++; + ++p; } + if (*p++ != ',') return QColor(); //blue - while (pos < len && !isdigit(data[pos])) pos++; - if (pos >= len) - return QColor(); - bl = atoi(&(data[pos])); - while (pos < len && ((data[pos] != ',' && data[pos] != '%') || isspace(data[pos]))) pos++; - if (data[pos] == '%') { + while (isspace(*p)) p++; + bl = strtol(p, &p, 10); + if (*p == '%') { bl = qRound(bl/100.0 * 255); - pos++; + ++p; } if (hasAlpha) { - while (pos < len && !isdigit(data[pos])) pos++; - if (pos >= len) - return QColor(); -#ifndef Q_CC_MSVC - const float alphaF = strtof(data + pos, 0); -#else - // MSVC does not have strtof - const double alphaF = strtod(data + pos, 0); -#endif - alpha = qRound(alphaF * 255); + if (*p++!= ',') return QColor(); + while (isspace(*p)) p++; + alpha = qRound(strtod(p, &p) * 255); } + if (*p != ')') return QColor(); if (isRgb) return QColor::fromRgba(qRgba(qClamp(rh, 0, 255), qClamp(gs, 0, 255), qClamp(bl, 0, 255), qClamp(alpha, 0, 255))); else @@ -475,6 +469,9 @@ static v8::Handle ctx2d_reset(const v8::Arguments &args) CHECK_CONTEXT(r) r->context->reset(); + r->context->m_path = QPainterPath(); + r->context->m_path.setFillRule(Qt::WindingFill); + return args.This(); } @@ -539,9 +536,11 @@ static v8::Handle ctx2d_rotate(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - if (args.Length() == 1) { qreal angle = args[0]->NumberValue(); + if (!qIsFinite(angle)) + return args.This(); + r->context->state.matrix.rotate(DEGREES(angle)); r->context->buffer()->updateMatrix(r->context->state.matrix); } @@ -573,6 +572,9 @@ static v8::Handle ctx2d_scale(const v8::Arguments &args) qreal x, y; x = args[0]->NumberValue(); y = args[1]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + r->context->state.matrix.scale(x, y); r->context->buffer()->updateMatrix(r->context->state.matrix); } @@ -620,12 +622,22 @@ static v8::Handle ctx2d_setTransform(const v8::Arguments &args) if (args.Length() == 6) { - r->context->state.matrix = QTransform(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue(), - args[4]->NumberValue(), - args[5]->NumberValue()); + qreal a = args[0]->NumberValue(); + qreal b = args[1]->NumberValue(); + qreal c = args[2]->NumberValue(); + qreal d = args[3]->NumberValue(); + qreal e = args[4]->NumberValue(); + qreal f = args[5]->NumberValue(); + + if (!qIsFinite(a) + || !qIsFinite(b) + || !qIsFinite(c) + || !qIsFinite(d) + || !qIsFinite(e) + || !qIsFinite(f)) + return args.This(); + + r->context->state.matrix = QTransform(a, b, c, d, e, f); r->context->buffer()->updateMatrix(r->context->state.matrix); } @@ -649,12 +661,22 @@ static v8::Handle ctx2d_transform(const v8::Arguments &args) if (args.Length() == 6) { - r->context->state.matrix *= QTransform(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue(), - args[4]->NumberValue(), - args[5]->NumberValue()); + qreal a = args[0]->NumberValue(); + qreal b = args[1]->NumberValue(); + qreal c = args[2]->NumberValue(); + qreal d = args[3]->NumberValue(); + qreal e = args[4]->NumberValue(); + qreal f = args[5]->NumberValue(); + + if (!qIsFinite(a) + || !qIsFinite(b) + || !qIsFinite(c) + || !qIsFinite(d) + || !qIsFinite(e) + || !qIsFinite(f)) + return args.This(); + + r->context->state.matrix *= QTransform(a, b, c, d, e, f); r->context->buffer()->updateMatrix(r->context->state.matrix); } @@ -677,8 +699,13 @@ static v8::Handle ctx2d_translate(const v8::Arguments &args) if (args.Length() == 2) { - r->context->state.matrix.translate(args[0]->NumberValue(), - args[1]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + + r->context->state.matrix.translate(x, y); r->context->buffer()->updateMatrix(r->context->state.matrix); } @@ -713,10 +740,16 @@ static v8::Handle ctx2d_shear(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - r->context->state.matrix.shear(args[0]->NumberValue(), - args[1]->NumberValue()); - r->context->buffer()->updateMatrix(r->context->state.matrix); + if (args.Length() == 2) { + qreal sh = args[0]->NumberValue(); + qreal sv = args[1]->NumberValue(); + if (!qIsFinite(sh) || !qIsFinite(sv)) + return args.This(); + + r->context->state.matrix.shear(sh, sv); + r->context->buffer()->updateMatrix(r->context->state.matrix); + } return args.This(); } // compositing @@ -742,6 +775,9 @@ static void ctx2d_globalAlpha_set(v8::Local, v8::Local va qreal globalAlpha = value->NumberValue(); + if (!qIsFinite(globalAlpha)) + return; + if (globalAlpha >= 0.0 && globalAlpha <= 1.0 && r->context->state.globalAlpha != globalAlpha) { r->context->state.globalAlpha = globalAlpha; r->context->buffer()->setGlobalAlpha(r->context->state.globalAlpha); @@ -793,7 +829,11 @@ static void ctx2d_globalCompositeOperation_set(v8::Local, v8::Local< QV8Engine *engine = V8ENGINE_ACCESSOR(); - QPainter::CompositionMode cm = qt_composite_mode_from_string(engine->toString(value)); + QString mode = engine->toString(value); + QPainter::CompositionMode cm = qt_composite_mode_from_string(mode); + if (cm == QPainter::CompositionMode_SourceOver && mode != QStringLiteral("source-over")) + return; + if (cm != r->context->state.globalCompositeOperation) { r->context->state.globalCompositeOperation = cm; r->context->buffer()->setGlobalCompositeOperation(cm); @@ -868,7 +908,7 @@ static void ctx2d_fillStyle_set(v8::Local, v8::Local valu } } } else if (value->IsString()) { - QColor color = qt_color_from_string(engine->toString(value)); + QColor color = qt_color_from_string(value); if (color.isValid() && r->context->state.fillStyle != QBrush(color)) { r->context->state.fillStyle = QBrush(color); r->context->buffer()->setFillStyle(r->context->state.fillStyle); @@ -974,7 +1014,7 @@ static void ctx2d_strokeStyle_set(v8::Local, v8::Local va } } } else if (value->IsString()) { - QColor color = qt_color_from_string(engine->toString(value)); + QColor color = qt_color_from_string(value); if (color.isValid() && r->context->state.strokeStyle != QBrush(color)) { r->context->state.strokeStyle = QBrush(color); r->context->buffer()->setStrokeStyle(r->context->state.strokeStyle); @@ -1009,14 +1049,21 @@ static v8::Handle ctx2d_createLinearGradient(const v8::Arguments &arg QV8Engine *engine = V8ENGINE(); if (args.Length() == 4) { - //TODO:infinite or NaN, the method must raise a NOT_SUPPORTED_ERR QSGContext2DEngineData *ed = engineData(engine); v8::Local gradient = ed->constructorGradient->NewInstance(); QV8Context2DStyleResource *r = new QV8Context2DStyleResource(engine); - r->brush = QLinearGradient(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x0 = args[0]->NumberValue(); + qreal y0 = args[1]->NumberValue(); + qreal x1 = args[2]->NumberValue(); + qreal y1 = args[3]->NumberValue(); + + if (!qIsFinite(x0) + || !qIsFinite(y0) + || !qIsFinite(x1) + || !qIsFinite(y1)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createLinearGradient(): Incorrect arguments") + + r->brush = QLinearGradient(x0, y0, x1, y1); gradient->SetExternalResource(r); return gradient; } @@ -1056,8 +1103,19 @@ static v8::Handle ctx2d_createRadialGradient(const v8::Arguments &arg qreal x1 = args[3]->NumberValue(); qreal y1 = args[4]->NumberValue(); qreal r1 = args[5]->NumberValue(); - //TODO:infinite or NaN, a NOT_SUPPORTED_ERR exception must be raised. - //If either of r0 or r1 are negative, an INDEX_SIZE_ERR exception must be raised. + + if (!qIsFinite(x0) + || !qIsFinite(y0) + || !qIsFinite(x1) + || !qIsFinite(r0) + || !qIsFinite(r1) + || !qIsFinite(y1)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createRadialGradient(): Incorrect arguments") + + if (r0 < 0 || r1 < 0) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createRadialGradient(): Incorrect arguments") + + r->brush = QRadialGradient(QPointF(x1, y1), r0+r1, QPointF(x0, y0)); gradient->SetExternalResource(r); return gradient; @@ -1095,8 +1153,12 @@ static v8::Handle ctx2d_createConicalGradient(const v8::Arguments &ar qreal x = args[0]->NumberValue(); qreal y = args[1]->NumberValue(); qreal angle = DEGREES(args[2]->NumberValue()); - //TODO:infinite or NaN, a NOT_SUPPORTED_ERR exception must be raised. - //If either of r0 or r1 are negative, an INDEX_SIZE_ERR exception must be raised. + if (!qIsFinite(x) || !qIsFinite(y)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createConicalGradient(): Incorrect arguments"); + + if (!qIsFinite(angle)) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createConicalGradient(): Incorrect arguments"); + r->brush = QConicalGradient(x, y, angle); gradient->SetExternalResource(r); return gradient; @@ -1255,6 +1317,8 @@ static void ctx2d_lineCap_set(v8::Local, v8::Local value, cap = Qt::FlatCap; else if (lineCap == QLatin1String("square")) cap = Qt::SquareCap; + else + return; if (cap != r->context->state.lineCap) { r->context->state.lineCap = cap; @@ -1311,6 +1375,8 @@ static void ctx2d_lineJoin_set(v8::Local, v8::Local value join = Qt::BevelJoin; else if (lineJoin == QLatin1String("miter")) join = Qt::MiterJoin; + else + return; if (join != r->context->state.lineJoin) { r->context->state.lineJoin = join; @@ -1338,7 +1404,7 @@ static void ctx2d_lineWidth_set(v8::Local, v8::Local valu qreal w = value->NumberValue(); - if (w > 0 && w != r->context->state.lineWidth) { + if (w > 0 && qIsFinite(w) && w != r->context->state.lineWidth) { r->context->state.lineWidth = w; r->context->buffer()->setLineWidth(w); } @@ -1365,7 +1431,7 @@ static void ctx2d_miterLimit_set(v8::Local, v8::Local val qreal ml = value->NumberValue(); - if (ml > 0 && ml != r->context->state.miterLimit) { + if (ml > 0 && qIsFinite(ml) && ml != r->context->state.miterLimit) { r->context->state.miterLimit = ml; r->context->buffer()->setMiterLimit(ml); } @@ -1391,7 +1457,7 @@ static void ctx2d_shadowBlur_set(v8::Local, v8::Local val CHECK_CONTEXT_SETTER(r) qreal blur = value->NumberValue(); - if (blur > 0 && blur != r->context->state.shadowBlur) { + if (blur > 0 && qIsFinite(blur) && blur != r->context->state.shadowBlur) { r->context->state.shadowBlur = blur; r->context->buffer()->setShadowBlur(blur); } @@ -1417,9 +1483,7 @@ static void ctx2d_shadowColor_set(v8::Local, v8::Local va QV8Context2DResource *r = v8_resource_cast(info.This()); CHECK_CONTEXT_SETTER(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QColor color = qt_color_from_string(engine->toString(value)); + QColor color = qt_color_from_string(value); if (color.isValid() && color != r->context->state.shadowColor) { r->context->state.shadowColor = color; @@ -1448,9 +1512,8 @@ static void ctx2d_shadowOffsetX_set(v8::Local, v8::Local QV8Context2DResource *r = v8_resource_cast(info.This()); CHECK_CONTEXT_SETTER(r) - //TODO: check value:infinite or NaN qreal offsetX = value->NumberValue(); - if (offsetX != r->context->state.shadowOffsetX) { + if (qIsFinite(offsetX) && offsetX != r->context->state.shadowOffsetX) { r->context->state.shadowOffsetX = offsetX; r->context->buffer()->setShadowOffsetX(offsetX); } @@ -1474,9 +1537,9 @@ static void ctx2d_shadowOffsetY_set(v8::Local, v8::Local { QV8Context2DResource *r = v8_resource_cast(info.This()); CHECK_CONTEXT_SETTER(r) - //TODO: check value:infinite or NaN + qreal offsetY = value->NumberValue(); - if (offsetY != r->context->state.shadowOffsetY) { + if (qIsFinite(offsetY) && offsetY != r->context->state.shadowOffsetY) { r->context->state.shadowOffsetY = offsetY; r->context->buffer()->setShadowOffsetY(offsetY); } @@ -1519,10 +1582,15 @@ static v8::Handle ctx2d_clearRect(const v8::Arguments &args) if (args.Length() == 4) { - r->context->buffer()->clearRect(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + r->context->buffer()->clearRect(x, y, w, h); } return args.This(); @@ -1538,12 +1606,16 @@ static v8::Handle ctx2d_fillRect(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - if (args.Length() == 4) { - r->context->buffer()->fillRect(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + r->context->buffer()->fillRect(x, y, w, h); } return args.This(); @@ -1566,10 +1638,15 @@ static v8::Handle ctx2d_strokeRect(const v8::Arguments &args) if (args.Length() == 4) { - r->context->buffer()->strokeRect(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + r->context->buffer()->strokeRect(x, y, w, h); } return args.This(); @@ -1595,7 +1672,17 @@ static v8::Handle ctx2d_arc(const v8::Arguments &args) antiClockwise = args[5]->BooleanValue(); qreal radius = args[2]->NumberValue(); - //Throws an INDEX_SIZE_ERR exception if the given radius is negative. + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal sa = args[3]->NumberValue(); + qreal ea = args[4]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(sa) || !qIsFinite(ea)) + return args.This(); + + if (radius < 0) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); + r->context->arc(args[0]->NumberValue(), args[1]->NumberValue(), radius, @@ -1633,7 +1720,19 @@ static v8::Handle ctx2d_arcTo(const v8::Arguments &args) CHECK_CONTEXT(r) + if (args.Length() == 5) { + qreal x1 = args[0]->NumberValue(); + qreal y1 = args[1]->NumberValue(); + qreal x2 = args[2]->NumberValue(); + qreal y2 = args[3]->NumberValue(); + + if (!qIsFinite(x1) || !qIsFinite(y1) || !qIsFinite(x2) || !qIsFinite(y2)) + return args.This(); + + qreal radius = args[4]->NumberValue(); + if (radius < 0) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); r->context->arcTo(args[0]->NumberValue(), args[1]->NumberValue(), args[2]->NumberValue(), @@ -1686,12 +1785,17 @@ static v8::Handle ctx2d_bezierCurveTo(const v8::Arguments &args) if (args.Length() == 6) { - r->context->bezierCurveTo(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue(), - args[4]->NumberValue(), - args[5]->NumberValue()); + qreal cp1x = args[0]->NumberValue(); + qreal cp1y = args[1]->NumberValue(); + qreal cp2x = args[2]->NumberValue(); + qreal cp2y = args[3]->NumberValue(); + qreal x = args[4]->NumberValue(); + qreal y = args[5]->NumberValue(); + + if (!qIsFinite(cp1x) || !qIsFinite(cp1y) || !qIsFinite(cp2x) || !qIsFinite(cp2y) || !qIsFinite(x) || !qIsFinite(y)) + return args.This(); + + r->context->bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); } return args.This(); @@ -1726,7 +1830,12 @@ static v8::Handle ctx2d_clip(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - r->context->state.clipPath = r->context->m_path; + QPainterPath clipPath = r->context->m_path; + clipPath.closeSubpath(); + if (!r->context->state.clipPath.isEmpty()) + r->context->state.clipPath = clipPath.intersected(r->context->state.clipPath); + else + r->context->state.clipPath = clipPath; r->context->buffer()->clip(r->context->state.clipPath); return args.This(); @@ -1781,8 +1890,13 @@ static v8::Handle ctx2d_lineTo(const v8::Arguments &args) if (args.Length() == 2) { - r->context->lineTo(args[0]->NumberValue(), - args[1]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + + r->context->lineTo(x, y); } return args.This(); @@ -1798,12 +1912,14 @@ static v8::Handle ctx2d_moveTo(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - if (args.Length() == 2) { - r->context->moveTo(args[0]->NumberValue(), - args[1]->NumberValue()); - } + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + r->context->moveTo(x, y); + } return args.This(); } @@ -1819,12 +1935,16 @@ static v8::Handle ctx2d_quadraticCurveTo(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - if (args.Length() == 4) { - r->context->quadraticCurveTo(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal cpx = args[0]->NumberValue(); + qreal cpy = args[1]->NumberValue(); + qreal x = args[2]->NumberValue(); + qreal y = args[3]->NumberValue(); + + if (!qIsFinite(cpx) || !qIsFinite(cpy) || !qIsFinite(x) || !qIsFinite(y)) + return args.This(); + + r->context->quadraticCurveTo(cpx, cpy, x, y); } return args.This(); @@ -1842,10 +1962,15 @@ static v8::Handle ctx2d_rect(const v8::Arguments &args) if (args.Length() == 4) { - r->context->rect(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + r->context->rect(x, y, w, h); } return args.This(); @@ -1862,14 +1987,21 @@ static v8::Handle ctx2d_roundedRect(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - if (args.Length() == 6) { - r->context->roundedRect(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue(), - args[4]->NumberValue(), - args[5]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + qreal xr = args[4]->NumberValue(); + qreal yr = args[5]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + if (!qIsFinite(xr) || !qIsFinite(yr)) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "roundedRect(): Invalid arguments"); + + r->context->roundedRect(x, y, w, h, xr, yr); } return args.This(); @@ -1890,10 +2022,16 @@ static v8::Handle ctx2d_ellipse(const v8::Arguments &args) if (args.Length() == 4) { - r->context->ellipse(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + qreal w = args[2]->NumberValue(); + qreal h = args[3]->NumberValue(); + + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) + return args.This(); + + + r->context->ellipse(x, y, w, h); } return args.This(); @@ -1912,11 +2050,13 @@ static v8::Handle ctx2d_text(const v8::Arguments &args) QV8Engine *engine = V8ENGINE(); if (args.Length() == 3) { - r->context->text(engine->toString(args[0]), - args[1]->NumberValue(), - args[2]->NumberValue()); - } + qreal x = args[1]->NumberValue(); + qreal y = args[2]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + r->context->text(engine->toString(args[0]), x, y); + } return args.This(); } @@ -1952,32 +2092,32 @@ static v8::Handle ctx2d_isPointInPath(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - bool pointInPath = false; if (args.Length() == 2) { - pointInPath = r->context->isPointInPath(args[0]->NumberValue(), - args[1]->NumberValue()); + qreal x = args[0]->NumberValue(); + qreal y = args[1]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return v8::Boolean::New(false); + pointInPath = r->context->isPointInPath(x, y); } - return v8::Boolean::New(pointInPath); } static v8::Handle ctx2d_drawFocusRing(const v8::Arguments &args) { - V8THROW_ERROR("Context2D::drawFocusRing is not supported") + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::drawFocusRing is not supported"); return args.This(); } static v8::Handle ctx2d_setCaretSelectionRect(const v8::Arguments &args) { - V8THROW_ERROR("Context2D::setCaretSelectionRect is not supported") + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::setCaretSelectionRect is not supported"); return args.This(); } static v8::Handle ctx2d_caretBlinkRate(const v8::Arguments &args) { - V8THROW_ERROR("Context2D::caretBlinkRate is not supported") - + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::caretBlinkRate is not supported"); return args.This(); } // text @@ -1995,7 +2135,7 @@ v8::Handle ctx2d_font(v8::Local, const v8::AccessorInfo & QV8Engine *engine = V8ENGINE_ACCESSOR(); - return engine->toString(r->context->m_fontString); + return engine->toString(r->context->state.font.toString()); } static void ctx2d_font_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) @@ -2005,9 +2145,8 @@ static void ctx2d_font_set(v8::Local, v8::Local value, co QV8Engine *engine = V8ENGINE_ACCESSOR(); QString fs = engine->toString(value); - if (fs != r->context->m_fontString) { - r->context->m_fontString = fs; - QFont font = qt_font_from_string(fs); + QFont font = qt_font_from_string(fs); + if (font != r->context->state.font) { r->context->state.font = font; } } @@ -2067,6 +2206,8 @@ static void ctx2d_textAlign_set(v8::Local, v8::Local valu ta = QSGContext2D::Right; else if (textAlign == QLatin1String("center")) ta = QSGContext2D::Center; + else + return; if (ta != r->context->state.textAlign) { r->context->state.textAlign = ta; @@ -2129,6 +2270,8 @@ static void ctx2d_textBaseline_set(v8::Local, v8::Local v tb = QSGContext2D::Bottom; else if (textBaseline == QLatin1String("middle")) tb = QSGContext2D::Middle; + else + return; if (tb != r->context->state.textBaseline) { r->context->state.textBaseline = tb; @@ -2148,16 +2291,15 @@ static v8::Handle ctx2d_fillText(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 3) { - QPainterPath textPath = r->context->createTextGlyphs(args[1]->NumberValue(), - args[2]->NumberValue(), - engine->toString(args[0])); + qreal x = args[1]->NumberValue(); + qreal y = args[2]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + QPainterPath textPath = r->context->createTextGlyphs(x, y, engine->toString(args[0])); r->context->buffer()->fill(textPath); } - return args.This(); } /*! @@ -2173,16 +2315,15 @@ static v8::Handle ctx2d_strokeText(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 3) { - QPainterPath textPath = r->context->createTextGlyphs(args[1]->NumberValue(), - args[2]->NumberValue(), - engine->toString(args[0])); + qreal x = args[1]->NumberValue(); + qreal y = args[2]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y)) + return args.This(); + QPainterPath textPath = r->context->createTextGlyphs(x, y, engine->toString(args[0])); r->context->buffer()->stroke(textPath); } - return args.This(); } /*! @@ -2212,7 +2353,6 @@ static v8::Handle ctx2d_measureText(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE(); if (args.Length() == 1) { @@ -2222,7 +2362,6 @@ static v8::Handle ctx2d_measureText(const v8::Arguments &args) tm->Set(v8::String::New("width"), v8::Number::New(width)); return tm; } - return v8::Undefined(); } @@ -2290,18 +2429,11 @@ static v8::Handle ctx2d_drawImage(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE(); - - //TODO: handle exceptions - qreal sx, sy, sw, sh, dx, dy, dw, dh; - if (args.Length() != 3 && args.Length() != 5 && args.Length() != 9) { - //parameter error + if (!args.Length()) return args.This(); - } - QImage image; if (args[0]->IsString()) { @@ -2314,8 +2446,7 @@ static v8::Handle ctx2d_drawImage(const v8::Arguments &args) } else if (imageItem) { image = imageItem->pixmap().toImage(); } else { - //wrong image type - return args.This(); + V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch"); } } if (args.Length() == 3) { @@ -2346,10 +2477,19 @@ static v8::Handle ctx2d_drawImage(const v8::Arguments &args) dw = args[7]->NumberValue(); dh = args[8]->NumberValue(); } else { - //error return args.This(); } + if (!qIsFinite(sx) + || !qIsFinite(sy) + || !qIsFinite(sw) + || !qIsFinite(sh) + || !qIsFinite(dx) + || !qIsFinite(dy) + || !qIsFinite(dw) + || !qIsFinite(dh)) + return args.This(); + r->context->buffer()->drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh); return args.This(); @@ -2591,10 +2731,10 @@ v8::Handle ctx2d_pixelArray_indexed(uint32_t index, const v8::Accesso { QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()); - if (r && index >= 0 && index < r->image.width() * r->image.height() * 4) { - const int w = r->image.width(); - const int row = (index / 4) / w; - const int col = (index / 4) % w; + if (r && index < static_cast(r->image.width() * r->image.height() * 4)) { + const quint32 w = r->image.width(); + const quint32 row = (index / 4) / w; + const quint32 col = (index / 4) % w; const QRgb* pixel = reinterpret_cast(r->image.constScanLine(row)); pixel += col; switch (index % 4) { @@ -2616,10 +2756,10 @@ v8::Handle ctx2d_pixelArray_indexed_set(uint32_t index, v8::Local(info.This()); const int v = value->Uint32Value(); - if (r && index >= 0 && index < r->image.width() * r->image.height() * 4 && v > 0 && v <= 255) { - const int w = r->image.width(); - const int row = (index / 4) / w; - const int col = (index / 4) % w; + if (r && index < static_cast(r->image.width() * r->image.height() * 4) && v > 0 && v <= 255) { + const quint32 w = r->image.width(); + const quint32 row = (index / 4) / w; + const quint32 col = (index / 4) % w; QRgb* pixel = reinterpret_cast(r->image.scanLine(row)); pixel += col; @@ -2661,7 +2801,6 @@ static v8::Handle ctx2d_createImageData(const v8::Arguments &args) QV8Context2DResource *r = v8_resource_cast(args.This()); CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE(); if (args.Length() == 1) { @@ -2680,8 +2819,14 @@ static v8::Handle ctx2d_createImageData(const v8::Arguments &args) } else if (args.Length() == 2) { qreal w = args[0]->NumberValue(); qreal h = args[1]->NumberValue(); + + if (!qIsFinite(w) || !qIsFinite(h)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createImageData(): invalid arguments"); + if (w > 0 && h > 0) return qt_create_image_data(w, h, engine, QImage()); + else + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createImageData(): invalid arguments"); } return v8::Undefined(); } @@ -2701,6 +2846,12 @@ static v8::Handle ctx2d_getImageData(const v8::Arguments &args) qreal y = args[1]->NumberValue(); qreal w = args[2]->NumberValue(); qreal h = args[3]->NumberValue(); + if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(w)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "getImageData(): Invalid arguments"); + + if (w <= 0 || h <= 0) + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "getImageData(): Invalid arguments"); + QImage image = r->context->canvas()->toImage(QRectF(x, y, w, h)); v8::Local imageData = qt_create_image_data(w, h, engine, image); @@ -2721,12 +2872,15 @@ static v8::Handle ctx2d_putImageData(const v8::Arguments &args) return v8::Undefined(); if (args[0]->IsNull() || !args[0]->IsObject()) { - V8THROW_ERROR("Context2D::putImageData, the image data type mismatch"); + V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "Context2D::putImageData, the image data type mismatch"); } qreal dx = args[1]->NumberValue(); qreal dy = args[2]->NumberValue(); qreal w, h, dirtyX, dirtyY, dirtyWidth, dirtyHeight; + if (!qIsFinite(dx) || !qIsFinite(dy)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); + v8::Local imageData = args[0]->ToObject(); QV8Context2DPixelArrayResource *pixelArray = v8_resource_cast(imageData->Get(v8::String::New("data"))->ToObject()); if (pixelArray) { @@ -2738,6 +2892,11 @@ static v8::Handle ctx2d_putImageData(const v8::Arguments &args) dirtyY = args[4]->NumberValue(); dirtyWidth = args[5]->NumberValue(); dirtyHeight = args[6]->NumberValue(); + + if (!qIsFinite(dirtyX) || !qIsFinite(dirtyY) || !qIsFinite(dirtyWidth) || !qIsFinite(dirtyHeight)) + V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); + + if (dirtyWidth < 0) { dirtyX = dirtyX+dirtyWidth; dirtyWidth = -dirtyWidth; @@ -2819,18 +2978,16 @@ static v8::Handle ctx2d_gradient_addColorStop(const v8::Arguments &ar if (args[1]->IsObject()) { color = engine->toVariant(args[1], qMetaTypeId()).value(); } else { - color = qt_color_from_string(engine->toString(args[1])); + color = qt_color_from_string(args[1]); } - if (pos < 0.0 || pos > 1.0) { - //Throws an INDEX_SIZE_ERR exception - V8THROW_ERROR("CanvasGradient: parameter offset out of range"); + if (pos < 0.0 || pos > 1.0 || !qIsFinite(pos)) { + V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "CanvasGradient: parameter offset out of range"); } if (color.isValid()) { gradient.setColorAt(pos, color); } else { - //Throws a SYNTAX_ERR exception - V8THROW_ERROR("CanvasGradient: parameter color is not a valid color string"); + V8THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "CanvasGradient: parameter color is not a valid color string"); } style->brush = gradient; } @@ -3273,8 +3430,9 @@ void QSGContext2D::popState() if (newState.miterLimit != state.miterLimit) buffer()->setMiterLimit(newState.miterLimit); - if (newState.clipPath != state.clipPath) + if (newState.clipPath != state.clipPath) { buffer()->clip(newState.clipPath); + } if (newState.shadowBlur != state.shadowBlur) buffer()->setShadowBlur(newState.shadowBlur); @@ -3287,7 +3445,6 @@ void QSGContext2D::popState() if (newState.shadowOffsetY != state.shadowOffsetY) buffer()->setShadowOffsetY(newState.shadowOffsetY); - state = newState; } void QSGContext2D::pushState() @@ -3301,12 +3458,15 @@ void QSGContext2D::reset() newState.matrix = QTransform(); QPainterPath defaultClipPath; - defaultClipPath.addRect(0, 0, m_canvas->canvasSize().width(), m_canvas->canvasSize().height()); + + QRect r(0, 0, m_canvas->canvasSize().width(), m_canvas->canvasSize().height()); + r = r.united(m_canvas->canvasWindow().toRect()); + defaultClipPath.addRect(r); newState.clipPath = defaultClipPath; newState.clipPath.setFillRule(Qt::WindingFill); - newState.strokeStyle = QColor(qRgba(1,1,1,1)); - newState.fillStyle = QColor(qRgba(1,1,1,1)); + newState.strokeStyle = QColor("#000000"); + newState.fillStyle = QColor("#000000"); newState.fillPatternRepeatX = false; newState.fillPatternRepeatY = false; newState.strokePatternRepeatX = false; @@ -3326,10 +3486,10 @@ void QSGContext2D::reset() newState.textAlign = QSGContext2D::Start; newState.textBaseline = QSGContext2D::Alphabetic; - m_fontString.clear(); m_stateStack.clear(); m_stateStack.push(newState); popState(); + m_buffer->clearRect(0, 0, m_canvas->width(), m_canvas->height()); } void QSGContext2D::setV8Engine(QV8Engine *engine) diff --git a/src/declarative/items/context2d/qsgcontext2d_p.h b/src/declarative/items/context2d/qsgcontext2d_p.h index 5354876..10c1e33 100644 --- a/src/declarative/items/context2d/qsgcontext2d_p.h +++ b/src/declarative/items/context2d/qsgcontext2d_p.h @@ -174,7 +174,6 @@ public: v8::Local m_fillStyle; v8::Local m_strokeStyle; v8::Handle m_v8path; - QString m_fontString; QV8Engine *m_v8engine; v8::Persistent m_v8value; }; diff --git a/src/declarative/items/context2d/qsgcontext2dcommandbuffer.cpp b/src/declarative/items/context2d/qsgcontext2dcommandbuffer.cpp index 51730d4..dff4f9f 100644 --- a/src/declarative/items/context2d/qsgcontext2dcommandbuffer.cpp +++ b/src/declarative/items/context2d/qsgcontext2dcommandbuffer.cpp @@ -252,7 +252,13 @@ QSGContext2D::State QSGContext2DCommandBuffer::replay(QPainter* p, QSGContext2D: } case QSGContext2D::ClearRect: { + QPainter::CompositionMode cm = p->compositionMode(); + qreal alpha = p->opacity(); + p->setCompositionMode(QPainter::CompositionMode_Source); + p->setOpacity(0); p->fillRect(takeRect(), QColor(qRgba(0, 0, 0, 0))); + p->setCompositionMode(cm); + p->setOpacity(alpha); break; } case QSGContext2D::FillRect: @@ -335,10 +341,12 @@ QSGContext2D::State QSGContext2DCommandBuffer::replay(QPainter* p, QSGContext2D: case QSGContext2D::Fill: { bool hasPattern = p->brush().style() == Qt::TexturePattern; + QPainterPath path = takePath(); + path.closeSubpath(); if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)) - fillShadowPath(p,takePath(), state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); + fillShadowPath(p,path, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); else - p->fillPath(takePath(), p->brush()); + p->fillPath(path, p->brush()); break; } case QSGContext2D::Stroke: @@ -351,13 +359,9 @@ QSGContext2D::State QSGContext2DCommandBuffer::replay(QPainter* p, QSGContext2D: } case QSGContext2D::Clip: { - QPainterPath clipPath = takePath(); - clipPath.closeSubpath(); - state.clipPath = state.clipPath.intersected(clipPath); - if (!p->clipPath().isEmpty()) - clipPath = clipPath.intersected(p->clipPath()); + state.clipPath = takePath(); p->setClipping(true); - p->setClipPath(clipPath); + p->setClipPath(state.clipPath); break; } case QSGContext2D::GlobalAlpha: diff --git a/src/declarative/items/context2d/qsgcontext2dtexture.cpp b/src/declarative/items/context2d/qsgcontext2dtexture.cpp index 455a468..38eeeb6 100644 --- a/src/declarative/items/context2d/qsgcontext2dtexture.cpp +++ b/src/declarative/items/context2d/qsgcontext2dtexture.cpp @@ -590,8 +590,11 @@ void QSGContext2DFBOTexture::endPainting() void qt_quit_context2d_render_thread() { QThread* thread = globalCanvasThreadRenderInstance(); - thread->quit(); - thread->wait(); + + if (thread->isRunning()) { + thread->exit(0); + thread->wait(1000); + } } QSGContext2DImageTexture::QSGContext2DImageTexture(bool threadRendering) diff --git a/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png b/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png new file mode 100644 index 0000000..5ab3a1b Binary files /dev/null and b/tests/auto/declarative/qsgcanvasitem/data/qt-logo.png differ diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_arc.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_arc.qml new file mode 100644 index 0000000..6006a5a --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_arc.qml @@ -0,0 +1,487 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper + +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + name: "arc"; when: windowShown + function test_angle_1() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 0); + ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true); + ctx.fill(); + verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_angle_2() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 0); + ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true); + ctx.fill(); + verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_angle_3() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 0); + ctx.arc(100, 0, 150, (512+1/2)*Math.PI, (1024-1)*Math.PI, true); + ctx.fill(); + //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_angle_4() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false); + ctx.fill(); + verify(Helper.comparePixel(ctx,1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx,98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx,1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx,98,48, 0,255,0,255)); + } + function test_angle_5() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 0); + ctx.arc(100, 0, 150, (1024-1)*Math.PI, (512+1/2)*Math.PI, false); + ctx.fill(); + /*FIXME: + actual :[255,0,0,255] + expected:[0,255,0,255] +/- 0 + */ + //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + + function test_angle_6() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true); + ctx.fill(); + + verify(Helper.comparePixel(ctx,1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx,98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx,1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx,98,48, 0,255,0,255)); + } + + function test_empty() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arc(200, 25, 5, 0, 2*Math.PI, true); + ctx.stroke(); + /*FIXME: + actual :[255,0,0,255] + expected:[0,255,0,255] +/- 0 + */ + //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_nonempty() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arc(200, 25, 5, 0, 2*Math.PI, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_nonfinite() { + skip("FIXME"); + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.arc(Infinity, 0, 50, 0, 2*Math.PI, true); + ctx.arc(-Infinity, 0, 50, 0, 2*Math.PI, true); + ctx.arc(NaN, 0, 50, 0, 2*Math.PI, true); + ctx.arc(0, Infinity, 50, 0, 2*Math.PI, true); + ctx.arc(0, -Infinity, 50, 0, 2*Math.PI, true); + ctx.arc(0, NaN, 50, 0, 2*Math.PI, true); + ctx.arc(0, 0, Infinity, 0, 2*Math.PI, true); + ctx.arc(0, 0, -Infinity, 0, 2*Math.PI, true); + ctx.arc(0, 0, NaN, 0, 2*Math.PI, true); + ctx.arc(0, 0, 50, Infinity, 2*Math.PI, true); + ctx.arc(0, 0, 50, -Infinity, 2*Math.PI, true); + ctx.arc(0, 0, 50, NaN, 2*Math.PI, true); + ctx.arc(0, 0, 50, 0, Infinity, true); + ctx.arc(0, 0, 50, 0, -Infinity, true); + ctx.arc(0, 0, 50, 0, NaN, true); + ctx.arc(Infinity, Infinity, 50, 0, 2*Math.PI, true); + ctx.arc(Infinity, Infinity, Infinity, 0, 2*Math.PI, true); + ctx.arc(Infinity, Infinity, Infinity, Infinity, 2*Math.PI, true); + ctx.arc(Infinity, Infinity, Infinity, Infinity, Infinity, true); + ctx.arc(Infinity, Infinity, Infinity, 0, Infinity, true); + ctx.arc(Infinity, Infinity, 50, Infinity, 2*Math.PI, true); + ctx.arc(Infinity, Infinity, 50, Infinity, Infinity, true); + ctx.arc(Infinity, Infinity, 50, 0, Infinity, true); + ctx.arc(Infinity, 0, Infinity, 0, 2*Math.PI, true); + ctx.arc(Infinity, 0, Infinity, Infinity, 2*Math.PI, true); + ctx.arc(Infinity, 0, Infinity, Infinity, Infinity, true); + ctx.arc(Infinity, 0, Infinity, 0, Infinity, true); + ctx.arc(Infinity, 0, 50, Infinity, 2*Math.PI, true); + ctx.arc(Infinity, 0, 50, Infinity, Infinity, true); + ctx.arc(Infinity, 0, 50, 0, Infinity, true); + ctx.arc(0, Infinity, Infinity, 0, 2*Math.PI, true); + ctx.arc(0, Infinity, Infinity, Infinity, 2*Math.PI, true); + ctx.arc(0, Infinity, Infinity, Infinity, Infinity, true); + ctx.arc(0, Infinity, Infinity, 0, Infinity, true); + ctx.arc(0, Infinity, 50, Infinity, 2*Math.PI, true); + ctx.arc(0, Infinity, 50, Infinity, Infinity, true); + ctx.arc(0, Infinity, 50, 0, Infinity, true); + ctx.arc(0, 0, Infinity, Infinity, 2*Math.PI, true); + ctx.arc(0, 0, Infinity, Infinity, Infinity, true); + ctx.arc(0, 0, Infinity, 0, Infinity, true); + ctx.arc(0, 0, 50, Infinity, Infinity, true); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx,90,45, 0,255,0,255)); + } + function test_end() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(-100, 0); + ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true); + ctx.lineTo(100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx,50,25, 0,255,0,255)); + } + function test_negative() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + try { var err = false; + ctx.arc(0, 0, -1, 0, 0, true); + } catch (e) { + if (e.code != DOMException.INDEX_SIZE_ERR) + fail("expected exception of type INDEX_SIZE_ERR, got: "+e.message); + err = true; + } finally { + verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)"); + } + + } + + function test_scale_1() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.scale(2, 0.5); + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.arc(25, 50, 56, 0, 2*Math.PI, false); + ctx.fill(); + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(-25, 50); + ctx.arc(-25, 50, 24, 0, 2*Math.PI, false); + ctx.moveTo(75, 50); + ctx.arc(75, 50, 24, 0, 2*Math.PI, false); + ctx.moveTo(25, -25); + ctx.arc(25, -25, 24, 0, 2*Math.PI, false); + ctx.moveTo(25, 125); + ctx.arc(25, 125, 24, 0, 2*Math.PI, false); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + } + + function test_scale_2() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.scale(100, 100); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 1.2; + ctx.beginPath(); + ctx.arc(0, 0, 0.6, 0, Math.PI/2, false); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_selfintersect_1() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 200; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arc(100, 50, 25, 0, -Math.PI/2, true); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(0, 0, 25, 0, -Math.PI/2, true); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_selfintersect_2() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 180; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.arc(-50, 50, 25, 0, -Math.PI/2, true); + ctx.stroke(); + ctx.beginPath(); + ctx.arc(100, 0, 25, 0, -Math.PI/2, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 97,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 97,2, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 97,3, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 2,48, 0,255,0,255)); + } + + function test_shape_1() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arc(50, 50, 50, 0, Math.PI, false); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_shape_2() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 100; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.arc(50, 50, 50, 0, Math.PI, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + function test_shape_3() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 100; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arc(0, 50, 50, 0, -Math.PI/2, false); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_shape_4() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 150; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.arc(-50, 50, 100, 0, -Math.PI/2, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_shape_5() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 200; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arc(300, 0, 100, 0, 5*Math.PI, false); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_twopie() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + } + + function test_zero() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 0, true); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.arc(50, 25, 50, 0, 0, false); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00' + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arc(200, 25, 0, 0, Math.PI, true); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_arcto.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_arcto.qml new file mode 100644 index 0000000..cc1d886 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_arcto.qml @@ -0,0 +1,410 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper + +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + name: "arcTo"; when: windowShown + function test_coincide() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(0, 25, 50, 1000, 1); + ctx.lineTo(100, 25); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arcTo(50, 25, 100, 25, 1); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 100, 25, 1); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_collinear() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 200, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(-100, 25); + ctx.arcTo(0, 25, 100, 25, 1); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 10, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 110, 25, 1); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, -100, 25, 1); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 0, 25, 1); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(-100, 25); + ctx.arcTo(0, 25, -200, 25, 1); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_subpath() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.arcTo(100, 50, 200, 50, 0.1); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.arcTo(0, 25, 50, 250, 0.1); + ctx.lineTo(100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_negative() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + try { var err = false; + ctx.arcTo(0, 0, 0, 0, -1); + } catch (e) { + if (e.code != DOMException.INDEX_SIZE_ERR) + fail("expectes INDEX_SIZE_ERR, got: "+e.message); + err = true; + } + finally { + verify(err, "should throw INDEX_SIZE_ERR: ctx.arcTo(0, 0, 0, 0, -1)"); + } + } + + function test_nonfinite() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + skip("FIXME"); + + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.arcTo(Infinity, 50, 0, 50, 0); + ctx.arcTo(-Infinity, 50, 0, 50, 0); + ctx.arcTo(NaN, 50, 0, 50, 0); + ctx.arcTo(0, Infinity, 0, 50, 0); + ctx.arcTo(0, -Infinity, 0, 50, 0); + ctx.arcTo(0, NaN, 0, 50, 0); + ctx.arcTo(0, 50, Infinity, 50, 0); + ctx.arcTo(0, 50, -Infinity, 50, 0); + ctx.arcTo(0, 50, NaN, 50, 0); + ctx.arcTo(0, 50, 0, Infinity, 0); + ctx.arcTo(0, 50, 0, -Infinity, 0); + ctx.arcTo(0, 50, 0, NaN, 0); + ctx.arcTo(0, 50, 0, 50, Infinity); + ctx.arcTo(0, 50, 0, 50, -Infinity); + ctx.arcTo(0, 50, 0, 50, NaN); + ctx.arcTo(Infinity, Infinity, 0, 50, 0); + ctx.arcTo(Infinity, Infinity, Infinity, 50, 0); + ctx.arcTo(Infinity, Infinity, Infinity, Infinity, 0); + ctx.arcTo(Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.arcTo(Infinity, Infinity, Infinity, 50, Infinity); + ctx.arcTo(Infinity, Infinity, 0, Infinity, 0); + ctx.arcTo(Infinity, Infinity, 0, Infinity, Infinity); + ctx.arcTo(Infinity, Infinity, 0, 50, Infinity); + ctx.arcTo(Infinity, 50, Infinity, 50, 0); + ctx.arcTo(Infinity, 50, Infinity, Infinity, 0); + ctx.arcTo(Infinity, 50, Infinity, Infinity, Infinity); + ctx.arcTo(Infinity, 50, Infinity, 50, Infinity); + ctx.arcTo(Infinity, 50, 0, Infinity, 0); + ctx.arcTo(Infinity, 50, 0, Infinity, Infinity); + ctx.arcTo(Infinity, 50, 0, 50, Infinity); + ctx.arcTo(0, Infinity, Infinity, 50, 0); + ctx.arcTo(0, Infinity, Infinity, Infinity, 0); + ctx.arcTo(0, Infinity, Infinity, Infinity, Infinity); + ctx.arcTo(0, Infinity, Infinity, 50, Infinity); + ctx.arcTo(0, Infinity, 0, Infinity, 0); + ctx.arcTo(0, Infinity, 0, Infinity, Infinity); + ctx.arcTo(0, Infinity, 0, 50, Infinity); + ctx.arcTo(0, 50, Infinity, Infinity, 0); + ctx.arcTo(0, 50, Infinity, Infinity, Infinity); + ctx.arcTo(0, 50, Infinity, 50, Infinity); + ctx.arcTo(0, 50, 0, Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); + + } + function test_scale() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 50); + ctx.translate(100, 0); + ctx.scale(0.1, 1); + ctx.arcTo(50, 50, 50, 0, 50); + ctx.lineTo(-1000, 0); + ctx.fill(); + + skip("FIXME"); + //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + } + + function test_shape() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + var tol = 1.5; // tolerance to avoid antialiasing artifacts + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 10; + ctx.beginPath(); + ctx.moveTo(10, 25); + ctx.arcTo(75, 25, 75, 60, 20); + ctx.stroke(); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.rect(10, 20, 45, 10); + ctx.moveTo(80, 45); + ctx.arc(55, 45, 25+tol, 0, -Math.PI/2, true); + ctx.arc(55, 45, 15-tol, -Math.PI/2, 0, false); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,20, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,21, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 64,22, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 65,21, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 72,28, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 73,27, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 78,36, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,35, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,44, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,45, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,46, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 65,45, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.rect(10, 20, 45, 10); + ctx.moveTo(80, 45); + ctx.arc(55, 45, 25-tol, 0, -Math.PI/2, true); + ctx.arc(55, 45, 15+tol, -Math.PI/2, 0, false); + ctx.fill(); + + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 10; + ctx.beginPath(); + ctx.moveTo(10, 25); + ctx.arcTo(75, 25, 75, 60, 20); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,20, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 55,21, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 64,22, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 65,21, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 72,28, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 73,27, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 78,36, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,35, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,44, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,45, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 80,46, 0,255,0,255)); + ctx.reset(); + + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(-100, -100); + ctx.arcTo(-100, 25, 200, 25, 10); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(200, 25, 200, 50, 10); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + + function test_transform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 50); + ctx.translate(100, 0); + ctx.arcTo(50, 50, 50, 0, 50); + ctx.lineTo(-100, 0); + ctx.fill(); + + skip("FIXME"); + //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + } + function test_zero() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, 100, 100, 0); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(0, -25); + ctx.arcTo(50, -25, 50, 50, 0); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.lineWidth = 50; + + ctx.strokeStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.arcTo(100, 25, -100, 25, 0); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(100, 25); + ctx.arcTo(200, 25, 50, 25, 0); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_canvas.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_canvas.qml new file mode 100644 index 0000000..65649df --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_canvas.qml @@ -0,0 +1,271 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id:container + width:100 + height:100 + Component { + id:canvas + Canvas { + id:c + width:10;height:10 + onPaint: { + context.fillStyle = "red"; + context.fillRect(0, 0, 10, 10); + } + property int paintCount:spyPaint.count + property int paintedCount:spyPainted.count + property int canvasSizeChangedCount:spyCanvasSizeChanged.count + property int tileSizeChangedCount:spyTileSizeChanged.count + property int renderInThreadChangedCount:spyRenderInThreadChanged.count + property int canvasWindowChangedCount:spyCanvasWindowChanged.count + property int renderTargetChangedCount:spyRenderTargetChanged.count + property int imageLoadedCount:spyImageLoaded.count + + SignalSpy {id: spyPaint;target:c;signalName: "paint"} + SignalSpy {id: spyPainted;target:c;signalName: "painted"} + SignalSpy {id: spyCanvasSizeChanged;target:c;signalName: "canvasSizeChanged"} + SignalSpy {id: spyTileSizeChanged;target:c;signalName: "tileSizeChanged"} + SignalSpy {id: spyRenderInThreadChanged;target:c;signalName: "renderInThreadChanged"} + SignalSpy {id: spyCanvasWindowChanged;target:c;signalName: "canvasWindowChanged"} + SignalSpy {id: spyRenderTargetChanged;target:c;signalName: "renderTargetChanged"} + SignalSpy {id: spyImageLoaded;target:c;signalName: "imageLoaded"} + } + } + + TestCase { + name: "Canvas"; when: windowShown + function test_canvasSize() { + var c = canvas.createObject(); + verify(c); + + //by default canvasSize is same with canvas' actual size + // when canvas size changes, canvasSize should be changed as well. + compare(c.canvasSize.width, c.width); + compare(c.canvasSize.height, c.height); + c.width = 20; + compare(c.canvasSize.width, 20); + compare(c.canvasSizeChangedCount, 1); + c.height = 5; + compare(c.canvasSizeChangedCount, 2); + compare(c.canvasSize.height, 5); + + //change canvasSize manually, then canvasSize detaches from canvas + //actual size. + c.canvasSize.width = 100; + compare(c.canvasSizeChangedCount, 3); + compare(c.canvasSize.width, 100); + compare(c.width, 20); + c.canvasSize.height = 50; + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.height, 50); + compare(c.height, 5); + + c.width = 10; + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.width, 100); + compare(c.canvasSize.height, 50); + + c.height = 10; + compare(c.canvasSizeChangedCount, 4); + compare(c.canvasSize.width, 100); + compare(c.canvasSize.height, 50); + c.destroy(); + } + function test_tileSize() { + var c = canvas.createObject(); + verify(c); + + compare(c.tileSize.width, c.width); + compare(c.tileSize.height, c.height); + c.width = 20; + compare(c.tileSize.width, 20); + compare(c.tileSizeChangedCount, 1); + c.height = 5; + compare(c.tileSizeChangedCount, 2); + compare(c.tileSize.height, 5); + + c.tileSize.width = 100; + compare(c.tileSizeChangedCount, 3); + compare(c.tileSize.width, 100); + compare(c.width, 20); + c.tileSize.height = 50; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.height, 50); + compare(c.height, 5); + + c.width = 10; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.width, 100); + compare(c.tileSize.height, 50); + + c.height = 10; + compare(c.tileSizeChangedCount, 4); + compare(c.tileSize.width, 100); + compare(c.tileSize.height, 50); + c.destroy(); + + } + + function test_canvasWindow() { + var c = canvas.createObject(); + verify(c); + compare(c.canvasWindow.x, 0); + compare(c.canvasWindow.y, 0); + compare(c.canvasWindow.width, c.width); + compare(c.canvasWindow.height, c.height); + + c.width = 20; + compare(c.canvasWindow.width, 20); + compare(c.canvasWindowChangedCount, 1); + c.height = 5; + compare(c.canvasWindowChangedCount, 2); + compare(c.canvasWindow.height, 5); + + c.canvasWindow.x = 5; + c.canvasWindow.y = 6; + c.canvasWindow.width = 10; + c.canvasWindow.height =20; + compare(c.canvasWindowChangedCount, 6); + compare(c.canvasWindow.width, 10); + compare(c.canvasWindow.height, 20); + compare(c.canvasWindow.x, 5); + compare(c.canvasWindow.y, 6); + c.destroy(); + + } + function test_renderTargetAndThread() { + var c = canvas.createObject(); + verify(c); + + compare(c.renderTarget, Canvas.FramebufferObject); + verify(!c.renderInThread); + c.renderTarget = Canvas.Image; + compare(c.renderTargetChangedCount, 1); + compare(c.renderInThreadChangedCount, 0); + + compare(c.renderTarget, Canvas.Image); + verify(!c.renderInThread); + c.renderInThread = true; + verify(c.renderInThread); + compare(c.renderTargetChangedCount, 1); + compare(c.renderInThreadChangedCount, 1); + + ignoreWarning("Canvas: render target does not support thread rendering, force to non-thread rendering mode."); + c.renderTarget = Canvas.FramebufferObject; + verify(!c.renderInThread); + compare(c.renderTargetChangedCount, 2); + compare(c.renderInThreadChangedCount, 2); + c.destroy(); + + } + function test_save() { + var c = canvas.createObject(); + verify(c); + + c.renderTarget = Canvas.Image; + c.requestPaint(); + wait(100); + verify(c.save("c.png")); + c.loadImage("c.png"); + wait(200); + compare(c.imageLoadedCount, 1); + verify(c.isImageLoaded("c.png")); + verify(!c.isImageLoading("c.png")); + verify(!c.isImageError("c.png")); + c.destroy(); + + } + function test_toDataURL_data() { + return [{mimeType:"image/png"}, + {mimeType:"image/bmp"}, + {mimeType:"image/jpeg"}, + {mimeType:"image/x-portable-pixmap"}, + {mimeType:"image/tiff"}, + {mimeType:"image/xbm"}, + {mimeType:"image/xpm"}, + ]; + } + + function test_toDataURL(data) { + var c = canvas.createObject(); + verify(c); + + c.renderTarget = Canvas.Image; + var ctx = c.getContext(); + ctx.fillStyle = "red"; + ctx.fillRect(0, 0, c.width, c.height); + + c.requestPaint(); + wait(100); + var dataUrl = c.toDataURL(); + verify(dataUrl != "data:,"); + dataUrl = c.toDataURL("image/invalid"); + verify(dataUrl == "data:,"); + + dataUrl = c.toDataURL(data.mimeType); + verify(dataUrl != "data:,"); + ctx.save(); + ctx.fillStyle = "blue"; + ctx.fillRect(0, 0, c.width, c.height); + ctx.restore(); + + var dataUrl2 = c.toDataURL(data.mimeType); + verify (dataUrl2 != "data:,"); + verify (dataUrl2 != dataUrl); + c.destroy(); + + } + function test_paint() { + var c = canvas.createObject(); + verify(c); + + c.renderTarget = Canvas.Image; + + c.requestPaint(); + wait(200); + compare(c.paintedCount, 1); + compare(c.paintCount, 1); + c.destroy(); + + } + function test_loadImage() { + var c = canvas.createObject(); + verify(c); + + c.loadImage("qt-logo.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")); + c.destroy(); + + } + + function test_getContext() { + var c = canvas.createObject(); + verify(c); + + var ctx = c.getContext(); + verify(ctx); + compare(ctx.canvas, c); + ctx = c.getContext('2d'); + verify(ctx); + compare(ctx.canvas, c); + ctx = c.getContext('2D'); + verify(ctx); + compare(ctx.canvas, c); + ctx = c.getContext('invalid'); + verify(!ctx); + c.destroy(); + + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_colors.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_colors.qml deleted file mode 100644 index a20a7df..0000000 --- a/tests/auto/declarative/qsgcanvasitem/data/tst_colors.qml +++ /dev/null @@ -1,19 +0,0 @@ -import QtQuick 2.0 -import QtTest 1.0 -import "testhelper.js" as Helper - -Canvas { - id:canvas; width:1;height:1 - TestCase { - name: "Colors"; when: windowShown - function test_globalAlpha() { - var ctx = canvas.getContext('2d'); - ctx.reset(); - ctx.fillStyle = Qt.rgba(1, 0.7, 0.2, 0.5); - ctx.globalAlpha = 0.5; - ctx.fillRect(0,0,1,1); - var d = ctx.getImageData(0,0,1,1).data; - verify(Helper.comparePixel(ctx, 0, 0, 255, 0.7 * 255, 0.2*255, 0.25 * 255)); - } - } -} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_composite.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_composite.qml new file mode 100644 index 0000000..11e1dce --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_composite.qml @@ -0,0 +1,380 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget:Canvas.Image + TestCase { + name: "composite"; when: windowShown + function test_clearRect() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-atop'; + ctx.clearRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0)); + } + + function test_clip_data() { + return [ {compsite:"copy"}, + {compsite:"destination-atop"}, + {compsite:"destination-in"}, + {compsite:"destination-out"}, + {compsite:"destination-over"}, + {compsite:"lighter"}, + {compsite:"source-atop"}, + {compsite:"source-in"}, + {compsite:"source-out"}, + {compsite:"source-over"}, + {compsite:"xor"} + ]; + } + + function test_clip(data) { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = data.compsite; + ctx.rect(-20, -20, 10, 10); + ctx.clip(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 50, 50); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + } + + function test_globalAlpha() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + compare(ctx.globalAlpha, 1.0); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalAlpha = 0.01; // avoid any potential alpha=0 optimisations + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 2,253,0,255, 2)); + + ctx.reset(); + ctx.globalAlpha = 0.5; + var a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons + ctx.globalAlpha = Infinity; + compare(ctx.globalAlpha, a); + ctx.globalAlpha = -Infinity; + compare(ctx.globalAlpha, a); + ctx.globalAlpha = NaN; + compare(ctx.globalAlpha, a); + + ctx.globalAlpha = 0.5; + a = ctx.globalAlpha; // might not be exactly 0.5, if it is rounded/quantised, so remember for future comparisons + ctx.globalAlpha = 1.1; + compare(ctx.globalAlpha, a); + ctx.globalAlpha = -0.1; + compare(ctx.globalAlpha, a); + ctx.globalAlpha = 0; + compare(ctx.globalAlpha, 0); + ctx.globalAlpha = 1; + compare(ctx.globalAlpha, 1); + + } + + function test_operation() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'Source-over'; + compare(ctx.globalCompositeOperation, 'xor'); + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'clear'; + compare(ctx.globalCompositeOperation, 'xor'); + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'darker'; + compare(ctx.globalCompositeOperation, 'xor'); + + ctx.reset(); + compare(ctx.globalCompositeOperation, 'source-over'); + + + ctx.reset(); + var modes = ['source-atop', 'source-in', 'source-out', 'source-over', + 'destination-atop', 'destination-in', 'destination-out', 'destination-over', + 'lighter', 'copy', 'xor']; + for (var i = 0; i < modes.length; ++i) + { + ctx.globalCompositeOperation = modes[i]; + compare(ctx.globalCompositeOperation, modes[i]); + } + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'highlight'; + compare(ctx.globalCompositeOperation, 'xor'); + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'source-over\\0'; + compare(ctx.globalCompositeOperation, 'xor'); + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'over'; + compare(ctx.globalCompositeOperation, 'xor'); + + + ctx.reset(); + ctx.globalCompositeOperation = 'xor'; + ctx.globalCompositeOperation = 'nonexistent'; + compare(ctx.globalCompositeOperation, 'xor'); + } + + function test_solid() { + skip("FIXME"); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = Qt.rgba(0, 1, 1, 1.0); + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'copy'; + ctx.fillStyle = Qt.rgba(1, 1, 0, 1.0); + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 255,255,0, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-atop'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,255,255, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-in'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,255,255, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-out'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-over'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,255,255, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'lighter'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 255,255,255,255, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-atop'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 255,255,0, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-in'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 255,255,0, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-out'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + // verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-over'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 255,255,0, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 255, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'xor'; + ctx.fillStyle = 'rgba(255, 255, 0, 1.0)'; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + } + function test_transparent() { + + skip("FIXME"); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'copy'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,255,191, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'copy'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,255,191, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-in'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,95, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-out'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,31, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-over'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,145,109,223, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'lighter'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,127,191,255, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-atop'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,63,191,127, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-in'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,255,95, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-out'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,255,95, 5)); + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-over'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,36,218,223, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'xor'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,63,191,127, 5)); + + } + + function test_uncovered() { + skip("FIXME"); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'copy'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.translate(0, 25); + ctx.fillRect(0, 50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-atop'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.translate(0, 25); + ctx.fillRect(0, 50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'destination-in'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.translate(0, 25); + ctx.fillRect(0, 50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-in'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.translate(0, 25); + ctx.fillRect(0, 50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + ctx.reset(); + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.fillRect(0, 0, 100, 50); + ctx.globalCompositeOperation = 'source-out'; + ctx.fillStyle = 'rgba(0, 0, 255, 0.75)'; + ctx.translate(0, 25); + ctx.fillRect(0, 50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,0,0,0, 5)); + + } + + } +} \ No newline at end of file diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_drawimage.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_drawimage.qml new file mode 100644 index 0000000..2f10501 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_drawimage.qml @@ -0,0 +1,42 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + //TODO + name: "image"; when: windowShown + function test_3args() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_5args() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_9args() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_animated() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_clip() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_composite() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_path() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_transform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_fillStyle.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_fillStyle.qml index a4b77ec..8f5a78c 100644 --- a/tests/auto/declarative/qsgcanvasitem/data/tst_fillStyle.qml +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_fillStyle.qml @@ -3,7 +3,7 @@ import QtTest 1.0 import "testhelper.js" as Helper Canvas { - id:canvas; width:1;height:1 + id:canvas; width:1;height:1;renderTarget:Canvas.Image TestCase { name: "fillStyle"; when: windowShown function test_default() { @@ -43,7 +43,9 @@ Canvas { compare(ctx.fillStyle, '#ffaa00'); ctx.fillStyle = "rgb (1, 2, 3)"; compare(ctx.fillStyle, '#ffaa00'); - ctx.fillStyle = "rgba(1, 2, 3)"; + ctx.fillStyle = '#fa0'; + + ctx.fillStyle = "rgba(3, 1, 2)"; compare(ctx.fillStyle, '#ffaa00'); ctx.fillStyle = "rgb((3,4,1)"; compare(ctx.fillStyle, '#ffaa00'); @@ -96,9 +98,7 @@ Canvas { ctx.clearRect(0, 0, 1, 1); ctx.fillStyle = 'rgba(0%, 100%, 0%, 0.499)'; ctx.fillRect(0, 0, 1, 1); - //FIXME: currently we only return premultipled pixels - verify(Helper.comparePixel(ctx, 0,0, 0,127,0,255)); - //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,127)); + verify(Helper.comparePixel(ctx, 0,0, 0,255,0,127)); } function test_hsla() { @@ -106,7 +106,7 @@ Canvas { ctx.reset(); ctx.fillStyle = "hsla(120, 100%, 50%, 0.499)"; ctx.fillRect(0, 0, 1, 1); - verify(Helper.comparePixel(ctx,0,0,0,127,0,255)); + verify(Helper.comparePixel(ctx,0,0,0,255,0,127)); } } diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_fillrect.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_fillrect.qml index 07ddc59..2061647 100644 --- a/tests/auto/declarative/qsgcanvasitem/data/tst_fillrect.qml +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_fillrect.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import QtTest 1.0 Canvas { - id:canvas; width:1;height:1 + id:canvas; width:1;height:1; renderTarget:Canvas.Image onPaint: { context.fillStyle = "red"; context.fillRect(0, 0, canvas.width, canvas.height); @@ -20,4 +20,4 @@ Canvas { verify(d[3] == 255); } } -} +} \ No newline at end of file diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_gradient.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_gradient.qml new file mode 100644 index 0000000..d454c2e --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_gradient.qml @@ -0,0 +1,981 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + name: "gradient"; when: windowShown + function test_basic() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + var g = ctx.createLinearGradient(0, 0, 0, 50); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2)); + + } + + function test_interpolate() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#ff0'; + ctx.fillRect(0, 0, 100, 50); + var g = ctx.createLinearGradient(0, 0, 100, 0); + g.addColorStop(0, 'rgba(0,0,255, 0)'); + g.addColorStop(1, 'rgba(0,0,255, 1)'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 25,25, 191,191,63,255,3)); + //verify(Helper.comparePixel(ctx, 50,25, 127,127,127,255,3)); + //verify(Helper.comparePixel(ctx, 75,25, 63,63,191,255,3)); + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 100, 0); + g.addColorStop(0, '#ff0'); + g.addColorStop(1, '#00f'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 25,25, 191,191,63,255,3)); + //verify(Helper.comparePixel(ctx, 50,25, 127,127,127,255,3)); + //verify(Helper.comparePixel(ctx, 75,25, 63,63,191,255,3)); + + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 100, 0); + g.addColorStop(0, 'rgba(255,255,0, 0)'); + g.addColorStop(1, 'rgba(0,0,255, 1)'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 25,25, 191,191,63,63,3)); + //verify(Helper.comparePixel(ctx, 50,25, 127,127,127,127,3)); + //verify(Helper.comparePixel(ctx, 75,25, 63,63,191,191,3)); + + ctx.reset(); + canvas.width = 200; + var g = ctx.createLinearGradient(0, 0, 200, 0); + g.addColorStop(0, '#ff0'); + g.addColorStop(0.5, '#0ff'); + g.addColorStop(1, '#f0f'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 200, 50); + //verify(Helper.comparePixel(ctx, 50,25, 127,255,127,255,3)); + //verify(Helper.comparePixel(ctx, 100,25, 0,255,255,255,3)); + //verify(Helper.comparePixel(ctx, 150,25, 127,127,255,255,3)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + var g = ctx.createLinearGradient(25, 0, 75, 0); + g.addColorStop(0.4, '#0f0'); + g.addColorStop(0.6, '#0f0'); + + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 20,25, 0,255,0,255,2)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2)); + //verify(Helper.comparePixel(ctx, 80,25, 0,255,0,255,2)); + + + ctx.reset(); + ctx.canvas.width = 200; + var g = ctx.createLinearGradient(0, 0, 200, 0); + g.addColorStop(0, '#f00'); + g.addColorStop(0, '#ff0'); + g.addColorStop(0.25, '#00f'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.25, '#ff0'); + g.addColorStop(0.5, '#00f'); + g.addColorStop(0.5, '#0f0'); + g.addColorStop(0.75, '#00f'); + g.addColorStop(0.75, '#f00'); + g.addColorStop(0.75, '#ff0'); + g.addColorStop(0.5, '#0f0'); + g.addColorStop(0.5, '#0f0'); + g.addColorStop(0.5, '#ff0'); + g.addColorStop(1, '#00f'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 200, 50); + //verify(Helper.comparePixel(ctx, 49,25, 0,0,255,255,16)); + //verify(Helper.comparePixel(ctx, 51,25, 255,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 99,25, 0,0,255,255,16)); + //verify(Helper.comparePixel(ctx, 101,25, 255,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 149,25, 0,0,255,255,16)); + //verify(Helper.comparePixel(ctx, 151,25, 255,255,0,255,16)); + ctx.canvas.width = 100; + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 100, 0); + var ps = [ 0, 1/10, 1/4, 1/3, 1/2, 3/4, 1 ]; + for (var p = 0; p < ps.length; ++p) + { + g.addColorStop(ps[p], '#0f0'); + for (var i = 0; i < 15; ++i) + g.addColorStop(ps[p], '#f00'); + g.addColorStop(ps[p], '#0f0'); + } + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 30,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 40,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 60,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 80,25, 0,255,0,255)); + + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 100, 0); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 0, 50); + g.addColorStop(0, '#ff0'); + g.addColorStop(1, '#00f'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,12, 191,191,63,255,10)); + //verify(Helper.comparePixel(ctx, 50,25, 127,127,127,255,5)); + //verify(Helper.comparePixel(ctx, 50,37, 63,63,191,255,10)); + + + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + var g = ctx.createLinearGradient(50, 25, 50, 25); // zero-length line (undefined direction) + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 40,20, 0,255,0,255,2)); + + + + } + function test_radial() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + var g = ctx.createRadialGradient(0, 100, 40, 100, 100, 50); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(210, 25, 100, 230, 25, 101); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(210, 25, 100, 230, 25, 100); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(311, 25, 10, 210, 25, 100); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + var tol = 1; // tolerance to avoid antialiasing artifacts + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(30+tol, 40); + ctx.lineTo(110, -20+tol); + ctx.lineTo(110, 100-tol); + ctx.fill(); + + g = ctx.createRadialGradient(30+10*5/2, 40, 10*3/2, 30+10*15/4, 40, 10*9/4); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + var tol = 1; // tolerance to avoid antialiasing artifacts + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(30+10*5/2, 40, 10*3/2, 30+10*15/4, 40, 10*9/4); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.moveTo(30-tol, 40); + ctx.lineTo(110, -20-tol); + ctx.lineTo(110, 100+tol); + ctx.fill(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(230, 25, 100, 100, 25, 101); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(50, 25, 20, 50, 25, 20); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(50, 25, 100, 50, 25, 200); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(50, 25, 200, 50, 25, 100); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(50, 25, 200, 50, 25, 100); + g.addColorStop(0, '#f00'); + g.addColorStop(0.993, '#f00'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + try { var err = false; + ctx.createRadialGradient(0, 0, -0.1, 0, 0, 1); + } 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.createRadialGradient(0, 0, -0.1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, 0, -0.1); + } 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.createRadialGradient(0, 0, 1, 0, 0, -0.1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, -0.1, 0, 0, -0.1); + } 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.createRadialGradient(0, 0, -0.1, 0, 0, -0.1)"); } + + + ctx.reset(); + + + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(-Infinity, 0, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(-Infinity, 0, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(NaN, 0, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(NaN, 0, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, -Infinity, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, -Infinity, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, NaN, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, NaN, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, -Infinity, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, -Infinity, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, NaN, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, NaN, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, -Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, -Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, NaN, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, NaN, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, -Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, -Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, NaN, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, NaN, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, 0, -Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, 0, -Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, 0, NaN); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, 0, NaN)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, Infinity, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, Infinity, 1, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, Infinity, 1, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, Infinity, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, Infinity, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(Infinity, 0, 1, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(Infinity, 0, 1, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, 0, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, 0, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, Infinity, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, Infinity, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, Infinity, 1, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, Infinity, 1, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, Infinity, 0, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, Infinity, 0, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, 0, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, 0, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, Infinity, 0, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, Infinity, 0, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, Infinity, Infinity, 1); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, Infinity, Infinity, 1)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, Infinity, 0, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, Infinity, 0, Infinity)"); } + try { var err = false; + ctx.createRadialGradient(0, 0, 1, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createRadialGradient(0, 0, 1, 0, Infinity, Infinity)"); } + + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(200, 25, 10, 200, 25, 20); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#0f0'); + ctx.fillStyle = g;ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(200, 25, 20, 200, 25, 10); + g.addColorStop(0, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g;ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(200, 25, 20, 200, 25, 10); + g.addColorStop(0, '#0f0'); + g.addColorStop(0.001, '#f00'); + g.addColorStop(1, '#f00');ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));//verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(150, 25, 50, 200, 25, 100); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g;ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(-80, 25, 70, 0, 25, 150); + g.addColorStop(0, '#f00'); + g.addColorStop(0.01, '#0f0'); + g.addColorStop(0.99, '#0f0');g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16));//verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + g = ctx.createRadialGradient(120, -15, 25, 140, -30, 50); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g;ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));//verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + g = ctx.createRadialGradient(0, 0, 0, 0, 0, 11.2); + g.addColorStop(0, '#0f0'); + g.addColorStop(0.5, '#0f0');g.addColorStop(0.51, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.translate(50, 25);ctx.scale(10, 10); + ctx.fillRect(-5, -2.5, 10, 5); + //verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + ctx.reset(); + ctx.translate(100, 0); + g = ctx.createRadialGradient(0, 0, 0, 0, 0, 11.2); + g.addColorStop(0, '#0f0');g.addColorStop(0.5, '#0f0'); + g.addColorStop(0.51, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g;ctx.translate(-50, 25); + ctx.scale(10, 10); + ctx.fillRect(-5, -2.5, 10, 5); + //verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + + ctx.reset(); + g = ctx.createRadialGradient(0, 0, 0, 0, 0, 11.2); + g.addColorStop(0, '#0f0'); + g.addColorStop(0.5, '#0f0');g.addColorStop(0.51, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50);ctx.translate(50, 25); + ctx.scale(10, 10); + ctx.fillRect(-5, -2.5, 10, 5); + //verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255));//verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + + } + function test_linear() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + try { var err = false; + ctx.createLinearGradient(Infinity, 0, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, 0, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(-Infinity, 0, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(-Infinity, 0, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(NaN, 0, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(NaN, 0, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, Infinity, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, Infinity, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, -Infinity, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, -Infinity, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, NaN, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, NaN, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, Infinity, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, Infinity, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, -Infinity, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, -Infinity, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, NaN, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, NaN, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, 1, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, 1, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, 1, -Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, 1, -Infinity)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, 1, NaN); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, 1, NaN)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, Infinity, 1, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, Infinity, 1, 0)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, Infinity, Infinity, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, Infinity, Infinity, 0)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, Infinity, 1, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, Infinity, 1, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, 0, Infinity, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, 0, Infinity, 0)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, 0, Infinity, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(Infinity, 0, 1, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(Infinity, 0, 1, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(0, Infinity, Infinity, 0); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, Infinity, Infinity, 0)"); } + try { var err = false; + ctx.createLinearGradient(0, Infinity, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, Infinity, Infinity, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(0, Infinity, 1, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, Infinity, 1, Infinity)"); } + try { var err = false; + ctx.createLinearGradient(0, 0, Infinity, Infinity); + } catch (e) { if (e.code != DOMException.NOT_SUPPORTED_ERR) fail("Failed assertion: expected exception of type NOT_SUPPORTED_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type NOT_SUPPORTED_ERR: ctx.createLinearGradient(0, 0, Infinity, Infinity)"); } + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 200, 0); + g.addColorStop(0, '#f00'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.75, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.translate(-50, 0); + ctx.fillRect(50, 0, 100, 50); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + ctx.reset(); + ctx.translate(100, 0); + g = ctx.createLinearGradient(0, 0, 200, 0); + g.addColorStop(0, '#f00'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.75, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.translate(-150, 0); + ctx.fillRect(50, 0, 100, 50); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + + ctx.reset(); + g = ctx.createLinearGradient(0, 0, 200, 0); + g.addColorStop(0, '#f00'); + g.addColorStop(0.25, '#0f0'); + g.addColorStop(0.75, '#0f0'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + ctx.translate(-50, 0); + ctx.fillRect(50, 0, 100, 50); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + + } + function test_object() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + var g1 = ctx.createLinearGradient(0, 0, 100, 0); + var g2 = ctx.createLinearGradient(0, 0, 100, 0); + ctx.fillStyle = g1; + + + ctx.reset(); + var g = ctx.createLinearGradient(0, 0, 100, 0); + try { var err = false; + g.addColorStop(0, ""); + } catch (e) { if (e.code != DOMException.SYNTAX_ERR) fail("Failed assertion: expected exception of type SYNTAX_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type SYNTAX_ERR: g.addColorStop(0, \"\")"); } + try { var err = false; + g.addColorStop(0, 'undefined'); + } catch (e) { if (e.code != DOMException.SYNTAX_ERR) fail("Failed assertion: expected exception of type SYNTAX_ERR, got: "+e.message); err = true; } finally { verify(err, "should throw exception of type SYNTAX_ERR: g.addColorStop(0, 'undefined')"); } + + + ctx.reset(); + g = ctx.createLinearGradient(0, 0, 100, 0); + try { var err = false; + g.addColorStop(-1, '#000'); + } 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: g.addColorStop(-1, '#000')"); } + try { var err = false; + g.addColorStop(2, '#000'); + } 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: g.addColorStop(2, '#000')"); } + try { var err = false; + g.addColorStop(Infinity, '#000'); + } 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: g.addColorStop(Infinity, '#000')"); } + try { var err = false; + g.addColorStop(-Infinity, '#000'); + } 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: g.addColorStop(-Infinity, '#000')"); } + try { var err = false; + g.addColorStop(NaN, '#000'); + } 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: g.addColorStop(NaN, '#000')"); } + + + ctx.reset(); + g = ctx.createLinearGradient(-100, 0, 200, 0); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + g.addColorStop(0.1, '#0f0'); + g.addColorStop(0.9, '#0f0'); + ctx.fillRect(0, 0, 100, 50); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255,2)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + g = ctx.createRadialGradient(120, 25, 10, 211, 25, 100); + g.addColorStop(0, '#f00'); + g.addColorStop(1, '#f00'); + ctx.fillStyle = g; + ctx.fillRect(0, 0, 100, 50); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255,16)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + + } + + function test_conical() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + var g = ctx.createConicalGradient(10, 10, 50); + //TODO + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_line.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_line.qml new file mode 100644 index 0000000..baf9987 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_line.qml @@ -0,0 +1,831 @@ +import QtQuick 2.0 +import QtTest 1.0 +import"testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50;renderTarget: Canvas.Image + TestCase { + name: "line"; when: windowShown + function test_default() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + compare(ctx.lineWidth, 1); + compare(ctx.lineCap, 'butt'); + compare(ctx.lineJoin, 'miter'); + compare(ctx.miterLimit, 10); + } + + function test_cross() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 200; + ctx.lineJoin = 'bevel'; + + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(110, 50); + ctx.lineTo(110, 60); + ctx.lineTo(100, 60); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + } + + function test_join() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + var tol = 1; // tolerance to avoid antialiasing artifacts + + ctx.lineJoin = 'bevel'; + ctx.lineWidth = 20; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + + ctx.fillRect(10, 10, 20, 20); + ctx.fillRect(20, 20, 20, 20); + ctx.beginPath(); + ctx.moveTo(30, 20); + ctx.lineTo(40-tol, 20); + ctx.lineTo(30, 10+tol); + ctx.fill(); + + ctx.beginPath(); + ctx.moveTo(10, 20); + ctx.lineTo(30, 20); + ctx.lineTo(30, 40); + ctx.stroke(); + + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + + ctx.beginPath(); + ctx.moveTo(60, 20); + ctx.lineTo(80, 20); + ctx.lineTo(80, 40); + ctx.stroke(); + + ctx.fillRect(60, 10, 20, 20); + ctx.fillRect(70, 20, 20, 20); + ctx.beginPath(); + ctx.moveTo(80, 20); + ctx.lineTo(90+tol, 20); + ctx.lineTo(80, 10-tol); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 34,16, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 34,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 35,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 36,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 36,14, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 84,16, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 84,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 85,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 86,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 86,14, 0,255,0,255)); + + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineJoin = 'miter'; + ctx.lineWidth = 200; + + ctx.beginPath(); + ctx.moveTo(100, 50); + ctx.lineTo(100, 1000); + ctx.lineTo(1000, 1000); + ctx.lineTo(1000, 50); + ctx.closePath(); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + + ctx.reset(); + ctx.lineJoin = 'bevel' + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = 'invalid'; + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = 'ROUND'; + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = 'round\\0'; + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = 'round '; + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = ""; + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'bevel'; + ctx.lineJoin = 'butt'; + compare(ctx.lineJoin, 'bevel'); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineJoin = 'miter'; + ctx.lineWidth = 20; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + + ctx.fillRect(10, 10, 30, 20); + ctx.fillRect(20, 10, 20, 30); + + ctx.beginPath(); + ctx.moveTo(10, 20); + ctx.lineTo(30, 20); + ctx.lineTo(30, 40); + ctx.stroke(); + + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + + ctx.beginPath(); + ctx.moveTo(60, 20); + ctx.lineTo(80, 20); + ctx.lineTo(80, 40); + ctx.stroke(); + + ctx.fillRect(60, 10, 30, 20); + ctx.fillRect(70, 10, 20, 30); + + verify(Helper.comparePixel(ctx, 38,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 39,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 40,10, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 41,9, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 42,8, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 88,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 89,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 91,9, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 92,8, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineJoin = 'miter'; + ctx.lineWidth = 200; + + ctx.beginPath(); + ctx.moveTo(100, 50); + ctx.lineTo(100, 1000); + ctx.lineTo(1000, 1000); + ctx.lineTo(1000, 50); + ctx.lineTo(100, 50); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 300; + ctx.lineJoin = 'round'; + ctx.beginPath(); + ctx.moveTo(-100, 25); + ctx.lineTo(0, 25); + ctx.lineTo(-100, 25); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + var tol = 1; // tolerance to avoid antialiasing artifacts + + ctx.lineJoin = 'round'; + ctx.lineWidth = 20; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + + ctx.fillRect(10, 10, 20, 20); + ctx.fillRect(20, 20, 20, 20); + ctx.beginPath(); + ctx.moveTo(30, 20); + ctx.arc(30, 20, 10-tol, 0, 2*Math.PI, true); + ctx.fill(); + + ctx.beginPath(); + ctx.moveTo(10, 20); + ctx.lineTo(30, 20); + ctx.lineTo(30, 40); + ctx.stroke(); + + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + + ctx.beginPath(); + ctx.moveTo(60, 20); + ctx.lineTo(80, 20); + ctx.lineTo(80, 40); + ctx.stroke(); + + ctx.fillRect(60, 10, 20, 20); + ctx.fillRect(70, 20, 20, 20); + ctx.beginPath(); + ctx.moveTo(80, 20); + ctx.arc(80, 20, 10+tol, 0, 2*Math.PI, true); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 36,14, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 36,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 37,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 38,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 38,12, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 86,14, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 86,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 87,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 88,13, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 88,12, 0,255,0,255)); + + ctx.reset(); + ctx.lineJoin = 'bevel' + compare(ctx.lineJoin, 'bevel'); + + ctx.lineJoin = 'round'; + compare(ctx.lineJoin, 'round'); + + ctx.lineJoin = 'miter'; + compare(ctx.lineJoin, 'miter'); + + } + function test_miter() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 200; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#0f0'; + ctx.miterLimit = 2.614; + ctx.beginPath(); + ctx.moveTo(100, 1000); + ctx.lineTo(100, 100); + ctx.lineTo(1000, 1000); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.miterLimit = 2.613; + ctx.beginPath(); + ctx.moveTo(100, 1000); + ctx.lineTo(100, 100); + ctx.lineTo(1000, 1000); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 400; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#f00'; + ctx.miterLimit = 1.414; + ctx.beginPath(); + ctx.moveTo(200, 1000); + ctx.lineTo(200, 200); + ctx.lineTo(1000, 201); // slightly non-right-angle to avoid being a special case + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.miterLimit = 1.5; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = 1.5; + ctx.miterLimit = 0; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = 1.5; + ctx.miterLimit = -1; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = 1.5; + ctx.miterLimit = Infinity; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = 1.5; + ctx.miterLimit = -Infinity; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = 1.5; + ctx.miterLimit = NaN; + compare(ctx.miterLimit, 1.5); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 200; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#f00'; + ctx.miterLimit = 1.414; + ctx.beginPath(); + ctx.strokeRect(100, 25, 200, 0); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 1600; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#0f0'; + ctx.miterLimit = 1.083; + ctx.beginPath(); + ctx.moveTo(800, 10000); + ctx.lineTo(800, 300); + ctx.lineTo(10000, -8900); + ctx.stroke(); + + ctx.strokeStyle = '#f00'; + ctx.miterLimit = 1.082; + ctx.beginPath(); + ctx.moveTo(800, 10000); + ctx.lineTo(800, 300); + ctx.lineTo(10000, -8900); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 400; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#f00'; + ctx.miterLimit = 1.414; + ctx.beginPath(); + ctx.moveTo(200, 1000); + ctx.lineTo(200, 200); + ctx.lineTo(1000, 200); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + ctx.reset(); + ctx.miterLimit = 1.5; + compare(ctx.miterLimit, 1.5); + + ctx.miterLimit = "1e1"; + compare(ctx.miterLimit, 10); + + ctx.miterLimit = 1/1024; + compare(ctx.miterLimit, 1/1024); + + ctx.miterLimit = 1000; + compare(ctx.miterLimit, 1000); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 400; + ctx.lineJoin = 'miter'; + + ctx.strokeStyle = '#0f0'; + ctx.miterLimit = 1.416; + ctx.beginPath(); + ctx.moveTo(200, 1000); + ctx.lineTo(200, 200); + ctx.lineTo(1000, 201); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + + + } + function test_width() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 20; + // Draw a green line over a red box, to check the line is not too small + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(15, 15, 20, 20); + ctx.beginPath(); + ctx.moveTo(25, 15); + ctx.lineTo(25, 35); + ctx.stroke(); + + // Draw a green box over a red line, to check the line is not too large + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(75, 15); + ctx.lineTo(75, 35); + ctx.stroke(); + ctx.fillRect(65, 15, 20, 20); + + verify(Helper.comparePixel(ctx, 14,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 15,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 16,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 34,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 35,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 36,25, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 64,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 65,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 66,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 84,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 85,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 86,25, 0,255,0,255)); + + ctx.reset(); + ctx.lineWidth = 1.5; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = 1.5; + ctx.lineWidth = 0; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = 1.5; + ctx.lineWidth = -1; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = 1.5; + ctx.lineWidth = Infinity; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = 1.5; + ctx.lineWidth = -Infinity; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = 1.5; + ctx.lineWidth = NaN; + compare(ctx.lineWidth, 1.5); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(50, 50); + ctx.strokeStyle = '#0f0'; + ctx.moveTo(0, 0.5); + ctx.lineTo(2, 0.5); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,5, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,45, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 4; + // Draw a green line over a red box, to check the line is not too small + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(15, 15, 20, 20); + ctx.save(); + ctx.scale(5, 1); + ctx.beginPath(); + ctx.moveTo(5, 15); + ctx.lineTo(5, 35); + ctx.stroke(); + ctx.restore(); + + // Draw a green box over a red line, to check the line is not too large + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.save(); + ctx.scale(-5, 1); + ctx.beginPath(); + ctx.moveTo(-15, 15); + ctx.lineTo(-15, 35); + ctx.stroke(); + ctx.restore(); + ctx.fillRect(65, 15, 20, 20); + + verify(Helper.comparePixel(ctx, 14,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 15,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 16,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 34,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 35,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 36,25, 0,255,0,255)); + + //verify(Helper.comparePixel(ctx, 64,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 65,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 66,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 84,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 85,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 86,25, 0,255,0,255)); + + ctx.reset(); + ctx.lineWidth = 1.5; + compare(ctx.lineWidth, 1.5); + + ctx.lineWidth = "1e1"; + compare(ctx.lineWidth, 10); + + ctx.lineWidth = 1/1024; + compare(ctx.lineWidth, 1/1024); + + ctx.lineWidth = 1000; + compare(ctx.lineWidth, 1000); + + } + function test_cap() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineCap = 'butt'; + ctx.lineWidth = 20; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(15, 15, 20, 20); + ctx.beginPath(); + ctx.moveTo(25, 15); + ctx.lineTo(25, 35); + ctx.stroke(); + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(75, 15); + ctx.lineTo(75, 35); + ctx.stroke(); + ctx.fillRect(65, 15, 20, 20); + + verify(Helper.comparePixel(ctx, 25,14, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,16, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,34, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,35, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,36, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 75,14, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,15, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,16, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,34, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,35, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,36, 0,255,0,255)); + + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineJoin = 'bevel'; + ctx.lineCap = 'square'; + ctx.lineWidth = 400; + + ctx.beginPath(); + ctx.moveTo(200, 200); + ctx.lineTo(200, 1000); + ctx.lineTo(1000, 1000); + ctx.lineTo(1000, 200); + ctx.closePath(); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + ctx.reset(); + + ctx.lineCap = 'butt' + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = 'invalid'; + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = 'ROUND'; + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = 'round\\0'; + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = 'round '; + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = ""; + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'butt'; + ctx.lineCap = 'bevel'; + compare(ctx.lineCap, 'butt'); + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineJoin = 'bevel'; + ctx.lineCap = 'square'; + ctx.lineWidth = 400; + + ctx.beginPath(); + ctx.moveTo(200, 200); + ctx.lineTo(200, 1000); + ctx.lineTo(1000, 1000); + ctx.lineTo(1000, 200); + ctx.lineTo(200, 200); + ctx.stroke(); + + //FIXME:!!! + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 48,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + var tol = 1; // tolerance to avoid antialiasing artifacts + + ctx.lineCap = 'round'; + ctx.lineWidth = 20; + + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + + ctx.beginPath(); + ctx.moveTo(35-tol, 15); + ctx.arc(25, 15, 10-tol, 0, Math.PI, true); + ctx.arc(25, 35, 10-tol, Math.PI, 0, true); + ctx.fill(); + + ctx.beginPath(); + ctx.moveTo(25, 15); + ctx.lineTo(25, 35); + ctx.stroke(); + + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + + ctx.beginPath(); + ctx.moveTo(75, 15); + ctx.lineTo(75, 35); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(85+tol, 15); + ctx.arc(75, 15, 10+tol, 0, Math.PI, true); + ctx.arc(75, 35, 10+tol, Math.PI, 0, true); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 17,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 32,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 17,43, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,43, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 32,43, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 67,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 82,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 67,43, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,43, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 82,43, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineCap = 'square'; + ctx.lineWidth = 20; + + ctx.fillStyle = '#f00'; + ctx.strokeStyle = '#0f0'; + ctx.fillRect(15, 5, 20, 40); + ctx.beginPath(); + ctx.moveTo(25, 15); + ctx.lineTo(25, 35); + ctx.stroke(); + + ctx.fillStyle = '#0f0'; + ctx.strokeStyle = '#f00'; + ctx.beginPath(); + ctx.moveTo(75, 15); + ctx.lineTo(75, 35); + ctx.stroke(); + ctx.fillRect(65, 5, 20, 40); + + verify(Helper.comparePixel(ctx, 25,4, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,5, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,44, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,45, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,46, 0,255,0,255)); + + verify(Helper.comparePixel(ctx, 75,4, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,5, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,6, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,44, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,45, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,46, 0,255,0,255)); + + ctx.reset(); + ctx.lineCap = 'butt' + compare(ctx.lineCap, 'butt'); + + ctx.lineCap = 'round'; + compare(ctx.lineCap, 'round'); + + ctx.lineCap = 'square'; + compare(ctx.lineCap, 'square'); + + } + } +} \ No newline at end of file diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_path.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_path.qml new file mode 100644 index 0000000..b04ccf5 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_path.qml @@ -0,0 +1,1443 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper + +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + name: "path"; when: windowShown + + function test_basic() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.closePath(); + ctx.fillStyle = '#f00'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + 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)); + + + canvas.width = 100; + ctx.rect(0, 0, 100, 50); + canvas.width = 100; + ctx.fillStyle = '#f00'; + ctx.fill(); + //verify(Helper.comparePixel(ctx, 20,20, 0,0,0,0)); + } + function test_beginPath() { + var ctx = canvas.getContext('2d'); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.rect(0, 0, 100, 50); + ctx.beginPath(); + ctx.fillStyle = '#f00'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_closePath() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.closePath(); + ctx.fillStyle = '#f00'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.moveTo(-100, 25); + ctx.lineTo(-100, -100); + ctx.lineTo(200, -100); + ctx.lineTo(200, 25); + ctx.closePath(); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.moveTo(-100, 25); + ctx.lineTo(-100, -1000); + ctx.closePath(); + ctx.lineTo(1000, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_isPointInPath() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.arc(50, 25, 10, 0, Math.PI, false); + verify(!ctx.isPointInPath(50, 10)); + verify(!ctx.isPointInPath(50, 20)); + //verify(!ctx.isPointInPath(50, 30)); + verify(!ctx.isPointInPath(50, 40)); + verify(!ctx.isPointInPath(30, 20)); + verify(!ctx.isPointInPath(70, 20)); + verify(!ctx.isPointInPath(30, 30)); + verify(!ctx.isPointInPath(70, 30)); + + ctx.reset(); + ctx.rect(0, 0, 20, 20); + verify(ctx.isPointInPath(10, 10)); + verify(!ctx.isPointInPath(30, 10)); + + ctx.reset(); + ctx.rect(20, 0, 20, 20); + //verify(ctx.isPointInPath(10, 10)); + verify(ctx.isPointInPath(30, 10)); + + ctx.reset(); + ctx.bezierCurveTo(50, -50, 50, 100, 75, 25); + verify(!ctx.isPointInPath(25, 20)); + verify(!ctx.isPointInPath(25, 30)); + //verify(ctx.isPointInPath(30, 20)); + verify(!ctx.isPointInPath(30, 30)); + //verify(!ctx.isPointInPath(40, 2)); + //verify(ctx.isPointInPath(40, 20)); + verify(!ctx.isPointInPath(40, 30)); + verify(!ctx.isPointInPath(40, 47)); + //verify(ctx.isPointInPath(45, 20)); + //verify(!ctx.isPointInPath(45, 30)); + //verify(!ctx.isPointInPath(55, 20)); + //verify(ctx.isPointInPath(55, 30)); + verify(!ctx.isPointInPath(60, 2)); + //verify(!ctx.isPointInPath(60, 20)); + verify(ctx.isPointInPath(60, 30)); + verify(!ctx.isPointInPath(60, 47)); + verify(!ctx.isPointInPath(70, 20)); + verify(ctx.isPointInPath(70, 30)); + verify(!ctx.isPointInPath(75, 20)); + verify(!ctx.isPointInPath(75, 30)); + + ctx.reset(); + ctx.arc(50, 25, 10, 0, 7, false); + verify(!ctx.isPointInPath(50, 10)); + //verify(ctx.isPointInPath(50, 20)); + //verify(ctx.isPointInPath(50, 30)); + verify(!ctx.isPointInPath(50, 40)); + verify(!ctx.isPointInPath(30, 20)); + verify(!ctx.isPointInPath(70, 20)); + verify(!ctx.isPointInPath(30, 30)); + //verify(!ctx.isPointInPath(70, 30)); + + ctx.reset(); + ctx.rect(0, 0, 20, 20); + verify(ctx.isPointInPath(0, 0)); + verify(ctx.isPointInPath(10, 0)); + //verify(ctx.isPointInPath(20, 0)); + //verify(ctx.isPointInPath(20, 10)); + //verify(ctx.isPointInPath(20, 20)); + //verify(ctx.isPointInPath(10, 20)); + //verify(ctx.isPointInPath(0, 20)); + verify(ctx.isPointInPath(0, 10)); + verify(!ctx.isPointInPath(10, -0.01)); + verify(!ctx.isPointInPath(10, 20.01)); + verify(!ctx.isPointInPath(-0.01, 10)); + //verify(!ctx.isPointInPath(20.01, 10)); + + ctx.reset(); + verify(!ctx.isPointInPath(0, 0)); + + + ctx.reset(); + ctx.rect(-100, -50, 200, 100); + //verify(ctx.isPointInPath(Infinity, 0)); + //verify(ctx.isPointInPath(-Infinity, 0)); + //verify(ctx.isPointInPath(NaN, 0)); + //verify(ctx.isPointInPath(0, Infinity)); + //verify(ctx.isPointInPath(0, -Infinity)); + //verify(ctx.isPointInPath(0, NaN)); + //verify(ctx.isPointInPath(NaN, NaN)); + + ctx.reset(); + ctx.rect(0, -100, 20, 20); + ctx.rect(20, -10, 20, 20); + verify(!ctx.isPointInPath(10, -110)); + verify(ctx.isPointInPath(10, -90)); + verify(!ctx.isPointInPath(10, -70)); + //verify(!ctx.isPointInPath(30, -20)); + //verify(ctx.isPointInPath(30, 0)); + //verify(!ctx.isPointInPath(30, 20)); + + ctx.reset(); + ctx.rect(0, 0, 20, 20); + ctx.beginPath(); + ctx.rect(20, 0, 20, 20); + ctx.closePath(); + ctx.rect(40, 0, 20, 20); + verify(!ctx.isPointInPath(10, 10)); + verify(ctx.isPointInPath(30, 10)); + verify(ctx.isPointInPath(50, 10)); + + ctx.reset(); + ctx.translate(50, 0); + ctx.rect(0, 0, 20, 20); + verify(!ctx.isPointInPath(-40, 10)); + verify(!ctx.isPointInPath(10, 10)); + //verify(!ctx.isPointInPath(49, 10)); + verify(ctx.isPointInPath(51, 10)); + verify(ctx.isPointInPath(69, 10)); + verify(!ctx.isPointInPath(71, 10)); + + ctx.reset(); + ctx.rect(50, 0, 20, 20); + ctx.translate(50, 0); + verify(!ctx.isPointInPath(-40, 10)); + verify(!ctx.isPointInPath(10, 10)); + //verify(!ctx.isPointInPath(49, 10)); + verify(ctx.isPointInPath(51, 10)); + verify(ctx.isPointInPath(69, 10)); + verify(!ctx.isPointInPath(71, 10)); + + ctx.reset(); + ctx.scale(-1, 1); + ctx.rect(-70, 0, 20, 20); + verify(!ctx.isPointInPath(-40, 10)); + verify(!ctx.isPointInPath(10, 10)); + //verify(!ctx.isPointInPath(49, 10)); + verify(ctx.isPointInPath(51, 10)); + verify(ctx.isPointInPath(69, 10)); + verify(!ctx.isPointInPath(71, 10)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(20, 0); + ctx.lineTo(20, 20); + ctx.lineTo(0, 20); + verify(ctx.isPointInPath(10, 10)); + //verify(!ctx.isPointInPath(30, 10)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(50, 0); + ctx.lineTo(50, 50); + ctx.lineTo(0, 50); + ctx.lineTo(0, 0); + ctx.lineTo(10, 10); + ctx.lineTo(10, 40); + ctx.lineTo(40, 40); + ctx.lineTo(40, 10); + ctx.lineTo(10, 10); + + verify(ctx.isPointInPath(5, 5)); + verify(ctx.isPointInPath(25, 5)); + verify(ctx.isPointInPath(45, 5)); + verify(ctx.isPointInPath(5, 25)); + verify(!ctx.isPointInPath(25, 25)); + verify(ctx.isPointInPath(45, 25)); + verify(ctx.isPointInPath(5, 45)); + verify(ctx.isPointInPath(25, 45)); + verify(ctx.isPointInPath(45, 45)); + } + + + function test_fill() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + ctx.reset(); + ctx.fillStyle = '#00f'; + ctx.fillRect(0, 0, 100, 50); + + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.lineTo(100, 50); + ctx.fillStyle = '#f00'; + ctx.fill(); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + + //verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 10,40, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#000'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.rect(0, 0, 100, 50); + ctx.closePath(); + ctx.rect(10, 10, 80, 30); + ctx.fill(); + + //verify(Helper.comparePixel(ctx, 50,25, 0,127,0,255, 1)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.lineTo(-10, -10); + ctx.lineTo(0, 0); + ctx.lineTo(100, 0); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fill(); + + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.lineTo(-10, -10); + ctx.lineTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.moveTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.lineTo(-10, -10); + ctx.lineTo(-20, -20); + ctx.lineTo(120, -20); + ctx.lineTo(120, 70); + ctx.lineTo(-20, 70); + ctx.lineTo(-20, -20); + ctx.lineTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + } + function test_stroke() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.moveTo(40, 25); + ctx.moveTo(60, 25); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#000'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = 'rgba(0, 255, 0, 0.5)'; + ctx.lineWidth = 50; + ctx.moveTo(0, 20); + ctx.lineTo(100, 20); + ctx.moveTo(0, 30); + ctx.lineTo(100, 30); + ctx.stroke(); + + //verify(Helper.comparePixel(ctx, 50,25, 0,127,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arcTo(50, 25, 150, 25, 10); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.arc(50, 25, 10, 0, 0, false); + ctx.stroke(); + + // verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.lineTo(50, 25); + ctx.closePath(); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 400; + ctx.lineJoin = 'miter'; + ctx.miterLimit = 1.4; + + ctx.beginPath(); + ctx.moveTo(-1000, 200, 0, 0); + ctx.lineTo(-100, 200); + ctx.lineTo(-100, 200); + ctx.lineTo(-100, 200); + ctx.lineTo(-100, 1000); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.quadraticCurveTo(50, 25, 50, 25); + ctx.stroke(); + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.bezierCurveTo(50, 25, 50, 25, 50, 25); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.moveTo(50, 25); + ctx.lineTo(50, 25); + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + + ctx.beginPath(); + ctx.rect(50, 25, 0, 0); + ctx.stroke(); + + ctx.strokeRect(50, 25, 0, 0); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.rect(25, 12.5, 50, 25); + ctx.save(); + ctx.scale(50, 25); + ctx.strokeStyle = '#0f0'; + ctx.stroke(); + ctx.restore(); + + ctx.beginPath(); + ctx.rect(-25, -12.5, 150, 75); + ctx.save(); + ctx.scale(50, 25); + ctx.strokeStyle = '#f00'; + ctx.stroke(); + ctx.restore(); + + //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.rect(25, 12.5, 50, 25); + ctx.save(); + ctx.rotate(Math.PI/2); + ctx.scale(25, 50); + ctx.strokeStyle = '#0f0'; + ctx.stroke(); + ctx.restore(); + + ctx.beginPath(); + ctx.rect(-25, -12.5, 150, 75); + ctx.save(); + ctx.rotate(Math.PI/2); + ctx.scale(25, 50); + ctx.strokeStyle = '#f00'; + ctx.stroke(); + ctx.restore(); + + //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.save(); + ctx.beginPath(); + ctx.moveTo(49, -50); + ctx.lineTo(201, -50); + ctx.rotate(Math.PI/4); + ctx.scale(1, 283); + ctx.strokeStyle = '#0f0'; + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.beginPath(); + ctx.translate(-150, 0); + ctx.moveTo(49, -50); + ctx.lineTo(199, -50); + ctx.rotate(Math.PI/4); + ctx.scale(1, 142); + ctx.strokeStyle = '#f00'; + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.beginPath(); + ctx.translate(-150, 0); + ctx.moveTo(49, -50); + ctx.lineTo(199, -50); + ctx.rotate(Math.PI/4); + ctx.scale(1, 142); + ctx.strokeStyle = '#f00'; + ctx.stroke(); + ctx.restore(); + + //verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.lineWidth = 50; + ctx.moveTo(-100, 25); + ctx.lineTo(-100, -100); + ctx.lineTo(200, -100); + ctx.lineTo(200, 25); + ctx.strokeStyle = '#f00'; + ctx.stroke(); + + ctx.closePath(); + ctx.strokeStyle = '#0f0'; + ctx.stroke(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 40; + ctx.moveTo(0, 10); + ctx.lineTo(100, 10); + ctx.moveTo(100, 40); + ctx.lineTo(0, 40); + ctx.stroke(); + + 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.beginPath(); + ctx.rect(0, 0, 100, 50); + ctx.clip(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.rect(-100, 0, 100, 50); + ctx.clip(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.clip(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.rect(0, 0, 50, 50); + ctx.clip(); + ctx.beginPath(); + ctx.rect(50, 0, 50, 50) + ctx.clip(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#0f0'; + + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.clip(); + + ctx.lineTo(0, 0); + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.lineTo(-10, -10); + ctx.lineTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.clip(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.beginPath(); + ctx.moveTo(-10, -10); + ctx.lineTo(110, -10); + ctx.lineTo(110, 60); + ctx.lineTo(-10, 60); + ctx.lineTo(-10, -10); + ctx.clip(); + + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(0, 50); + ctx.lineTo(100, 50); + ctx.lineTo(100, 0); + ctx.lineTo(0, 0); + ctx.clip(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_moveTo() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.rect(0, 0, 10, 50); + ctx.moveTo(100, 0); + ctx.lineTo(10, 0); + ctx.lineTo(10, 50); + ctx.lineTo(100, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 90,25, 0,255,0,255)); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.moveTo(0, 25); + ctx.moveTo(100, 25); + ctx.moveTo(0, 25); + ctx.lineTo(100, 25); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.moveTo(100, 0); + ctx.moveTo(100, 50); + ctx.moveTo(0, 50); + ctx.fillStyle = '#f00'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.moveTo(Infinity, 50); + ctx.moveTo(-Infinity, 50); + ctx.moveTo(NaN, 50); + ctx.moveTo(0, Infinity); + ctx.moveTo(0, -Infinity); + ctx.moveTo(0, NaN); + ctx.moveTo(Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_lineTo() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.lineTo(100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.lineTo(100, 50); + ctx.stroke(); + // verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.lineTo(0, 25); + ctx.lineTo(100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(-100, -100); + ctx.lineTo(0, 25); + ctx.lineTo(100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.lineTo(Infinity, 50); + ctx.lineTo(-Infinity, 50); + ctx.lineTo(NaN, 50); + ctx.lineTo(0, Infinity); + ctx.lineTo(0, -Infinity); + ctx.lineTo(0, NaN); + ctx.lineTo(Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); + + } + function test_bezierCurveTo() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.bezierCurveTo(100, 25, 100, 25, 100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.bezierCurveTo(100, 50, 200, 50, 200, 50); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 95,45, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.bezierCurveTo(0, 25, 100, 25, 100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 5,45, 0,255,0,255)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.bezierCurveTo(Infinity, 50, 0, 50, 0, 50); + ctx.bezierCurveTo(-Infinity, 50, 0, 50, 0, 50); + ctx.bezierCurveTo(NaN, 50, 0, 50, 0, 50); + ctx.bezierCurveTo(0, Infinity, 0, 50, 0, 50); + ctx.bezierCurveTo(0, -Infinity, 0, 50, 0, 50); + ctx.bezierCurveTo(0, NaN, 0, 50, 0, 50); + ctx.bezierCurveTo(0, 50, Infinity, 50, 0, 50); + ctx.bezierCurveTo(0, 50, -Infinity, 50, 0, 50); + ctx.bezierCurveTo(0, 50, NaN, 50, 0, 50); + ctx.bezierCurveTo(0, 50, 0, Infinity, 0, 50); + ctx.bezierCurveTo(0, 50, 0, -Infinity, 0, 50); + ctx.bezierCurveTo(0, 50, 0, NaN, 0, 50); + ctx.bezierCurveTo(0, 50, 0, 50, Infinity, 50); + ctx.bezierCurveTo(0, 50, 0, 50, -Infinity, 50); + ctx.bezierCurveTo(0, 50, 0, 50, NaN, 50); + ctx.bezierCurveTo(0, 50, 0, 50, 0, Infinity); + ctx.bezierCurveTo(0, 50, 0, 50, 0, -Infinity); + ctx.bezierCurveTo(0, 50, 0, 50, 0, NaN); + ctx.bezierCurveTo(Infinity, Infinity, 0, 50, 0, 50); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, 50, 0, 50); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, Infinity, 50, 0, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, 0, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, Infinity, 0, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, Infinity, 0, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, 0, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, 0, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, Infinity, 0, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, Infinity, 0, 50, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, 0, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, 0, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, 50, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, 0, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, Infinity, 50, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, 0, 50); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, Infinity, 0, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, 50, Infinity, 50); + ctx.bezierCurveTo(Infinity, 50, 0, 50, Infinity, Infinity); + ctx.bezierCurveTo(Infinity, 50, 0, 50, 0, Infinity); + ctx.bezierCurveTo(0, Infinity, Infinity, 50, 0, 50); + ctx.bezierCurveTo(0, Infinity, Infinity, Infinity, 0, 50); + ctx.bezierCurveTo(0, Infinity, Infinity, Infinity, Infinity, 50); + ctx.bezierCurveTo(0, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(0, Infinity, Infinity, Infinity, 0, Infinity); + ctx.bezierCurveTo(0, Infinity, Infinity, 50, Infinity, 50); + ctx.bezierCurveTo(0, Infinity, Infinity, 50, Infinity, Infinity); + ctx.bezierCurveTo(0, Infinity, Infinity, 50, 0, Infinity); + ctx.bezierCurveTo(0, Infinity, 0, Infinity, 0, 50); + ctx.bezierCurveTo(0, Infinity, 0, Infinity, Infinity, 50); + ctx.bezierCurveTo(0, Infinity, 0, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(0, Infinity, 0, Infinity, 0, Infinity); + ctx.bezierCurveTo(0, Infinity, 0, 50, Infinity, 50); + ctx.bezierCurveTo(0, Infinity, 0, 50, Infinity, Infinity); + ctx.bezierCurveTo(0, Infinity, 0, 50, 0, Infinity); + ctx.bezierCurveTo(0, 50, Infinity, Infinity, 0, 50); + ctx.bezierCurveTo(0, 50, Infinity, Infinity, Infinity, 50); + ctx.bezierCurveTo(0, 50, Infinity, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(0, 50, Infinity, Infinity, 0, Infinity); + ctx.bezierCurveTo(0, 50, Infinity, 50, Infinity, 50); + ctx.bezierCurveTo(0, 50, Infinity, 50, Infinity, Infinity); + ctx.bezierCurveTo(0, 50, Infinity, 50, 0, Infinity); + ctx.bezierCurveTo(0, 50, 0, Infinity, Infinity, 50); + ctx.bezierCurveTo(0, 50, 0, Infinity, Infinity, Infinity); + ctx.bezierCurveTo(0, 50, 0, Infinity, 0, Infinity); + ctx.bezierCurveTo(0, 50, 0, 50, Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.scale(1000, 1000); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 0.055; + ctx.beginPath(); + ctx.moveTo(-2, 3.1); + ctx.bezierCurveTo(-2, -1, 2.1, -1, 2.1, 3.1); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 55; + ctx.beginPath(); + ctx.moveTo(-2000, 3100); + ctx.bezierCurveTo(-2000, -1000, 2100, -1000, 2100, 3100); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + } + function test_quadraticCurveTo() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.moveTo(0, 25); + ctx.quadraticCurveTo(100, 25, 100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.quadraticCurveTo(100, 50, 200, 50); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 95,45, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.beginPath(); + ctx.quadraticCurveTo(0, 25, 100, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 5,45, 0,255,0,255)); + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.quadraticCurveTo(Infinity, 50, 0, 50); + ctx.quadraticCurveTo(-Infinity, 50, 0, 50); + ctx.quadraticCurveTo(NaN, 50, 0, 50); + ctx.quadraticCurveTo(0, Infinity, 0, 50); + ctx.quadraticCurveTo(0, -Infinity, 0, 50); + ctx.quadraticCurveTo(0, NaN, 0, 50); + ctx.quadraticCurveTo(0, 50, Infinity, 50); + ctx.quadraticCurveTo(0, 50, -Infinity, 50); + ctx.quadraticCurveTo(0, 50, NaN, 50); + ctx.quadraticCurveTo(0, 50, 0, Infinity); + ctx.quadraticCurveTo(0, 50, 0, -Infinity); + ctx.quadraticCurveTo(0, 50, 0, NaN); + ctx.quadraticCurveTo(Infinity, Infinity, 0, 50); + ctx.quadraticCurveTo(Infinity, Infinity, Infinity, 50); + ctx.quadraticCurveTo(Infinity, Infinity, Infinity, Infinity); + ctx.quadraticCurveTo(Infinity, Infinity, 0, Infinity); + ctx.quadraticCurveTo(Infinity, 50, Infinity, 50); + ctx.quadraticCurveTo(Infinity, 50, Infinity, Infinity); + ctx.quadraticCurveTo(Infinity, 50, 0, Infinity); + ctx.quadraticCurveTo(0, Infinity, Infinity, 50); + ctx.quadraticCurveTo(0, Infinity, Infinity, Infinity); + ctx.quadraticCurveTo(0, Infinity, 0, Infinity); + ctx.quadraticCurveTo(0, 50, Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.scale(1000, 1000); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 0.055; + ctx.beginPath(); + ctx.moveTo(-1, 1.05); + ctx.quadraticCurveTo(0, -1, 1.2, 1.05); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 55; + ctx.beginPath(); + ctx.moveTo(-1000, 1050); + ctx.quadraticCurveTo(0, -1000, 1200, 1050); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + } + function test_rect() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#0f0'; + ctx.rect(0, 0, 100, 50); + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 200; + ctx.lineJoin = 'miter'; + ctx.rect(100, 50, 100, 100); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.rect(200, 100, 400, 1000); + ctx.lineTo(-2000, -1000); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 450; + ctx.lineCap = 'round'; + ctx.lineJoin = 'bevel'; + ctx.rect(150, 150, 2000, 2000); + ctx.lineTo(160, 160); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.beginPath(); + ctx.fillStyle = '#0f0'; + ctx.rect(0, 0, 50, 25); + ctx.rect(100, 0, -50, 25); + ctx.rect(0, 50, 50, -25); + ctx.rect(100, 50, -50, -25); + ctx.fill(); + verify(Helper.comparePixel(ctx, 25,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,37, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,37, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.beginPath(); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.moveTo(-100, 25); + ctx.lineTo(-50, 25); + ctx.rect(200, 25, 1, 1); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + ctx.reset(); + ctx.moveTo(0, 0); + ctx.lineTo(100, 0); + ctx.rect(Infinity, 50, 1, 1); + ctx.rect(-Infinity, 50, 1, 1); + ctx.rect(NaN, 50, 1, 1); + ctx.rect(0, Infinity, 1, 1); + ctx.rect(0, -Infinity, 1, 1); + ctx.rect(0, NaN, 1, 1); + ctx.rect(0, 50, Infinity, 1); + ctx.rect(0, 50, -Infinity, 1); + ctx.rect(0, 50, NaN, 1); + ctx.rect(0, 50, 1, Infinity); + ctx.rect(0, 50, 1, -Infinity); + ctx.rect(0, 50, 1, NaN); + ctx.rect(Infinity, Infinity, 1, 1); + ctx.rect(Infinity, Infinity, Infinity, 1); + ctx.rect(Infinity, Infinity, Infinity, Infinity); + ctx.rect(Infinity, Infinity, 1, Infinity); + ctx.rect(Infinity, 50, Infinity, 1); + ctx.rect(Infinity, 50, Infinity, Infinity); + ctx.rect(Infinity, 50, 1, Infinity); + ctx.rect(0, Infinity, Infinity, 1); + ctx.rect(0, Infinity, Infinity, Infinity); + ctx.rect(0, Infinity, 1, Infinity); + ctx.rect(0, 50, Infinity, Infinity); + ctx.lineTo(100, 50); + ctx.lineTo(0, 50); + ctx.fillStyle = '#0f0'; + ctx.fill(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + //verify(Helper.comparePixel(ctx, 90,45, 0,255,0,255)); + + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 90; + ctx.beginPath(); + ctx.rect(45, 20, 10, 10); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.beginPath(); + ctx.fillStyle = '#f00'; + ctx.rect(0, 0, 50, 50); + ctx.rect(100, 50, -50, -50); + ctx.rect(0, 25, 100, -25); + ctx.rect(100, 25, -100, 25); + ctx.fill(); + verify(Helper.comparePixel(ctx, 25,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,12, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 25,37, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,37, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.rect(0, 50, 100, 0); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.rect(50, -100, 0, 250); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 100; + ctx.beginPath(); + ctx.rect(50, 25, 0, 0); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#0f0'; + ctx.lineWidth = 50; + ctx.rect(100, 25, 0, 0); + ctx.lineTo(0, 25); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.moveTo(0, 0); + ctx.rect(100, 25, 0, 0); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineJoin = 'miter'; + ctx.miterLimit = 1.5; + ctx.lineWidth = 200; + ctx.beginPath(); + ctx.rect(100, 25, 1000, 0); + ctx.stroke(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_clearRect() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.beginPath(); + ctx.rect(0, 0, 100, 50); + ctx.clearRect(0, 0, 16, 16); + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_fillRect() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.beginPath(); + ctx.rect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 16, 16); + ctx.fillStyle = '#0f0'; + ctx.fill(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + + function test_strokeRect() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.beginPath(); + ctx.rect(0, 0, 100, 50); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 5; + ctx.strokeRect(0, 0, 16, 16); + ctx.fillStyle = '#0f0'; + ctx.fill(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_transform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(-100, 0); + ctx.rect(100, 0, 100, 50); + ctx.translate(0, -100); + ctx.fillStyle = '#0f0'; + ctx.fill(); + + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#0f0'; + ctx.moveTo(0, 0); + ctx.translate(100, 0); + ctx.lineTo(0, 0); + ctx.translate(0, 50); + ctx.lineTo(0, 0); + ctx.translate(-100, 0); + ctx.lineTo(0, 0); + ctx.translate(1000, 1000); + ctx.rotate(Math.PI/2); + ctx.scale(0.1, 0.1); + ctx.fill(); + //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + ctx.reset(); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.fillStyle = '#f00'; + ctx.translate(-100, 0); + ctx.rect(0, 0, 100, 50); + ctx.fill(); + ctx.translate(100, 0); + ctx.fill(); + + ctx.beginPath(); + ctx.strokeStyle = '#f00'; + ctx.lineWidth = 50; + ctx.translate(0, -50); + ctx.moveTo(0, 25); + ctx.lineTo(100, 25); + ctx.stroke(); + ctx.translate(0, 50); + ctx.stroke(); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_pattern.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_pattern.qml new file mode 100644 index 0000000..dd5b662 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_pattern.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + //TODO + name: "pattern"; when: windowShown + function test_basic() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_animated() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_image() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_modified() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_paint() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_repeat() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_pixel.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_pixel.qml new file mode 100644 index 0000000..1a3793d --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_pixel.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + //TODO + name: "pixel"; when: windowShown + function test_createImageData() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_getImageData() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_object() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_putImageData() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_filters() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_shadow.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_shadow.qml new file mode 100644 index 0000000..4405ca6 --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_shadow.qml @@ -0,0 +1,59 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + //TODO + + name: "shadow"; when: windowShown + function test_basic() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_blur() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + + function test_clip() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + + function test_composite() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + + function test_enable() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + + function test_gradient() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_image() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_offset() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_pattern() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_stroke() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_tranform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_state.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_state.qml new file mode 100644 index 0000000..f0040ce --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_state.qml @@ -0,0 +1,389 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + 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) + { + compare(ctx.lineWidth, i); + 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(); + + + } + + 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); + 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); + ctx.restore(); + ctx.fillStyle = '#f00'; + ctx.fillRect(-200, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + } + + + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_strokeStyle.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_strokeStyle.qml index 84f830d..6b42f8a 100644 --- a/tests/auto/declarative/qsgcanvasitem/data/tst_strokeStyle.qml +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_strokeStyle.qml @@ -3,7 +3,7 @@ import QtTest 1.0 import "testhelper.js" as Helper Canvas { - id:canvas; width:1;height:1 + id:canvas; width:100;height:50; renderTarget:Canvas.Image TestCase { name: "strokeStyle"; when: windowShown function test_default() { diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_text.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_text.qml new file mode 100644 index 0000000..baeb17c --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_text.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + //TODO + name: "text"; when: windowShown + function test_baseLine() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_align() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_stroke() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_fill() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_font() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + function test_measure() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/data/tst_transform.qml b/tests/auto/declarative/qsgcanvasitem/data/tst_transform.qml new file mode 100644 index 0000000..834a22f --- /dev/null +++ b/tests/auto/declarative/qsgcanvasitem/data/tst_transform.qml @@ -0,0 +1,487 @@ +import QtQuick 2.0 +import QtTest 1.0 +import "testhelper.js" as Helper +Canvas { + id:canvas; width:100;height:50; renderTarget: Canvas.Image + TestCase { + name: "transform"; when: windowShown + function test_order() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(2, 1); + ctx.rotate(Math.PI / 2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, -50, 50, 50); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + } + function test_rotate() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI / 2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, -100, 50, 100); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.rotate(Infinity); + ctx.rotate(-Infinity); + ctx.rotate(NaN); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI); // should fail obviously if this is 3.1 degrees + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(Math.PI * (1 + 4096)); // == pi (mod 2*pi) + // We need about pi +/- 0.001 in order to get correct-looking results + // 32-bit floats can store pi*4097 with precision 2^-10, so that should + // be safe enough on reasonable implementations + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,2, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,47, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(-Math.PI * (1 + 4096)); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,2, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 98,47, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.rotate(0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + } + function test_scale() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(2, 4); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 12.5); + verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(1e5, 1e5); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 1, 1); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.scale(Math.sqrt(2), Math.sqrt(2)); + ctx.scale(Math.sqrt(2), Math.sqrt(2)); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 25); + verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.save(); + ctx.scale(-1, 1); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-50, 0, 50, 50); + ctx.restore(); + + ctx.save(); + ctx.scale(1, -1); + ctx.fillStyle = '#0f0'; + ctx.fillRect(50, -50, 50, 50); + ctx.restore(); + verify(Helper.comparePixel(ctx, 25,25, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 75,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.scale(Infinity, 0.1); + ctx.scale(-Infinity, 0.1); + ctx.scale(NaN, 0.1); + ctx.scale(0.1, Infinity); + ctx.scale(0.1, -Infinity); + ctx.scale(0.1, NaN); + ctx.scale(Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + + ctx.save(); + ctx.translate(50, 0); + ctx.scale(0, 1); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.restore(); + + ctx.save(); + ctx.translate(0, 25); + ctx.scale(1, 0); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + ctx.restore(); + + // Firefox has a bug where it renders the canvas as empty and toDataURL throws an exception + canvas.toDataURL(); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + } + function test_setTransform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.setTransform(1/2,0, 0,1/2, 0,0); + ctx.setTransform(2,0, 0,2, 0,0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 50, 25); + verify(Helper.comparePixel(ctx, 75,35, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.setTransform(Infinity, 0, 0, 0, 0, 0); + ctx.setTransform(-Infinity, 0, 0, 0, 0, 0); + ctx.setTransform(NaN, 0, 0, 0, 0, 0); + ctx.setTransform(0, Infinity, 0, 0, 0, 0); + ctx.setTransform(0, -Infinity, 0, 0, 0, 0); + ctx.setTransform(0, NaN, 0, 0, 0, 0); + ctx.setTransform(0, 0, Infinity, 0, 0, 0); + ctx.setTransform(0, 0, -Infinity, 0, 0, 0); + ctx.setTransform(0, 0, NaN, 0, 0, 0); + ctx.setTransform(0, 0, 0, Infinity, 0, 0); + ctx.setTransform(0, 0, 0, -Infinity, 0, 0); + ctx.setTransform(0, 0, 0, NaN, 0, 0); + ctx.setTransform(0, 0, 0, 0, Infinity, 0); + ctx.setTransform(0, 0, 0, 0, -Infinity, 0); + ctx.setTransform(0, 0, 0, 0, NaN, 0); + ctx.setTransform(0, 0, 0, 0, 0, Infinity); + ctx.setTransform(0, 0, 0, 0, 0, -Infinity); + ctx.setTransform(0, 0, 0, 0, 0, NaN); + ctx.setTransform(Infinity, Infinity, 0, 0, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, 0); + ctx.setTransform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, Infinity, 0, 0, Infinity); + ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, 0); + ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, 0); + ctx.setTransform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, 0, Infinity, 0, Infinity); + ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, 0); + ctx.setTransform(Infinity, Infinity, 0, 0, Infinity, Infinity); + ctx.setTransform(Infinity, Infinity, 0, 0, 0, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, 0, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, 0); + ctx.setTransform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, 0, Infinity, Infinity, 0, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.setTransform(Infinity, 0, Infinity, 0, Infinity, Infinity); + ctx.setTransform(Infinity, 0, Infinity, 0, 0, Infinity); + ctx.setTransform(Infinity, 0, 0, Infinity, 0, 0); + ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, 0); + ctx.setTransform(Infinity, 0, 0, Infinity, Infinity, Infinity); + ctx.setTransform(Infinity, 0, 0, Infinity, 0, Infinity); + ctx.setTransform(Infinity, 0, 0, 0, Infinity, 0); + ctx.setTransform(Infinity, 0, 0, 0, Infinity, Infinity); + ctx.setTransform(Infinity, 0, 0, 0, 0, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, 0, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, 0, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, 0); + ctx.setTransform(0, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(0, Infinity, Infinity, Infinity, 0, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, Infinity, 0); + ctx.setTransform(0, Infinity, Infinity, 0, Infinity, Infinity); + ctx.setTransform(0, Infinity, Infinity, 0, 0, Infinity); + ctx.setTransform(0, Infinity, 0, Infinity, 0, 0); + ctx.setTransform(0, Infinity, 0, Infinity, Infinity, 0); + ctx.setTransform(0, Infinity, 0, Infinity, Infinity, Infinity); + ctx.setTransform(0, Infinity, 0, Infinity, 0, Infinity); + ctx.setTransform(0, Infinity, 0, 0, Infinity, 0); + ctx.setTransform(0, Infinity, 0, 0, Infinity, Infinity); + ctx.setTransform(0, Infinity, 0, 0, 0, Infinity); + ctx.setTransform(0, 0, Infinity, Infinity, 0, 0); + ctx.setTransform(0, 0, Infinity, Infinity, Infinity, 0); + ctx.setTransform(0, 0, Infinity, Infinity, Infinity, Infinity); + ctx.setTransform(0, 0, Infinity, Infinity, 0, Infinity); + ctx.setTransform(0, 0, Infinity, 0, Infinity, 0); + ctx.setTransform(0, 0, Infinity, 0, Infinity, Infinity); + ctx.setTransform(0, 0, Infinity, 0, 0, Infinity); + ctx.setTransform(0, 0, 0, Infinity, Infinity, 0); + ctx.setTransform(0, 0, 0, Infinity, Infinity, Infinity); + ctx.setTransform(0, 0, 0, Infinity, 0, Infinity); + ctx.setTransform(0, 0, 0, 0, Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + // Create green with a red square ring inside it + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.fillRect(20, 10, 60, 30); + ctx.fillStyle = '#0f0'; + ctx.fillRect(40, 20, 20, 10); + + // Draw a skewed shape to fill that gap, to make sure it is aligned correctly + ctx.setTransform(1,4, 2,3, 5,6); + // Post-transform coordinates: + // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; + // Hence pre-transform coordinates: + var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], + [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], + [-7.4,11.2]]; + ctx.beginPath(); + ctx.moveTo(pts[0][0], pts[0][1]); + for (var i = 0; i < pts.length; ++i) + ctx.lineTo(pts[i][0], pts[i][1]); + ctx.fill(); + /* + //FIXME: + verify(Helper.comparePixel(ctx, 21,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 21,39, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,39, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 39,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 61,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 39,31, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 61,31, 0,255,0,255)); + */ + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.transform(1,0, 0,1, 0,0); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + } + function test_transform() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.transform(1,2, 3,4, 5,6); + ctx.transform(-2,1, 3/2,-1/2, 1,-2); + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.transform(Infinity, 0, 0, 0, 0, 0); + ctx.transform(-Infinity, 0, 0, 0, 0, 0); + ctx.transform(NaN, 0, 0, 0, 0, 0); + ctx.transform(0, Infinity, 0, 0, 0, 0); + ctx.transform(0, -Infinity, 0, 0, 0, 0); + ctx.transform(0, NaN, 0, 0, 0, 0); + ctx.transform(0, 0, Infinity, 0, 0, 0); + ctx.transform(0, 0, -Infinity, 0, 0, 0); + ctx.transform(0, 0, NaN, 0, 0, 0); + ctx.transform(0, 0, 0, Infinity, 0, 0); + ctx.transform(0, 0, 0, -Infinity, 0, 0); + ctx.transform(0, 0, 0, NaN, 0, 0); + ctx.transform(0, 0, 0, 0, Infinity, 0); + ctx.transform(0, 0, 0, 0, -Infinity, 0); + ctx.transform(0, 0, 0, 0, NaN, 0); + ctx.transform(0, 0, 0, 0, 0, Infinity); + ctx.transform(0, 0, 0, 0, 0, -Infinity); + ctx.transform(0, 0, 0, 0, 0, NaN); + ctx.transform(Infinity, Infinity, 0, 0, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, 0, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, 0); + ctx.transform(Infinity, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.transform(Infinity, Infinity, Infinity, Infinity, 0, Infinity); + ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, Infinity, Infinity, 0, Infinity, Infinity); + ctx.transform(Infinity, Infinity, Infinity, 0, 0, Infinity); + ctx.transform(Infinity, Infinity, 0, Infinity, 0, 0); + ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, 0); + ctx.transform(Infinity, Infinity, 0, Infinity, Infinity, Infinity); + ctx.transform(Infinity, Infinity, 0, Infinity, 0, Infinity); + ctx.transform(Infinity, Infinity, 0, 0, Infinity, 0); + ctx.transform(Infinity, Infinity, 0, 0, Infinity, Infinity); + ctx.transform(Infinity, Infinity, 0, 0, 0, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, 0, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, 0, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, Infinity, Infinity, Infinity); + ctx.transform(Infinity, 0, Infinity, Infinity, 0, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, 0); + ctx.transform(Infinity, 0, Infinity, 0, Infinity, Infinity); + ctx.transform(Infinity, 0, Infinity, 0, 0, Infinity); + ctx.transform(Infinity, 0, 0, Infinity, 0, 0); + ctx.transform(Infinity, 0, 0, Infinity, Infinity, 0); + ctx.transform(Infinity, 0, 0, Infinity, Infinity, Infinity); + ctx.transform(Infinity, 0, 0, Infinity, 0, Infinity); + ctx.transform(Infinity, 0, 0, 0, Infinity, 0); + ctx.transform(Infinity, 0, 0, 0, Infinity, Infinity); + ctx.transform(Infinity, 0, 0, 0, 0, Infinity); + ctx.transform(0, Infinity, Infinity, 0, 0, 0); + ctx.transform(0, Infinity, Infinity, Infinity, 0, 0); + ctx.transform(0, Infinity, Infinity, Infinity, Infinity, 0); + ctx.transform(0, Infinity, Infinity, Infinity, Infinity, Infinity); + ctx.transform(0, Infinity, Infinity, Infinity, 0, Infinity); + ctx.transform(0, Infinity, Infinity, 0, Infinity, 0); + ctx.transform(0, Infinity, Infinity, 0, Infinity, Infinity); + ctx.transform(0, Infinity, Infinity, 0, 0, Infinity); + ctx.transform(0, Infinity, 0, Infinity, 0, 0); + ctx.transform(0, Infinity, 0, Infinity, Infinity, 0); + ctx.transform(0, Infinity, 0, Infinity, Infinity, Infinity); + ctx.transform(0, Infinity, 0, Infinity, 0, Infinity); + ctx.transform(0, Infinity, 0, 0, Infinity, 0); + ctx.transform(0, Infinity, 0, 0, Infinity, Infinity); + ctx.transform(0, Infinity, 0, 0, 0, Infinity); + ctx.transform(0, 0, Infinity, Infinity, 0, 0); + ctx.transform(0, 0, Infinity, Infinity, Infinity, 0); + ctx.transform(0, 0, Infinity, Infinity, Infinity, Infinity); + ctx.transform(0, 0, Infinity, Infinity, 0, Infinity); + ctx.transform(0, 0, Infinity, 0, Infinity, 0); + ctx.transform(0, 0, Infinity, 0, Infinity, Infinity); + ctx.transform(0, 0, Infinity, 0, 0, Infinity); + ctx.transform(0, 0, 0, Infinity, Infinity, 0); + ctx.transform(0, 0, 0, Infinity, Infinity, Infinity); + ctx.transform(0, 0, 0, Infinity, 0, Infinity); + ctx.transform(0, 0, 0, 0, Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + ctx.reset(); + + // Create green with a red square ring inside it + ctx.fillStyle = '#0f0'; + ctx.fillRect(0, 0, 100, 50); + ctx.fillStyle = '#f00'; + ctx.fillRect(20, 10, 60, 30); + ctx.fillStyle = '#0f0'; + ctx.fillRect(40, 20, 20, 10); + + // Draw a skewed shape to fill that gap, to make sure it is aligned correctly + ctx.transform(1,4, 2,3, 5,6); + // Post-transform coordinates: + // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]]; + // Hence pre-transform coordinates: + var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2], + [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2], + [-7.4,11.2]]; + ctx.beginPath(); + ctx.moveTo(pts[0][0], pts[0][1]); + for (var i = 0; i < pts.length; ++i) + ctx.lineTo(pts[i][0], pts[i][1]); + ctx.fill(); + /* + //FIXME: + verify(Helper.comparePixel(ctx, 21,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,11, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 21,39, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 79,39, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 39,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 61,19, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 39,31, 0,255,0,255)); + verify(Helper.comparePixel(ctx, 61,31, 0,255,0,255)); + */ + } + function test_translate() { + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 50); + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -50, 100, 50); + verify(Helper.comparePixel(ctx, 90,40, 0,255,0,255)); + ctx.reset(); + + ctx.fillStyle = '#f00'; + ctx.fillRect(0, 0, 100, 50); + + ctx.translate(100, 10); + ctx.translate(Infinity, 0.1); + ctx.translate(-Infinity, 0.1); + ctx.translate(NaN, 0.1); + ctx.translate(0.1, Infinity); + ctx.translate(0.1, -Infinity); + ctx.translate(0.1, NaN); + ctx.translate(Infinity, Infinity); + + ctx.fillStyle = '#0f0'; + ctx.fillRect(-100, -10, 100, 50); + + verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255)); + + + } + } +} diff --git a/tests/auto/declarative/qsgcanvasitem/qsgcanvasitem.pro b/tests/auto/declarative/qsgcanvasitem/qsgcanvasitem.pro index 62b1611..c237f93 100644 --- a/tests/auto/declarative/qsgcanvasitem/qsgcanvasitem.pro +++ b/tests/auto/declarative/qsgcanvasitem/qsgcanvasitem.pro @@ -8,3 +8,26 @@ SOURCES += tst_qsgcanvasitem.cpp importFiles.files = data importFiles.path = . DEPLOYMENT += importFiles + +OTHER_FILES += \ + data/testhelper.js \ + data/tst_transform.qml \ + data/tst_text.qml \ + data/tst_strokeStyle.qml \ + data/tst_state.qml \ + data/tst_shadow.qml \ + data/tst_pattern.qml \ + data/tst_path.qml \ + data/tst_line.qml \ + data/tst_fillStyle.qml \ + data/tst_fillrect.qml \ + data/tst_drawimage.qml \ + data/tst_composite.qml \ + data/tst_canvas.qml \ + data/tst_pixel.qml \ + data/tst_gradient.qml \ + data/tst_arcto.qml \ + data/tst_arc.qml + + +