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 using Inkscape::ColorProfile;
16 class ColorProfileTest : public CxxTest::TestSuite
17 {
18 public:
19 SPDocument* _doc;
21 ColorProfileTest() :
22 _doc(0)
23 {
24 }
26 virtual ~ColorProfileTest()
27 {
28 if ( _doc )
29 {
30 sp_document_unref( _doc );
31 }
32 }
34 static void createSuiteSubclass( ColorProfileTest*& dst )
35 {
36 ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
37 if ( prof ) {
38 if ( prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN ) {
39 TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
40 dst = new ColorProfileTest();
41 }
42 g_object_unref(prof);
43 }
44 }
46 // createSuite and destroySuite get us per-suite setup and teardown
47 // without us having to worry about static initialization order, etc.
48 static ColorProfileTest *createSuite()
49 {
50 ColorProfileTest* suite = Inkscape::createSuiteAndDocument<ColorProfileTest>( createSuiteSubclass );
51 return suite;
52 }
54 static void destroySuite( ColorProfileTest *suite )
55 {
56 delete suite;
57 }
59 // ---------------------------------------------------------------
60 // ---------------------------------------------------------------
61 // ---------------------------------------------------------------
63 void testSetRenderingIntent()
64 {
65 struct {
66 gchar const *attr;
67 guint intVal;
68 }
69 const cases[] = {
70 {"auto", (guint)Inkscape::RENDERING_INTENT_AUTO},
71 {"perceptual", (guint)Inkscape::RENDERING_INTENT_PERCEPTUAL},
72 {"relative-colorimetric", (guint)Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC},
73 {"saturation", (guint)Inkscape::RENDERING_INTENT_SATURATION},
74 {"absolute-colorimetric", (guint)Inkscape::RENDERING_INTENT_ABSOLUTE_COLORIMETRIC},
75 {"something-else", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
76 {"auto2", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
77 };
79 ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
80 TS_ASSERT( prof );
81 SP_OBJECT(prof)->document = _doc;
83 for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
84 std::string descr(cases[i].attr);
85 sp_object_set(SP_OBJECT(prof), SP_ATTR_RENDERING_INTENT, cases[i].attr);
86 TSM_ASSERT_EQUALS( descr, prof->rendering_intent, (guint)cases[i].intVal );
87 }
89 g_object_unref(prof);
90 }
92 void testSetLocal()
93 {
94 gchar const* cases[] = {
95 "local",
96 "something",
97 };
99 ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
100 TS_ASSERT( prof );
101 SP_OBJECT(prof)->document = _doc;
103 for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
104 sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, cases[i]);
105 TS_ASSERT( prof->local );
106 if ( prof->local ) {
107 TS_ASSERT_EQUALS( std::string(prof->local), std::string(cases[i]) );
108 }
109 }
110 sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, NULL);
111 TS_ASSERT_EQUALS( prof->local, (gchar*)0 );
113 g_object_unref(prof);
114 }
116 void testSetName()
117 {
118 gchar const* cases[] = {
119 "name",
120 "something",
121 };
123 ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
124 TS_ASSERT( prof );
125 SP_OBJECT(prof)->document = _doc;
127 for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
128 sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, cases[i]);
129 TS_ASSERT( prof->name );
130 if ( prof->name ) {
131 TS_ASSERT_EQUALS( std::string(prof->name), std::string(cases[i]) );
132 }
133 }
134 sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, NULL);
135 TS_ASSERT_EQUALS( prof->name, (gchar*)0 );
137 g_object_unref(prof);
138 }
139 };
141 #endif // SEEN_COLOR_PROFILE_TEST_H
143 /*
144 Local Variables:
145 mode:c++
146 c-file-style:"stroustrup"
147 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
148 indent-tabs-mode:nil
149 fill-column:99
150 End:
151 */
152 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :