Commit 6408ea61 authored by Laurent Montel's avatar Laurent Montel 😁

MAke sure that generated code is ok

parent 63016b4e
......@@ -38,18 +38,32 @@ void SieveDateSpinBoxTest::shouldAssignValue_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::newRow("empty") << QString() << QStringLiteral("*");
QTest::newRow("1") << QStringLiteral("1") << QStringLiteral("1");
QTest::newRow("*") << QStringLiteral("*") << QStringLiteral("*");
//Maximum :)
QTest::newRow("500") << QStringLiteral("500") << QStringLiteral("99");
QTest::addColumn<KSieveUi::SelectDateWidget::DateType>("type");
//Year
QTest::newRow("empty") << QString() << QStringLiteral("0000") << KSieveUi::SelectDateWidget::Year;
QTest::newRow("year-1") << QStringLiteral("1") << QStringLiteral("0001") << KSieveUi::SelectDateWidget::Year;
QTest::newRow("year-*") << QStringLiteral("*") << QStringLiteral("*") << KSieveUi::SelectDateWidget::Year;
QTest::newRow("year-500") << QStringLiteral("500") << QStringLiteral("0500") << KSieveUi::SelectDateWidget::Year;
//Month
QTest::newRow("month-1") << QStringLiteral("1") << QStringLiteral("01") << KSieveUi::SelectDateWidget::Month;
QTest::newRow("month-*") << QStringLiteral("*") << QStringLiteral("*") << KSieveUi::SelectDateWidget::Month;
QTest::newRow("month-500") << QStringLiteral("500") << QStringLiteral("12") << KSieveUi::SelectDateWidget::Month;
//Second
QTest::newRow("second-1") << QStringLiteral("1") << QStringLiteral("01") << KSieveUi::SelectDateWidget::Second;
QTest::newRow("second-*") << QStringLiteral("*") << QStringLiteral("*") << KSieveUi::SelectDateWidget::Second;
QTest::newRow("second-500") << QStringLiteral("500") << QStringLiteral("59") << KSieveUi::SelectDateWidget::Second;
}
void SieveDateSpinBoxTest::shouldAssignValue()
{
QFETCH(QString, input);
QFETCH(QString, output);
QFETCH(KSieveUi::SelectDateWidget::DateType, type);
KSieveUi::SieveDateSpinBox spinbox;
spinbox.setType(type);
spinbox.setCode(input);
QCOMPARE(spinbox.code(), output);
}
......
......@@ -31,7 +31,6 @@
#include "libksieve_debug.h"
#include <QDate>
Q_DECLARE_METATYPE(KSieveUi::SelectDateWidget::DateType)
using namespace KSieveUi;
SelectDateWidget::SelectDateWidget(QWidget *parent)
......
......@@ -75,5 +75,6 @@ private:
QStackedWidget *mStackWidget;
};
}
Q_DECLARE_METATYPE(KSieveUi::SelectDateWidget::DateType)
#endif // SELECTDATEWIDGET_H
......@@ -18,6 +18,7 @@
*/
#include "sievedatespinbox.h"
#include "libksieve_debug.h"
#include <QDebug>
using namespace KSieveUi;
......@@ -43,7 +44,31 @@ void SieveDateSpinBox::setRange(int minValue, int maxValue)
void SieveDateSpinBox::setType(KSieveUi::SelectDateWidget::DateType type)
{
mType = type;
//TODO update it ?
switch (type) {
case SelectDateWidget::Year:
setRange(0, 9999);
break;
case SelectDateWidget::Month:
setRange(1, 12);
break;
case SelectDateWidget::Day:
setRange(1, 31);
break;
case SelectDateWidget::Hour:
setRange(0, 23);
break;
case SelectDateWidget::Minute:
setRange(0, 59);
break;
case SelectDateWidget::Second:
setRange(0, 59);
break;
case SelectDateWidget::Weekday:
setRange(0, 6);
break;
default:
qCWarning(LIBKSIEVE_LOG) << "This type mustn't be selected " << mType;
}
}
void SieveDateSpinBox::setCode(const QString &str)
......@@ -61,5 +86,37 @@ QString SieveDateSpinBox::code() const
if (value() == minimum()) {
return QStringLiteral("*");
}
return QString::number(value());
return convertValue();
}
QString SieveDateSpinBox::convertValue() const
{
QString str;
switch (mType) {
case SelectDateWidget::Year:
str = QStringLiteral("%1").arg(value(), 4, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Month:
str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Day:
str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Hour:
str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Minute:
str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Second:
str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
break;
case SelectDateWidget::Weekday:
str = QStringLiteral("%1").arg(value());
break;
default:
qCWarning(LIBKSIEVE_LOG) << "This type mustn't be selected " << mType;
break;
}
return str;
}
......@@ -39,6 +39,7 @@ public:
QString code() const;
private:
QString convertValue() const;
SelectDateWidget::DateType mType;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment