Code

Adding rendering-intent to <color-profile>
[inkscape.git] / src / color-profile-test.h
3 #include <cxxtest/TestSuite.h>
4 #include <cassert>
6 #include "inkscape-private.h"
7 #include "sp-object.h"
8 #include "document.h"
10 #include "color-profile.h"
11 #include "color-profile-fns.h"
13 using Inkscape::ColorProfile;
15 /// Dummy functions to keep linker happy
16 #if !defined(DUMMY_MAIN_TEST_CALLS_SEEN)
17 #define DUMMY_MAIN_TEST_CALLS_SEEN
18 int sp_main_gui (int, char const**) { return 0; }
19 int sp_main_console (int, char const**) { return 0; }
20 #endif // DUMMY_MAIN_TEST_CALLS_SEEN
22 class ColorProfileTest : public CxxTest::TestSuite
23 {
24 public:
26     ColorProfileTest() :
27         TestSuite(),
28         _doc(0)
29     {
30     }
31     virtual ~ColorProfileTest() {}
33 // createSuite and destroySuite get us per-suite setup and teardown
34 // without us having to worry about static initialization order, etc.
35     static ColorProfileTest *createSuite()
36     {
37         ColorProfileTest* suite = 0;
38         bool canRun = false;
40         g_type_init();
41         Inkscape::GC::init();
43         ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
44         canRun = prof;
45         canRun &= prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN;
46         TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
47         g_object_unref(prof);
49         if ( canRun ) {
50             // Create the global inkscape object.
51             static_cast<void>(g_object_new(inkscape_get_type(), NULL));
52             SPDocument* tmp = sp_document_new_dummy();
53             if ( tmp ) {
54                 suite = new ColorProfileTest();
55                 suite->_doc = tmp;
56             }
57         }
59         return suite;
60     }
62     static void destroySuite( ColorProfileTest *suite )
63     {
64         delete suite; 
65     }
68     SPDocument* _doc;
70     // ---------------------------------------------------------------
72     void testSetRenderingIntent()
73     {
74         struct {
75             gchar const *attr;
76             guint intVal;
77         }
78         const cases[] = {
79             {"auto", (guint)Inkscape::RENDERING_INTENT_AUTO},
80             {"perceptual", (guint)Inkscape::RENDERING_INTENT_PERCEPTUAL},
81             {"relative-colorimetric", (guint)Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC},
82             {"saturation", (guint)Inkscape::RENDERING_INTENT_SATURATION},
83             {"absolute-colorimetric", (guint)Inkscape::RENDERING_INTENT_ABSOLUTE_COLORIMETRIC},
84             {"something-else", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
85             {"auto2", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
86         };
88         ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
89         TS_ASSERT( prof );
90         SP_OBJECT(prof)->document = _doc;
92         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
93             std::string descr(cases[i].attr);
94             sp_object_set(SP_OBJECT(prof), SP_ATTR_RENDERING_INTENT, cases[i].attr);
95             TSM_ASSERT_EQUALS( descr, prof->rendering_intent, (guint)cases[i].intVal );
96         }
98         g_object_unref(prof);
99     }
101     void testSetLocal()
102     {
103         gchar const* cases[] = {
104             "local",
105             "something",
106         };
108         ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
109         TS_ASSERT( prof );
110         SP_OBJECT(prof)->document = _doc;
112         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
113             sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, cases[i]);
114             TS_ASSERT( prof->local );
115             if ( prof->local ) {
116                 TS_ASSERT_EQUALS( std::string(prof->local), std::string(cases[i]) );
117             }
118         }
119         sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, NULL);
120         TS_ASSERT_EQUALS( prof->local, (gchar*)0 );
122         g_object_unref(prof);
123     }
125     void testSetName()
126     {
127         gchar const* cases[] = {
128             "name",
129             "something",
130         };
132         ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
133         TS_ASSERT( prof );
134         SP_OBJECT(prof)->document = _doc;
136         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
137             sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, cases[i]);
138             TS_ASSERT( prof->name );
139             if ( prof->name ) {
140                 TS_ASSERT_EQUALS( std::string(prof->name), std::string(cases[i]) );
141             }
142         }
143         sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, NULL);
144         TS_ASSERT_EQUALS( prof->name, (gchar*)0 );
146         g_object_unref(prof);
147     }
148 };
150 /*
151   Local Variables:
152   mode:c++
153   c-file-style:"stroustrup"
154   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
155   indent-tabs-mode:nil
156   fill-column:99
157   End:
158 */
159 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :