|
@@ -46,6 +46,14 @@ private slots:
|
|
|
void testSetValue();
|
|
|
void testSetValue_data();
|
|
|
|
|
|
+ void testSetValueOutsideRange();
|
|
|
+
|
|
|
+ void testSetMinimum();
|
|
|
+ void testSetMinimum_data();
|
|
|
+
|
|
|
+ void testSetMaximum();
|
|
|
+ void testSetMaximum_data();
|
|
|
+
|
|
|
void testSetRange();
|
|
|
void testSetRange_data();
|
|
|
|
|
@@ -92,9 +100,9 @@ void ctkDoubleSpinBoxTester::testToLocals()
|
|
|
{
|
|
|
bool ok;
|
|
|
QLocale().toDouble("+.0", &ok);
|
|
|
- qDebug() << "+.0" << ok;
|
|
|
+ QVERIFY(ok);
|
|
|
QLocale().toDouble("0.0 1", &ok);
|
|
|
- qDebug() << "0.0 1" << ok;
|
|
|
+ QVERIFY(!ok);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -102,26 +110,15 @@ void ctkDoubleSpinBoxTester::testSetValue()
|
|
|
{
|
|
|
ctkDoubleSpinBox spinBox;
|
|
|
spinBox.setValue(25.);
|
|
|
- // Compare with a QDoubleSpinBox as we are supposed to have the same behavior.
|
|
|
- QDoubleSpinBox compareSpinBox;
|
|
|
- compareSpinBox.setValue(25.);
|
|
|
|
|
|
QFETCH(double, value);
|
|
|
-
|
|
|
- QSignalSpy valueChangedSpy(&spinBox,
|
|
|
- SIGNAL(valueChanged(double)));
|
|
|
+ QSignalSpy valueChangedSpy(&spinBox, SIGNAL(valueChanged(double)));
|
|
|
spinBox.setValue(value);
|
|
|
- QSignalSpy compareValueChangedSpy(&compareSpinBox,
|
|
|
- SIGNAL(valueChanged(double)));
|
|
|
- compareSpinBox.setValue(value);
|
|
|
-
|
|
|
- QCOMPARE(spinBox.value(), compareSpinBox.value());
|
|
|
- QCOMPARE(valueChangedSpy.count(), compareValueChangedSpy.count());
|
|
|
|
|
|
QFETCH(double, expectedValue);
|
|
|
QCOMPARE(spinBox.value(), expectedValue);
|
|
|
|
|
|
- const bool valueChanged = expectedValue != 25.;
|
|
|
+ const bool valueChanged = (expectedValue != 25.);
|
|
|
QCOMPARE(valueChangedSpy.count(), valueChanged ? 1 : 0);
|
|
|
}
|
|
|
|
|
@@ -132,14 +129,83 @@ void ctkDoubleSpinBoxTester::testSetValue_data()
|
|
|
QTest::addColumn<double>("expectedValue");
|
|
|
|
|
|
QTest::newRow("1. -> 1.]") << 1. << 1.;
|
|
|
+ QTest::newRow("25. -> 25.]") << 25. << 25.;
|
|
|
+ QTest::newRow("25.00001 -> 25.00001]") << 25.00001 << 25.00001;
|
|
|
QTest::newRow("100. -> 99.99]") << 100. << 99.99;
|
|
|
QTest::newRow("-1. -> 0.]") << -1. << 0.;
|
|
|
|
|
|
- QTest::newRow("min -> 0.") << std::numeric_limits<double>::min() << 0.;
|
|
|
+ QTest::newRow("min -> 0.") << std::numeric_limits<double>::min() << std::numeric_limits<double>::min();
|
|
|
QTest::newRow("max -> 99.99") << std::numeric_limits<double>::max() << 99.99;
|
|
|
QTest::newRow("-inf -> 0.") << -std::numeric_limits<double>::infinity() << 0.;
|
|
|
QTest::newRow("inf -> 99.99") << std::numeric_limits<double>::infinity() << 99.99;
|
|
|
- QTest::newRow("NaN -> 99.99") << std::numeric_limits<double>::quiet_NaN() << 99.99;
|
|
|
+ QTest::newRow("NaN -> 99.99") << std::numeric_limits<double>::quiet_NaN() << 0.;
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
+void ctkDoubleSpinBoxTester::testSetValueOutsideRange()
|
|
|
+{
|
|
|
+ // This test is a bit different from testSetValue(), we start at 0. and must
|
|
|
+ // stay in 0.
|
|
|
+ ctkDoubleSpinBox spinBox;
|
|
|
+ QSignalSpy valueChangedSpy(&spinBox, SIGNAL(valueChanged(double)));
|
|
|
+ spinBox.setValue(-10.);
|
|
|
+ QCOMPARE(spinBox.value(), 0.);
|
|
|
+ QCOMPARE(valueChangedSpy.count(), 0);
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
+void ctkDoubleSpinBoxTester::testSetMinimum()
|
|
|
+{
|
|
|
+ ctkDoubleSpinBox spinBox;
|
|
|
+ QFETCH(double, minimum);
|
|
|
+ spinBox.setMinimum(minimum);
|
|
|
+
|
|
|
+ QFETCH(double, expectedMinimum);
|
|
|
+ QFETCH(double, expectedValue);
|
|
|
+
|
|
|
+ QCOMPARE(spinBox.minimum(), expectedMinimum);
|
|
|
+ QCOMPARE(spinBox.value(), expectedValue);
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
+void ctkDoubleSpinBoxTester::testSetMinimum_data()
|
|
|
+{
|
|
|
+ QTest::addColumn<double>("minimum");
|
|
|
+ QTest::addColumn<double>("expectedMinimum");
|
|
|
+ QTest::addColumn<double>("expectedValue");
|
|
|
+
|
|
|
+ QTest::newRow("0. -> 0.") << 0. << 0. << 0.;
|
|
|
+ QTest::newRow("99.99 -> 99.99") << 99.99 << 99.99 << 99.99;
|
|
|
+ QTest::newRow("10.0123 -> 10.0123") << 10.0123 << 10.0123 << 10.0123;
|
|
|
+ QTest::newRow("-10.0123 -> 0.") << -10.0123 << -10.0123 << 0.;
|
|
|
+ QTest::newRow("200.0123 -> 200.0123") << 200.0123 << 200.0123 << 200.0123;
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
+void ctkDoubleSpinBoxTester::testSetMaximum()
|
|
|
+{
|
|
|
+ ctkDoubleSpinBox spinBox;
|
|
|
+ QFETCH(double, maximum);
|
|
|
+ spinBox.setMaximum(maximum);
|
|
|
+
|
|
|
+ QFETCH(double, expectedMaximum);
|
|
|
+ QFETCH(double, expectedValue);
|
|
|
+ QCOMPARE(spinBox.maximum(), expectedMaximum);
|
|
|
+ QCOMPARE(spinBox.value(), expectedValue);
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
+void ctkDoubleSpinBoxTester::testSetMaximum_data()
|
|
|
+{
|
|
|
+ QTest::addColumn<double>("maximum");
|
|
|
+ QTest::addColumn<double>("expectedMaximum");
|
|
|
+ QTest::addColumn<double>("expectedValue");
|
|
|
+
|
|
|
+ QTest::newRow("0. -> 0.") << 0. << 0. << 0.;
|
|
|
+ QTest::newRow("99.99 -> 0.") << 99.99 << 99.99 << 0.;
|
|
|
+ QTest::newRow("10.0123 -> 0.") << 10.0123 << 10.0123 << 0.;
|
|
|
+ QTest::newRow("-10.0123 -> -10.0123") << -10.0123 << -10.0123 << -10.0123;
|
|
|
+ QTest::newRow("200.0123 -> 0.") << 200.0123 << 200.0123 << 0.;
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
@@ -147,22 +213,13 @@ void ctkDoubleSpinBoxTester::testSetRange()
|
|
|
{
|
|
|
ctkDoubleSpinBox spinBox;
|
|
|
spinBox.setValue(25.);
|
|
|
- QDoubleSpinBox compareSpinBox;
|
|
|
- compareSpinBox.setValue(25.);
|
|
|
|
|
|
QSignalSpy valueChangedSpy(&spinBox,
|
|
|
SIGNAL(valueChanged(double)));
|
|
|
- QSignalSpy compareValueChangedSpy(&compareSpinBox,
|
|
|
- SIGNAL(valueChanged(double)));
|
|
|
|
|
|
QFETCH(double, minimum);
|
|
|
QFETCH(double, maximum);
|
|
|
spinBox.setRange(minimum, maximum);
|
|
|
- compareSpinBox.setRange(minimum, maximum);
|
|
|
-
|
|
|
- ctkTest::COMPARE(spinBox.minimum(), compareSpinBox.minimum());
|
|
|
- ctkTest::COMPARE(spinBox.maximum(), compareSpinBox.maximum());
|
|
|
- ctkTest::COMPARE(spinBox.value(), compareSpinBox.value());
|
|
|
|
|
|
QFETCH(double, expectedMinimum);
|
|
|
QFETCH(double, expectedMaximum);
|
|
@@ -192,7 +249,7 @@ void ctkDoubleSpinBoxTester::testSetRange_data()
|
|
|
QTest::newRow("[min,max]")
|
|
|
<< std::numeric_limits<double>::min()
|
|
|
<< std::numeric_limits<double>::max()
|
|
|
- << 0. // rounded (see QDoubleSpinBox::setMinimum() doc)
|
|
|
+ << std::numeric_limits<double>::min()
|
|
|
<< QVariant(std::numeric_limits<double>::max()).toDouble()
|
|
|
<< 25.;
|
|
|
QTest::newRow("[-max,max]")
|
|
@@ -238,10 +295,11 @@ void ctkDoubleSpinBoxTester::testDecimalsByKey()
|
|
|
QTest::keyClick(spinBox.lineEdit(), static_cast<Qt::Key>(key));
|
|
|
|
|
|
QFETCH(QString, expectedText);
|
|
|
+ QFETCH(double, expectedValue);
|
|
|
QFETCH(int, expectedDecimals);
|
|
|
|
|
|
QCOMPARE(spinBox.text(), expectedText);
|
|
|
- QCOMPARE(spinBox.value(), expectedText.toDouble());
|
|
|
+ QCOMPARE(spinBox.value(), expectedValue);
|
|
|
QCOMPARE(spinBox.decimals(), expectedDecimals);
|
|
|
QCOMPARE(spy.count(), spinBox.decimals() != oldDecimals ? 1 : 0);
|
|
|
}
|
|
@@ -253,126 +311,157 @@ void ctkDoubleSpinBoxTester::testDecimalsByKey_data()
|
|
|
QTest::addColumn<int>("cursorPosition");
|
|
|
QTest::addColumn<int>("key");
|
|
|
QTest::addColumn<QString>("expectedText");
|
|
|
+ QTest::addColumn<double>("expectedValue");
|
|
|
QTest::addColumn<int>("expectedDecimals");
|
|
|
|
|
|
QList<int> options;
|
|
|
// ctkDoubleSpinBox::DecimalsByKey
|
|
|
options << ctkDoubleSpinBox::DecimalsByKey;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'1' -> 11.23") << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'del' -> .23") << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'backspace' -> 1.23") << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'1' -> 11.23") << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'del' -> 123") << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'backspace' -> .23") << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'1' -> 1.12") << options.last() << 2 << int(Qt::Key_1) << "1.12" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'del' -> 1.3") << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'backspace' -> 123") << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'1' -> 1.21") << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'del' -> 1.2") << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'backspace' -> 1.3") << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'1' -> 1.231") << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'del' -> 1.23") << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'backspace' -> 1.2") << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'1' -> 11.23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 11.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'del' -> .23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_Delete) << ".23" << .23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 0:'backspace' -> 1.23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 1.23 << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'1' -> 11.23")
|
|
|
+ << options.last() << 1 << int(Qt::Key_1) << "11.23" << 11.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'del' -> 123")
|
|
|
+ << options.last() << 1 << int(Qt::Key_Delete) << "123" << 123. << 0;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 1:'backspace' -> .23")
|
|
|
+ << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << .23 << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'1' -> 1.12")
|
|
|
+ << options.last() << 2 << int(Qt::Key_1) << "1.12" << 1.12 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'del' -> 1.3")
|
|
|
+ << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1.3 << 1;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 2:'backspace' -> 123")
|
|
|
+ << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 123. << 0;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'1' -> 1.21")
|
|
|
+ << options.last() << 3 << int(Qt::Key_1) << "1.21" << 1.21 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'del' -> 1.2")
|
|
|
+ << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1.2 << 1;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 3:'backspace' -> 1.3")
|
|
|
+ << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1.3 << 1;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'1' -> 1.231")
|
|
|
+ << options.last() << 4 << int(Qt::Key_1) << "1.231" << 1.231 << 3;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'del' -> 1.23")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey 4:'backspace' -> 1.2")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1.2 << 1;
|
|
|
|
|
|
// ctkDoubleSpinBox::ReplaceDecimals
|
|
|
options << ctkDoubleSpinBox::ReplaceDecimals;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.23") << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .23") << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.23") << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.23") << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 123") << options.last() << 1 << int(Qt::Key_Delete) << "123" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .23") << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.13") << options.last() << 2 << int(Qt::Key_1) << "1.13" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.3") << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 123") << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.21") << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.2") << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.3") << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 2;
|
|
|
-
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.23") << options.last() << 4 << int(Qt::Key_1) << "1.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.23") << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.2") << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 11.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_Delete) << ".23" << .23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.23")
|
|
|
+ << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 1.23 << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.23")
|
|
|
+ << options.last() << 1 << int(Qt::Key_1) << "11.23" << 11.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 123")
|
|
|
+ << options.last() << 1 << int(Qt::Key_Delete) << "123" << 123. << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .23")
|
|
|
+ << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << .23 << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.13")
|
|
|
+ << options.last() << 2 << int(Qt::Key_1) << "1.13" << 1.13 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.3")
|
|
|
+ << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1.3 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 123")
|
|
|
+ << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 123. << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.21")
|
|
|
+ << options.last() << 3 << int(Qt::Key_1) << "1.21" << 1.21 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.2")
|
|
|
+ << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1.2 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.3")
|
|
|
+ << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1.3 << 2;
|
|
|
+
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.23")
|
|
|
+ << options.last() << 4 << int(Qt::Key_1) << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.23")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.2")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1.2 << 2;
|
|
|
|
|
|
// ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals
|
|
|
options << (ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals);
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'1' -> 11.23")
|
|
|
- << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 11.23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'del' -> .23")
|
|
|
- << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_Delete) << ".23" << .23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 0:'backspace' -> 1.23")
|
|
|
- << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 1.23 << 2;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'1' -> 11.23")
|
|
|
- << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
|
|
|
+ << options.last() << 1 << int(Qt::Key_1) << "11.23" << 11.23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'del' -> 123")
|
|
|
- << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
|
|
|
+ << options.last() << 1 << int(Qt::Key_Delete) << "123" << 123. << 0;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 1:'backspace' -> .23")
|
|
|
- << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
|
|
|
+ << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << .23 << 2;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'1' -> 1.13")
|
|
|
- << options.last() << 2 << int(Qt::Key_1) << "1.13" << 2;
|
|
|
+ << options.last() << 2 << int(Qt::Key_1) << "1.13" << 1.13 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'del' -> 1.3")
|
|
|
- << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
|
|
|
+ << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1.3 << 1;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 2:'backspace' -> 123")
|
|
|
- << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
|
|
|
+ << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 123. << 0;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'1' -> 1.21")
|
|
|
- << options.last() << 3 << int(Qt::Key_1) << "1.21" << 2;
|
|
|
+ << options.last() << 3 << int(Qt::Key_1) << "1.21" << 1.21 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'del' -> 1.2")
|
|
|
- << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
|
|
|
+ << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1.2 << 1;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 3:'backspace' -> 1.3")
|
|
|
- << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
|
|
|
+ << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1.3 << 1;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'1' -> 1.231")
|
|
|
- << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
|
|
|
+ << options.last() << 4 << int(Qt::Key_1) << "1.231" << 1.231 << 3;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'del' -> 1.23")
|
|
|
- << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.23")
|
|
|
- << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
|
|
|
+ << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::ReplaceDecimals 4:'backspace' -> 1.2")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1.2 << 1;
|
|
|
|
|
|
// ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals
|
|
|
options << (ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals);
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'1' -> 11.23")
|
|
|
- << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_1) << "11.23"<< 11.23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'del' -> .23")
|
|
|
- << options.last() << 0 << int(Qt::Key_Delete) << ".23" << 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_Delete) << ".23" << .23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 0:'backspace' -> 1.23")
|
|
|
- << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 2;
|
|
|
+ << options.last() << 0 << int(Qt::Key_Backspace) << "1.23" << 1.23 << 2;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'1' -> 11.23")
|
|
|
- << options.last() << 1 << int(Qt::Key_1) << "11.23" << 2;
|
|
|
+ << options.last() << 1 << int(Qt::Key_1) << "11.23" << 11.23 << 2;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'del' -> 123")
|
|
|
- << options.last() << 1 << int(Qt::Key_Delete) << "123" << 0;
|
|
|
+ << options.last() << 1 << int(Qt::Key_Delete) << "123" << 123. << 0;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 1:'backspace' -> .23")
|
|
|
- << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << 2;
|
|
|
+ << options.last() << 1 << int(Qt::Key_Backspace) << ".23" << .23 << 2;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'1' -> 1.123")
|
|
|
- << options.last() << 2 << int(Qt::Key_1) << "1.123" << 3;
|
|
|
+ << options.last() << 2 << int(Qt::Key_1) << "1.123" << 1.123 << 3;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'del' -> 1.3")
|
|
|
- << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1;
|
|
|
+ << options.last() << 2 << int(Qt::Key_Delete) << "1.3" << 1.3 << 1;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 2:'backspace' -> 123")
|
|
|
- << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 0;
|
|
|
+ << options.last() << 2 << int(Qt::Key_Backspace) << "123" << 123. << 0;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'1' -> 1.213")
|
|
|
- << options.last() << 3 << int(Qt::Key_1) << "1.213" << 3;
|
|
|
+ << options.last() << 3 << int(Qt::Key_1) << "1.213" << 1.213 << 3;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'del' -> 1.2")
|
|
|
- << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1;
|
|
|
+ << options.last() << 3 << int(Qt::Key_Delete) << "1.2" << 1.2 << 1;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 3:'backspace' -> 1.3")
|
|
|
- << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1;
|
|
|
+ << options.last() << 3 << int(Qt::Key_Backspace) << "1.3" << 1.3 << 1;
|
|
|
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'1' -> 1.231")
|
|
|
- << options.last() << 4 << int(Qt::Key_1) << "1.231" << 3;
|
|
|
+ << options.last() << 4 << int(Qt::Key_1) << "1.231" << 1.231 << 3;
|
|
|
QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'del' -> 1.23")
|
|
|
- << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 2;
|
|
|
- QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'backspace' -> 1.23")
|
|
|
- << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1;
|
|
|
+ << options.last() << 4 << int(Qt::Key_Delete) << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("ctkDoubleSpinBox::DecimalsByKey|ctkDoubleSpinBox::InsertDecimals 4:'backspace' -> 1.2")
|
|
|
+ << options.last() << 4 << int(Qt::Key_Backspace) << "1.2" << 1.2 << 1;
|
|
|
|
|
|
foreach(int option, options)
|
|
|
{
|
|
@@ -380,19 +469,19 @@ void ctkDoubleSpinBoxTester::testDecimalsByKey_data()
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
{
|
|
|
QTest::newRow(QString("%1 %2:'a' -> 1.23").arg(option).arg(i).toLatin1())
|
|
|
- << option << i << int(Qt::Key_A) << "1.23" << 2;
|
|
|
+ << option << i << int(Qt::Key_A) << "1.23" << 1.23 << 2;
|
|
|
}
|
|
|
// sign keys are only for the first digit
|
|
|
QTest::newRow(QString("%1 0:'+' -> 1.23").arg(option).toLatin1())
|
|
|
- << option << 0 << int(Qt::Key_Plus) << "+1.23" << 2;
|
|
|
+ << option << 0 << int(Qt::Key_Plus) << "+1.23" << 1.23 << 2;
|
|
|
QTest::newRow(QString("%1 0:'-' -> -1.23").arg(option).toLatin1())
|
|
|
- << option << 0 << int(Qt::Key_Minus) << "-1.23" << 2;
|
|
|
+ << option << 0 << int(Qt::Key_Minus) << "-1.23" << -1.23 << 2;
|
|
|
for (int i = 1; i < 5; ++i)
|
|
|
{
|
|
|
QTest::newRow(QString("%1 %2:'+' -> 1.23").arg(option).arg(i).toLatin1())
|
|
|
- << option << i << int(Qt::Key_Plus) << "1.23" << 2;
|
|
|
+ << option << i << int(Qt::Key_Plus) << "1.23" << 1.23 << 2;
|
|
|
QTest::newRow(QString("%1 %2:'-' -> 1.23").arg(option).arg(i).toLatin1())
|
|
|
- << option << i << int(Qt::Key_Minus) << "1.23" << 2;
|
|
|
+ << option << i << int(Qt::Key_Minus) << "1.23" << 1.23 << 2;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -456,10 +545,11 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue()
|
|
|
spinBox.setValue(value);
|
|
|
|
|
|
QFETCH(QString, expectedText);
|
|
|
+ QFETCH(double, expectedValue);
|
|
|
QFETCH(int, expectedDecimals);
|
|
|
|
|
|
QCOMPARE(spinBox.text(), expectedText);
|
|
|
- QCOMPARE(spinBox.value(), expectedText.toDouble());
|
|
|
+ QCOMPARE(spinBox.value(), expectedValue);
|
|
|
QCOMPARE(spinBox.decimals(), expectedDecimals);
|
|
|
QCOMPARE(spy.count(), spinBox.decimals() != oldDecimals ? 1 : 0);
|
|
|
}
|
|
@@ -469,20 +559,21 @@ void ctkDoubleSpinBoxTester::testDecimalsByValue_data()
|
|
|
{
|
|
|
QTest::addColumn<double>("value");
|
|
|
QTest::addColumn<QString>("expectedText");
|
|
|
+ QTest::addColumn<double>("expectedValue");
|
|
|
QTest::addColumn<int>("expectedDecimals");
|
|
|
|
|
|
- QTest::newRow("0") << 0. << "0"<< 0;
|
|
|
- QTest::newRow("0.1") << 0.1 << "0.1" << 1;
|
|
|
- QTest::newRow("0.02") << 0.02 << "0.02" << 2;
|
|
|
- QTest::newRow("10.003") << 10.003 << "10.003" << 3;
|
|
|
- QTest::newRow("-0.0004") << -0.0004 << "-0.0004" << 4;
|
|
|
- QTest::newRow("0.000056") << 0.000056 << "0.000056" << 6;
|
|
|
+ QTest::newRow("0") << 0. << "0"<< 0. << 0;
|
|
|
+ QTest::newRow("0.1") << 0.1 << "0.1" << 0.1 << 1;
|
|
|
+ QTest::newRow("0.02") << 0.02 << "0.02" << 0.02 << 2;
|
|
|
+ QTest::newRow("10.003") << 10.003 << "10.003" << 10.003 << 3;
|
|
|
+ QTest::newRow("-0.0004") << -0.0004 << "-0.0004" << -0.0004 << 4;
|
|
|
+ QTest::newRow("0.000056") << 0.000056 << "0.000056" << 0.000056 << 6;
|
|
|
// internally represented as 123456.001109999997425
|
|
|
- QTest::newRow("5.00111") << 5.00111 << "5.00111" << 5;
|
|
|
- QTest::newRow("same value with more decimals") << 1.234567 << "1.234567" << 6;
|
|
|
- QTest::newRow("same value") << 1.23 << "1.23" << 2;
|
|
|
- QTest::newRow("same value with less decimals") << 1.234 << "1.234" << 3;
|
|
|
- QTest::newRow("16 decimals") << 0.1234567891013151 << "0.1235" << 4;
|
|
|
+ QTest::newRow("5.00111") << 5.00111 << "5.00111" << 5.00111 << 5;
|
|
|
+ QTest::newRow("same value with more decimals") << 1.234567 << "1.234567" << 1.234567 << 6;
|
|
|
+ QTest::newRow("same value") << 1.23 << "1.23" << 1.23 << 2;
|
|
|
+ QTest::newRow("same value with less decimals") << 1.234 << "1.234" << 1.234 << 3;
|
|
|
+ QTest::newRow("16 decimals") << 0.1234567891013151 << "0.1235" << 0.1234567891013151 << 4;
|
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|