void GraphicalIntTest::test_setValue() { GraphicalInt * value = new GraphicalInt(false); QDoubleSpinBox * spinBox = findSpinBox(value); QVERIFY( is_not_null(spinBox) ); // // 1. check with ints // QVERIFY( value->setValue(-1456) ); QCOMPARE( int(spinBox->value()), -1456 ); QVERIFY( value->setValue(215468548) ); QCOMPARE( int(spinBox->value()), 215468548 ); // // 2. check with other types // QVERIFY( !value->setValue(3.141592) ); QCOMPARE( int(spinBox->value()), 215468548 ); QVERIFY( !value->setValue(true) ); QCOMPARE( int(spinBox->value()), 215468548 ); QVERIFY( !value->setValue("789654123") ); QCOMPARE( int(spinBox->value()), 215468548 ); delete value; }
void GraphicalIntTest::test_valueString() { GraphicalInt * value = new GraphicalInt(false); value->setValue(78646); QCOMPARE( value->valueString(), QString("78646") ); value->setValue(165464); QCOMPARE( value->valueString(), QString("165464") ); delete value; }
void GraphicalIntTest::test_signalEmmitting() { GraphicalInt * value = new GraphicalInt(false); QDoubleSpinBox * spinBox = findSpinBox(value); QSignalSpy spy(value, SIGNAL(valueChanged())); // // 1. through setValue() // value->setValue(125464); value->setValue(-876541); // 2 signals should have been emitted QCOMPARE( spy.count(), 2 ); spy.clear(); // // 2. by simulating keyboard events // spinBox->clear(); value->show(); // make the value visible (it ignores keyboard events if not) QTest::keyClicks(spinBox, "-2014" ); QTest::keyClicks(spinBox, "357" ); QTest::keyClicks(spinBox, "aq45s2" ); // 10 signals should have been emitted (one per character) // (13 chars entered but 'a', 'q' and 's' were ignored) QCOMPARE( spy.count(), 10 ); spy.clear(); // // 3. when committing // value->commit(); // 1 signal should have been emitted QCOMPARE( spy.count(), 1 ); delete value; }