File indexing completed on 2025-02-16 04:55:55

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "selectheadertypecomboboxtest.h"
0008 #include "../sieveconditions/widgets/selectheadertypecombobox.h"
0009 
0010 #include <QLineEdit>
0011 #include <QTest>
0012 
0013 #ifndef Q_OS_WIN
0014 void initLocale()
0015 {
0016     setenv("LC_ALL", "en_US.utf-8", 1);
0017 }
0018 
0019 Q_CONSTRUCTOR_FUNCTION(initLocale)
0020 #endif
0021 
0022 SelectHeaderTypeComboBoxTest::SelectHeaderTypeComboBoxTest(QObject *parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 SelectHeaderTypeComboBoxTest::~SelectHeaderTypeComboBoxTest() = default;
0028 
0029 void SelectHeaderTypeComboBoxTest::shouldHaveDefaultValue()
0030 {
0031     KSieveUi::SelectHeaderTypeComboBox combox;
0032     QVERIFY(combox.isEditable());
0033     QVERIFY(combox.count() > 0);
0034     QCOMPARE(combox.currentText(), QString());
0035     QCOMPARE(combox.currentData().toString(), QString());
0036     QCOMPARE(combox.currentIndex(), 0);
0037     QVERIFY(!combox.itemText(combox.count() - 1).isEmpty());
0038     QCOMPARE(combox.itemData(combox.count() - 1).toString(), QString());
0039     // Don't verify first element and last as we already did
0040     for (int i = 1; i < combox.count() - 1; ++i) {
0041         QVERIFY(!combox.itemData(i).toString().isEmpty());
0042         QVERIFY(!combox.itemText(i).isEmpty());
0043     }
0044 
0045     KSieveUi::SelectHeaderTypeComboBox combox1(true); /*onlyEnvelopType*/
0046     QVERIFY(combox1.isEditable());
0047     QVERIFY(combox1.count() > 0);
0048     QCOMPARE(combox1.currentText(), QString());
0049     QCOMPARE(combox1.currentData().toString(), QString());
0050     QCOMPARE(combox1.currentIndex(), 0);
0051     QVERIFY(!combox1.itemText(combox1.count() - 1).isEmpty());
0052     QCOMPARE(combox1.itemData(combox1.count() - 1).toString(), QString());
0053 
0054     // Don't verify first element and last as we already did
0055     for (int i = 1; i < combox1.count() - 1; ++i) {
0056         QVERIFY(!combox1.itemData(i).toString().isEmpty());
0057         QVERIFY(!combox1.itemText(i).isEmpty());
0058     }
0059 }
0060 
0061 void SelectHeaderTypeComboBoxTest::shouldSetCode_data()
0062 {
0063     QTest::addColumn<QString>("code");
0064     QTest::addColumn<int>("index");
0065     QTest::addColumn<QString>("currentText");
0066     QTest::addColumn<bool>("onlyEnvelopType");
0067     QTest::addColumn<bool>("readOnly");
0068     QTest::newRow("empty") << QString() << 0 << QString() << false << false;
0069     QTest::newRow("empty only header") << QString() << 0 << QString() << false << false;
0070     QTest::newRow("from") << QStringLiteral("from") << 9 << QStringLiteral("From") << false << true;
0071 }
0072 
0073 void SelectHeaderTypeComboBoxTest::shouldSetCode()
0074 {
0075     QFETCH(QString, code);
0076     QFETCH(int, index);
0077     QFETCH(QString, currentText);
0078     QFETCH(bool, onlyEnvelopType);
0079     QFETCH(bool, readOnly);
0080     KSieveUi::SelectHeaderTypeComboBox combox(onlyEnvelopType);
0081     combox.setCode(code);
0082     QCOMPARE(combox.currentText(), currentText);
0083     QCOMPARE(combox.currentIndex(), index);
0084     QCOMPARE(combox.lineEdit()->isReadOnly(), readOnly);
0085 }
0086 
0087 QTEST_MAIN(SelectHeaderTypeComboBoxTest)
0088 
0089 #include "moc_selectheadertypecomboboxtest.cpp"