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
|
{
Test all with:
./runtests --format=plain --suite=TTestCTXMLFixFragment
Test individually:
./runtests --format=plain --suite=TestFixXMLFragmentComment
./runtests --format=plain --suite=TestFixXMLValue
}
unit TestCTXMLFixFragments;
{$mode objfpc}{$H+}
interface
uses
fpcunit, testregistry, Classes, SysUtils, FileProcs,
CTXMLFixFragment;
type
{ TTestCTXMLFixFragment }
TTestCTXMLFixFragment = class(TTestCase)
protected
function TestFrag(Title, Fragment, FixedFragment: string): boolean;
function TestAttr(Title, Value, FixedValue: string): boolean;
published
procedure TestFixXMLFragmentComment;
procedure TestFixXMLFragmentInvalidCharacters;
procedure TestFixXMLFragmentOpenTag;
procedure TestFixXMLFragmentAttribute;
procedure TestFixXMLFragmentCloseTag;
procedure TestFixXMLFragmentBugReports;
// attribute value
procedure TestFixXMLValue;
end;
implementation
{ TTestCTXMLFixFragment }
function TTestCTXMLFixFragment.TestFrag(Title, Fragment, FixedFragment: string
): boolean;
var
s: String;
begin
Result:=true;
s:=Fragment;
FixFPDocFragment(s,true,true,nil,false);
AssertEquals(Title+' fragment: '+DbgStr(Fragment),dbgstr(FixedFragment),dbgstr(s));
end;
function TTestCTXMLFixFragment.TestAttr(Title, Value, FixedValue: string
): boolean;
var
s: String;
begin
Result:=true;
s:=Value;
FixFPDocAttributeValue(s);
AssertEquals(Title+' value: '+DbgStr(Value),dbgstr(FixedValue),dbgstr(s));
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentComment;
begin
TestFrag('close comment','<!--','<!---->');
TestFrag('close comment and delete invalid char','<!--null'#0#1#2'comment','<!--nullcomment-->');
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentInvalidCharacters;
begin
TestFrag('delete special characters','A'#0'B'#1#127,'AB');
TestFrag('replace tag characters','LT< GT>AMP&','LT< GT>AMP&');
TestFrag('lower case special characters','<','<');
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentOpenTag;
begin
TestFrag('valid short tag','<link/>','<link/>');
TestFrag('valid short with empty attribute tag','<link id=""/>','<link id=""/>');
TestFrag('missing tag name','<>','<>');
TestFrag('lower case tag name','<A></a>','<a></a>');
TestFrag('invalid character in tag','<a "></a>','<a >"></a>');
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentAttribute;
begin
TestFrag('lower case attribute name','<a Name=""></a>','<a name=""></a>');
TestFrag('missing attribute equal','<a name ""></a>','<a name =""></a>');
TestFrag('missing attribute value','<a name=></a>','<a name=""></a>');
TestFrag('missing attribute quotes','<a name=1></a>','<a name="1"></a>');
TestFrag('missing attribute ending quote','<a name="1></a>','<a name="1"></a>');
TestFrag('invalid character in xml fragment attribute value','<a name="&"></a>','<a name="&"></a>');
TestFrag('amp attribute value','<a name="&"></a>','<a name="&"></a>');
TestFrag('lt attribute value','<a name="operator<"></a>','<a name="operator<"></a>');
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentCloseTag;
begin
TestFrag('lower case close tag name','<a></A>','<a></a>');
TestFrag('close open tag','<a>','<a/>');
TestFrag('close open sub tag','<p><a></p>','<p><a/></p>');
TestFrag('disable invalid close tag','</p>','</p>');
end;
procedure TTestCTXMLFixFragment.TestFixXMLFragmentBugReports;
begin
TestFrag('15120','operator <(TPoint, TPoint): Boolean',
'operator <(TPoint, TPoint): Boolean');
TestFrag('16671','<br>',
'<br/>');
TestFrag('18800','<link id="foo"/>','<link id="foo"/>');
end;
procedure TTestCTXMLFixFragment.TestFixXMLValue;
begin
TestAttr('invalid character in xml attribute value','operator<','operator<');
TestAttr('correct character in xml attribute value','&','&');
TestAttr('lower case character name in attribute value','&','&');
TestAttr('" in attribute value','"','"');
TestAttr(''' in attribute value','''',''');
TestAttr('< in attribute value','<','<');
TestAttr('> in attribute value','>','>');
end;
initialization
RegisterTest(TTestCTXMLFixFragment);
end.
|