Skip to content
Snippets Groups Projects
Commit 3bd3b146 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

First Qt unit test for AnisoPyramidItem

parent 052face5
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@ endif()
if(BORNAGAIN_GUI)
add_subdirectory(GUI)
add_subdirectory(Tests/UnitTests/TestGUI)
endif()
add_subdirectory(Tests/FunctionalTests) # functional tests (make check)
......
......@@ -169,14 +169,15 @@ void GUIObjectBuilder::visit(const FormFactorAnisoPyramid *sample)
ParameterizedItem *particleItem = m_levelToParent[getLevel()-1];
ParameterizedItem *ffItem = particleItem->setGroupProperty(
ParticleItem::P_FORM_FACTOR, "AnisoPyramid");
ffItem->setRegisteredProperty(AnisoPyramidItem::P_LENGTH,
sample->getLength());
ffItem->setRegisteredProperty(AnisoPyramidItem::P_WIDTH,
sample->getWidth());
ffItem->setRegisteredProperty(AnisoPyramidItem::P_HEIGHT,
sample->getHeight());
ffItem->setRegisteredProperty(AnisoPyramidItem::P_ALPHA,
Units::rad2deg(sample->getAlpha()));
// ffItem->setRegisteredProperty(AnisoPyramidItem::P_LENGTH,
// sample->getLength());
// ffItem->setRegisteredProperty(AnisoPyramidItem::P_WIDTH,
// sample->getWidth());
// ffItem->setRegisteredProperty(AnisoPyramidItem::P_HEIGHT,
// sample->getHeight());
// ffItem->setRegisteredProperty(AnisoPyramidItem::P_ALPHA,
// Units::rad2deg(sample->getAlpha()));
TransformFromDomain::setItemFromSample(ffItem, sample);
m_levelToParent[getLevel()] = particleItem;
}
......
......@@ -195,14 +195,13 @@ ParameterizedItem * ParameterizedItem::setGroupProperty(
void ParameterizedItem::registerProperty(const QString &name, const QVariant &variant, PropertyAttribute property_attribute)
{
qDebug() << " XXX ParameterizedItem::registerProperty() " << modelType() << name;
//qDebug() << " XXX ParameterizedItem::registerProperty() " << modelType() << name;
if(m_registered_properties.contains(name))
throw GUIHelpers::Error("ParameterizedItem::registerProperty() -> Error. Already existing property "+name);
m_registered_properties << name;
m_property_attribute[name] = property_attribute;
//if(visibility == HiddenProperty) m_hidden_properties << name;
setProperty(name.toUtf8().constData(), variant);
}
......
......@@ -8,11 +8,27 @@
#include "Numeric.h"
#include "Units.h"
#include "GUIHelpers.h"
#include "FormFactors.h"
#include "FormFactorItems.h"
#include <QString>
#include <QDebug>
#include <vector>
void TransformFromDomain::setItemFromSample(ParameterizedItem *item,
const FormFactorAnisoPyramid *sample)
{
item->setRegisteredProperty(AnisoPyramidItem::P_LENGTH,
sample->getLength());
item->setRegisteredProperty(AnisoPyramidItem::P_WIDTH,
sample->getWidth());
item->setRegisteredProperty(AnisoPyramidItem::P_HEIGHT,
sample->getHeight());
item->setRegisteredProperty(AnisoPyramidItem::P_ALPHA,
Units::rad2deg(sample->getAlpha()));
}
void TransformFromDomain::setItemFromSample(ParameterizedItem *item,
const InterferenceFunction2DParaCrystal *sample)
{
......
#ifndef TRANSFORMFROMDOMAIN_H
#define TRANSFORMFROMDOMAIN_H
class FormFactorAnisoPyramid;
class ParameterizedItem;
class InterferenceFunction2DParaCrystal;
class InterferenceFunction1DParaCrystal;
namespace TransformFromDomain
{
void setItemFromSample(ParameterizedItem *item,
const FormFactorAnisoPyramid *sample);
void setItemFromSample(ParameterizedItem *item,
const InterferenceFunction2DParaCrystal *sample);
void setItemFromSample(ParameterizedItem *item,
const InterferenceFunction1DParaCrystal *sample);
......
############################################################################
# CMakeLists.txt file for building and running unit tests
############################################################################
enable_testing()
file(GLOB source_files "*.cpp")
file(GLOB include_files "*.h")
find_package(Qt5Widgets REQUIRED)
include_directories(
${Boost_INCLUDE_DIRS}
${BornAgainCore_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
# ${GSL_INCLUDE_DIR}
${BornAgainGUI_INCLUDE_DIRS}
)
# to build executable right in lib directory to not to have problems with finding libBornAgainCore.dll under Windows
#set_property(TARGET TestGUI PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_AUTOMOC ON)
add_executable( TestGUI ${source_files} ${include_files})
target_link_libraries(TestGUI
${BornAgainCore_LIBRARY}
# ${Boost_LIBRARIES}
# ${GSL_LIBRARIES}
${BornAgainGUI_LIBRARY}
)
qt5_use_modules(TestGUI Widgets Core Gui Script Designer PrintSupport Test)
add_test( TestGUI TestGUI) # TestName ExeName
# add execution of TestCore just after compilation
add_custom_command(TARGET TestGUI POST_BUILD COMMAND TestGUI)
#ifndef TESTFORMFACTORITEMS_H
#define TESTFORMFACTORITEMS_H
#include <QtTest>
#include "FormFactors.h"
#include "FormFactorItems.h"
#include "TransformToDomain.h"
#include "TransformFromDomain.h"
#include "Units.h"
#include "Numeric.h"
class TestFormFactorItems : public QObject {
Q_OBJECT
private slots:
void test_AnisoPyramidItem();
private:
};
#endif
inline void TestFormFactorItems::test_AnisoPyramidItem()
{
// to domain
AnisoPyramidItem item;
item.setRegisteredProperty(AnisoPyramidItem::P_LENGTH, 20.0);
item.setRegisteredProperty(AnisoPyramidItem::P_WIDTH, 16.0);
item.setRegisteredProperty(AnisoPyramidItem::P_HEIGHT, 13.0);
item.setRegisteredProperty(AnisoPyramidItem::P_ALPHA, 60.0);
FormFactorAnisoPyramid *ff = dynamic_cast<FormFactorAnisoPyramid *>(TransformToDomain::createFormFactor(item));
QVERIFY(ff);
QVERIFY(ff->getLength() == 20.0);
QVERIFY(ff->getWidth() == 16.0);
QVERIFY(ff->getHeight() == 13.0);
QVERIFY( Numeric::areAlmostEqual(ff->getAlpha(), Units::deg2rad(60.0)));
delete ff;
// from domain
FormFactorAnisoPyramid ff2(2.0, 1.6, 1.3, 70.0*Units::degree);
AnisoPyramidItem item2;
TransformFromDomain::setItemFromSample(&item2, &ff2);
QVERIFY(item2.getRegisteredProperty(AnisoPyramidItem::P_LENGTH).toDouble() == 2.0);
QVERIFY(item2.getRegisteredProperty(AnisoPyramidItem::P_WIDTH).toDouble() == 1.6);
QVERIFY(item2.getRegisteredProperty(AnisoPyramidItem::P_HEIGHT).toDouble() == 1.3);
QVERIFY(item2.getRegisteredProperty(AnisoPyramidItem::P_ALPHA).toDouble() == 70.0);
}
#include <QtTest>
#include <QString>
#include <QDebug>
#include "TestFormFactorItems.h"
int main(int argc, char** argv) {
QApplication app(argc, argv);
TestFormFactorItems test1;
return QTest::qExec(&test1, argc, argv);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment