| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the test suite of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
|
| 43 |
#include <QtTest/QtTest> |
| 44 |
|
| 45 |
#include <q3canvas.h> |
| 46 |
#include <qapplication.h> |
| 47 |
#include <qpixmap.h> |
| 48 |
#include <qpainter.h> |
| 49 |
#include <qlabel.h> |
| 50 |
|
| 51 |
//TESTED_CLASS=Q3CanvasEllipse Q3CanvasItem Q3CanvasItemList Q3CanvasLine Q3CanvasPixmap Q3CanvasPixmapArray Q3CanvasPolygon Q3CanvasPolygonalItem Q3CanvasRectangle Q3CanvasSpline Q3CanvasSprite Q3CanvasText Q3CanvasView |
| 52 |
//TESTED_FILES= |
| 53 |
|
| 54 |
class tst_Q3Canvas : public QObject |
| 55 |
{ |
| 56 |
Q_OBJECT |
| 57 |
|
| 58 |
public: |
| 59 |
tst_Q3Canvas(); |
| 60 |
virtual ~tst_Q3Canvas(); |
| 61 |
|
| 62 |
|
| 63 |
public slots: |
| 64 |
void initTestCase(); |
| 65 |
void cleanupTestCase(); |
| 66 |
void init(); |
| 67 |
void cleanup(); |
| 68 |
private slots: |
| 69 |
void width(); |
| 70 |
void height(); |
| 71 |
void onCanvas(); |
| 72 |
void task26486(); |
| 73 |
void moveLine(); |
| 74 |
|
| 75 |
void moveRectangle(); |
| 76 |
void qcanvaspixmaparraycrash(); |
| 77 |
|
| 78 |
private: |
| 79 |
Q3Canvas *testWidget; |
| 80 |
Q3CanvasView *testWidgetView; |
| 81 |
|
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
tst_Q3Canvas::tst_Q3Canvas() |
| 86 |
{ |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
tst_Q3Canvas::~tst_Q3Canvas() |
| 91 |
{ |
| 92 |
} |
| 93 |
|
| 94 |
void tst_Q3Canvas::initTestCase() |
| 95 |
{ |
| 96 |
testWidget = new Q3Canvas(0); |
| 97 |
testWidgetView = new Q3CanvasView(testWidget); |
| 98 |
testWidgetView->show(); |
| 99 |
} |
| 100 |
|
| 101 |
void tst_Q3Canvas::cleanupTestCase() |
| 102 |
{ |
| 103 |
delete testWidget; |
| 104 |
delete testWidgetView; |
| 105 |
} |
| 106 |
|
| 107 |
void tst_Q3Canvas::init() |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
void tst_Q3Canvas::cleanup() |
| 112 |
{ |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
void tst_Q3Canvas::width() |
| 117 |
{ |
| 118 |
testWidget->resize(100,100); |
| 119 |
QVERIFY(testWidget->width() == 100); |
| 120 |
} |
| 121 |
|
| 122 |
void tst_Q3Canvas::height() |
| 123 |
{ |
| 124 |
testWidget->resize(100,100); |
| 125 |
QVERIFY(testWidget->height() == 100); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
void tst_Q3Canvas::onCanvas() |
| 130 |
{ |
| 131 |
testWidget->resize(100,100); |
| 132 |
QVERIFY(testWidget->onCanvas(0, 0)); |
| 133 |
QVERIFY(!testWidget->onCanvas(testWidget->width(), testWidget->height())); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
class MyCanvas : public Q3Canvas |
| 138 |
{ |
| 139 |
public: |
| 140 |
MyCanvas(int width, int height) : Q3Canvas(width, height) {} |
| 141 |
protected: |
| 142 |
void drawBackground(QPainter & p, const QRect &) |
| 143 |
{ |
| 144 |
p.setPen(QPen(Qt::red)); |
| 145 |
p.drawRect(0,0,width()-1, height()-1); |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
void tst_Q3Canvas::task26486() |
| 151 |
{ |
| 152 |
/* |
| 153 |
If a rectangle is drawn on the background of the canvas, where the |
| 154 |
rectangle has a width of Q3Canvas::width()-1 then it should draw on |
| 155 |
the edge of the canvas. It dose not, it draws 1 pixel in. |
| 156 |
If a transfomation is applied this dose not happen. |
| 157 |
See Task 26486 |
| 158 |
*/ |
| 159 |
|
| 160 |
MyCanvas canvas(100,100); |
| 161 |
Q3CanvasView view; |
| 162 |
view.setCanvas(&canvas); |
| 163 |
|
| 164 |
view.resize(canvas.width() + 20, canvas.height() + 20); |
| 165 |
view.show(); |
| 166 |
|
| 167 |
QPixmap testPix("backgroundrect.png"); |
| 168 |
|
| 169 |
QEXPECT_FAIL("", "Broken, see task 26486", Continue); |
| 170 |
QPixmap expect = QPixmap::grabWidget(&view); |
| 171 |
QVERIFY(pixmapsAreEqual(&expect,&testPix)); |
| 172 |
|
| 173 |
/*QLabel l(0); |
| 174 |
l.setPixmap(QPixmap::grabWidget(&view)); |
| 175 |
l.show(); |
| 176 |
while (1) |
| 177 |
qApp->processEvents(); |
| 178 |
*/ |
| 179 |
} |
| 180 |
|
| 181 |
void tst_Q3Canvas::moveLine() |
| 182 |
{ |
| 183 |
Q3CanvasLine canvasLine(testWidget); |
| 184 |
canvasLine.setPoints(0,0,10,10); |
| 185 |
canvasLine.show(); |
| 186 |
canvasLine.moveBy(50,50); |
| 187 |
|
| 188 |
QCOMPARE(canvasLine.startPoint(), QPoint(0,0)); |
| 189 |
QCOMPARE(canvasLine.endPoint(), QPoint(10,10)); |
| 190 |
|
| 191 |
QCOMPARE(canvasLine.x(), 50.0); |
| 192 |
QCOMPARE(canvasLine.y(), 50.0); |
| 193 |
|
| 194 |
canvasLine.moveBy(10, -20); |
| 195 |
QCOMPARE(canvasLine.startPoint(), QPoint(0,0)); |
| 196 |
QCOMPARE(canvasLine.endPoint(), QPoint(10,10)); |
| 197 |
|
| 198 |
QCOMPARE(canvasLine.x(), 60.0); |
| 199 |
QCOMPARE(canvasLine.y(), 30.0); |
| 200 |
|
| 201 |
canvasLine.moveBy(-10, -10); |
| 202 |
QCOMPARE(canvasLine.startPoint(), QPoint(0,0)); |
| 203 |
QCOMPARE(canvasLine.endPoint(), QPoint(10,10)); |
| 204 |
|
| 205 |
QCOMPARE(canvasLine.x(), 50.0); |
| 206 |
QCOMPARE(canvasLine.y(), 20.0); |
| 207 |
} |
| 208 |
|
| 209 |
void tst_Q3Canvas::moveRectangle() |
| 210 |
{ |
| 211 |
Q3CanvasRectangle canvasRectangle(testWidget); |
| 212 |
canvasRectangle.show(); |
| 213 |
|
| 214 |
canvasRectangle.moveBy(50,50); |
| 215 |
|
| 216 |
QCOMPARE(canvasRectangle.x(), 50.0); |
| 217 |
QCOMPARE(canvasRectangle.y(), 50.0); |
| 218 |
|
| 219 |
canvasRectangle.moveBy(10, -20); |
| 220 |
|
| 221 |
QCOMPARE(canvasRectangle.x(), 60.0); |
| 222 |
QCOMPARE(canvasRectangle.y(), 30.0); |
| 223 |
|
| 224 |
canvasRectangle.moveBy(-10, -10); |
| 225 |
|
| 226 |
QCOMPARE(canvasRectangle.x(), 50.0); |
| 227 |
QCOMPARE(canvasRectangle.y(), 20.0); |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
void tst_Q3Canvas::qcanvaspixmaparraycrash() |
| 232 |
{ |
| 233 |
Q3CanvasPixmapArray pixArray("foo%1.png", 2); |
| 234 |
QVERIFY(true); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
QTEST_MAIN(tst_Q3Canvas) |
| 239 |
#include "tst_q3canvas.moc" |