mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 04:26:13 +02:00
* fcl-xml testing suite, working around excessive string conversions by using new method assertEqualsW to compare wide strings. Since TTestCase.assertEquals method already exists with ansistring arguments, and its first argument is a literal in most cases, overloading does not help here.
git-svn-id: trunk@20442 -
This commit is contained in:
parent
d59c0237b2
commit
134e5167f1
@ -20,7 +20,7 @@ unit domunit;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, DOM, XMLRead, contnrs, fpcunit;
|
Classes, SysUtils, xmlutils, DOM, XMLRead, contnrs, fpcunit;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ these two types are separated for the purpose of readability }
|
{ these two types are separated for the purpose of readability }
|
||||||
@ -42,7 +42,7 @@ type
|
|||||||
procedure GC(obj: TObject);
|
procedure GC(obj: TObject);
|
||||||
procedure Load(out doc; const uri: string);
|
procedure Load(out doc; const uri: string);
|
||||||
procedure LoadStringData(out Doc; const data: string);
|
procedure LoadStringData(out Doc; const data: string);
|
||||||
function getResourceURI(const res: WideString): WideString;
|
function getResourceURI(const res: XMLString): XMLString;
|
||||||
function ContentTypeIs(const t: string): Boolean;
|
function ContentTypeIs(const t: string): Boolean;
|
||||||
function GetImplementation: TDOMImplementation;
|
function GetImplementation: TDOMImplementation;
|
||||||
procedure CheckFeature(const name: string);
|
procedure CheckFeature(const name: string);
|
||||||
@ -50,6 +50,7 @@ type
|
|||||||
procedure assertEquals(const id: string; exp, act: TObject); overload;
|
procedure assertEquals(const id: string; exp, act: TObject); overload;
|
||||||
procedure assertEqualsList(const id: string; const exp: array of DOMString; const act: _list);
|
procedure assertEqualsList(const id: string; const exp: array of DOMString; const act: _list);
|
||||||
procedure assertEqualsCollection(const id: string; const exp: array of DOMString; const act: _collection);
|
procedure assertEqualsCollection(const id: string; const exp: array of DOMString; const act: _collection);
|
||||||
|
procedure assertEqualsW(const id: string; const exp, act: DOMString);
|
||||||
procedure assertEqualsNoCase(const id: string; const exp, act: DOMString);
|
procedure assertEqualsNoCase(const id: string; const exp, act: DOMString);
|
||||||
procedure assertSame(const id: string; exp, act: TDOMNode);
|
procedure assertSame(const id: string; exp, act: TDOMNode);
|
||||||
procedure assertSize(const id: string; size: Integer; obj: TDOMNodeList);
|
procedure assertSize(const id: string; size: Integer; obj: TDOMNodeList);
|
||||||
@ -58,7 +59,7 @@ type
|
|||||||
procedure assertURIEquals(const id: string;
|
procedure assertURIEquals(const id: string;
|
||||||
scheme, path, host, file_, name, query, fragment: PChar;
|
scheme, path, host, file_, name, query, fragment: PChar;
|
||||||
IsAbsolute: Boolean; const Actual: DOMString);
|
IsAbsolute: Boolean; const Actual: DOMString);
|
||||||
function bad_condition(const TagName: WideString): Boolean;
|
function bad_condition(const TagName: XMLString): Boolean;
|
||||||
property implementationAttribute[const name: string]: Boolean read getImplAttr write setImplAttr;
|
property implementationAttribute[const name: string]: Boolean read getImplAttr write setImplAttr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ begin
|
|||||||
assertNotNull(id, exp);
|
assertNotNull(id, exp);
|
||||||
assertNotNull(id, act);
|
assertNotNull(id, act);
|
||||||
assertEquals(id, exp.nodeType, act.nodeType);
|
assertEquals(id, exp.nodeType, act.nodeType);
|
||||||
assertEquals(id, exp.nodeValue, act.nodeValue);
|
assertEqualsW(id, exp.nodeValue, act.nodeValue);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -140,10 +141,10 @@ procedure TDOMTestBase.assertEqualsList(const id: string;
|
|||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
begin
|
begin
|
||||||
AssertEquals(id, Length(exp), Length(act));
|
AssertEquals(id+'(length)', Length(exp), Length(act));
|
||||||
// compare ordered
|
// compare ordered
|
||||||
for I := 0 to High(exp) do
|
for I := 0 to High(exp) do
|
||||||
AssertEquals(id, exp[I], act[I]);
|
AssertEqualsW(id+'['+IntToStr(I)+']', exp[I], act[I]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDOMTestBase.assertEqualsCollection(const id: string; const exp: array of DOMString; const act: _collection);
|
procedure TDOMTestBase.assertEqualsCollection(const id: string; const exp: array of DOMString; const act: _collection);
|
||||||
@ -163,6 +164,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDOMTestBase.assertEqualsW(const id: string; const exp, act: DOMString);
|
||||||
|
begin
|
||||||
|
AssertTrue(id + ComparisonMsg(exp, act), exp = act);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDOMTestBase.assertEqualsNoCase(const id: string; const exp, act: DOMString);
|
procedure TDOMTestBase.assertEqualsNoCase(const id: string; const exp, act: DOMString);
|
||||||
begin
|
begin
|
||||||
// TODO: could write custom comparison because range is limited to ASCII
|
// TODO: could write custom comparison because range is limited to ASCII
|
||||||
@ -181,11 +187,11 @@ begin
|
|||||||
AssertEquals(id, size, obj.Length);
|
AssertEquals(id, size, obj.Length);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDOMTestBase.getResourceURI(const res: WideString): WideString;
|
function TDOMTestBase.getResourceURI(const res: XMLString): XMLString;
|
||||||
var
|
var
|
||||||
Base, Base2: WideString;
|
Base, Base2: XMLString;
|
||||||
|
|
||||||
function CheckFile(const uri: WideString; out name: WideString): Boolean;
|
function CheckFile(const uri: XMLString; out name: XMLString): Boolean;
|
||||||
var
|
var
|
||||||
filename: string;
|
filename: string;
|
||||||
begin
|
begin
|
||||||
@ -196,7 +202,7 @@ end;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Base := GetTestFilesURI;
|
Base := GetTestFilesURI;
|
||||||
if Pos(WideString('level2/html'), Base) <> 0 then
|
if Pos(XMLString('level2/html'), Base) <> 0 then
|
||||||
begin
|
begin
|
||||||
// This is needed to run HTML testsuite off the CVS snapshot.
|
// This is needed to run HTML testsuite off the CVS snapshot.
|
||||||
// Web version simply uses all level1 files copied to level2.
|
// Web version simply uses all level1 files copied to level2.
|
||||||
@ -287,9 +293,9 @@ begin
|
|||||||
AssertEquals(id, string(name), ChangeFileExt(URI.Document, ''));
|
AssertEquals(id, string(name), ChangeFileExt(URI.Document, ''));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDOMTestBase.bad_condition(const TagName: WideString): Boolean;
|
function TDOMTestBase.bad_condition(const TagName: XMLString): Boolean;
|
||||||
begin
|
begin
|
||||||
Fail('Unsupported condition: '+ TagName);
|
Fail('Unsupported condition: '+ AnsiString(TagName));
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ type
|
|||||||
procedure attr_ownership04;
|
procedure attr_ownership04;
|
||||||
procedure attr_ownership05;
|
procedure attr_ownership05;
|
||||||
procedure replacesamechild;
|
procedure replacesamechild;
|
||||||
|
procedure insertbeforefirst;
|
||||||
procedure nsFixup1;
|
procedure nsFixup1;
|
||||||
procedure nsFixup2;
|
procedure nsFixup2;
|
||||||
procedure nsFixup3;
|
procedure nsFixup3;
|
||||||
@ -149,15 +150,32 @@ begin
|
|||||||
el := root.ChildNodes[1];
|
el := root.ChildNodes[1];
|
||||||
prev := el.PreviousSibling;
|
prev := el.PreviousSibling;
|
||||||
next := el.NextSibling;
|
next := el.NextSibling;
|
||||||
AssertEquals('prev_name_before', 'child1', prev.NodeName);
|
AssertEqualsW('prev_name_before', 'child1', prev.NodeName);
|
||||||
AssertEquals('next_name_before', 'child3', next.NodeName);
|
AssertEqualsW('next_name_before', 'child3', next.NodeName);
|
||||||
root.replaceChild(el, el);
|
root.replaceChild(el, el);
|
||||||
prev := el.PreviousSibling;
|
prev := el.PreviousSibling;
|
||||||
next := el.NextSibling;
|
next := el.NextSibling;
|
||||||
AssertNotNull('prev_after', prev);
|
AssertNotNull('prev_after', prev);
|
||||||
AssertNotNull('prev_after', next);
|
AssertNotNull('prev_after', next);
|
||||||
AssertEquals('prev_name_after', 'child1', prev.NodeName);
|
AssertEqualsW('prev_name_after', 'child1', prev.NodeName);
|
||||||
AssertEquals('next_name_after', 'child3', next.NodeName);
|
AssertEqualsW('next_name_after', 'child3', next.NodeName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// verify that inserting a node before the first child sets
|
||||||
|
// both refnode.previoussibling and newnode.nextsibling properties
|
||||||
|
procedure TDOMTestExtra.insertbeforefirst;
|
||||||
|
var
|
||||||
|
doc: TDOMDocument;
|
||||||
|
root, refchild, newchild: TDOMNode;
|
||||||
|
begin
|
||||||
|
LoadStringData(doc, '<root><child1/><child2/><child3/></root>');
|
||||||
|
root := doc.DocumentElement;
|
||||||
|
refchild := root.FirstChild;
|
||||||
|
newchild := doc.CreateElement('new');
|
||||||
|
root.insertbefore(newchild, refchild);
|
||||||
|
AssertEquals('prev', refchild.previoussibling, newchild);
|
||||||
|
AssertEquals('next', newchild.nextsibling, refchild);
|
||||||
|
AssertEquals('child', root.firstchild, newchild);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -190,13 +208,13 @@ begin
|
|||||||
LoadStringData(parsedDoc, stream.DataString);
|
LoadStringData(parsedDoc, stream.DataString);
|
||||||
|
|
||||||
docElem := parsedDoc.documentElement;
|
docElem := parsedDoc.documentElement;
|
||||||
assertEquals('docElemLocalName', 'test', docElem.localName);
|
assertEqualsW('docElemLocalName', 'test', docElem.localName);
|
||||||
assertEquals('docElemNS', nsURI1, docElem.namespaceURI);
|
assertEqualsW('docElemNS', nsURI1, docElem.namespaceURI);
|
||||||
|
|
||||||
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
||||||
assertEquals('ns2_elementCount', 1, list.Length);
|
assertEquals('ns2_elementCount', 1, list.Length);
|
||||||
el := TDOMElement(list[0]);
|
el := TDOMElement(list[0]);
|
||||||
assertEquals('ns2_nodeName', 'test', el.nodeName);
|
assertEqualsW('ns2_nodeName', 'test', el.nodeName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// verify the namespace fixup with two nested elements
|
// verify the namespace fixup with two nested elements
|
||||||
@ -225,13 +243,13 @@ begin
|
|||||||
LoadStringData(parsedDoc, stream.DataString);
|
LoadStringData(parsedDoc, stream.DataString);
|
||||||
|
|
||||||
docElem := parsedDoc.documentElement;
|
docElem := parsedDoc.documentElement;
|
||||||
assertEquals('docElemLocalName', 'test', docElem.localName);
|
assertEqualsW('docElemLocalName', 'test', docElem.localName);
|
||||||
assertEquals('docElemNS', nsURI1, docElem.namespaceURI);
|
assertEqualsW('docElemNS', nsURI1, docElem.namespaceURI);
|
||||||
|
|
||||||
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
||||||
assertEquals('ns2_elementCount', 1, list.Length);
|
assertEquals('ns2_elementCount', 1, list.Length);
|
||||||
el := TDOMElement(list[0]);
|
el := TDOMElement(list[0]);
|
||||||
assertEquals('ns2_nodeName', 'b:test', el.nodeName);
|
assertEqualsW('ns2_nodeName', 'b:test', el.nodeName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// verify the namespace fixup with two nested elements and an attribute
|
// verify the namespace fixup with two nested elements and an attribute
|
||||||
@ -262,14 +280,14 @@ begin
|
|||||||
LoadStringData(parsedDoc, stream.DataString);
|
LoadStringData(parsedDoc, stream.DataString);
|
||||||
|
|
||||||
docElem := parsedDoc.documentElement;
|
docElem := parsedDoc.documentElement;
|
||||||
assertEquals('docElemLocalName', 'test', docElem.localName);
|
assertEqualsW('docElemLocalName', 'test', docElem.localName);
|
||||||
assertEquals('docElemNS', nsURI1, docElem.namespaceURI);
|
assertEqualsW('docElemNS', nsURI1, docElem.namespaceURI);
|
||||||
|
|
||||||
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
list := docElem.GetElementsByTagNameNS(nsURI2, '*');
|
||||||
assertEquals('ns2_elementCount', 1, list.Length);
|
assertEquals('ns2_elementCount', 1, list.Length);
|
||||||
el := TDOMElement(list[0]);
|
el := TDOMElement(list[0]);
|
||||||
attr := el.GetAttributeNodeNS(nsURI1, 'attr');
|
attr := el.GetAttributeNodeNS(nsURI1, 'attr');
|
||||||
assertEquals('attr_nodeName', 'a:attr', attr.nodeName);
|
assertEqualsW('attr_nodeName', 'a:attr', attr.nodeName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ begin
|
|||||||
nodeType := node.nodeType;
|
nodeType := node.nodeType;
|
||||||
assertEquals('PIisFifthChild', 7, nodeType);
|
assertEquals('PIisFifthChild', 7, nodeType);
|
||||||
nodeValue := TDOMProcessingInstruction(node).data;
|
nodeValue := TDOMProcessingInstruction(node).data;
|
||||||
assertEquals('trailingPIData', '', nodeValue);
|
assertEqualsW('trailingPIData', '', nodeValue);
|
||||||
node := node.nextSibling;
|
node := node.nextSibling;
|
||||||
nodeType := node.nodeType;
|
nodeType := node.nodeType;
|
||||||
assertEquals('TextisSixthChild', 3, nodeType);
|
assertEquals('TextisSixthChild', 3, nodeType);
|
||||||
@ -178,7 +178,7 @@ begin
|
|||||||
nodeType := node.nodeType;
|
nodeType := node.nodeType;
|
||||||
assertEquals('PIisFifthChild', 7, nodeType);
|
assertEquals('PIisFifthChild', 7, nodeType);
|
||||||
nodeValue := TDOMProcessingInstruction(node).data;
|
nodeValue := TDOMProcessingInstruction(node).data;
|
||||||
assertEquals('trailingPIData', '', nodeValue);
|
assertEqualsW('trailingPIData', '', nodeValue);
|
||||||
node := node.nextSibling;
|
node := node.nextSibling;
|
||||||
assertNull('SixthIsNull', node);
|
assertNull('SixthIsNull', node);
|
||||||
end;
|
end;
|
||||||
@ -223,7 +223,7 @@ begin
|
|||||||
attrSpecified := attr.specified;
|
attrSpecified := attr.specified;
|
||||||
assertTrue('titleSpecified', attrSpecified);
|
assertTrue('titleSpecified', attrSpecified);
|
||||||
attrValue := attr.nodeValue;
|
attrValue := attr.nodeValue;
|
||||||
assertEquals('titleValue', 'default', attrValue);
|
assertEqualsW('titleValue', 'default', attrValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ tests that namespace fixup is done while serializing }
|
{ tests that namespace fixup is done while serializing }
|
||||||
@ -256,11 +256,11 @@ begin
|
|||||||
|
|
||||||
docElem := parsedDoc.documentElement;
|
docElem := parsedDoc.documentElement;
|
||||||
docElemLocalName := docElem.localName;
|
docElemLocalName := docElem.localName;
|
||||||
assertEquals('docElemLocalName', 'test', docElemLocalName);
|
assertEqualsW('docElemLocalName', 'test', docElemLocalName);
|
||||||
docElemNS := TDOMNode(docElem).namespaceURI;
|
docElemNS := TDOMNode(docElem).namespaceURI;
|
||||||
assertEquals('docElemNS', namespaceURI, docElemNS);
|
assertEqualsW('docElemNS', namespaceURI, docElemNS);
|
||||||
attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
|
attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
|
||||||
assertEquals('properNSAttrValue', 'test value', attrValue);
|
assertEqualsW('properNSAttrValue', 'test value', attrValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ tests that namespace fixup is done while serializing }
|
{ tests that namespace fixup is done while serializing }
|
||||||
@ -293,11 +293,11 @@ begin
|
|||||||
|
|
||||||
docElem := parsedDoc.documentElement;
|
docElem := parsedDoc.documentElement;
|
||||||
docElemLocalName := docElem.localName;
|
docElemLocalName := docElem.localName;
|
||||||
assertEquals('docElemLocalName', 'test', docElemLocalName);
|
assertEqualsW('docElemLocalName', 'test', docElemLocalName);
|
||||||
docElemNS := TDOMNode(docElem).namespaceURI;
|
docElemNS := TDOMNode(docElem).namespaceURI;
|
||||||
assertEquals('docElemNS', namespaceURI, docElemNS);
|
assertEqualsW('docElemNS', namespaceURI, docElemNS);
|
||||||
attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
|
attrValue := docElem.getAttributeNS(namespaceURI, 'attr');
|
||||||
assertEquals('properNSAttrValue', 'test value', attrValue);
|
assertEqualsW('properNSAttrValue', 'test value', attrValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
@ -427,6 +427,8 @@ begin
|
|||||||
rslt.Add(indent + 'AssertEqualsCollection(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
rslt.Add(indent + 'AssertEqualsCollection(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
||||||
else if cond = '_list' then
|
else if cond = '_list' then
|
||||||
rslt.Add(indent + 'AssertEqualsList(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
rslt.Add(indent + 'AssertEqualsList(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
||||||
|
else if cond = 'DOMString' then
|
||||||
|
rslt.Add(indent + 'AssertEqualsW(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
||||||
else if node['ignoreCase'] = 'true' then
|
else if node['ignoreCase'] = 'true' then
|
||||||
rslt.Add(indent + 'AssertEqualsNoCase(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
rslt.Add(indent + 'AssertEqualsNoCase(''' + node['id'] + ''', ' + ReplaceQuotes(node['expected']) + ', ' + node['actual'] + ');')
|
||||||
else
|
else
|
||||||
@ -975,7 +977,7 @@ begin
|
|||||||
if ParamCount < 2 then
|
if ParamCount < 2 then
|
||||||
begin
|
begin
|
||||||
writeln;
|
writeln;
|
||||||
writeln('Usage: ', ParamStr(0), ' <suite dir> <outputunit.pp> [-f]');
|
writeln('Usage: ', ExtractFileName(ParamStr(0)), ' <suite dir> <outputunit.pp> [-f]');
|
||||||
writeln(' -f: force conversion of tests which contain unknown tags');
|
writeln(' -f: force conversion of tests which contain unknown tags');
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user