From 3e4d271a22fac888e9e78480ba8e9b6e39ed73a1 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 13 Mar 2017 13:23:15 +0100 Subject: [PATCH] Detector GUI's unit test moved to dedicated file. --- Tests/UnitTests/GUI/TestDetectorItems.h | 31 +++++++++++ Tests/UnitTests/GUI/TestGUI.cpp | 3 ++ Tests/UnitTests/GUI/TestMapperCases.h | 72 +++++-------------------- 3 files changed, 48 insertions(+), 58 deletions(-) create mode 100644 Tests/UnitTests/GUI/TestDetectorItems.h diff --git a/Tests/UnitTests/GUI/TestDetectorItems.h b/Tests/UnitTests/GUI/TestDetectorItems.h new file mode 100644 index 00000000000..b641be82746 --- /dev/null +++ b/Tests/UnitTests/GUI/TestDetectorItems.h @@ -0,0 +1,31 @@ +#include <QtTest> +#include "RectangularDetectorItem.h" +#include "InstrumentModel.h" +#include "ComboProperty.h" + +class TestDetectorItems : public QObject { + Q_OBJECT + +private slots: + void test_detectorAlignment(); +}; + +inline void TestDetectorItems::test_detectorAlignment() +{ + InstrumentModel model; + SessionItem* detector = model.insertNewItem(Constants::RectangularDetectorType); + + ComboProperty alignment + = detector->getItemValue(RectangularDetectorItem::P_ALIGNMENT).value<ComboProperty>(); + // generic has some more items visible + alignment.setValue(Constants::ALIGNMENT_GENERIC); + detector->setItemValue(RectangularDetectorItem::P_ALIGNMENT, + QVariant::fromValue<ComboProperty>(alignment)); + QVERIFY(detector->getItem(RectangularDetectorItem::P_NORMAL)->isVisible()); + + // should be disabled if we switch + alignment.setValue(Constants::ALIGNMENT_TO_REFLECTED_BEAM); + detector->setItemValue(RectangularDetectorItem::P_ALIGNMENT, + QVariant::fromValue<ComboProperty>(alignment)); + QVERIFY(detector->getItem(RectangularDetectorItem::P_NORMAL)->isVisible() == false); +} diff --git a/Tests/UnitTests/GUI/TestGUI.cpp b/Tests/UnitTests/GUI/TestGUI.cpp index 4993478816b..ef8dabe9441 100644 --- a/Tests/UnitTests/GUI/TestGUI.cpp +++ b/Tests/UnitTests/GUI/TestGUI.cpp @@ -20,6 +20,7 @@ #include "TestTranslations.h" #include "TestGroupProperty.h" #include "TestParameterTreeUtils.h" +#include "TestDetectorItems.h" int main(int argc, char** argv) { QCoreApplication app(argc, argv); @@ -46,6 +47,7 @@ int main(int argc, char** argv) { TestGroupProperty testGroupProperty; TestParticleDistributionItem testParticleDistributionItem; TestParameterTreeUtils testParameterTreeUtils; + TestDetectorItems testDetectorItems; bool status(false); @@ -69,6 +71,7 @@ int main(int argc, char** argv) { status |= QTest::qExec(&testGroupProperty, argc, argv); status |= QTest::qExec(&testParticleDistributionItem, argc, argv); status |= QTest::qExec(&testParameterTreeUtils, argc, argv); + status |= QTest::qExec(&testDetectorItems, argc, argv); return status; } diff --git a/Tests/UnitTests/GUI/TestMapperCases.h b/Tests/UnitTests/GUI/TestMapperCases.h index 61741d9e4b0..3bf0c366f9e 100644 --- a/Tests/UnitTests/GUI/TestMapperCases.h +++ b/Tests/UnitTests/GUI/TestMapperCases.h @@ -1,97 +1,53 @@ -#include "SessionItem.h" #include "SampleModel.h" -#include "InstrumentModel.h" -#include "item_constants.h" #include "ParticleItem.h" -#include "ParticleCompositionItem.h" -#include "InterferenceFunctionItems.h" #include "ParticleLayoutItem.h" -#include "DetectorItems.h" -#include "SphericalDetectorItem.h" -#include "RectangularDetectorItem.h" #include "ComboProperty.h" #include "DocumentModel.h" #include "SimulationOptionsItem.h" -#include "Lattice2DItems.h" -#include <memory> #include <QtTest> -class TestMapperCases : public QObject { +class TestMapperCases : public QObject +{ Q_OBJECT private slots: void test_ParticeleCompositionUpdate(); - void test_instrumentAlignmentPropertyVisibility(); -// void test_removeMaskOnDetectorChange(); void test_SimulationOptionsComputationToggle(); }; inline void TestMapperCases::test_ParticeleCompositionUpdate() { SampleModel model; - SessionItem *multilayer = model.insertNewItem(Constants::MultiLayerType); - SessionItem *layer = model.insertNewItem(Constants::LayerType, multilayer->index()); - SessionItem *layout = model.insertNewItem(Constants::ParticleLayoutType, layer->index()); + SessionItem* multilayer = model.insertNewItem(Constants::MultiLayerType); + SessionItem* layer = model.insertNewItem(Constants::LayerType, multilayer->index()); + SessionItem* layout = model.insertNewItem(Constants::ParticleLayoutType, layer->index()); // composition added to layout should have abundance enabled - SessionItem *compositionFree = model.insertNewItem(Constants::ParticleCompositionType, layout->index()); + SessionItem* compositionFree + = model.insertNewItem(Constants::ParticleCompositionType, layout->index()); QVERIFY(compositionFree->getItem(ParticleItem::P_ABUNDANCE)->isEnabled()); // composition added to distribution should have abundance disabled - SessionItem *distribution = model.insertNewItem(Constants::ParticleDistributionType, layout->index()); - SessionItem *composition = model.insertNewItem(Constants::ParticleCompositionType, distribution->index()); + SessionItem* distribution + = model.insertNewItem(Constants::ParticleDistributionType, layout->index()); + SessionItem* composition + = model.insertNewItem(Constants::ParticleCompositionType, distribution->index()); QVERIFY(composition->getItem(ParticleItem::P_ABUNDANCE)->isEnabled() == false); composition = distribution->takeRow(composition->parentRow()); QVERIFY(composition->getItem(ParticleItem::P_ABUNDANCE)->isEnabled()); delete composition; - -} - -inline void TestMapperCases::test_instrumentAlignmentPropertyVisibility() -{ - InstrumentModel model; - SessionItem *instrument = model.insertNewItem(Constants::InstrumentType); - SessionItem *detector = model.insertNewItem(Constants::DetectorContainerType, instrument->index()); - detector->setGroupProperty(DetectorContainerItem::P_DETECTOR, Constants::RectangularDetectorType); - SessionItem *rectangular = detector->getGroupItem(DetectorContainerItem::P_DETECTOR); - - - ComboProperty alignment = rectangular->getItemValue(RectangularDetectorItem::P_ALIGNMENT) - .value<ComboProperty>(); - // generic has some more items visible - alignment.setValue(Constants::ALIGNMENT_GENERIC); - rectangular->setItemValue(RectangularDetectorItem::P_ALIGNMENT, QVariant::fromValue<ComboProperty>(alignment)); - QVERIFY(rectangular->getItem(RectangularDetectorItem::P_NORMAL)->isVisible()); - - // should be disabled if we switch - alignment.setValue(Constants::ALIGNMENT_TO_REFLECTED_BEAM); - rectangular->setItemValue(RectangularDetectorItem::P_ALIGNMENT, QVariant::fromValue<ComboProperty>(alignment)); - QVERIFY(rectangular->getItem(RectangularDetectorItem::P_NORMAL)->isVisible() == false); - } -//inline void TestMapperCases::test_removeMaskOnDetectorChange() -//{ -// InstrumentModel model; -// SessionItem *instrument = model.insertNewItem(Constants::InstrumentType); -// SessionItem *detector = model.insertNewItem(Constants::DetectorContainerType, instrument->index()); -// detector->setGroupProperty(DetectorContainerItem::P_DETECTOR, Constants::RectangularDetectorType); -// model.insertNewItem(Constants::MaskContainerType, detector->index()); -// QVERIFY(detector->getItems(DetectorContainerItem::T_MASKS).size() == 1); -// // after change the mask container should be removed -// detector->setGroupProperty(DetectorContainerItem::P_DETECTOR, Constants::SphericalDetectorType); -// QVERIFY(detector->getItems(DetectorContainerItem::T_MASKS).size() == 0); -//} - inline void TestMapperCases::test_SimulationOptionsComputationToggle() { DocumentModel model; model.insertNewItem(Constants::SimulationOptionsType); - SimulationOptionsItem *item = model.getSimulationOptionsItem(); + SimulationOptionsItem* item = model.getSimulationOptionsItem(); - ComboProperty combo = item->getItemValue(SimulationOptionsItem::P_COMPUTATION_METHOD).value<ComboProperty>(); + ComboProperty combo + = item->getItemValue(SimulationOptionsItem::P_COMPUTATION_METHOD).value<ComboProperty>(); QCOMPARE(combo.getValue(), Constants::SIMULATION_ANALYTICAL); QVERIFY(item->getItem(SimulationOptionsItem::P_MC_POINTS)->isEnabled() == false); -- GitLab