summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qclipboard/paster/main.cpp
blob: bf47b10ba6b9408267eb4000cbf34f44fcf41939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
#include <QtGui/QImage>
#include <QtGui/QColor>
#include <QtCore/QStringList>
#include <QtCore/QCommandLineParser>

int main(int argc, char **argv)
{
    QGuiApplication app(argc, argv);
    QCommandLineParser parser;
    parser.addHelpOption();
    QCommandLineOption textOption(QStringLiteral("text"),
                                  QStringLiteral("Text to compare"),
                                  QStringLiteral("text"));
    parser.addOption(textOption);
    QCommandLineOption imageOption(QStringLiteral("image"),
                                   QStringLiteral("Perform image check"));
    parser.addOption(imageOption);
    parser.process(QCoreApplication::arguments());

    if (parser.isSet(imageOption)) {
#ifndef QT_NO_CLIPBOARD
        const QImage actual = QGuiApplication::clipboard()->image();
#else
        const QImage actual;
#endif
        // Perform hard-coded checks on copied image (size, pixel 0,0: transparent,
        // pixel 1,0: blue). Note: Windows sets RGB of transparent to 0xFF when converting
        // to DIB5.
        if (actual.size() != QSize(100, 100))
            return 1;
        const QRgb pixel00 = actual.pixel(QPoint(0, 0));
        if (qAlpha(pixel00))
            return 2;
        const QRgb pixel01 = actual.pixel(QPoint(1, 0));
        if (pixel01 != QColor(Qt::blue).rgba())
            return 3;
        return 0;
    }

    QString expected;
    if (parser.isSet(textOption))
        expected = parser.value(textOption);
    if (!expected.isEmpty()) {
#ifndef QT_NO_CLIPBOARD
        const QString actual = QGuiApplication::clipboard()->text();
#else
        const QString actual;
#endif
        return actual == expected ? 0 : 1;
    }
    return -2;
}