~centralelyon2010/inkscape/imagelinks2

650 by joncruz
Moved four more tests to CxxTest
1
#ifndef SEEN_SP_GRADIENT_TEST_H
2
#define SEEN_SP_GRADIENT_TEST_H
3
4
#include "document-using-test.h"
5
6
7
#include "sp-gradient.h"
8
#include "svg/svg.h"
9
#include "xml/repr.h"
6884 by Ted Gould
Merging from trunk
10
#include <2geom/transforms.h>
6887 by Ted Gould
Merge from trunk
11
#include "helper/geom.h"
650 by joncruz
Moved four more tests to CxxTest
12
13
class SPGradientTest : public DocumentUsingTest
14
{
15
public:
8422 by cilix42
Revert recent refactoring changes by johnce because they break the build, which cannot be fixed easily.
16
    SPDocument* _doc;
650 by joncruz
Moved four more tests to CxxTest
17
18
    SPGradientTest() :
19
        _doc(0)
20
    {
21
    }
22
23
    virtual ~SPGradientTest()
24
    {
25
        if ( _doc )
26
        {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
27
            _doc->doUnref();
650 by joncruz
Moved four more tests to CxxTest
28
        }
29
    }
30
31
    static void createSuiteSubclass( SPGradientTest *& dst )
32
    {
33
        SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
34
        if ( gr ) {
6887 by Ted Gould
Merge from trunk
35
            UTEST_ASSERT(gr->gradientTransform.isIdentity());
36
            UTEST_ASSERT(gr->gradientTransform == Geom::identity());
650 by joncruz
Moved four more tests to CxxTest
37
            g_object_unref(gr);
38
39
            dst = new SPGradientTest();
40
        }
41
    }
42
43
    static SPGradientTest *createSuite()
44
    {
45
        return Inkscape::createSuiteAndDocument<SPGradientTest>( createSuiteSubclass );
46
    }
47
48
    static void destroySuite( SPGradientTest *suite ) { delete suite; }
49
50
// -------------------------------------------------------------------------
51
// -------------------------------------------------------------------------
52
53
    void testSetGradientTransform()
54
    {
55
        SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
56
        SP_OBJECT(gr)->document = _doc;
57
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
58
        SP_OBJECT(gr)->setKeyValue( SP_ATTR_GRADIENTTRANSFORM, "translate(5, 8)");
59
        TS_ASSERT_EQUALS( gr->gradientTransform, Geom::Affine(Geom::Translate(5, 8)) );
650 by joncruz
Moved four more tests to CxxTest
60
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
61
        SP_OBJECT(gr)->setKeyValue( SP_ATTR_GRADIENTTRANSFORM, "");
6887 by Ted Gould
Merge from trunk
62
        TS_ASSERT_EQUALS( gr->gradientTransform, Geom::identity() );
650 by joncruz
Moved four more tests to CxxTest
63
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
64
        SP_OBJECT(gr)->setKeyValue( SP_ATTR_GRADIENTTRANSFORM, "rotate(90)");
65
        TS_ASSERT_EQUALS( gr->gradientTransform, Geom::Affine(rotate_degrees(90)) );
650 by joncruz
Moved four more tests to CxxTest
66
67
        g_object_unref(gr);
68
    }
69
70
71
    void testWrite()
72
    {
73
        SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
74
        SP_OBJECT(gr)->document = _doc;
75
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
76
        SP_OBJECT(gr)->setKeyValue( SP_ATTR_GRADIENTTRANSFORM, "matrix(0, 1, -1, 0, 0, 0)");
77
        Inkscape::XML::Document *xml_doc = _doc->getReprDoc();
2253 by mental
start switching sp_repr_new* over to XML::Document::create*, and rename create methods to match DOM
78
        Inkscape::XML::Node *repr = xml_doc->createElement("svg:radialGradient");
650 by joncruz
Moved four more tests to CxxTest
79
        SP_OBJECT(gr)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
80
        {
81
            gchar const *tr = repr->attribute("gradientTransform");
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
82
            Geom::Affine svd;
650 by joncruz
Moved four more tests to CxxTest
83
            bool const valid = sp_svg_transform_read(tr, &svd);
84
            TS_ASSERT( valid );
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
85
            TS_ASSERT_EQUALS( svd, Geom::Affine(rotate_degrees(90)) );
650 by joncruz
Moved four more tests to CxxTest
86
        }
87
88
        g_object_unref(gr);
89
    }
90
91
92
    void testGetG2dGetGs2dSetGs2d()
93
    {
94
        SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
95
        SP_OBJECT(gr)->document = _doc;
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
96
        Geom::Affine const grXform(2, 1,
650 by joncruz
Moved four more tests to CxxTest
97
                                 1, 3,
98
                                 4, 6);
99
        gr->gradientTransform = grXform;
6887 by Ted Gould
Merge from trunk
100
        Geom::Rect const unit_rect(Geom::Point(0, 0), Geom::Point(1, 1));
650 by joncruz
Moved four more tests to CxxTest
101
        {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
102
            Geom::Affine const g2d(sp_gradient_get_g2d_matrix(gr, Geom::identity(), unit_rect));
103
            Geom::Affine const gs2d(sp_gradient_get_gs2d_matrix(gr, Geom::identity(), unit_rect));
6887 by Ted Gould
Merge from trunk
104
            TS_ASSERT_EQUALS( g2d, Geom::identity() );
105
            TS_ASSERT( Geom::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
106
6887 by Ted Gould
Merge from trunk
107
            sp_gradient_set_gs2d_matrix(gr, Geom::identity(), unit_rect, gs2d);
108
            TS_ASSERT( Geom::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
109
        }
110
111
        gr->gradientTransform = grXform;
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
112
        Geom::Affine const funny(2, 3,
650 by joncruz
Moved four more tests to CxxTest
113
                               4, 5,
114
                               6, 7);
115
        {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
116
            Geom::Affine const g2d(sp_gradient_get_g2d_matrix(gr, funny, unit_rect));
117
            Geom::Affine const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, unit_rect));
650 by joncruz
Moved four more tests to CxxTest
118
            TS_ASSERT_EQUALS( g2d, funny );
6887 by Ted Gould
Merge from trunk
119
            TS_ASSERT( Geom::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
120
121
            sp_gradient_set_gs2d_matrix(gr, funny, unit_rect, gs2d);
6887 by Ted Gould
Merge from trunk
122
            TS_ASSERT( Geom::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
123
        }
124
125
        gr->gradientTransform = grXform;
6887 by Ted Gould
Merge from trunk
126
        Geom::Rect const larger_rect(Geom::Point(5, 6), Geom::Point(8, 10));
650 by joncruz
Moved four more tests to CxxTest
127
        {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
128
            Geom::Affine const g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
129
            Geom::Affine const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
130
            TS_ASSERT_EQUALS( g2d, Geom::Affine(3, 0,
650 by joncruz
Moved four more tests to CxxTest
131
                                              0, 4,
132
                                              5, 6) * funny );
6887 by Ted Gould
Merge from trunk
133
            TS_ASSERT( Geom::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
134
135
            sp_gradient_set_gs2d_matrix(gr, funny, larger_rect, gs2d);
6887 by Ted Gould
Merge from trunk
136
            TS_ASSERT( Geom::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
137
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
138
            SP_OBJECT(gr)->setKeyValue( SP_ATTR_GRADIENTUNITS, "userSpaceOnUse");
139
            Geom::Affine const user_g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
140
            Geom::Affine const user_gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
650 by joncruz
Moved four more tests to CxxTest
141
            TS_ASSERT_EQUALS( user_g2d, funny );
6887 by Ted Gould
Merge from trunk
142
            TS_ASSERT( Geom::matrix_equalp(user_gs2d, gr->gradientTransform * user_g2d, 1e-12) );
650 by joncruz
Moved four more tests to CxxTest
143
        }
144
        g_object_unref(gr);
145
    }
146
147
};
148
149
150
#endif // SEEN_SP_GRADIENT_TEST_H
151
152
/*
153
  Local Variables:
154
  mode:c++
155
  c-file-style:"stroustrup"
156
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
157
  indent-tabs-mode:nil
158
  fill-column:99
159
  End:
160
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
161
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :