Browse Source

+ from Darius Blaszijk: GetSuiteAsXML and TestSuiteAsXML implementation

git-svn-id: trunk@7493 -
florian 18 years ago
parent
commit
b261bdf52f
1 changed files with 40 additions and 0 deletions
  1. 40 0
      packages/fcl-fpcunit/src/xmltestreport.pp

+ 40 - 0
packages/fcl-fpcunit/src/xmltestreport.pp

@@ -65,9 +65,47 @@ type
     property Document: TXMLDocument read FDoc;
     property Document: TXMLDocument read FDoc;
   end;
   end;
 
 
+function GetSuiteAsXML(aSuite: TTestSuite): string;
+function TestSuiteAsXML(n: TDOMElement; FDoc: TXMLDocument; aSuite:TTestSuite): string;
 
 
 implementation
 implementation
 
 
+function GetSuiteAsXML(aSuite: TTestSuite): string;
+var
+  FDoc: TXMLDocument;
+  n: TDOMElement;
+  stream : TStringStream;
+begin
+  Result := '';
+
+  if aSuite <> nil then
+  begin
+    FDoc:= TXMLDocument.Create;
+
+    n := FDoc.CreateElement('TestSuites');
+    FDoc.AppendChild(n);
+
+    TestSuiteAsXML(n, FDoc, aSuite);
+
+    stream := TStringStream.Create('');
+    WriteXMLFile(FDoc, stream);
+    writeln(stream.DataString);
+    stream.Free;
+  end;
+end;
+
+function TestSuiteAsXML(n: TDOMElement; FDoc: TXMLDocument; aSuite:TTestSuite): string;
+var
+  i: integer;
+begin
+  for i := 0 to Pred(aSuite.Tests.Count) do
+    if TTest(aSuite.Tests.Items[i]) is TTestSuite then
+      TestSuiteAsXML(n, FDoc, TTestSuite(aSuite.Tests.Items[i]))
+    else
+      if TTest(aSuite.Tests.Items[i]) is TTestCase then
+        n.AppendChild(FDoc.CreateTextNode(TTestcase(aSuite.Tests.Items[i]).TestName + ' '));
+end;
+
 
 
 { TXMLResultsWriter }
 { TXMLResultsWriter }
 
 
@@ -251,3 +289,5 @@ end;
 
 
 end.
 end.
 
 
+
+