Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / color-profile-test.h
2 #ifndef SEEN_COLOR_PROFILE_TEST_H
3 #define SEEN_COLOR_PROFILE_TEST_H
5 #include <cxxtest/TestSuite.h>
6 #include <cassert>
8 #include "test-helpers.h"
11 #include "color-profile.h"
12 #include "color-profile-fns.h"
14 class ColorProfileTest : public CxxTest::TestSuite
15 {
16 public:
17     SPDocument* _doc;
19     ColorProfileTest() :
20         _doc(0)
21     {
22     }
24     virtual ~ColorProfileTest()
25     {
26         if ( _doc )
27         {
28             _doc->doUnref();
29         }
30     }
32     static void createSuiteSubclass( ColorProfileTest*& dst )
33     {
34         Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
35         if ( prof ) {
36             if ( prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN ) {
37                 TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
38                 dst = new ColorProfileTest();
39             }
40             g_object_unref(prof);
41         }
42     }
44 // createSuite and destroySuite get us per-suite setup and teardown
45 // without us having to worry about static initialization order, etc.
46     static ColorProfileTest *createSuite()
47     {
48         ColorProfileTest* suite = Inkscape::createSuiteAndDocument<ColorProfileTest>( createSuiteSubclass );
49         return suite;
50     }
52     static void destroySuite( ColorProfileTest *suite )
53     {
54         delete suite; 
55     }
57     // ---------------------------------------------------------------
58     // ---------------------------------------------------------------
59     // ---------------------------------------------------------------
61     void testSetRenderingIntent()
62     {
63         struct {
64             gchar const *attr;
65             guint intVal;
66         }
67         const cases[] = {
68             {"auto", (guint)Inkscape::RENDERING_INTENT_AUTO},
69             {"perceptual", (guint)Inkscape::RENDERING_INTENT_PERCEPTUAL},
70             {"relative-colorimetric", (guint)Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC},
71             {"saturation", (guint)Inkscape::RENDERING_INTENT_SATURATION},
72             {"absolute-colorimetric", (guint)Inkscape::RENDERING_INTENT_ABSOLUTE_COLORIMETRIC},
73             {"something-else", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
74             {"auto2", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
75         };
77         Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
78         TS_ASSERT( prof );
79         SP_OBJECT(prof)->document = _doc;
81         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
82             std::string descr(cases[i].attr);
83             SP_OBJECT(prof)->setKeyValue( SP_ATTR_RENDERING_INTENT, cases[i].attr);
84             TSM_ASSERT_EQUALS( descr, prof->rendering_intent, (guint)cases[i].intVal );
85         }
87         g_object_unref(prof);
88     }
90     void testSetLocal()
91     {
92         gchar const* cases[] = {
93             "local",
94             "something",
95         };
97         Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
98         TS_ASSERT( prof );
99         SP_OBJECT(prof)->document = _doc;
101         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
102             SP_OBJECT(prof)->setKeyValue( SP_ATTR_LOCAL, cases[i]);
103             TS_ASSERT( prof->local );
104             if ( prof->local ) {
105                 TS_ASSERT_EQUALS( std::string(prof->local), std::string(cases[i]) );
106             }
107         }
108         SP_OBJECT(prof)->setKeyValue( SP_ATTR_LOCAL, NULL);
109         TS_ASSERT_EQUALS( prof->local, (gchar*)0 );
111         g_object_unref(prof);
112     }
114     void testSetName()
115     {
116         gchar const* cases[] = {
117             "name",
118             "something",
119         };
121         Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
122         TS_ASSERT( prof );
123         SP_OBJECT(prof)->document = _doc;
125         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
126             SP_OBJECT(prof)->setKeyValue( SP_ATTR_NAME, cases[i]);
127             TS_ASSERT( prof->name );
128             if ( prof->name ) {
129                 TS_ASSERT_EQUALS( std::string(prof->name), std::string(cases[i]) );
130             }
131         }
132         SP_OBJECT(prof)->setKeyValue( SP_ATTR_NAME, NULL);
133         TS_ASSERT_EQUALS( prof->name, (gchar*)0 );
135         g_object_unref(prof);
136     }
137 };
139 #endif // SEEN_COLOR_PROFILE_TEST_H
141 /*
142   Local Variables:
143   mode:c++
144   c-file-style:"stroustrup"
145   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
146   indent-tabs-mode:nil
147   fill-column:99
148   End:
149 */
150 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :