mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-11-04 09:39:43 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			130 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			130 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
{
 | 
						|
 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','<!--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
 | 
						|
  AddToNonPascalTestSuite(TTestCTXMLFixFragment);
 | 
						|
 | 
						|
end.
 | 
						|
 |