| 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 | |
| 29 | |
| 30 | #include <QtTest/QtTest> |
| 31 | |
| 32 | #include <qstring.h> |
| 33 | |
| 34 | #include <ostream> |
| 35 | #include <sstream> |
| 36 | |
| 37 | class tst_QStl: public QObject |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | private slots: |
| 42 | void streaming_data(); |
| 43 | void streaming(); |
| 44 | |
| 45 | void concatenate(); |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | static inline std::ostream &operator<<(std::ostream &out, const QString &string) |
| 50 | { |
| 51 | out << string.toLocal8Bit().constData(); |
| 52 | return out; |
| 53 | } |
| 54 | |
| 55 | void tst_QStl::streaming_data() |
| 56 | { |
| 57 | QTest::addColumn<QString>(name: "str"); |
| 58 | |
| 59 | QTest::newRow(dataTag: "hello") << "hello"; |
| 60 | QTest::newRow(dataTag: "empty") << ""; |
| 61 | } |
| 62 | |
| 63 | void tst_QStl::streaming() |
| 64 | { |
| 65 | QFETCH(QString, str); |
| 66 | |
| 67 | std::ostringstream buf; |
| 68 | buf << str; |
| 69 | |
| 70 | std::string result = buf.str(); |
| 71 | |
| 72 | QCOMPARE(QString::fromLatin1(result.data()), str); |
| 73 | } |
| 74 | |
| 75 | void tst_QStl::concatenate() |
| 76 | { |
| 77 | std::ostringstream buf; |
| 78 | buf << QLatin1String("Hello ") << QLatin1String( "World"); |
| 79 | |
| 80 | QCOMPARE(QString::fromLatin1(buf.str().data()), QString("Hello World")); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | QTEST_APPLESS_MAIN(tst_QStl) |
| 85 | #include "tst_qstl.moc" |
| 86 |
