summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp
blob: 1b11782bbd7d0fb5daa987afa28f63c0211e2585 (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QTest>
#include <QtGui/QPixmap>
#include <QtGui/QImage>

class tst_QDataStream : public QObject
{
Q_OBJECT

private slots:
    void stream_with_pixmap();
};

void tst_QDataStream::stream_with_pixmap()
{
    // This is a QVariantMap with a 3x3 red QPixmap and two strings inside
    const QByteArray ba = QByteArray::fromBase64(
        "AAAAAwAAAAIAegAAAAoAAAAACgB0AGgAZQByAGUAAAACAHAAAABBAAAAAAGJUE5H"
        "DQoaCgAAAA1JSERSAAAAAwAAAAMIAgAAANlKIugAAAAJcEhZcwAADsQAAA7EAZUr"
        "DhsAAAAQSURBVAiZY/zPAAVMDJgsAB1bAQXZn5ieAAAAAElFTkSuQmCCAAAAAgBh"
        "AAAACgAAAAAKAGgAZQBsAGwAbw==");
    QImage dummy; // Needed to make sure qtGui is loaded

    QTest::ignoreMessage(QtWarningMsg, "QPixmap::fromImageInPlace: "
                         "QPixmap cannot be created without a QGuiApplication");

    QVariantMap map;
    QDataStream d(ba);
    d.setVersion(QDataStream::Qt_5_12);
    d >> map;

    QCOMPARE(map["a"].toString(), QString("hello"));
    // The pixmap is null because this is not a QGuiApplication:
    QCOMPARE(map["p"].value<QPixmap>(), QPixmap());
    QCOMPARE(map["z"].toString(), QString("there"));
}

QTEST_GUILESS_MAIN(tst_QDataStream)

#include "tst_qdatastream_core_pixmap.moc"