1 /* 2 * Unit test suite for customlinecap 3 * 4 * Copyright (C) 2008 Nikolay Sivov 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "objbase.h" 22 #include "gdiplus.h" 23 #include "wine/test.h" 24 25 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got) 26 #define expectf(expected, got) ok(got == expected, "Expected %.2f, got %.2f\n", expected, got) 27 28 static void test_constructor_destructor(void) 29 { 30 GpCustomLineCap *custom; 31 GpPath *path, *path2; 32 GpStatus stat; 33 34 stat = GdipCreatePath(FillModeAlternate, &path); 35 expect(Ok, stat); 36 stat = GdipAddPathRectangle(path, 5.0, 5.0, 10.0, 10.0); 37 expect(Ok, stat); 38 39 stat = GdipCreatePath(FillModeAlternate, &path2); 40 expect(Ok, stat); 41 stat = GdipAddPathRectangle(path2, 5.0, 5.0, 10.0, 10.0); 42 expect(Ok, stat); 43 44 /* NULL args */ 45 stat = GdipCreateCustomLineCap(NULL, NULL, LineCapFlat, 0.0, NULL); 46 expect(InvalidParameter, stat); 47 stat = GdipCreateCustomLineCap(path, NULL, LineCapFlat, 0.0, NULL); 48 expect(InvalidParameter, stat); 49 stat = GdipCreateCustomLineCap(NULL, path, LineCapFlat, 0.0, NULL); 50 expect(InvalidParameter, stat); 51 stat = GdipCreateCustomLineCap(NULL, NULL, LineCapFlat, 0.0, &custom); 52 expect(InvalidParameter, stat); 53 stat = GdipDeleteCustomLineCap(NULL); 54 expect(InvalidParameter, stat); 55 56 /* valid args */ 57 stat = GdipCreateCustomLineCap(NULL, path2, LineCapFlat, 0.0, &custom); 58 expect(Ok, stat); 59 stat = GdipDeleteCustomLineCap(custom); 60 expect(Ok, stat); 61 /* it's strange but native returns NotImplemented on stroke == NULL */ 62 custom = NULL; 63 stat = GdipCreateCustomLineCap(path, NULL, LineCapFlat, 10.0, &custom); 64 todo_wine expect(NotImplemented, stat); 65 todo_wine ok(custom == NULL, "Expected a failure on creation\n"); 66 if(stat == Ok) GdipDeleteCustomLineCap(custom); 67 68 GdipDeletePath(path2); 69 GdipDeletePath(path); 70 } 71 72 static void test_linejoin(void) 73 { 74 GpCustomLineCap *custom; 75 GpPath *path; 76 GpLineJoin join; 77 GpStatus stat; 78 79 stat = GdipCreatePath(FillModeAlternate, &path); 80 expect(Ok, stat); 81 stat = GdipAddPathRectangle(path, 5.0, 5.0, 10.0, 10.0); 82 expect(Ok, stat); 83 84 stat = GdipCreateCustomLineCap(NULL, path, LineCapFlat, 0.0, &custom); 85 expect(Ok, stat); 86 87 /* NULL args */ 88 stat = GdipGetCustomLineCapStrokeJoin(NULL, NULL); 89 expect(InvalidParameter, stat); 90 stat = GdipGetCustomLineCapStrokeJoin(custom, NULL); 91 expect(InvalidParameter, stat); 92 stat = GdipGetCustomLineCapStrokeJoin(NULL, &join); 93 expect(InvalidParameter, stat); 94 stat = GdipSetCustomLineCapStrokeJoin(NULL, LineJoinBevel); 95 expect(InvalidParameter, stat); 96 97 /* LineJoinMiter is default */ 98 stat = GdipGetCustomLineCapStrokeJoin(custom, &join); 99 expect(Ok, stat); 100 expect(LineJoinMiter, join); 101 102 /* set/get */ 103 stat = GdipSetCustomLineCapStrokeJoin(custom, LineJoinBevel); 104 expect(Ok, stat); 105 stat = GdipGetCustomLineCapStrokeJoin(custom, &join); 106 expect(Ok, stat); 107 expect(LineJoinBevel, join); 108 stat = GdipSetCustomLineCapStrokeJoin(custom, LineJoinRound); 109 expect(Ok, stat); 110 stat = GdipGetCustomLineCapStrokeJoin(custom, &join); 111 expect(Ok, stat); 112 expect(LineJoinRound, join); 113 stat = GdipSetCustomLineCapStrokeJoin(custom, LineJoinMiterClipped); 114 expect(Ok, stat); 115 stat = GdipGetCustomLineCapStrokeJoin(custom, &join); 116 expect(Ok, stat); 117 expect(LineJoinMiterClipped, join); 118 119 GdipDeleteCustomLineCap(custom); 120 GdipDeletePath(path); 121 } 122 123 static void test_inset(void) 124 { 125 GpCustomLineCap *custom; 126 GpPath *path; 127 REAL inset; 128 GpStatus stat; 129 130 stat = GdipCreatePath(FillModeAlternate, &path); 131 expect(Ok, stat); 132 stat = GdipAddPathRectangle(path, 5.0, 5.0, 10.0, 10.0); 133 expect(Ok, stat); 134 135 stat = GdipCreateCustomLineCap(NULL, path, LineCapFlat, 0.0, &custom); 136 expect(Ok, stat); 137 138 /* NULL args */ 139 stat = GdipGetCustomLineCapBaseInset(NULL, NULL); 140 expect(InvalidParameter, stat); 141 stat = GdipGetCustomLineCapBaseInset(NULL, &inset); 142 expect(InvalidParameter, stat); 143 stat = GdipGetCustomLineCapBaseInset(custom, NULL); 144 expect(InvalidParameter, stat); 145 /* valid args */ 146 inset = (REAL)0xdeadbeef; 147 stat = GdipGetCustomLineCapBaseInset(custom, &inset); 148 expect(Ok, stat); 149 expectf(0.0, inset); 150 151 GdipDeleteCustomLineCap(custom); 152 GdipDeletePath(path); 153 } 154 155 static void test_scale(void) 156 { 157 GpCustomLineCap *custom; 158 GpPath *path; 159 REAL scale; 160 GpStatus stat; 161 162 stat = GdipCreatePath(FillModeAlternate, &path); 163 expect(Ok, stat); 164 stat = GdipAddPathRectangle(path, 5.0, 5.0, 10.0, 10.0); 165 expect(Ok, stat); 166 167 stat = GdipCreateCustomLineCap(NULL, path, LineCapFlat, 0.0, &custom); 168 expect(Ok, stat); 169 170 /* NULL args */ 171 stat = GdipGetCustomLineCapWidthScale(NULL, NULL); 172 expect(InvalidParameter, stat); 173 stat = GdipGetCustomLineCapWidthScale(NULL, &scale); 174 expect(InvalidParameter, stat); 175 stat = GdipGetCustomLineCapWidthScale(custom, NULL); 176 expect(InvalidParameter, stat); 177 178 stat = GdipSetCustomLineCapWidthScale(NULL, 2.0); 179 expect(InvalidParameter, stat); 180 181 /* valid args: read default */ 182 scale = (REAL)0xdeadbeef; 183 stat = GdipGetCustomLineCapWidthScale(custom, &scale); 184 expect(Ok, stat); 185 expectf(1.0, scale); 186 187 /* set and read back some scale values: there is no limit for the scale */ 188 stat = GdipSetCustomLineCapWidthScale(custom, 2.5); 189 expect(Ok, stat); 190 scale = (REAL)0xdeadbeef; 191 stat = GdipGetCustomLineCapWidthScale(custom, &scale); 192 expect(Ok, stat); 193 expectf(2.5, scale); 194 195 stat = GdipSetCustomLineCapWidthScale(custom, 42.0); 196 expect(Ok, stat); 197 scale = (REAL)0xdeadbeef; 198 stat = GdipGetCustomLineCapWidthScale(custom, &scale); 199 expect(Ok, stat); 200 expectf(42.0, scale); 201 202 stat = GdipSetCustomLineCapWidthScale(custom, 3000.0); 203 expect(Ok, stat); 204 scale = (REAL)0xdeadbeef; 205 stat = GdipGetCustomLineCapWidthScale(custom, &scale); 206 expect(Ok, stat); 207 expectf(3000.0, scale); 208 209 stat = GdipSetCustomLineCapWidthScale(custom, 0.0); 210 expect(Ok, stat); 211 scale = (REAL)0xdeadbeef; 212 stat = GdipGetCustomLineCapWidthScale(custom, &scale); 213 expect(Ok, stat); 214 expectf(0.0, scale); 215 216 GdipDeleteCustomLineCap(custom); 217 GdipDeletePath(path); 218 } 219 220 static void test_create_adjustable_cap(void) 221 { 222 GpAdjustableArrowCap *cap; 223 REAL inset, scale; 224 GpLineJoin join; 225 GpStatus stat; 226 GpLineCap base; 227 228 stat = GdipCreateAdjustableArrowCap(10.0, 10.0, TRUE, NULL); 229 todo_wine 230 ok(stat == InvalidParameter, "Unexpected return code, %d\n", stat); 231 232 stat = GdipCreateAdjustableArrowCap(17.0, 15.0, TRUE, &cap); 233 todo_wine 234 ok(stat == Ok, "Failed to create adjustable cap, %d\n", stat); 235 if (stat != Ok) 236 return; 237 238 stat = GdipGetAdjustableArrowCapMiddleInset(cap, NULL); 239 ok(stat == InvalidParameter, "Unexpected return code, %d\n", stat); 240 241 stat = GdipGetAdjustableArrowCapMiddleInset(cap, &inset); 242 ok(stat == Ok, "Unexpected return code, %d\n", stat); 243 ok(inset == 0.0f, "Unexpected middle inset %f\n", inset); 244 245 stat = GdipGetCustomLineCapBaseCap((GpCustomLineCap*)cap, &base); 246 ok(stat == Ok, "Unexpected return code, %d\n", stat); 247 ok(base == LineCapTriangle, "Unexpected base cap %d\n", base); 248 249 stat = GdipSetCustomLineCapBaseCap((GpCustomLineCap*)cap, LineCapSquare); 250 ok(stat == Ok, "Unexpected return code, %d\n", stat); 251 252 stat = GdipGetCustomLineCapBaseCap((GpCustomLineCap*)cap, &base); 253 ok(stat == Ok, "Unexpected return code, %d\n", stat); 254 ok(base == LineCapSquare, "Unexpected base cap %d\n", base); 255 256 stat = GdipGetCustomLineCapBaseInset((GpCustomLineCap*)cap, &inset); 257 ok(stat == Ok, "Unexpected return code, %d\n", stat); 258 259 stat = GdipGetCustomLineCapWidthScale((GpCustomLineCap*)cap, &scale); 260 ok(stat == Ok, "Unexpected return code, %d\n", stat); 261 ok(scale == 1.0f, "Unexpected width scale %f\n", scale); 262 263 stat = GdipGetCustomLineCapStrokeJoin((GpCustomLineCap*)cap, &join); 264 ok(stat == Ok, "Unexpected return code, %d\n", stat); 265 ok(join == LineJoinMiter, "Unexpected stroke join %d\n", join); 266 267 GdipDeleteCustomLineCap((GpCustomLineCap*)cap); 268 } 269 270 static void test_captype(void) 271 { 272 GpAdjustableArrowCap *arrowcap; 273 GpCustomLineCap *custom; 274 CustomLineCapType type; 275 GpStatus stat; 276 GpPath *path; 277 278 stat = GdipGetCustomLineCapType(NULL, NULL); 279 ok(stat == InvalidParameter, "Unexpected return code, %d\n", stat); 280 281 type = 10; 282 stat = GdipGetCustomLineCapType(NULL, &type); 283 ok(stat == InvalidParameter, "Unexpected return code, %d\n", stat); 284 ok(type == 10, "Unexpected cap type, %d\n", type); 285 286 /* default cap */ 287 stat = GdipCreatePath(FillModeAlternate, &path); 288 ok(stat == Ok, "Failed to create path, %d\n", stat); 289 stat = GdipAddPathRectangle(path, 5.0, 5.0, 10.0, 10.0); 290 ok(stat == Ok, "AddPathRectangle failed, %d\n", stat); 291 292 stat = GdipCreateCustomLineCap(NULL, path, LineCapFlat, 0.0, &custom); 293 ok(stat == Ok, "Failed to create cap, %d\n", stat); 294 stat = GdipGetCustomLineCapType(custom, &type); 295 ok(stat == Ok, "Failed to get cap type, %d\n", stat); 296 ok(type == CustomLineCapTypeDefault, "Unexpected cap type %d\n", stat); 297 GdipDeleteCustomLineCap(custom); 298 GdipDeletePath(path); 299 300 /* arrow cap */ 301 stat = GdipCreateAdjustableArrowCap(17.0, 15.0, TRUE, &arrowcap); 302 todo_wine 303 ok(stat == Ok, "Failed to create adjustable cap, %d\n", stat); 304 if (stat != Ok) 305 return; 306 307 stat = GdipGetCustomLineCapType((GpCustomLineCap*)arrowcap, &type); 308 ok(stat == Ok, "Failed to get cap type, %d\n", stat); 309 ok(type == CustomLineCapTypeAdjustableArrow, "Unexpected cap type %d\n", stat); 310 311 GdipDeleteCustomLineCap((GpCustomLineCap*)arrowcap); 312 } 313 314 START_TEST(customlinecap) 315 { 316 struct GdiplusStartupInput gdiplusStartupInput; 317 ULONG_PTR gdiplusToken; 318 HMODULE hmsvcrt; 319 int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask); 320 321 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */ 322 hmsvcrt = LoadLibraryA("msvcrt"); 323 _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s"); 324 if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e); 325 326 gdiplusStartupInput.GdiplusVersion = 1; 327 gdiplusStartupInput.DebugEventCallback = NULL; 328 gdiplusStartupInput.SuppressBackgroundThread = 0; 329 gdiplusStartupInput.SuppressExternalCodecs = 0; 330 331 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 332 333 test_constructor_destructor(); 334 test_linejoin(); 335 test_inset(); 336 test_scale(); 337 test_create_adjustable_cap(); 338 test_captype(); 339 340 GdiplusShutdown(gdiplusToken); 341 } 342