summaryrefslogtreecommitdiff
path: root/basebmp/test/basictest.cxx
blob: ef819c81ab6ee15929f4093cb60041be9d06fd33 (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
// autogenerated file with codegen.pl

#include <cppunit/simpleheader.hxx>

#include <basegfx/vector/b2isize.hxx>
#include <basegfx/point/b2ipoint.hxx>

#include <basebmp/color.hxx>
#include <basebmp/scanlineformats.hxx>
#include <basebmp/bitmapdevice.hxx>

using namespace ::basebmp;

namespace
{

class BasicTest : public CppUnit::TestFixture
{
public:
    void testConstruction()
    {
        const basegfx::B2ISize aSize(101,101);
        basegfx::B2ISize       aSize2(aSize);
        BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
                                                           true,
                                                           Format::ONE_BIT_MSB_PAL ));
        CPPUNIT_ASSERT_MESSAGE("right size",
                               pDevice->getSize() == aSize2 );
        CPPUNIT_ASSERT_MESSAGE("Top down format",
                               pDevice->isTopDown() == true );
        CPPUNIT_ASSERT_MESSAGE("Scanline format",
                               pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL );
        CPPUNIT_ASSERT_MESSAGE("Scanline len",
                               pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
    }

    void testPixelFuncs()
    {
        // 1bpp
        const basegfx::B2ISize aSize(101,101);
        BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
                                                           true,
                                                           Format::ONE_BIT_MSB_PAL ));

        const basegfx::B2IPoint aPt(3,3);
        const Color aCol(0xFFFFFFFF);
        pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
        CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
                               pDevice->getPixel(aPt) == aCol);

        const basegfx::B2IPoint aPt2(0,0);
        const Color aCol2(0xFFFFFFFF);
        pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
        CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
                               pDevice->getPixel(aPt2) == aCol2);

        const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
        const Color aCol3(0x00000000);
        pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
        CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
                               pDevice->getPixel(aPt3) == aCol3);

        const basegfx::B2IPoint aPt4(-100000,-100000);
        pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
        const basegfx::B2IPoint aPt5(100000,100000);
        pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );

        // 8bpp
        {
            pDevice = createBitmapDevice( aSize,
                                          true,
                                          Format::EIGHT_BIT_TC_MASK );

            const Color aCol4(0x01);
            pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
                                   pDevice->getPixel(aPt) == aCol4);

            const Color aCol5(0x0F);
            pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
                                   pDevice->getPixel(aPt2) == aCol5);

            const Color aCol6(0xFF);
            pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
                                   pDevice->getPixel(aPt3) == aCol6);
        }

        // 32bpp
        {
            pDevice = createBitmapDevice( aSize,
                                          true,
                                          Format::THIRTYTWO_BIT_TC_MASK );

            const Color aCol4(0x01010101);
            pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
                                   pDevice->getPixel(aPt) == aCol4);

            const Color aCol5(0x0F0F0F0F);
            pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
                                   pDevice->getPixel(aPt2) == aCol5);

            const Color aCol6(0xFFFFFFFF);
            pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
            CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
                                   pDevice->getPixel(aPt3) == aCol6);
        }
    }

    // Change the following lines only, if you add, remove or rename
    // member functions of the current class,
    // because these macros are need by auto register mechanism.

    CPPUNIT_TEST_SUITE(BasicTest);
    CPPUNIT_TEST(testConstruction);
    CPPUNIT_TEST(testPixelFuncs);
    CPPUNIT_TEST_SUITE_END();
};

// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
}


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

// this macro creates an empty function, which will called by the RegisterAllFunctions()
// to let the user the possibility to also register some functions by hand.
NOADDITIONAL;