From fc2432bec30a1a86d7de869a9b8c3776f22051d6 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 9 Jul 1999 21:06:59 +0000 Subject: [PATCH] + Initial implementation by sebastian Guenther --- fcl/tests/cfgtest.pp | 46 +++++ fcl/tests/fpdoc.dtd | 54 ++++++ fcl/tests/kword.xml | 436 +++++++++++++++++++++++++++++++++++++++++++ fcl/tests/simple.xml | 8 + fcl/tests/xmldump.pp | 74 ++++++++ 5 files changed, 618 insertions(+) create mode 100644 fcl/tests/cfgtest.pp create mode 100644 fcl/tests/fpdoc.dtd create mode 100644 fcl/tests/kword.xml create mode 100644 fcl/tests/simple.xml create mode 100644 fcl/tests/xmldump.pp diff --git a/fcl/tests/cfgtest.pp b/fcl/tests/cfgtest.pp new file mode 100644 index 0000000000..1d7de37bbb --- /dev/null +++ b/fcl/tests/cfgtest.pp @@ -0,0 +1,46 @@ +// $Id$ + +{$MODE objfpc} +{$H+} + +program cfgtest; +uses xmlcfg; +var + cfg: TXMLConfig; +begin + + WriteLn('Writing a sample XML configuration to "testcfg.xml"...'); + + cfg := TXMLConfig.Create('testcfg.xml'); + cfg.SetValue('cfgtest/MainWindow/Constraints/Width', 600); + cfg.SetValue('cfgtest/MainWindow/Constraints/Height', 400); + cfg.SetValue('cfgtest/MainWindow/Caption', 'TXMLConfig Test'); + cfg.SetValue('cfgtest/SomeForm/Presets/Preset1/Name', 'Example'); + cfg.SetValue('TipOfTheDay/Disabled', True); + cfg.Free; + + WriteLn('Ok; now I''ll try to read back all values...'); + + cfg := TXMLConfig.Create('testcfg.xml'); + if cfg.GetValue('cfgtest/MainWindow/Constraints/Width', 0) <> 600 then + WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Width'); + if cfg.GetValue('cfgtest/MainWindow/Constraints/Height', 400) <> 400 then + WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Height'); + if cfg.GetValue('cfgtest/MainWindow/Caption', '') <> 'TXMLConfig Test' then + WriteLn('Invalid value: cfgtest/MainWindow/Caption'); + if cfg.GetValue('cfgtest/SomeForm/Presets/Preset1/Name', '') <> 'Example' then + WriteLn('Invalid value: cfgtest/SomeForm/Presets/Preset1/Name'); + if cfg.GetValue('TipOfTheDay/Disabled', False) <> True then + WriteLn('Invalid value: TipOfTheDay/Disabled'); + cfg.Free; + + WriteLn('Done!'); +end. + + +{ + $Log$ + Revision 1.1 1999-07-09 21:06:59 michael + + Initial implementation by sebastian Guenther + +} diff --git a/fcl/tests/fpdoc.dtd b/fcl/tests/fpdoc.dtd new file mode 100644 index 0000000000..3aa044e716 --- /dev/null +++ b/fcl/tests/fpdoc.dtd @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fcl/tests/kword.xml b/fcl/tests/kword.xml new file mode 100644 index 0000000000..e21be93981 --- /dev/null +++ b/fcl/tests/kword.xml @@ -0,0 +1,436 @@ + + + + + + + + + + + + Just a XML test, this file has been created by an early alpha version of KWord... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fcl/tests/simple.xml b/fcl/tests/simple.xml new file mode 100644 index 0000000000..7bc896127c --- /dev/null +++ b/fcl/tests/simple.xml @@ -0,0 +1,8 @@ + + + + + Just a test! This < was an entity reference. + + + diff --git a/fcl/tests/xmldump.pp b/fcl/tests/xmldump.pp new file mode 100644 index 0000000000..c1f91d22ac --- /dev/null +++ b/fcl/tests/xmldump.pp @@ -0,0 +1,74 @@ +// $Id$ + +{$MODE objfpc} +{$H+} + +program xmldump; +uses sysutils, DOM, xmlread; +const + NodeNames: array[ELEMENT_NODE..NOTATION_NODE] of String = ( + 'Element', + 'Attribute', + 'Text', + 'CDATA section', + 'Entity reference', + 'Entity', + 'Processing instruction', + 'Comment', + 'Document', + 'Document type', + 'Document fragment', + 'Notation' + ); + +procedure DumpNode(node: TDOMNode; spc: String); +var + i: Integer; + attr: TDOMNode; +begin + Write(spc, NodeNames[node.NodeType]); + if Copy(node.NodeName, 1, 1) <> '#' then + Write(' "', node.NodeName, '"'); + if node.NodeValue <> '' then + Write(' "', node.NodeValue, '"'); + + if (node.Attributes <> nil) and (node.Attributes.Length > 0) then begin + Write(','); + for i := 0 to node.Attributes.Length - 1 do begin + attr := node.Attributes.Item[i]; + Write(' ', attr.NodeName, ' = "', attr.NodeValue, '"'); + end; + end; + WriteLn; + + if node.FirstChild <> nil then + DumpNode(node.FirstChild, spc + ' '); + if node.NextSibling <> nil then + DumpNode(node.NextSibling, spc); +end; + +var + xml: TXMLDocument; +begin + if ParamCount <> 1 then begin + WriteLn('xmldump '); + exit; + end; + + if UpCase(ExtractFileExt(ParamStr(1))) = '.DTD' then + xml := ReadDTDFile(ParamStr(1)) + else + xml := ReadXMLFile(ParamStr(1)); + + WriteLn('Successfully parsed the document. Structure:'); + WriteLn; + DumpNode(xml, '| '); +end. + + +{ + $Log$ + Revision 1.1 1999-07-09 21:06:59 michael + + Initial implementation by sebastian Guenther + +}