Esempio n. 1
0
void GraphicalArrayTest::test_signalEmmitting()
{
  GraphicalArray * value = new GraphicalArray();
  QLineEdit * lineEdit = findLineEdit(value);
  QStringListModel * model = findModel(value);
  QSignalSpy spy(value, SIGNAL(valueChanged()));

  //
  // 1. through setValue()
  //
  value->setValue( QString("Hello World") ); // when the value is a string
  value->setValue( QStringList() << "Hello" << "World" ); // when the value is a string list
  value->setValue( 42 ); // when the value is not valid (so signal emitted)

  // 2 signals should have been emitted
  QCOMPARE( spy.count(), 2 );

  spy.clear();

  // clear the model
  model->setStringList( QStringList() );

  //
  // 2. by simulating keyboard events
  //
  // note: when validating, we wait 25 ms (last parameter) to let the event being processed
//  lineEdit->clear();
//  value->show(); // make the value visible (it ignores keyboard events if not)
//  lineEdit->setFocus(Qt::PopupFocusReason);
//  QTest::keyClicks(lineEdit, "123" );
//  QTest::keyClick(value, Qt::Key_Enter, Qt::NoModifier); // validate by pressing the 'ENTER' key on the keypad
//  QTest::keyClicks(lineEdit, "156" );
//  QTest::keyClicks(lineEdit, "456" );
//  QTest::keyClick(value, Qt::Key_Return, Qt::NoModifier); // validate by pressing the 'Return' key

  // 2 signals should have been emitted (one per validation)
//  QCOMPARE( spy.count(), 2 );

//  QCOMPARE( model->stringList(), QStringList() << "123" << "156456");
//  QCOMPARE( lineEdit->text(), QString() );

  spy.clear();
  //
  // 3. when committing
  //
  value->commit();

  // 1 signal should have been emitted
  QCOMPARE( spy.count(), 1 );

  delete value;
}
Esempio n. 2
0
void GraphicalArrayTest::test_setValue()
{
  QString sep(";");
  GraphicalArray * value = new GraphicalArray( new QIntValidator(), sep );
  QLineEdit * lineEdit = findLineEdit(value);
  QStringListModel * model = findModel(value);

  QStringList validList;
  QStringList invalidList;

  validList << "42" << "15465" << "-145314" << "42"; // duplicates should be kept
  invalidList << "25" << "1" << "something" << "32" << "3.14" << "-54789";

  QVERIFY( is_not_null(lineEdit) );

  //
  // 1. check with strings
  //
  // 1a. list that only contains valid values
  QVERIFY( value->setValue( validList.join(sep) ) );
  QCOMPARE( model->stringList(), validList );

  // 1c. only one value
  QVERIFY( value->setValue( QString("1456789") ) );
  QCOMPARE( model->stringList().count(), 1 );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  // 1b. list that contains some invalid values
  QVERIFY( !value->setValue( invalidList.join(sep) ) );
  QStringList list = model->stringList();

  // "something" and "3.14" are invalid integers and so the value shouldn't have changed
  QCOMPARE( model->stringList().count(), 1 );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  //
  // 2. check with other types
  //
  QVERIFY( !value->setValue(true) );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  QVERIFY( !value->setValue(3.145) );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  delete value;
}
Esempio n. 3
0
void GraphicalDoubleTest::test_isModified()
{
  GraphicalDouble * value = new GraphicalDouble();
  QLineEdit* lineEdit = findLineEdit(value);

  // 1. initially, it's not modified
  QVERIFY( !value->isModified() );

  // 2. change the value
  lineEdit->setText("12.45");
  QVERIFY( value->isModified() );

  // 3. change the value and commit
  lineEdit->setText("-5.879");
  QVERIFY( value->isModified() );
  value->commit();
  QVERIFY( !value->isModified() );

  delete value;
}
Esempio n. 4
0
void GraphicalDoubleTest::test_signalEmmitting()
{
  GraphicalDouble * value = new GraphicalDouble();
  QLineEdit * lineEdit = findLineEdit(value);
  QSignalSpy spy(value, SIGNAL(valueChanged()));

  //
  // 1. through setValue()
  //
  value->setValue(3.14159265);
  value->setValue(2.71);

  // 2 signals should have been emitted
  QCOMPARE( spy.count(), 2 );

  spy.clear();

  //
  // 2. by simulating keyboard events
  //
  lineEdit->clear();
  value->show(); // make the value visible (it ignores keyboard events if not)
  QTest::keyClicks(lineEdit, "-3.141-51a6e45.12r4+5w6" );

  // 18 signals should have been emitted
  // (24 chars where entered, but only "-3.141516e4512456" were accepted)
  QCOMPARE( spy.count(), 18 );

  spy.clear();
  //
  // 3. when committing
  //
  value->commit();

  // 1 signal should have been emitted
  QCOMPARE( spy.count(), 1 );

  delete value;
}
Esempio n. 5
0
void GraphicalArrayTest::test_constructor()
{
  GraphicalArray * value = new GraphicalArray();
  QStringListModel * model = findModel(value);

  // 1. value is empty, the line edit should be empty as well
  QVERIFY( is_not_null(model) );
  QVERIFY( model->stringList().empty() );

  delete value;

  QIntValidator * validator = new QIntValidator();
  value = new GraphicalArray( validator );
  QLineEdit * lineEdit = findLineEdit(value);

  // 2. validator objects should be the same
  QVERIFY( is_not_null(lineEdit) );
  QCOMPARE( lineEdit->validator(), validator );

  delete value;
  delete validator;
}
Esempio n. 6
0
void GraphicalDoubleTest::test_setValue()
{
  GraphicalDouble * value = new GraphicalDouble();
  QLineEdit * lineEdit = findLineEdit(value);

  QVERIFY( is_not_null(lineEdit) );

  //
  // 1. check with doubles
  //
  QVERIFY( value->setValue(3.14159265) );
  QCOMPARE( lineEdit->text(), QString("3.14159265") );

  QVERIFY( value->setValue(-2.71) );
  QCOMPARE( lineEdit->text(), QString("-2.71") );

  //
  // 2. check with other types
  //
  QVERIFY( value->setValue(12) );
  QCOMPARE( lineEdit->text(), QString("12") ); // value does not change

  QVERIFY( !value->setValue("Hello") );
  QCOMPARE( lineEdit->text(), QString("12") ); // value does not change

  QVERIFY( !value->setValue(true) );
  QCOMPARE( lineEdit->text(), QString("12") ); // value does not change

  QVERIFY( !value->setValue("1.6a45") );     // with an invalid character
  QCOMPARE( lineEdit->text(), QString("12") ); // value does not change

  QVERIFY( value->setValue("1.6E-45") );       // try scientific notation
  QCOMPARE( lineEdit->text(), QString("1.6E-45") );


  delete value;
}