summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/global/qglobal/tst_qglobal.cpp')
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
index 4eb3e4fc98..076e3eee1c 100644
--- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -43,6 +43,11 @@
#include <QtTest/QtTest>
#include <QtCore/qtypetraits.h>
+#include <QPair>
+#include <QTextCodec>
+#include <QSysInfo>
+#include <QLatin1String>
+
class tst_QGlobal: public QObject
{
Q_OBJECT
@@ -60,6 +65,9 @@ private slots:
void isEnum();
void qAlignOf();
void integerForSize();
+ void qprintable();
+ void qprintable_data();
+ void buildAbiEndianness();
};
void tst_QGlobal::qIsNull()
@@ -588,5 +596,74 @@ void tst_QGlobal::integerForSize()
Q_STATIC_ASSERT(sizeof(QIntegerForSize<8>::Unsigned) == 8);
}
+typedef QPair<const char *, const char *> stringpair;
+Q_DECLARE_METATYPE(stringpair)
+
+void tst_QGlobal::qprintable()
+{
+ QFETCH(QList<stringpair>, localestrings);
+ QFETCH(int, utf8index);
+
+ QVERIFY(utf8index >= 0 && utf8index < localestrings.count());
+ if (utf8index < 0 || utf8index >= localestrings.count())
+ return;
+
+ const char *const utf8string = localestrings.at(utf8index).second;
+
+ QString string = QString::fromUtf8(utf8string);
+
+ foreach (const stringpair &pair, localestrings) {
+ QTextCodec *codec = QTextCodec::codecForName(pair.first);
+ if (!codec)
+ continue;
+ QTextCodec::setCodecForLocale(codec);
+ // test qPrintable()
+ QVERIFY(qstrcmp(qPrintable(string), pair.second) == 0);
+ foreach (const stringpair &pair2, localestrings) {
+ if (pair2.second == pair.second)
+ continue;
+ QVERIFY(qstrcmp(qPrintable(string), pair2.second) != 0);
+ }
+ // test qUtf8Printable()
+ QVERIFY(qstrcmp(qUtf8Printable(string), utf8string) == 0);
+ foreach (const stringpair &pair2, localestrings) {
+ if (qstrcmp(pair2.second, utf8string) == 0)
+ continue;
+ QVERIFY(qstrcmp(qUtf8Printable(string), pair2.second) != 0);
+ }
+ }
+
+ QTextCodec::setCodecForLocale(0);
+}
+
+void tst_QGlobal::qprintable_data()
+{
+ QTest::addColumn<QList<stringpair> >("localestrings");
+ QTest::addColumn<int>("utf8index"); // index of utf8 string
+
+ // Unicode: HIRAGANA LETTER A, I, U, E, O (U+3442, U+3444, U+3446, U+3448, U+344a)
+ static const char *const utf8string = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a";
+ static const char *const eucjpstring = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa";
+ static const char *const sjisstring = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8";
+
+ QList<stringpair> japanesestrings;
+ japanesestrings << stringpair("UTF-8", utf8string)
+ << stringpair("EUC-JP", eucjpstring)
+ << stringpair("Shift_JIS", sjisstring);
+
+ QTest::newRow("Japanese") << japanesestrings << 0;
+
+}
+
+void tst_QGlobal::buildAbiEndianness()
+{
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ QLatin1String endian("little_endian");
+#elif Q_BYTE_ORDER == Q_BIG_ENDIAN
+ QLatin1String endian("big_endian");
+#endif
+ QVERIFY(QSysInfo::buildAbi().contains(endian));
+}
+
QTEST_APPLESS_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"