summaryrefslogtreecommitdiffstats
path: root/src/color-profile-test.h
blob: 5cd58c15cb1bde57aac4aa394c50ffc987c870eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef SEEN_COLOR_PROFILE_TEST_H
#define SEEN_COLOR_PROFILE_TEST_H

#include <cxxtest/TestSuite.h>
#include <cassert>

#include "test-helpers.h"


#include "color-profile.h"
#include "color-profile-fns.h"

using Inkscape::ColorProfile;

class ColorProfileTest : public CxxTest::TestSuite
{
public:
    SPDocument* _doc;

    ColorProfileTest() :
        _doc(0)
    {
    }

    virtual ~ColorProfileTest()
    {
        if ( _doc )
        {
            sp_document_unref( _doc );
        }
    }

    static void createSuiteSubclass( ColorProfileTest*& dst )
    {
        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
        if ( prof ) {
            if ( prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN ) {
                TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
                dst = new ColorProfileTest();
            }
            g_object_unref(prof);
        }
    }

// createSuite and destroySuite get us per-suite setup and teardown
// without us having to worry about static initialization order, etc.
    static ColorProfileTest *createSuite()
    {
        ColorProfileTest* suite = Inkscape::createSuiteAndDocument<ColorProfileTest>( createSuiteSubclass );
        return suite;
    }

    static void destroySuite( ColorProfileTest *suite )
    {
        delete suite; 
    }

    // ---------------------------------------------------------------
    // ---------------------------------------------------------------
    // ---------------------------------------------------------------

    void testSetRenderingIntent()
    {
        struct {
            gchar const *attr;
            guint intVal;
        }
        const cases[] = {
            {"auto", (guint)Inkscape::RENDERING_INTENT_AUTO},
            {"perceptual", (guint)Inkscape::RENDERING_INTENT_PERCEPTUAL},
            {"relative-colorimetric", (guint)Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC},
            {"saturation", (guint)Inkscape::RENDERING_INTENT_SATURATION},
            {"absolute-colorimetric", (guint)Inkscape::RENDERING_INTENT_ABSOLUTE_COLORIMETRIC},
            {"something-else", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
            {"auto2", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
        };

        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
        TS_ASSERT( prof );
        SP_OBJECT(prof)->document = _doc;

        for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
            std::string descr(cases[i].attr);
            sp_object_set(SP_OBJECT(prof), SP_ATTR_RENDERING_INTENT, cases[i].attr);
            TSM_ASSERT_EQUALS( descr, prof->rendering_intent, (guint)cases[i].intVal );
        }

        g_object_unref(prof);
    }

    void testSetLocal()
    {
        gchar const* cases[] = {
            "local",
            "something",
        };

        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
        TS_ASSERT( prof );
        SP_OBJECT(prof)->document = _doc;

        for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
            sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, cases[i]);
            TS_ASSERT( prof->local );
            if ( prof->local ) {
                TS_ASSERT_EQUALS( std::string(prof->local), std::string(cases[i]) );
            }
        }
        sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, NULL);
        TS_ASSERT_EQUALS( prof->local, (gchar*)0 );

        g_object_unref(prof);
    }

    void testSetName()
    {
        gchar const* cases[] = {
            "name",
            "something",
        };

        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
        TS_ASSERT( prof );
        SP_OBJECT(prof)->document = _doc;

        for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
            sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, cases[i]);
            TS_ASSERT( prof->name );
            if ( prof->name ) {
                TS_ASSERT_EQUALS( std::string(prof->name), std::string(cases[i]) );
            }
        }
        sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, NULL);
        TS_ASSERT_EQUALS( prof->name, (gchar*)0 );

        g_object_unref(prof);
    }
};

#endif // SEEN_COLOR_PROFILE_TEST_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :