1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #include <gtest/gtest.h>
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"
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
)
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) {
133 TEST(SPObjectTagsTest
, compare_dynamic_cast
)
137 Inkscape::ColorProfile
,
138 LivePathEffectObject
,
151 SPFeComponentTransfer
,
161 SPFeSpecularLighting
,
232 >([&] (char const *a
, char const *b
, bool b1
, bool b2
) {
233 ADD_FAILURE() << "For downcasting " << a
<< " -> " << b
<< ", got " << b2
<< ", expected " << b1
;