File indexing completed on 2024-05-12 16:45:27
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 /** @file 0007 * This file is a test for SKGDateEdit component. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skgtestdateedit.h" 0012 0013 #include <qtestevent.h> 0014 #include <qtestkeyboard.h> 0015 0016 #include <klocalizedstring.h> 0017 0018 #include "skgdateedit.h" 0019 0020 void SKGTESTDateEdit::Test_data() 0021 { 0022 KLocalizedString::setApplicationDomain("skrooge"); 0023 0024 QTest::addColumn<QTestEventList>("events"); 0025 QTest::addColumn<QDate>("expected"); 0026 0027 // Day 0028 { 0029 QTestEventList list; 0030 list.addKeyClick(Qt::Key_Up); 0031 list.addKeyClick(Qt::Key_Up); 0032 QTest::newRow("++") << list << QDate(1970, 7, 18); 0033 } 0034 0035 { 0036 QTestEventList list; 0037 list.addKeyClick(Qt::Key_Up); 0038 list.addKeyClick(Qt::Key_Down); 0039 QTest::newRow("+-") << list << QDate(1970, 7, 16); 0040 } 0041 0042 { 0043 QTestEventList list; 0044 list.addKeyClick(Qt::Key_Down); 0045 list.addKeyClick(Qt::Key_Down); 0046 QTest::newRow("--") << list << QDate(1970, 7, 14); 0047 } 0048 0049 { 0050 QTestEventList list; 0051 list.addKeyClick(Qt::Key_Down); 0052 list.addKeyClick(Qt::Key_Up); 0053 QTest::newRow("-+") << list << QDate(1970, 7, 16); 0054 } 0055 0056 // Month 0057 { 0058 QTestEventList list; 0059 list.addKeyClick(Qt::Key_PageUp); 0060 list.addKeyClick(Qt::Key_PageUp); 0061 QTest::newRow("++ctrl") << list << QDate(1970, 9, 16); 0062 } 0063 0064 { 0065 QTestEventList list; 0066 list.addKeyClick(Qt::Key_PageUp); 0067 list.addKeyClick(Qt::Key_PageDown); 0068 QTest::newRow("+-ctrl") << list << QDate(1970, 7, 16); 0069 } 0070 0071 { 0072 QTestEventList list; 0073 list.addKeyClick(Qt::Key_PageDown); 0074 list.addKeyClick(Qt::Key_PageDown); 0075 QTest::newRow("--ctrl") << list << QDate(1970, 5, 16); 0076 } 0077 0078 { 0079 QTestEventList list; 0080 list.addKeyClick(Qt::Key_PageDown); 0081 list.addKeyClick(Qt::Key_PageUp); 0082 QTest::newRow("-+ctrl") << list << QDate(1970, 7, 16); 0083 } 0084 0085 // Today 0086 { 0087 QTestEventList list; 0088 list.addKeyClick(Qt::Key_Equal); 0089 QTest::newRow("=") << list << QDate::currentDate(); 0090 } 0091 } 0092 0093 void SKGTESTDateEdit::Test() 0094 { 0095 QFETCH(QTestEventList, events); 0096 QFETCH(QDate, expected); 0097 0098 SKGDateEdit dateEditor(nullptr); 0099 dateEditor.setDate(QDate(1970, 7, 16)); 0100 events.simulate(&dateEditor); 0101 dateEditor.mode(); 0102 0103 QCOMPARE(dateEditor.date(), expected); 0104 } 0105 0106 QTEST_MAIN(SKGTESTDateEdit) 0107