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

Unit test for MaterialProperty in LayerItem context

parent a9678c6c
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@
#include "TestProxyModelStrategy.h"
#include "TestSessionItemUtils.h"
#include "TestComponentUtils.h"
#include "TestLayerItems.h"
#include <memory>
class GUITestFactory {
......@@ -83,6 +84,7 @@ int main(int argc, char** argv) {
// tests.add<TestGUIHelpers>();
// tests.add<TestFitParameterModel>();
tests.add<TestMaterialModel>();
tests.add<TestLayerItems>();
// tests.add<TestComboProperty>();
// tests.add<TestTranslations>();
// tests.add<TestGroupProperty>();
......
#include <QtTest>
#include "LayerItem.h"
#include "MaterialProperty.h"
#include "ApplicationModels.h"
#include "SampleModel.h"
#include "MaterialModel.h"
#include "MaterialItem.h"
#include "ModelMapper.h"
//! Tests for LayerItem
class TestLayerItems : public QObject {
Q_OBJECT
private slots:
void test_LayerDefaultMaterial();
void test_onMaterialChange();
};
//! Checking default material of the layer.
inline void TestLayerItems::test_LayerDefaultMaterial()
{
ApplicationModels models;
auto layer = models.sampleModel()->insertNewItem(Constants::LayerType);
auto materials = models.materialModel()->topItems();
auto defMaterial = materials.front();
MaterialProperty material = layer->getItemValue(LayerItem::P_MATERIAL).value<MaterialProperty>();
QCOMPARE(material.getName(), QString("Default"));
QCOMPARE(material.getIdentifier(), defMaterial->getItemValue(MaterialItem::P_IDENTIFIER).toString());
}
//! Checks that change of material in MaterialModel is propagated to the LayerItem.
inline void TestLayerItems::test_onMaterialChange()
{
ApplicationModels models;
auto layer = models.sampleModel()->insertNewItem(Constants::LayerType);
auto materials = models.materialModel()->topItems();
auto defMaterial = materials.front();
int property_changed(0);
layer->mapper()->setOnPropertyChange([&property_changed](const QString& name) {
if (name == LayerItem::P_MATERIAL)
++property_changed;
}, this);
defMaterial->setItemName("NewName");
QCOMPARE(property_changed, 2); // should be ==1, Fixme after implementing MaterialPropertyController
MaterialProperty material = layer->getItemValue(LayerItem::P_MATERIAL).value<MaterialProperty>();
QCOMPARE(material.getName(), QString("NewName"));
}
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