Fixes broken export to PDF with links.
[inkscape.git] / testfiles / src / sp-object-tags-test.cpp
blob89db0151c5d5623a40f389fb94bc61d085d26bfa
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #include <gtest/gtest.h>
3 #include <functional>
4 #include <typeinfo>
6 #include "object/box3d.h"
7 #include "object/box3d-side.h"
8 #include "object/color-profile.h"
9 #include "object/persp3d.h"
10 #include "object/sp-anchor.h"
11 #include "object/sp-clippath.h"
12 #include "object/sp-defs.h"
13 #include "object/sp-desc.h"
14 #include "object/sp-ellipse.h"
15 #include "object/sp-filter.h"
16 #include "object/sp-flowdiv.h"
17 #include "object/sp-flowregion.h"
18 #include "object/sp-flowtext.h"
19 #include "object/sp-font.h"
20 #include "object/sp-font-face.h"
21 #include "object/sp-glyph.h"
22 #include "object/sp-glyph-kerning.h"
23 #include "object/sp-grid.h"
24 #include "object/sp-guide.h"
25 #include "object/sp-hatch.h"
26 #include "object/sp-hatch-path.h"
27 #include "object/sp-image.h"
28 #include "object/sp-line.h"
29 #include "object/sp-linear-gradient.h"
30 #include "object/sp-marker.h"
31 #include "object/sp-mask.h"
32 #include "object/sp-mesh-gradient.h"
33 #include "object/sp-mesh-patch.h"
34 #include "object/sp-mesh-row.h"
35 #include "object/sp-metadata.h"
36 #include "object/sp-missing-glyph.h"
37 #include "object/sp-namedview.h"
38 #include "object/sp-offset.h"
39 #include "object/sp-page.h"
40 #include "object/sp-path.h"
41 #include "object/sp-pattern.h"
42 #include "object/sp-polyline.h"
43 #include "object/sp-radial-gradient.h"
44 #include "object/sp-rect.h"
45 #include "object/sp-root.h"
46 #include "object/sp-script.h"
47 #include "object/sp-solid-color.h"
48 #include "object/sp-spiral.h"
49 #include "object/sp-star.h"
50 #include "object/sp-stop.h"
51 #include "object/sp-string.h"
52 #include "object/sp-style-elem.h"
53 #include "object/sp-switch.h"
54 #include "object/sp-symbol.h"
55 #include "object/sp-tag.h"
56 #include "object/sp-tag-use.h"
57 #include "object/sp-text.h"
58 #include "object/sp-textpath.h"
59 #include "object/sp-title.h"
60 #include "object/sp-tref.h"
61 #include "object/sp-tspan.h"
62 #include "object/sp-use.h"
63 #include "live_effects/lpeobject.h"
64 #include "object/filters/blend.h"
65 #include "object/filters/colormatrix.h"
66 #include "object/filters/componenttransfer.h"
67 #include "object/filters/componenttransfer-funcnode.h"
68 #include "object/filters/composite.h"
69 #include "object/filters/convolvematrix.h"
70 #include "object/filters/diffuselighting.h"
71 #include "object/filters/displacementmap.h"
72 #include "object/filters/distantlight.h"
73 #include "object/filters/flood.h"
74 #include "object/filters/gaussian-blur.h"
75 #include "object/filters/image.h"
76 #include "object/filters/merge.h"
77 #include "object/filters/mergenode.h"
78 #include "object/filters/morphology.h"
79 #include "object/filters/offset.h"
80 #include "object/filters/pointlight.h"
81 #include "object/filters/specularlighting.h"
82 #include "object/filters/spotlight.h"
83 #include "object/filters/tile.h"
84 #include "object/filters/turbulence.h"
86 namespace {
88 // Error reporting function, because asserts can only be used inside test body.
89 using F = std::function<void(char const*, char const*, bool, bool)>;
91 // Ensure tree structure is consistent with actual class hierarchy.
92 template <typename A, typename B>
93 void test_real(F const &f)
95 constexpr bool b1 = std::is_base_of_v<A, B>;
96 constexpr bool b2 = first_tag<A> <= tag_of<B> && tag_of<B> <= last_tag<A>;
98 if constexpr (b1 != b2) {
99 f(typeid(A).name(), typeid(B).name(), b1, b2);
103 template <typename A, typename B>
104 void test_dispatcher2(F const &f)
106 test_real<A, B>(f);
107 test_real<B, A>(f);
110 template <typename A, typename B, typename... T>
111 void test_dispatcher(F const &f)
113 test_dispatcher2<A, B>(f);
114 if constexpr (sizeof...(T) >= 1) {
115 test_dispatcher<A, T...>(f);
119 // Calls test_real<A, B> for all distinct pairs of types A, B in T.
120 template <typename A, typename... T>
121 void test(F const &f)
123 if constexpr (sizeof...(T) >= 1) {
124 test_dispatcher<A, T...>(f);
126 if constexpr (sizeof...(T) >= 2) {
127 test<T...>(f);
131 } // namespace
133 TEST(SPObjectTagsTest, compare_dynamic_cast)
135 test<
136 SPObject,
137 Inkscape::ColorProfile,
138 LivePathEffectObject,
139 Persp3D,
140 SPDefs,
141 SPDesc,
142 SPFeDistantLight,
143 SPFeFuncNode,
144 SPFeMergeNode,
145 SPFePointLight,
146 SPFeSpotLight,
147 SPFilter,
148 SPFilterPrimitive,
149 SPFeBlend,
150 SPFeColorMatrix,
151 SPFeComponentTransfer,
152 SPFeComposite,
153 SPFeConvolveMatrix,
154 SPFeDiffuseLighting,
155 SPFeDisplacementMap,
156 SPFeFlood,
157 SPFeImage,
158 SPFeMerge,
159 SPFeMorphology,
160 SPFeOffset,
161 SPFeSpecularLighting,
162 SPFeTile,
163 SPFeTurbulence,
164 SPGaussianBlur,
165 SPFlowline,
166 SPFlowregionbreak,
167 SPFont,
168 SPFontFace,
169 SPGlyph,
170 SPGlyphKerning,
171 SPHkern,
172 SPVkern,
173 SPGrid,
174 SPGuide,
175 SPHatchPath,
176 SPItem,
177 SPFlowdiv,
178 SPFlowpara,
179 SPFlowregion,
180 SPFlowregionExclude,
181 SPFlowtext,
182 SPFlowtspan,
183 SPImage,
184 SPLPEItem,
185 SPGroup,
186 SPAnchor,
187 SPBox3D,
188 SPMarker,
189 SPRoot,
190 SPSwitch,
191 SPSymbol,
192 SPShape,
193 SPGenericEllipse,
194 SPLine,
195 SPOffset,
196 SPPath,
197 SPPolyLine,
198 SPPolygon,
199 Box3DSide,
200 SPRect,
201 SPSpiral,
202 SPStar,
203 SPTRef,
204 SPTSpan,
205 SPText,
206 SPTextPath,
207 SPUse,
208 SPMeshpatch,
209 SPMeshrow,
210 SPMetadata,
211 SPMissingGlyph,
212 SPObjectGroup,
213 SPClipPath,
214 SPMask,
215 SPNamedView,
216 SPPage,
217 SPPaintServer,
218 SPGradient,
219 SPLinearGradient,
220 SPMeshGradient,
221 SPRadialGradient,
222 SPHatch,
223 SPPattern,
224 SPSolidColor,
225 SPScript,
226 SPStop,
227 SPString,
228 SPStyleElem,
229 SPTag,
230 SPTagUse,
231 SPTitle
232 >([&] (char const *a, char const *b, bool b1, bool b2) {
233 ADD_FAILURE() << "For downcasting " << a << " -> " << b << ", got " << b2 << ", expected " << b1;