File: testhatchbrush.c

package info (click to toggle)
libgdiplus 6.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,312 kB
  • sloc: ansic: 78,330; sh: 4,236; makefile: 477
file content (189 lines) | stat: -rw-r--r-- 5,045 bytes parent folder | download | duplicates (3)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifdef WIN32
#ifndef __cplusplus
#error Please compile with a C++ compiler.
#endif
#endif

#if defined(USE_WINDOWS_GDIPLUS)
#include <Windows.h>
#include <GdiPlus.h>

#pragma comment(lib, "gdiplus.lib")
#else
#include <GdiPlusFlat.h>
#endif

#if defined(USE_WINDOWS_GDIPLUS)
using namespace Gdiplus;
using namespace DllExports;
#endif

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "testhelpers.h"

static void test_clone ()
{
    GpStatus status;
    GpBrush *brush;
    GpBrushType brushType;
    GpBrush *clone;

    GpHatchStyle hatchStyle;
    ARGB foregroundColor;
    ARGB backgroundColor;

    GdipCreateHatchBrush (HatchStyle10Percent, 0x00000001, 0x00000002, (GpHatch **)&brush);

    status = GdipCloneBrush (brush, &clone);
    assertEqualInt (status, Ok);
    assert (clone && brush != clone);

    GdipGetBrushType (clone, &brushType);
    assertEqualInt (brushType, BrushTypeHatchFill);

    GdipGetHatchStyle ((GpHatch *) clone, &hatchStyle);
    assertEqualInt (hatchStyle, HatchStyle10Percent);

    GdipGetHatchForegroundColor ((GpHatch *) clone, &foregroundColor);
    assertEqualInt (foregroundColor, 0x00000001);

    GdipGetHatchBackgroundColor ((GpHatch *) clone, &backgroundColor);
    assertEqualInt (backgroundColor, 0x00000002);

    GdipDeleteBrush (brush);
    GdipDeleteBrush (clone);
}

static void test_delete ()
{
    GpStatus status;
    GpHatch *brush;

    GdipCreateHatchBrush (HatchStyle05Percent, 0x00000001, 0x00000002, &brush);

    status = GdipDeleteBrush ((GpBrush *) brush);
    assertEqualInt (status, Ok);
}

static void test_createHatchBrush ()
{
    GpStatus status;
    GpHatch *brush;
    GpBrushType brushType;

    status = GdipCreateHatchBrush (HatchStyleMin, 0x00000001, 0x00000002, &brush);
    assertEqualInt (status, Ok);
    assert (brush != NULL && "Expected the brush to be initialized.");

    status = GdipGetBrushType ((GpBrush *) brush, &brushType);
    assertEqualInt (status, Ok);
    assertEqualInt (brushType, BrushTypeHatchFill);

    GdipDeleteBrush ((GpBrush *) brush);

    status = GdipCreateHatchBrush (HatchStyleMax, 0x00000001, 0x00000002, &brush);
    assertEqualInt (status, Ok);
    assert (brush != NULL && "Expected the brush to be initialized.");

    GdipDeleteBrush ((GpBrush *)brush);

    // Negative tests.
    brush = (GpHatch *) 0xCC;
    status = GdipCreateHatchBrush (HatchStyle05Percent, 0x00000001, 0x00000002, NULL);
    assertEqualInt (status, InvalidParameter);
    assert (brush == (GpHatch *) 0xCC);

    brush = (GpHatch *) 0xCC;
    status = GdipCreateHatchBrush ((HatchStyle)(HatchStyleMin - 1), 0x00000001, 0x00000002, &brush);
    assertEqualInt (status, InvalidParameter);
    assert (brush == (GpHatch *) 0xCC);

    brush = (GpHatch *) 0xCC;
    status = GdipCreateHatchBrush ((HatchStyle)(HatchStyleMax + 1), 0x00000001, 0x00000002, &brush);
    assertEqualInt (status, InvalidParameter);
    assert (brush == (GpHatch *) 0xCC);
}

static void test_getHatchStyle ()
{
    GpStatus status;
    GpHatch *brush;
    GpHatchStyle hatchStyle;

    GdipCreateHatchBrush (HatchStyle05Percent, 0x00000001, 0x00000002, &brush);

    status = GdipGetHatchStyle (brush, &hatchStyle);
    assertEqualInt (status, Ok);
    assertEqualInt (hatchStyle, HatchStyle05Percent);

    // Negative tests.
    status = GdipGetHatchStyle (NULL, &hatchStyle);
    assertEqualInt (status, InvalidParameter);

    status = GdipGetHatchStyle (brush, NULL);
    assertEqualInt (status, InvalidParameter);

    GdipDeleteBrush ((GpBrush *) brush);
}

static void test_getForegroundColor ()
{
    GpStatus status;
    GpHatch *brush;
    ARGB foregroundColor;

    GdipCreateHatchBrush (HatchStyle05Percent, 0x00000001, 0x00000002, &brush);

    status = GdipGetHatchForegroundColor (brush, &foregroundColor);
    assertEqualInt (status, Ok);
    assertEqualInt (foregroundColor, 0x00000001);

    // Negative tests.
    status = GdipGetHatchForegroundColor (NULL, &foregroundColor);
    assertEqualInt (status, InvalidParameter);

    status = GdipGetHatchForegroundColor (brush, NULL);
    assertEqualInt (status, InvalidParameter);

    GdipDeleteBrush ((GpBrush *) brush);
}

static void test_getBackgroundColor ()
{
    GpStatus status;
    GpHatch *brush;
    ARGB backgroundColor;

    GdipCreateHatchBrush (HatchStyle05Percent, 0x00000001, 0x00000002, &brush);

    status = GdipGetHatchBackgroundColor (brush, &backgroundColor);
    assertEqualInt (status, Ok);
    assertEqualInt (backgroundColor, 0x00000002);

    // Negative tests.
    status = GdipGetHatchBackgroundColor (NULL, &backgroundColor);
    assertEqualInt (status, InvalidParameter);

    status = GdipGetHatchBackgroundColor (brush, NULL);
    assertEqualInt (status, InvalidParameter);

    GdipDeleteBrush ((GpBrush *) brush);
}

int
main (int argc, char**argv)
{
	STARTUP;

    test_clone ();
    test_delete ();
    test_createHatchBrush ();
    test_getHatchStyle ();
    test_getForegroundColor ();
    test_getBackgroundColor ();

    SHUTDOWN;
    return 0;
}