7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for the GUI GraphicalValue class"
10 #include <QGridLayout>
15 #include <boost/assign/std/vector.hpp>
53 QGridLayout * layout =
dynamic_cast<QGridLayout*
>(array->layout()->itemAt(0)->widget()->layout());
54 const QValidator * validator =
nullptr;
58 QLineEdit * lineEdit =
dynamic_cast<QLineEdit*
>(layout->itemAtPosition(0, 0)->widget());
61 std::cerr <<
"Failed to find the line edit." << std::endl;
63 validator = lineEdit->validator();
66 std::cerr <<
"Failed to find the layout or cast it to QGridLayout." << std::endl;
73 BOOST_AUTO_TEST_SUITE( uiGraphicsGraphicalValueSuite )
81 AssertionManager::instance().AssertionDumps =
false;
82 AssertionManager::instance().AssertionThrows =
true;
83 ExceptionManager::instance().ExceptionDumps =
false;
84 ExceptionManager::instance().ExceptionOutputs =
false;
91 boost::shared_ptr<Option> option;
97 BOOST_CHECK_EQUAL( GraphicalValue::create_from_option(boost::shared_ptr< Option >()), (
GraphicalValue*)
nullptr );
102 option = boost::shared_ptr< OptionT<bool> >(
new OptionT<bool>(
"OptBool",
true));
103 value = GraphicalValue::create_from_option( option );
105 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalBool*>(value) ) );
112 option = boost::shared_ptr< OptionT<int> >(
new OptionT<int>(
"OptInt", int(-156754)));
113 value = GraphicalValue::create_from_option( option );
115 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalInt*>(value) ) );
122 option = boost::shared_ptr< OptionT<Uint> >(
new OptionT<Uint>(
"OptUint",
Uint(42)));
123 value = GraphicalValue::create_from_option( option );
125 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalInt*>(value) ) );
132 option = boost::shared_ptr< OptionT<Real> >(
new OptionT<Real>(
"OptReal", Real(3.141592)));
133 value = GraphicalValue::create_from_option( option );
135 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalDouble*>(value) ) );
142 option = boost::shared_ptr< OptionT<std::string> >(
new OptionT<std::string>(
"OptString", std::string()));
143 value = GraphicalValue::create_from_option( option );
145 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalString*>(value) ) );
152 option = boost::shared_ptr< OptionURI >(
new OptionURI(
"OptUri",
URI()));
153 value = GraphicalValue::create_from_option( option );
155 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalUri*>(value) ) );
164 boost::shared_ptr<Option> option;
166 const QValidator * validator;
171 BOOST_CHECK_EQUAL( GraphicalValue::create_from_option(boost::shared_ptr< Option >()), (
GraphicalValue*)
nullptr );
176 option = boost::shared_ptr< OptionArray<bool> >(
new OptionArray<bool>(
"OptBool", std::vector<bool>()));
177 value = GraphicalValue::create_from_option( option );
181 BOOST_CHECK(
is_not_null( dynamic_cast<GraphicalArray*>(value) ) );
186 "No validator found. Please check the warning above." );
190 const QRegExpValidator * val =
dynamic_cast<const QRegExpValidator*
>(validator);
192 BOOST_CHECK_EQUAL( val->regExp().pattern().toStdString(),
193 std::string(
"(true)|(false)|(1)|(0)|(on)|(off)") );
201 option = boost::shared_ptr< OptionArray<int> >(
new OptionArray<int>(
"OptInt", std::vector<int>()));
202 value = GraphicalValue::create_from_option( option );
206 BOOST_CHECK(
is_not_null( dynamic_cast<GraphicalArray*>(value) ) );
210 BOOST_CHECK_MESSAGE(
is_not_null(validator),
"No validator found. Please check the warning above." );
214 const QIntValidator * val =
dynamic_cast<const QIntValidator*
>(validator);
224 option = boost::shared_ptr< OptionArray<Uint> >(
new OptionArray<Uint>(
"OptUint", std::vector<Uint>()));
225 value = GraphicalValue::create_from_option( option );
229 BOOST_CHECK(
is_not_null( dynamic_cast<GraphicalArray*>(value) ) );
233 BOOST_CHECK_MESSAGE(
is_not_null(validator),
"No validator found. Please check the warning above." );
237 const QIntValidator * val =
dynamic_cast<const QIntValidator*
>(validator);
239 BOOST_CHECK_EQUAL( val->bottom(), 0);
248 option = boost::shared_ptr< OptionArray<Real> >(
new OptionArray<Real>(
"OptReal", std::vector<Real>()));
249 value = GraphicalValue::create_from_option( option );
253 BOOST_CHECK(
is_not_null( dynamic_cast<GraphicalArray*>(value) ) );
257 BOOST_CHECK_MESSAGE(
is_not_null(validator),
"No validator found. Please check the warning above." );
261 const QDoubleValidator * val =
dynamic_cast<const QDoubleValidator*
>(validator);
271 option = boost::shared_ptr< OptionArray<std::string> >(
new OptionArray<std::string>(
"OptString", std::vector<std::string>()));
272 value = GraphicalValue::create_from_option( option );
276 BOOST_CHECK(
is_not_null( dynamic_cast<GraphicalArray*>(value) ) );
280 BOOST_CHECK_MESSAGE(
is_null(validator),
"Validator found. We should not have a validator here.");
288 option = boost::shared_ptr< OptionArray<URI> >(
new OptionArray<URI>(
"OptString", std::vector<URI>()));
289 value = GraphicalValue::create_from_option( option );
293 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalUriArray*>(value) ) );
302 boost::shared_ptr<Option> option;
308 option = boost::shared_ptr< OptionT<bool> >(
new OptionT<bool>(
"OptBool",
true));
309 option->restricted_list() +=
false;
310 value = GraphicalValue::create_from_option( option );
312 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
319 option = boost::shared_ptr< OptionT<int> >(
new OptionT<int>(
"OptInt", int(-156754)));
320 option->restricted_list() += int(47687876);
321 value = GraphicalValue::create_from_option( option );
323 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
330 option = boost::shared_ptr< OptionT<Uint> >(
new OptionT<Uint>(
"OptUint",
Uint(42)));
331 option->restricted_list() +=
Uint(314);
332 value = GraphicalValue::create_from_option( option );
334 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
341 option = boost::shared_ptr< OptionT<Real> >(
new OptionT<Real>(
"OptReal", Real(3.141592)));
342 option->restricted_list() += Real(2.71);
343 value = GraphicalValue::create_from_option( option );
345 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
352 option = boost::shared_ptr< OptionT<std::string> >(
new OptionT<std::string>(
"OptString", std::string()));
353 option->restricted_list() += std::string(
"Hello, World!");
354 value = GraphicalValue::create_from_option( option );
356 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
363 option = boost::shared_ptr< OptionURI >(
new OptionURI(
"OptUri",
URI(
"http://www.google.com")));
364 option->restricted_list().push_back(
URI(
"cpath:/") );
365 value = GraphicalValue::create_from_option( option );
367 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalRestrictedList*>(value) ) );
376 boost::shared_ptr<Option> option;
382 std::vector<bool> vectBool;
383 vectBool.push_back(
true);
384 option = boost::shared_ptr< OptionArray<bool> >(
new OptionArray<bool>(
"OptBool", vectBool));
385 option->restricted_list() +=
false;
386 BOOST_CHECK_NO_THROW(value = GraphicalValue::create_from_option( option ));
388 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
395 std::vector<int> vectInt;
396 vectInt.push_back(-154786);
397 option = boost::shared_ptr< OptionArray<int> >(
new OptionArray<int>(
"OptInt", vectInt));
398 option->restricted_list() += int(47687876);
399 value = GraphicalValue::create_from_option( option );
401 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
408 std::vector<Uint> vectUint;
409 vectUint.push_back(42);
410 option = boost::shared_ptr< OptionArray<Uint> >(
new OptionArray<Uint>(
"OptUint", vectUint));
411 option->restricted_list() +=
Uint(3654614);
412 value = GraphicalValue::create_from_option( option );
414 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
421 std::vector<Real> vectReal;
422 vectReal.push_back(3.141592);
423 option = boost::shared_ptr< OptionArray<Real> >(
new OptionArray<Real>(
"OptReal", vectReal));
424 option->restricted_list() += Real(2.71);
425 value = GraphicalValue::create_from_option( option );
427 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
434 std::vector<std::string> vectString;
435 vectString.push_back(
"Hello");
437 option->restricted_list() += std::string(
", World!");
438 value = GraphicalValue::create_from_option( option );
440 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
447 std::vector<URI> vectUri;
448 vectUri.push_back(
URI(
"http://coolfluidsrv.vki.ac.be") );
449 option = boost::shared_ptr< OptionArray<URI> >(
new OptionArray<URI>(
"OptUri", vectUri));
450 option->restricted_list() +=
URI(
"cpath:/");
451 value = GraphicalValue::create_from_option( option );
453 BOOST_CHECK(
is_not_null(dynamic_cast<GraphicalArrayRestrictedList*>(value) ) );
460 BOOST_AUTO_TEST_SUITE_END()
QApplication * application()
bool is_null(T ptr)
predicate for comparison to nullptr
Top-level namespace for coolfluid.
BOOST_AUTO_TEST_CASE(init)
Basic Classes for Graphics applications used by CF.
unsigned int Uint
typedef for unsigned int
Most basic kernel library.
const QValidator * find_array_validator(const GraphicalArray *array)
bool is_not_null(T ptr)
predicate for comparison to nullptr