tests/auto/qkeysequence/tst_qkeysequence.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tests/auto/qkeysequence/tst_qkeysequence.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -119,6 +119,7 @@
     void symetricConstructors_data();
     void symetricConstructors();
     void checkMultipleNames();
+    void mnemonic_data();
     void mnemonic();
     void toString_data();
     void toString();
@@ -133,6 +134,7 @@
     void translated_data();
     void translated();
 
+
     void initTestCase();
 private:
     QTranslator *ourTranslator;
@@ -299,7 +301,7 @@
     QTest::newRow("findNext") << (int)QKeySequence::FindNext<< QString("F3");
     QTest::newRow("findPrevious") << (int)QKeySequence::FindPrevious << QString("SHIFT+F3");
     QTest::newRow("close") << (int)QKeySequence::Close<< QString("CTRL+F4");
-    QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H");    
+    QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H");
 #endif
     QTest::newRow("bold") << (int)QKeySequence::Bold << QString("CTRL+B");
     QTest::newRow("italic") << (int)QKeySequence::Italic << QString("CTRL+I");
@@ -357,17 +359,50 @@
 }
 
 
+
+void tst_QKeySequence::mnemonic_data()
+{
+    QTest::addColumn<QString>("string");
+    QTest::addColumn<QString>("key");
+    QTest::addColumn<bool>("warning");
+
+    QTest::newRow("1") << QString::fromLatin1("&bonjour") << QString::fromLatin1("ALT+B") << false;
+    QTest::newRow("2") << QString::fromLatin1("&&bonjour") << QString() << false;
+    QTest::newRow("3") << QString::fromLatin1("&&bon&jour") << QString::fromLatin1("ALT+J") << false;
+    QTest::newRow("4") << QString::fromLatin1("&&bon&jo&ur") << QString::fromLatin1("ALT+J") << true;
+    QTest::newRow("5") << QString::fromLatin1("b&on&&jour") << QString::fromLatin1("ALT+O") << false;
+    QTest::newRow("6") << QString::fromLatin1("bonjour") << QString() << false;
+    QTest::newRow("7") << QString::fromLatin1("&&&bonjour") << QString::fromLatin1("ALT+B") << false;
+    QTest::newRow("8") << QString::fromLatin1("bonjour&&&") << QString() << false;
+    QTest::newRow("9") << QString::fromLatin1("bo&&nj&o&&u&r") << QString::fromLatin1("ALT+O") << true;
+    QTest::newRow("10") << QString::fromLatin1("BON&JOUR") << QString::fromLatin1("ALT+J") << false;
+    QTest::newRow("11") << QString::fromUtf8("bonjour") << QString() << false;
+}
+
 void tst_QKeySequence::mnemonic()
 {
 #ifdef Q_WS_MAC
     QSKIP("mnemonics are not used on Mac OS X", SkipAll);
 #endif
-    QKeySequence k = QKeySequence::mnemonic("&Foo");
-    QVERIFY(k == QKeySequence("ALT+F"));
-    k = QKeySequence::mnemonic("&& &x");
-    QVERIFY(k == QKeySequence("ALT+X"));
+    QFETCH(QString, string);
+    QFETCH(QString, key);
+    QFETCH(bool, warning);
+
+#ifndef QT_NO_DEBUG
+    if (warning) {
+        QString str = QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurences of '&'").arg(string);
+        QTest::ignoreMessage(QtWarningMsg, qPrintable(str));
+    //    qWarning(qPrintable(str));
+    }
+#endif
+    QKeySequence seq = QKeySequence::mnemonic(string);
+    QKeySequence res = QKeySequence(key);
+
+    QCOMPARE(seq, res);
 }
 
+
+
 void tst_QKeySequence::toString_data()
 {
     QTest::addColumn<QString>("strSequence");