1/****************************************************************************
2**
3** Copyright (C) 2016 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#include <QtGui/QGuiApplication>
29#include <QtGui/QClipboard>
30#include <QtGui/QImage>
31#include <QtGui/QColor>
32#include <QtCore/QStringList>
33#include <QtCore/QCommandLineParser>
34
35int main(int argc, char **argv)
36{
37 QGuiApplication app(argc, argv);
38 QCommandLineParser parser;
39 parser.addHelpOption();
40 QCommandLineOption textOption(QStringLiteral("text"),
41 QStringLiteral("Text to compare"),
42 QStringLiteral("text"));
43 parser.addOption(commandLineOption: textOption);
44 QCommandLineOption imageOption(QStringLiteral("image"),
45 QStringLiteral("Perform image check"));
46 parser.addOption(commandLineOption: imageOption);
47 parser.process(arguments: QCoreApplication::arguments());
48
49 if (parser.isSet(option: imageOption)) {
50#ifndef QT_NO_CLIPBOARD
51 const QImage actual = QGuiApplication::clipboard()->image();
52#else
53 const QImage actual;
54#endif
55 // Perform hard-coded checks on copied image (size, pixel 0,0: transparent,
56 // pixel 1,0: blue). Note: Windows sets RGB of transparent to 0xFF when converting
57 // to DIB5.
58 if (actual.size() != QSize(100, 100))
59 return 1;
60 const QRgb pixel00 = actual.pixel(pt: QPoint(0, 0));
61 if (qAlpha(rgb: pixel00))
62 return 2;
63 const QRgb pixel01 = actual.pixel(pt: QPoint(1, 0));
64 if (pixel01 != QColor(Qt::blue).rgba())
65 return 3;
66 return 0;
67 }
68
69 QString expected;
70 if (parser.isSet(option: textOption))
71 expected = parser.value(option: textOption);
72 if (!expected.isEmpty()) {
73#ifndef QT_NO_CLIPBOARD
74 const QString actual = QGuiApplication::clipboard()->text();
75#else
76 const QString actual;
77#endif
78 return actual == expected ? 0 : 1;
79 }
80 return -2;
81}
82

source code of qtbase/tests/auto/gui/kernel/qclipboard/paster/main.cpp