Skip to content
Snippets Groups Projects
TestMultiLayerItem.cpp 5.54 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "GUI/Model/Sample/LayerItem.h"
    #include "GUI/Model/Sample/LayerRoughnessItems.h"
    #include "GUI/Model/Sample/MultiLayerItem.h"
    #include "GUI/Model/Sample/SampleModel.h"
    #include "GUI/Model/Types/DoubleDescriptor.h"
    
    #include "Tests/GTestWrapper/google_test.h"
    
    class TestMultiLayerItem : public ::testing::Test {
    };
    
    
    //! Testing layer appearance (enabled, disabled) in a MultiLayer made of two default layers.
    
    //! In two layer system top and bottom layers should have disabled thickness and roughness.
    
    TEST_F(TestMultiLayerItem, twoLayerSystem)
    
        auto* multilayer = model.addMultiLayer();
    
        auto* top = multilayer->addLayer();
        auto* bottom = multilayer->addLayer();
    
    
        // Thickness property should be disabled for top and bottom layers
    
        EXPECT_FALSE(top->thicknessItem()->isEnabled());
        EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
    
    
        // Thickness value should be 0.0 for top and bottom layers
    
        EXPECT_EQ(top->thickness(), 0.0);
        EXPECT_EQ(bottom->thickness(), 0.0);
    
    
        // Roughness group property should be disabled for top, and enabled for bottom layers
    
        EXPECT_FALSE(top->roughnessItem()->isEnabled());
        EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
    
    
        // Default roughness should be "LayerZeroRoughness"
    
        EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(top->roughness().currentItem()));
        EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(bottom->roughness().currentItem()));
    
    
    //! Testing layer appearance (enabled, disabled) in a MultiLayer made of three default layers.
    
    //! In three layer system middle layer's thickness/roughness should be enabled.
    
    
    TEST_F(TestMultiLayerItem, threeLayerSystem)
    
        auto* multilayer = model.addMultiLayer();
    
        auto* top = multilayer->addLayer();
        auto* middle = multilayer->addLayer();
        auto* bottom = multilayer->addLayer();
    
    
        // Thickness property should be disabled for top and bottom layers and enabled for middle
    
        EXPECT_FALSE(top->thicknessItem()->isEnabled());
        EXPECT_TRUE(middle->thicknessItem()->isEnabled());
        EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
    
    
        // Thickness value should be 0.0 for top and bottom layers
    
        EXPECT_EQ(top->thickness(), 0.0);
        EXPECT_EQ(middle->thickness(), 0.0);
        EXPECT_EQ(bottom->thickness(), 0.0);
    
    
        // Roughness group property should be disabled for top, and enabled for other layers
    
        EXPECT_FALSE(top->roughnessItem()->isEnabled());
        EXPECT_TRUE(middle->roughnessItem()->isEnabled());
        EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
    
    
        // Default roughness should be "LayerZeroRoughness"
    
        EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(top->roughness().currentItem()));
        EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(middle->roughness().currentItem()));
        EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(bottom->roughness().currentItem()));
    
    }
    
    //! Testing middle layer appearance when it is moved to the top.
    
    //! In three layer system, the moving of middle layer on top should lead to the disabling
    //! of roughness/thickness.
    
    
    TEST_F(TestMultiLayerItem, movingMiddleLayerOnTop)
    
        auto* multilayer = model.addMultiLayer();
    
        auto* top = multilayer->addLayer();
        auto* middle = multilayer->addLayer();
        auto* bottom = multilayer->addLayer();
    
    
        const double thickness = 10.0;
    
        middle->thickness().set(thickness);
    
    
        // Thickness property should be disabled for top and bottom layers and enabled for middle
    
        EXPECT_FALSE(top->thicknessItem()->isEnabled());
        EXPECT_TRUE(middle->thicknessItem()->isEnabled());
        EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
    
    
        // Roughness group property should be disabled for top, and enabled for other layers
    
        EXPECT_FALSE(top->roughnessItem()->isEnabled());
        EXPECT_TRUE(middle->roughnessItem()->isEnabled());
        EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
    
    
        // Thickness value should be 0.0 for top and bottom layers
    
        EXPECT_EQ(top->thickness(), 0.0);
        EXPECT_EQ(middle->thickness(), thickness);
        EXPECT_EQ(bottom->thickness(), 0.0);
    
    
        // Moving middle layer to top
    
        multilayer->moveLayer(middle, top);
    
        // checking that middle is top now, and top layer is middle now
    
        EXPECT_EQ(middle, multilayer->layers().at(0));
        EXPECT_EQ(top, multilayer->layers().at(1));
    
    
        // Thickness and roughness of middle layer should be disabled now
    
        EXPECT_FALSE(middle->thicknessItem()->isEnabled());
    
        EXPECT_FALSE(middle->roughnessItem()->isEnabled());
    
        // And, thickness of middle should become 0 to stress the fact that it become top
    
        EXPECT_EQ(middle->thickness(), 0.0);
    
        // Thickness and roughness of former top layer should be enabled now, since it is in the middle
    
        EXPECT_TRUE(top->thicknessItem()->isEnabled());
    
        EXPECT_TRUE(top->roughnessItem()->isEnabled());
    
    }
    
    //! Testing layer appearance when it is moved from a MultiLayer to canvas.
    //!
    //! If top layer was moved to canvas, its thickness and roughness should be reenabled.
    
    
    TEST_F(TestMultiLayerItem, movingLayerOnCanvas)
    
        auto* multilayer = model.addMultiLayer();
    
        auto* top = model.insertItem<LayerItem>(multilayer);
    
        model.insertItem<LayerItem>(multilayer);
    
    
        // Moving top layer to canvas
        model.moveItem(top, nullptr);
    
        // checking that it was moved
        EXPECT_EQ(top->parent(), model.rootItem());
    
        // thickness should be reenabled
    
    Pospelov, Gennady's avatar
    Pospelov, Gennady committed
        //    EXPECT_TRUE(top->getItem(LayerItem::P_THICKNESS)->isEnabled());
        //    EXPECT_TRUE(top->getItem(LayerItem::P_THICKNESS)->isEnabled());