summaryrefslogtreecommitdiffstats
path: root/testfiles/src/lpe-test.cpp
blob: 87d263fda56f1e2457718151ee16b94daaa8a7c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * LPE tests
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2020 Authors
 *
 * Released under GNU GPL version 2 or later, read the file 'COPYING' for more information
 */

#include <gtest/gtest.h>
#include <testfiles/lpespaths-test.h>
#include <src/document.h>
#include <src/inkscape.h>
#include <src/live_effects/lpe-bool.h>
#include <src/object/sp-ellipse.h>
#include <src/object/sp-lpe-item.h>

using namespace Inkscape;
using namespace Inkscape::LivePathEffect;

class LPETest : public LPESPathsTest {
public:
    void run() {
        testDoc(svg);
    }
};

// A) FILE BASED TESTS
// TEST_F(LPETest, Bool_multi_px_1_1)                          { run(); }
// TEST_F(LPETest, Bool_multi_mm_1_1)                          { run(); }
TEST_F(LPETest, AttachPath_0_92_5_mixed)                    { run(); }
TEST_F(LPETest, AttachPath_mm_1_0_2)                        { run(); }
TEST_F(LPETest, AttachPath_px_1_0_2)                        { run(); }
TEST_F(LPETest, BoundingBox_mixed_0_92_5)                   { run(); }
TEST_F(LPETest, BoundingBox_mm_1_0_2)                       { run(); }
TEST_F(LPETest, BoundingBox_px_1_0_2)                       { run(); }
TEST_F(LPETest, CloneOriginal_mixed_0_92_5)                 { run(); }
// linked item is broken in 1.0.2 because group cliboard items, use same version of 1.1 but resaved in 1.2 to get comapat in 1.0.1 or before the group clipboard is added
TEST_F(LPETest, CloneOriginal_boken_1_0_2)                  { run(); }
TEST_F(LPETest, CloneOriginal_mixed_px_1_1)                 { run(); }
TEST_F(LPETest, CloneOriginal_mixed_mm_1_1)                 { run(); }
TEST_F(LPETest, ConstructGrid_mixed_0_92_5)                 { run(); }
TEST_F(LPETest, ConstructGrid_mm_1_0_2)                     { run(); }
TEST_F(LPETest, ConstructGrid_px_1_0_2)                     { run(); }
TEST_F(LPETest, Transform2Points_path_0_92_5)               { run(); }
TEST_F(LPETest, Transform2Points_multi_px_1_0_2)            { run(); }
TEST_F(LPETest, Transform2Points_multi_mm_1_0_2)            { run(); }
TEST_F(LPETest, VonCoch_path_0_92_5)                        { run(); }
TEST_F(LPETest, VonCoch_multi_px_1_0_2)                     { run(); }
TEST_F(LPETest, VonCoch_multi_mm_1_0_2)                     { run(); }
TEST_F(LPETest, StitchSubPaths_path_0_92_5)                 { run(); }
TEST_F(LPETest, StitchSubPaths_multi_px_1_0_2)              { run(); }
TEST_F(LPETest, StitchSubPaths_multi_mm_1_0_2)              { run(); }
TEST_F(LPETest, Spiro_mixed_0_92_5)                         { run(); }
TEST_F(LPETest, Spiro_mm_1_0_2)                             { run(); }
TEST_F(LPETest, Spiro_px_1_0_2)                             { run(); }
TEST_F(LPETest, Slice_multi_px_1_1)                         { run(); }
TEST_F(LPETest, Slice_multi_mm_1_1)                         { run(); }
TEST_F(LPETest, Simplify_path_0_92_5)                       { run(); }
TEST_F(LPETest, Simplify_multi_px_1_0_2)                    { run(); }
TEST_F(LPETest, Simplify_multi_mm_1_0_2)                    { run(); }
TEST_F(LPETest, ShowHandles_path_0_92_5)                    { run(); }
TEST_F(LPETest, ShowHandles_multi_px_1_0_2)                 { run(); }
TEST_F(LPETest, ShowHandles_multi_mm_1_0_2)                 { run(); }
TEST_F(LPETest, Ruler_path_0_92_5)                          { run(); }
TEST_F(LPETest, Ruler_multi_px_1_0_2)                       { run(); }
TEST_F(LPETest, Ruler_multi_mm_1_0_2)                       { run(); }
TEST_F(LPETest, RoughHatches_path_0_92_5)                   { run(); }
TEST_F(LPETest, RoughHatches_multi_px_1_0_2)                { run(); }
TEST_F(LPETest, RoughHatches_multi_mm_1_0_2)                { run(); }
// Rougen Test till 1.1 fail because wrong implementation of rand on the LPE
TEST_F(LPETest, Roughen_path_1_1)                           { run(); }
TEST_F(LPETest, EllipseFromPoints_multi_px_1_0_2)           { run(); }
TEST_F(LPETest, EllipseFromPoints_multi_mm_1_0_2)           { run(); }
TEST_F(LPETest, PowerMask_multi_px_1_0_2)                   { run(); }
TEST_F(LPETest, PowerMask_multi_mm_1_0_2)                   { run(); }
TEST_F(LPETest, PowerClip_multi_px_1_0_2)                   { run(); }
TEST_F(LPETest, PowerClip_multi_mm_1_0_2)                   { run(); }
TEST_F(LPETest, PerspectiveEnvelope_mixed_0_92_5)           { run(); }
TEST_F(LPETest, PerspectiveEnvelope_multi_mm_1_0_2)         { run(); }
TEST_F(LPETest, PerspectiveEnvelope_multi_px_1_0_2)         { run(); }
TEST_F(LPETest, Offset_multi_px_1_0_2)                      { run(); }
TEST_F(LPETest, Offset_multi_mm_1_0_2)                      { run(); }
TEST_F(LPETest, Offset_multi_px_1_1)                        { run(); }
TEST_F(LPETest, MirrorSymmetry_path_0_92_5)                 { run(); }
TEST_F(LPETest, MirrorSymmetry_multi_px_1_0_2)              { run(); }
TEST_F(LPETest, MirrorSymmetry_multi_mm_1_0_2)              { run(); }
TEST_F(LPETest, MeasureSegments_multi_px_1_0_2)             { run(); }
TEST_F(LPETest, MeasureSegments_multi_mm_1_0_2)             { run(); }
TEST_F(LPETest, Lattice2_path_0_92_5)                       { run(); }
TEST_F(LPETest, Lattice2_multi_px_1_0_2)                    { run(); }
TEST_F(LPETest, Lattice2_multi_mm_1_0_2)                    { run(); }
TEST_F(LPETest, Knot_path_0_92_5)                           { run(); }
TEST_F(LPETest, Knot_multi_px_1_0_2)                        { run(); }
TEST_F(LPETest, Knot_multi_mm_1_0_2)                        { run(); }
TEST_F(LPETest, JoinType_multi_px_1_0_2)                    { run(); }
TEST_F(LPETest, JoinType_multi_mm_1_0_2)                    { run(); }
TEST_F(LPETest, Interpolate_path_0_92_5)                    { run(); }
TEST_F(LPETest, Interpolate_multi_px_1_0_2)                 { run(); }
TEST_F(LPETest, Interpolate_multi_mm_1_0_2)                 { run(); }
TEST_F(LPETest, InterpolatePoints_path_0_92_5)              { run(); }
TEST_F(LPETest, InterpolatePoints_multi_px_1_0_2)           { run(); }
TEST_F(LPETest, InterpolatePoints_multi_mm_1_0_2)           { run(); }
TEST_F(LPETest, Gears_path_0_92_5)                          { run(); }
TEST_F(LPETest, Gears_multi_px_1_0_2)                       { run(); }
TEST_F(LPETest, Gears_multi_mm_1_0_2)                       { run(); }
TEST_F(LPETest, FilletChamfer_multi_px_1_0_2)               { run(); }
TEST_F(LPETest, FilletChamfer_multi_mm_1_0_2)               { run(); }
// NEED to test on 0.92 no working one here (gnome 40)
// TEST_F(LPETest, FillBetweenStrokes_path_0_92_5)          { run(); }
TEST_F(LPETest, FillBetweenStrokes_path_multi_px_1_0_2)     { run(); }
TEST_F(LPETest, FillBetweenStrokes_path_multi_mm_1_0_2)     { run(); }
// NEED to test on 0.92 no working one here (gnome 40)
// TEST_F(LPETest, FillBetweenMany_multi_0_92_5)               { run(); }
TEST_F(LPETest, FillBetweenMany_multi_px_1_0_2)             { run(); }
TEST_F(LPETest, FillBetweenMany_multi_mm_1_0_2)             { run(); }
TEST_F(LPETest, Ellipse5pts_path_0_92_5)                    { run(); }
TEST_F(LPETest, Ellipse5pts_ellipse_px_1_0_2)               { run(); }
TEST_F(LPETest, Ellipse5pts_ellipse_mm_1_0_2)               { run(); }
TEST_F(LPETest, DashedStroke_multi_px_1_0_2)                { run(); }
TEST_F(LPETest, DashedStroke_multi_mm_1_0_2)                { run(); }
TEST_F(LPETest, RotateCopies_multi_mm_1_0_2)                { run(); }
TEST_F(LPETest, RotateCopies_multi_px_1_0_2)                { run(); }
// B) CUSTOM TESTS
// BOOL LPE
TEST_F(LPETest, Bool_canBeApplyedToNonSiblingPaths)
{
    std::string svg("\
<svg width='100' height='100'\
  xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'\
  xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape'>\
  <defs>\
    <inkscape:path-effect\
      id='path-effect1'\
      effect='bool_op'\
      operation='diff'\
      operand-path='#circle1'\
      lpeversion='1'\
      hide-linked='true' />\
  </defs>\
  <path id='rect1'\
    inkscape:path-effect='#path-effect1'\
    sodipodi:type='rect'\
    width='100' height='100' fill='#ff0000' />\
  <g id='group1'>\
    <circle id='circle1'\
      r='40' cy='50' cx='50' fill='#ffffff' style='display:inline'/>\
  </g>\
</svg>");

    SPDocument *doc = SPDocument::createNewDocFromMem(svg.c_str(), svg.size(), true);
    doc->ensureUpToDate();

    auto lpe_item = dynamic_cast<SPLPEItem *>(doc->getObjectById("rect1"));
    ASSERT_TRUE(lpe_item != nullptr);

    auto lpe_bool_op_effect = dynamic_cast<LPEBool *>(lpe_item->getFirstPathEffectOfType(EffectType::BOOL_OP));
    ASSERT_TRUE(lpe_bool_op_effect != nullptr);

    auto operand_path = lpe_bool_op_effect->getParameter("operand-path")->param_getSVGValue();
    auto circle = dynamic_cast<SPGenericEllipse *>(doc->getObjectById(operand_path.substr(1)));
    ASSERT_TRUE(circle != nullptr);
}