1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QTest>
30#include <qcursor.h>
31#include <qpixmap.h>
32#include <qbitmap.h>
33
34class tst_QCursor : public QObject
35{
36 Q_OBJECT
37
38private slots:
39 void equality();
40};
41
42#define VERIFY_EQUAL(lhs, rhs) \
43 QVERIFY(lhs == rhs); \
44 QVERIFY(rhs == lhs); \
45 QVERIFY(!(rhs != lhs)); \
46 QVERIFY(!(lhs != rhs))
47
48#define VERIFY_DIFFERENT(lhs, rhs) \
49 QVERIFY(lhs != rhs); \
50 QVERIFY(rhs != lhs); \
51 QVERIFY(!(rhs == lhs)); \
52 QVERIFY(!(lhs == rhs))
53
54void tst_QCursor::equality()
55{
56 VERIFY_EQUAL(QCursor(), QCursor());
57 VERIFY_EQUAL(QCursor(Qt::CrossCursor), QCursor(Qt::CrossCursor));
58 VERIFY_DIFFERENT(QCursor(Qt::CrossCursor), QCursor());
59
60 // Shape
61 QCursor shapeCursor(Qt::WaitCursor);
62 VERIFY_EQUAL(shapeCursor, shapeCursor);
63 QCursor shapeCursorCopy(shapeCursor);
64 VERIFY_EQUAL(shapeCursor, shapeCursorCopy);
65 shapeCursorCopy.setShape(Qt::DragMoveCursor);
66 VERIFY_DIFFERENT(shapeCursor, shapeCursorCopy);
67 shapeCursorCopy.setShape(shapeCursor.shape());
68 VERIFY_EQUAL(shapeCursor, shapeCursorCopy);
69
70 // Pixmap
71 QPixmap pixmap(16, 16);
72 QCursor pixmapCursor(pixmap);
73 VERIFY_EQUAL(pixmapCursor, pixmapCursor);
74 VERIFY_EQUAL(pixmapCursor, QCursor(pixmapCursor));
75 VERIFY_EQUAL(pixmapCursor, QCursor(pixmap));
76 VERIFY_DIFFERENT(pixmapCursor, QCursor());
77 VERIFY_DIFFERENT(pixmapCursor, QCursor(pixmap, 5, 5));
78 VERIFY_DIFFERENT(pixmapCursor, QCursor(QPixmap(16, 16)));
79 VERIFY_DIFFERENT(pixmapCursor, shapeCursor);
80
81 // Bitmap & mask
82 QBitmap bitmap(16, 16);
83 QBitmap mask(16, 16);
84 QCursor bitmapCursor(bitmap, mask);
85 VERIFY_EQUAL(bitmapCursor, bitmapCursor);
86 VERIFY_EQUAL(bitmapCursor, QCursor(bitmapCursor));
87 VERIFY_EQUAL(bitmapCursor, QCursor(bitmap, mask));
88 VERIFY_DIFFERENT(bitmapCursor, QCursor());
89 VERIFY_DIFFERENT(bitmapCursor, QCursor(bitmap, mask, 5, 5));
90 VERIFY_DIFFERENT(bitmapCursor, QCursor(bitmap, QBitmap(16, 16)));
91 VERIFY_DIFFERENT(bitmapCursor, QCursor(QBitmap(16, 16), mask));
92 VERIFY_DIFFERENT(bitmapCursor, shapeCursor);
93 VERIFY_DIFFERENT(bitmapCursor, pixmapCursor);
94
95 // Empty pixmap
96 for (int i = 0; i < 18; ++i)
97 QTest::ignoreMessage(type: QtWarningMsg, message: "QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
98
99 QPixmap emptyPixmap;
100 QCursor emptyPixmapCursor(emptyPixmap);
101 QCOMPARE(emptyPixmapCursor.shape(), Qt::ArrowCursor);
102 VERIFY_EQUAL(emptyPixmapCursor, QCursor());
103 VERIFY_EQUAL(emptyPixmapCursor, QCursor(emptyPixmap, 5, 5));
104 VERIFY_DIFFERENT(emptyPixmapCursor, shapeCursor);
105 VERIFY_DIFFERENT(emptyPixmapCursor, pixmapCursor);
106 VERIFY_DIFFERENT(emptyPixmapCursor, bitmapCursor);
107
108 // Empty bitmap & mask
109 QBitmap emptyBitmap;
110 QCursor emptyBitmapCursor(emptyBitmap, emptyBitmap);
111 QCOMPARE(emptyBitmapCursor.shape(), Qt::ArrowCursor);
112 VERIFY_EQUAL(emptyBitmapCursor, QCursor());
113 VERIFY_EQUAL(emptyBitmapCursor, QCursor(emptyBitmap, emptyBitmap, 5, 5));
114 VERIFY_EQUAL(emptyBitmapCursor, QCursor(emptyBitmap, mask));
115 VERIFY_EQUAL(emptyBitmapCursor, QCursor(bitmap, emptyBitmap));
116 VERIFY_EQUAL(emptyBitmapCursor, emptyPixmapCursor);
117 VERIFY_DIFFERENT(emptyBitmapCursor, shapeCursor);
118 VERIFY_DIFFERENT(emptyBitmapCursor, pixmapCursor);
119 VERIFY_DIFFERENT(emptyBitmapCursor, bitmapCursor);
120}
121
122#undef VERIFY_EQUAL
123#undef VERIFY_DIFFERENT
124
125QTEST_MAIN(tst_QCursor)
126#include "tst_qcursor.moc"
127

source code of qtbase/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp