~centralelyon2010/inkscape/imagelinks2

604 by joncruz
Adding unit test for verbs.
1
#include <cxxtest/TestSuite.h>
2
3
#include "verbs.h"
4
5
class VerbsTest : public CxxTest::TestSuite
6
{
7
public:
8
9
    class TestHook : public Inkscape::Verb {
10
    public:
11
        static int getInternalTableSize() { return _getBaseListSize(); }
12
13
    private:
14
        TestHook();
15
    };
16
17
    void testEnumLength()
18
    {
19
        TS_ASSERT_DIFFERS( 0, static_cast<int>(SP_VERB_LAST) );
20
        TS_ASSERT_EQUALS( static_cast<int>(SP_VERB_LAST) + 1, TestHook::getInternalTableSize() );
21
    }
22
23
    void testEnumFixed()
24
    {
25
        TS_ASSERT_EQUALS( 0, static_cast<int>(SP_VERB_INVALID) );
26
        TS_ASSERT_EQUALS( 1, static_cast<int>(SP_VERB_NONE) );
27
28
        TS_ASSERT_DIFFERS( 0, static_cast<int>(SP_VERB_LAST) );
29
        TS_ASSERT_DIFFERS( 1, static_cast<int>(SP_VERB_LAST) );
30
    }
31
32
    void testFetch()
33
    {
34
        for ( int i = 0; i < static_cast<int>(SP_VERB_LAST); i++ )
35
        {
36
            char tmp[16];
37
            snprintf( tmp, sizeof(tmp), "Verb# %d", i );
38
            tmp[sizeof(tmp)-1] = 0;
39
            std::string descr(tmp);
40
41
            Inkscape::Verb* verb = Inkscape::Verb::get(i);
42
            TSM_ASSERT( descr, verb );
43
            if ( verb )
44
            {
45
                TSM_ASSERT_EQUALS( descr, verb->get_code(), static_cast<unsigned int>(i) );
46
6970 by joncruz
Warning and 'using' cleanup.
47
                if ( i != static_cast<int>(SP_VERB_INVALID) )
604 by joncruz
Adding unit test for verbs.
48
                {
49
                    TSM_ASSERT( descr, verb->get_id() );
50
                    TSM_ASSERT( descr, verb->get_name() );
51
52
                    Inkscape::Verb* bounced = verb->getbyid( verb->get_id() );
53
                    // TODO - put this back once verbs are fixed
54
                    //TSM_ASSERT( descr, bounced );
55
                    if ( bounced )
56
                    {
57
                        TSM_ASSERT_EQUALS( descr, bounced->get_code(), static_cast<unsigned int>(i) );
58
                    }
6970 by joncruz
Warning and 'using' cleanup.
59
                    else
604 by joncruz
Adding unit test for verbs.
60
                    {
61
                        TS_FAIL( std::string("Unable to getbyid() for ") + descr + std::string(" ID: '") + std::string(verb->get_id()) + std::string("'") );
62
                    }
756 by joncruz
Fixed problem with std::map use making last verb inaccessible.
63
                }
604 by joncruz
Adding unit test for verbs.
64
                else
65
                {
66
                    TSM_ASSERT( std::string("SP_VERB_INVALID"), !verb->get_id() );
67
                    TSM_ASSERT( std::string("SP_VERB_INVALID"), !verb->get_name() );
68
                }
69
            }
70
        }
71
    }
72
73
};
74
75
/*
76
  Local Variables:
77
  mode:c++
78
  c-file-style:"stroustrup"
79
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
80
  indent-tabs-mode:nil
81
  fill-column:99
82
  End:
83
*/
84
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
85
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
86