{ 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, Classes, SysUtils, FileProcs, testglobals, 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',''); 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','',''); TestFrag('valid short with empty attribute tag','',''); TestFrag('missing tag name','<>','<>'); TestFrag('lower case tag name','',''); TestFrag('invalid character in tag','','">'); end; procedure TTestCTXMLFixFragment.TestFixXMLFragmentAttribute; begin TestFrag('lower case attribute name','',''); TestFrag('missing attribute equal','',''); TestFrag('missing attribute value','',''); TestFrag('missing attribute quotes','',''); TestFrag('missing attribute ending quote',''); TestFrag('invalid character in xml fragment attribute value','',''); TestFrag('amp attribute value','',''); TestFrag('lt attribute value','',''); end; procedure TTestCTXMLFixFragment.TestFixXMLFragmentCloseTag; begin TestFrag('lower case close tag name','',''); TestFrag('close open tag','',''); TestFrag('close open sub tag','
',''); TestFrag('disable invalid close tag','','</p>'); end; procedure TTestCTXMLFixFragment.TestFixXMLFragmentBugReports; begin TestFrag('15120','operator <(TPoint, TPoint): Boolean', 'operator <(TPoint, TPoint): Boolean'); TestFrag('16671','