source: trunk/Packages/bgrabitmap/uunittest.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 2.0 KB
Line 
1unit UUnitTest;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, BGRABitmapTypes;
9
10implementation
11
12procedure Test(AExpression: boolean; ADescription: string);
13begin
14 if not AExpression then
15 raise EAssertionFailed.Create('Assertion failed: '+ADescription);
16end;
17
18var error: boolean;
19
20initialization
21
22 Test(StrToBGRA('red ')=CSSRed,'ignore spaces');
23 Test(StrToBGRA('red@')=BGRAPixelTransparent,'error fallback to transparent');
24 Test(StrToBGRA('red@',CSSYellow)=CSSYellow,'error fallback to transparent');
25 Test(StrToBGRA('rgb(255,0,0)')=CSSRed,'rgb format');
26 Test(StrToBGRA('rgb(255,0,0,0.502)')=BGRA(255,0,0,128),'rgba format');
27 Test(StrToBGRA('rgb(255,0,?)')=BGRAPixelTransparent,'missing as an error');
28 Test(StrToBGRA('rgb(255,0,?)',CSSYellow)=CSSYellow,'missing as an error');
29 Test(PartialStrToBGRA('rgb(255,?,?,?)',BGRA(128,128,128,128),error)=BGRA(255,128,128,128),'missing values replacement');
30 Test(not error, 'missing is not an error');
31 Test(PartialStrToBGRA('rgb(255,?,?)',BGRA(128,128,128,128),error)=BGRA(255,128,128,255),'implicit rgb alpha');
32 Test(not error, 'missing is not an error');
33 Test(PartialStrToBGRA('rgb(255,abc,0)',BGRA(128,128,128,128),error)=BGRA(255,0,0,255),'error replaced by 0 for rgb');
34 Test(error, 'non numeric error');
35 Test(PartialStrToBGRA('#ff????',BGRA(128,128,128,128),error)=BGRA(255,128,128,255),'missing values replacement');
36 Test(not error, 'missing is not an error');
37 Test(PartialStrToBGRA('#f??',BGRA(128,128,128,128),error)=BGRA(255,128,128,255),'missing values replacement');
38 Test(not error, 'missing is not an error');
39 Test(PartialStrToBGRA('#12??3456',BGRA(128,128,128,128),error)=BGRA($12,128,$34,$56),'html color with missing values');
40 Test(not error, 'missing is not an error');
41 Test(BGRAToStr(VGARed)='FF0000FF','Default color format');
42 Test(BGRAToStr(BGRA(255,0,0), VGAColors)='Red','VGA color names');
43 Test(BGRAToStr(BGRA(255,255,0), CSSColors)='Yellow','CSS color names');
44 Test(BGRAToStr(BGRA(250,128,114), CSSColors)='Salmon','CSS color names');
45end.
46
Note: See TracBrowser for help on using the repository browser.