diff --git a/autotests/kdatecomboboxtest.cpp b/autotests/kdatecomboboxtest.cpp index 434eaa5..6421eaa 100644 --- a/autotests/kdatecomboboxtest.cpp +++ b/autotests/kdatecomboboxtest.cpp @@ -1,163 +1,156 @@ /* Copyright 2011 John Layt This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdatecomboboxtest.h" #include #include #include #include "kdatecombobox.h" QTEST_MAIN(KDateComboBoxTest) void KDateComboBoxTest::testDefaults() { - m_combo = new KDateComboBox(nullptr); - QCOMPARE(m_combo->date(), QDate::currentDate()); + QScopedPointer combo(new KDateComboBox); + QCOMPARE(combo->date(), QDate::currentDate()); // Missing support in QLocale; //QCOMPARE(m_combo->minimumDate(), KLocale::global()->calendar()->earliestValidDate()); //QCOMPARE(m_combo->maximumDate(), KLocale::global()->calendar()->latestValidDate()); - QCOMPARE(m_combo->isValid(), true); - QCOMPARE(m_combo->isNull(), false); - QCOMPARE(m_combo->options(), KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords); - QCOMPARE(m_combo->displayFormat(), QLocale::ShortFormat); - delete m_combo; + QCOMPARE(combo->isValid(), true); + QCOMPARE(combo->isNull(), false); + QCOMPARE(combo->options(), KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords); + QCOMPARE(combo->displayFormat(), QLocale::ShortFormat); } void KDateComboBoxTest::testValidNull() { - m_combo = new KDateComboBox(nullptr); - QCOMPARE(m_combo->isValid(), true); - QCOMPARE(m_combo->isNull(), false); - m_combo->setDate(QDate()); - QCOMPARE(m_combo->isValid(), false); - QCOMPARE(m_combo->isNull(), true); - m_combo->setDate(QDate(2000, 1, 1)); - m_combo->lineEdit()->setText(QStringLiteral("invalid")); - QCOMPARE(m_combo->isValid(), false); - QCOMPARE(m_combo->isNull(), false); - delete m_combo; + QScopedPointer combo(new KDateComboBox); + QCOMPARE(combo->isValid(), true); + QCOMPARE(combo->isNull(), false); + combo->setDate(QDate()); + QCOMPARE(combo->isValid(), false); + QCOMPARE(combo->isNull(), true); + combo->setDate(QDate(2000, 1, 1)); + combo->lineEdit()->setText(QStringLiteral("invalid")); + QCOMPARE(combo->isValid(), false); + QCOMPARE(combo->isNull(), false); } void KDateComboBoxTest::testDateRange() { - m_combo = new KDateComboBox(nullptr); - m_combo->setDate(QDate(2000, 1, 1)); + QScopedPointer combo(new KDateComboBox); + combo->setDate(QDate(2000, 1, 1)); // Missing support in QLocale; //QCOMPARE(m_combo->minimumDate(), KLocale::global()->calendar()->earliestValidDate()); //QCOMPARE(m_combo->maximumDate(), KLocale::global()->calendar()->latestValidDate()); - QCOMPARE(m_combo->isValid(), true); - - m_combo->setDateRange(QDate(2001, 1, 1), QDate(2002, 1, 1)); - QCOMPARE(m_combo->minimumDate(), QDate(2001, 1, 1)); - QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1)); - QCOMPARE(m_combo->isValid(), false); - - m_combo->setDate(QDate(2003, 1, 1)); - QCOMPARE(m_combo->isValid(), false); - m_combo->setDate(QDate(2001, 6, 1)); - QCOMPARE(m_combo->isValid(), true); - m_combo->setDate(QDate(2001, 1, 1)); - QCOMPARE(m_combo->isValid(), true); - m_combo->setDate(QDate(2002, 1, 1)); - QCOMPARE(m_combo->isValid(), true); - m_combo->setDate(QDate(2000, 12, 31)); - QCOMPARE(m_combo->isValid(), false); - m_combo->setDate(QDate(2002, 1, 2)); - QCOMPARE(m_combo->isValid(), false); - - m_combo->setDateRange(QDate(1995, 1, 1), QDate(1990, 1, 1)); - QCOMPARE(m_combo->minimumDate(), QDate(2001, 1, 1)); - QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1)); - - m_combo->setMinimumDate(QDate(2000, 1, 1)); - QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1)); - QCOMPARE(m_combo->maximumDate(), QDate(2002, 1, 1)); - - m_combo->setMaximumDate(QDate(2003, 1, 1)); - QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1)); - QCOMPARE(m_combo->maximumDate(), QDate(2003, 1, 1)); - - m_combo->resetDateRange(); - QVERIFY(!m_combo->minimumDate().isValid()); - QVERIFY(!m_combo->maximumDate().isValid()); + QCOMPARE(combo->isValid(), true); + + combo->setDateRange(QDate(2001, 1, 1), QDate(2002, 1, 1)); + QCOMPARE(combo->minimumDate(), QDate(2001, 1, 1)); + QCOMPARE(combo->maximumDate(), QDate(2002, 1, 1)); + QCOMPARE(combo->isValid(), false); + + combo->setDate(QDate(2003, 1, 1)); + QCOMPARE(combo->isValid(), false); + combo->setDate(QDate(2001, 6, 1)); + QCOMPARE(combo->isValid(), true); + combo->setDate(QDate(2001, 1, 1)); + QCOMPARE(combo->isValid(), true); + combo->setDate(QDate(2002, 1, 1)); + QCOMPARE(combo->isValid(), true); + combo->setDate(QDate(2000, 12, 31)); + QCOMPARE(combo->isValid(), false); + combo->setDate(QDate(2002, 1, 2)); + QCOMPARE(combo->isValid(), false); + + combo->setDateRange(QDate(1995, 1, 1), QDate(1990, 1, 1)); + QCOMPARE(combo->minimumDate(), QDate(2001, 1, 1)); + QCOMPARE(combo->maximumDate(), QDate(2002, 1, 1)); + + combo->setMinimumDate(QDate(2000, 1, 1)); + QCOMPARE(combo->minimumDate(), QDate(2000, 1, 1)); + QCOMPARE(combo->maximumDate(), QDate(2002, 1, 1)); + + combo->setMaximumDate(QDate(2003, 1, 1)); + QCOMPARE(combo->minimumDate(), QDate(2000, 1, 1)); + QCOMPARE(combo->maximumDate(), QDate(2003, 1, 1)); + + combo->resetDateRange(); + QVERIFY(!combo->minimumDate().isValid()); + QVERIFY(!combo->maximumDate().isValid()); // Check functioning when the minimum or maximum date is not already set - m_combo->setMinimumDate(QDate(2000, 1, 1)); - QCOMPARE(m_combo->minimumDate(), QDate(2000, 1, 1)); - QVERIFY(!m_combo->maximumDate().isValid()); + combo->setMinimumDate(QDate(2000, 1, 1)); + QCOMPARE(combo->minimumDate(), QDate(2000, 1, 1)); + QVERIFY(!combo->maximumDate().isValid()); - m_combo->resetMinimumDate(); - QVERIFY(!m_combo->minimumDate().isValid()); - QVERIFY(!m_combo->maximumDate().isValid()); + combo->resetMinimumDate(); + QVERIFY(!combo->minimumDate().isValid()); + QVERIFY(!combo->maximumDate().isValid()); - m_combo->setMaximumDate(QDate(2003, 1, 1)); - QVERIFY(!m_combo->minimumDate().isValid()); - QCOMPARE(m_combo->maximumDate(), QDate(2003, 1, 1)); + combo->setMaximumDate(QDate(2003, 1, 1)); + QVERIFY(!combo->minimumDate().isValid()); + QCOMPARE(combo->maximumDate(), QDate(2003, 1, 1)); - m_combo->resetMaximumDate(); - QVERIFY(!m_combo->minimumDate().isValid()); - QVERIFY(!m_combo->maximumDate().isValid()); + combo->resetMaximumDate(); + QVERIFY(!combo->minimumDate().isValid()); + QVERIFY(!combo->maximumDate().isValid()); - delete m_combo; } void KDateComboBoxTest::testDateList() { - m_combo = new KDateComboBox(nullptr); + QScopedPointer combo(new KDateComboBox); QMap map; // Test default map - QCOMPARE(m_combo->dateMap(), map); + QCOMPARE(combo->dateMap(), map); // Test basic map map.clear(); map.insert(QDate(2000, 1, 1), QStringLiteral("New Years Day")); map.insert(QDate(2000, 1, 2), QString()); map.insert(QDate(2000, 1, 3), QStringLiteral("separator")); map.insert(QDate(), QStringLiteral("No Date")); - m_combo->setDateMap(map); - QCOMPARE(m_combo->dateMap(), map); - - delete m_combo; + combo->setDateMap(map); + QCOMPARE(combo->dateMap(), map); } void KDateComboBoxTest::testOptions() { - m_combo = new KDateComboBox(nullptr); + QScopedPointer combo(new KDateComboBox); KDateComboBox::Options options = KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords; - QCOMPARE(m_combo->options(), options); + QCOMPARE(combo->options(), options); options = KDateComboBox::EditDate | KDateComboBox::WarnOnInvalid; - m_combo->setOptions(options); - QCOMPARE(m_combo->options(), options); - delete m_combo; + combo->setOptions(options); + QCOMPARE(combo->options(), options); } void KDateComboBoxTest::testDisplayFormat() { - m_combo = new KDateComboBox(nullptr); + QScopedPointer combo(new KDateComboBox); QLocale::FormatType format = QLocale::ShortFormat; - QCOMPARE(m_combo->displayFormat(), format); + QCOMPARE(combo->displayFormat(), format); format = QLocale::NarrowFormat; - m_combo->setDisplayFormat(format); - QCOMPARE(m_combo->displayFormat(), format); - delete m_combo; + combo->setDisplayFormat(format); + QCOMPARE(combo->displayFormat(), format); } diff --git a/autotests/kdatecomboboxtest.h b/autotests/kdatecomboboxtest.h index e83e14d..fd55aa6 100644 --- a/autotests/kdatecomboboxtest.h +++ b/autotests/kdatecomboboxtest.h @@ -1,44 +1,40 @@ /* Copyright 2011 John Layt This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDATECOMBOBOXTEST_H #define KDATECOMBOBOXTEST_H #include class KDateComboBox; class KDateComboBoxTest : public QWidget { Q_OBJECT private Q_SLOTS: void testDefaults(); void testValidNull(); void testDateRange(); void testDateList(); void testOptions(); void testDisplayFormat(); - -private: - - KDateComboBox *m_combo; }; #endif // KDATECOMBOBOXTEST_H