1 | unit UUnitTest;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, BGRABitmapTypes;
|
---|
9 |
|
---|
10 | implementation
|
---|
11 |
|
---|
12 | procedure Test(AExpression: boolean; ADescription: string);
|
---|
13 | begin
|
---|
14 | if not AExpression then
|
---|
15 | raise EAssertionFailed.Create('Assertion failed: '+ADescription);
|
---|
16 | end;
|
---|
17 |
|
---|
18 | var error: boolean;
|
---|
19 |
|
---|
20 | initialization
|
---|
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');
|
---|
45 | end.
|
---|
46 |
|
---|