7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the GUI GraphicalArray class"
10 #include <QHBoxLayout>
13 #include <QPushButton>
15 #include <QStringListModel>
42 QGridLayout * layout =
dynamic_cast<QGridLayout*
>(value->layout()->itemAt(0)->widget()->layout());
43 QWidget * widget =
nullptr;
46 widget = layout->itemAtPosition(row, col)->widget();
48 std::cerr <<
"Failed to find the layout or cast it to QGridLayout." << std::endl;
61 QLineEdit * lineEdit =
dynamic_cast<QLineEdit*
>(
find_widget(value, 0, 0));
64 std::cerr <<
"Failed to find the line edit." << std::endl;
77 QPushButton * button =
dynamic_cast<QPushButton*
>(
find_widget(value, 1, 1));
80 std::cerr <<
"Failed to find the remove button." << std::endl;
94 QListView * listView =
dynamic_cast<QListView*
>(
find_widget(value, 1, 0));
97 std::cerr <<
"Failed to find the list." << std::endl;
111 QStringListModel *
model =
nullptr;
115 model =
dynamic_cast<QStringListModel*
>( view->model() );
118 std::cerr <<
"Failed to find the view model." << std::endl;
126 BOOST_AUTO_TEST_SUITE( uiGraphicsGraphicalArraySuite )
161 BOOST_CHECK( model->stringList().empty() );
165 QIntValidator * validator =
new QIntValidator();
171 BOOST_CHECK_EQUAL( lineEdit->validator(), validator );
181 QValidator * validator =
new QIntValidator();
188 BOOST_CHECK_EQUAL( lineEdit->validator(), validator );
192 BOOST_CHECK_EQUAL( lineEdit->validator(), (QValidator*)
nullptr );
195 validator =
new QDoubleValidator(
nullptr);
199 BOOST_CHECK_EQUAL( lineEdit->validator(), validator );
215 QStringList validList;
216 QStringList invalidList;
219 validList <<
"42" <<
"15465" <<
"-145314" <<
"42";
220 invalidList <<
"25" <<
"1" <<
"something" <<
"32" <<
"3.14" <<
"-54789";
228 BOOST_CHECK( value->
set_value( validList.join(sep) ) );
230 list = model->stringList();
232 BOOST_CHECK_EQUAL( list.count(), validList.count() );
234 for(
int i = 0 ; i < list.count() ; ++i)
235 BOOST_CHECK_EQUAL( list.at(i).toStdString(), validList.at(i).toStdString() );
238 BOOST_CHECK( value->
set_value( QString(
"1456789") ) );
239 BOOST_CHECK_EQUAL( model->stringList().count(), 1 );
240 BOOST_CHECK_EQUAL( model->stringList().at(0).toStdString(), std::string(
"1456789") );
243 BOOST_CHECK( !value->
set_value( invalidList.join(sep) ) );
244 list = model->stringList();
247 BOOST_CHECK_EQUAL( model->stringList().count(), 1 );
248 BOOST_CHECK_EQUAL( model->stringList().at(0).toStdString(), std::string(
"1456789") );
254 BOOST_CHECK_EQUAL( model->stringList().at(0).toStdString(), std::string(
"1456789") );
257 BOOST_CHECK_EQUAL( model->stringList().at(0).toStdString(), std::string(
"1456789") );
268 QStringList stringList;
272 stringList <<
"hello" <<
"world" <<
"!";
275 theValue = value->
value();
276 BOOST_CHECK( theValue.type() == QVariant::StringList );
278 list = theValue.toStringList();
280 BOOST_CHECK_EQUAL( list.count(), 0 );
282 for(
int i = 0 ; i < list.count() ; ++i)
283 BOOST_CHECK_EQUAL( list.at(i).toStdString(), stringList.at(i).toStdString() );
286 model->setStringList( stringList );
288 theValue = value->
value();
290 list = theValue.toStringList();
292 BOOST_CHECK( theValue.type() == QVariant::StringList );
294 BOOST_CHECK_EQUAL( list.count(), stringList.count() );
296 for(
int i = 0 ; i < list.count() ; ++i)
297 BOOST_CHECK_EQUAL( list.at(i).toStdString(), stringList.at(i).toStdString() );
309 QSignalSpy spy(value, SIGNAL(value_changed()));
314 value->
set_value( QString(
"Hello World") );
315 value->
set_value( QStringList() <<
"Hello" <<
"World" );
319 BOOST_CHECK_EQUAL( spy.count(), 2 );
324 model->setStringList( QStringList() );
352 BOOST_CHECK_EQUAL( spy.count(), 1 );
364 BOOST_CHECK_EQUAL( value->
value_string().toStdString(), std::string(
"Hello") );
366 value->
set_value( QStringList() <<
"Hello" <<
"World");
367 BOOST_CHECK_EQUAL( value->
value_string().toStdString(), std::string(
"Hello;World") );
383 model->setStringList( QStringList() <<
"Hello" <<
"World" );
387 model->setStringList( QStringList() <<
"Hello" <<
"World" <<
"and" <<
"Happy" <<
"New" <<
"Year!" );
393 model->setStringList( QStringList() <<
"Hello" <<
"World" <<
"and" <<
"Happy" <<
"New" <<
"Year!" );
407 QItemSelectionModel::SelectionFlags flag = QItemSelectionModel::Select;
409 model->setStringList( QStringList() <<
"Hello" <<
"World" <<
"and" <<
"Happy" <<
"New" <<
"Year!" );
412 view->selectionModel()->select( model->index(0), flag );
413 view->selectionModel()->select( model->index(1), flag );
414 view->selectionModel()->select( model->index(3), flag );
415 view->selectionModel()->select( model->index(5), flag );
418 QTest::mouseClick( button, Qt::LeftButton );
420 QStringList values = model->stringList();
422 BOOST_CHECK_EQUAL( values.count(), 2 );
423 BOOST_CHECK_EQUAL( values.at(0).toStdString(), std::string(
"and") );
424 BOOST_CHECK_EQUAL( values.at(1).toStdString(), std::string(
"New") );
431 BOOST_AUTO_TEST_SUITE_END()
QApplication * application()
bool is_null(T ptr)
predicate for comparison to nullptr
bool AssertionThrows
assertions throw exceptions
QLineEdit * find_line_edit(const GraphicalArray *value)
bool ExceptionOutputs
if exception contructor should output
static AssertionManager & instance()
Gets the instance of the manager.
bool AssertionDumps
assertions dump backtraces
QWidget * find_widget(const GraphicalArray *value, int row, int col)
virtual QVariant value() const
bool ExceptionDumps
if exception contructor should dump backtrace
Conversions from and to std::string.
void set_validator(QValidator *validator)
QListView * find_list_view(const GraphicalArray *value)
QStringListModel * find_model(const GraphicalArray *value)
QPushButton * find_remove_button(const GraphicalArray *value)
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
virtual bool set_value(const QVariant &path)
tuple model
Global confifuration.
BOOST_AUTO_TEST_CASE(init)
Top-level namespace for coolfluid.
static ExceptionManager & instance()
Gets the instance of the manager.
static ThreadManager & instance()
Basic Classes for Graphics applications used by CF.
QString value_string() const
Most basic kernel library.
bool is_not_null(T ptr)
predicate for comparison to nullptr