diff options
Diffstat (limited to 'modules/xml/tests')
58 files changed, 1819 insertions, 0 deletions
diff --git a/modules/xml/tests/nonreg_tests/bug_10295.dia.ref b/modules/xml/tests/nonreg_tests/bug_10295.dia.ref new file mode 100755 index 000000000..1b4f10ee1 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10295.dia.ref @@ -0,0 +1,20 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Allan CORNET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10295 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=10295 +// +// <-- Short Description --> +// Due to a bug in libxml2, an internal error could lead to a segfault in vsprintf_chk +// +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +assert_checkequal(execstr("xmlWrite(doc, TMPDIR+''/A/B.xml'', %f)","errcatch"), 999); +xmlDelete(doc); diff --git a/modules/xml/tests/nonreg_tests/bug_10295.tst b/modules/xml/tests/nonreg_tests/bug_10295.tst new file mode 100755 index 000000000..d15debcc7 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10295.tst @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Allan CORNET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10295 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/show_bug.cgi?id=10295 +// +// <-- Short Description --> +// Due to a bug in libxml2, an internal error could lead to a segfault in vsprintf_chk +// + +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +assert_checkequal(execstr("xmlWrite(doc, TMPDIR+''/A/B.xml'', %f)","errcatch"), 999); +xmlDelete(doc);
\ No newline at end of file diff --git a/modules/xml/tests/nonreg_tests/bug_10645.dia.ref b/modules/xml/tests/nonreg_tests/bug_10645.dia.ref new file mode 100755 index 000000000..08f4feb17 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10645.dia.ref @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10645 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/10645 +// +// <-- Short Description --> +// File encoding could not be given as argument in xmlRead. +// +assert_checkerror("doc=xmlRead(""SCI/modules/xml/tests/nonreg_tests/bug_10645.xml"")",[],999); +doc = xmlRead("SCI/modules/xml/tests/nonreg_tests/bug_10645.xml","iso-8859-1"); +assert_checkequal(doc.root.content, "Clément"); +xmlDelete(doc); diff --git a/modules/xml/tests/nonreg_tests/bug_10645.tst b/modules/xml/tests/nonreg_tests/bug_10645.tst new file mode 100755 index 000000000..805b6c59a --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10645.tst @@ -0,0 +1,22 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10645 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/10645 +// +// <-- Short Description --> +// File encoding could not be given as argument in xmlRead. +// + +assert_checkerror("doc=xmlRead(""SCI/modules/xml/tests/nonreg_tests/bug_10645.xml"")",[],999); +doc = xmlRead("SCI/modules/xml/tests/nonreg_tests/bug_10645.xml","iso-8859-1"); +assert_checkequal(doc.root.content, "Clément"); +xmlDelete(doc);
\ No newline at end of file diff --git a/modules/xml/tests/nonreg_tests/bug_10645.xml b/modules/xml/tests/nonreg_tests/bug_10645.xml new file mode 100755 index 000000000..e3fb26e95 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10645.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<root> +Clément +</root>
\ No newline at end of file diff --git a/modules/xml/tests/nonreg_tests/bug_10670.dia.ref b/modules/xml/tests/nonreg_tests/bug_10670.dia.ref new file mode 100755 index 000000000..f607a72fa --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10670.dia.ref @@ -0,0 +1,19 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10670 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/10670 +// +// <-- Short Description --> +// There was a crash with xmlRead when argument had a bad dimension. +// +asserterrmsg = sprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"), "xmlRead" , 1); +assert_checkerror("xmlRead([""aze"" ""aze""])", asserterrmsg); diff --git a/modules/xml/tests/nonreg_tests/bug_10670.tst b/modules/xml/tests/nonreg_tests/bug_10670.tst new file mode 100755 index 000000000..7d5d1c9bc --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_10670.tst @@ -0,0 +1,20 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 10670 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/10670 +// +// <-- Short Description --> +// There was a crash with xmlRead when argument had a bad dimension. +// + +asserterrmsg = sprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"), "xmlRead" , 1); +assert_checkerror("xmlRead([""aze"" ""aze""])", asserterrmsg);
\ No newline at end of file diff --git a/modules/xml/tests/nonreg_tests/bug_11487.dia.ref b/modules/xml/tests/nonreg_tests/bug_11487.dia.ref new file mode 100755 index 000000000..6508160de --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_11487.dia.ref @@ -0,0 +1,27 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 11487 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/11487 +// +// <-- Short Description --> +// Infinite loop when a list was inserted into itself. +// +xml=["<root>";"<a>hello</a>";"<a>wolrd</a>";"</root>"]; +expected=["<?xml version=""1.0""?>";"<root>";" <a>hello</a>";" <a>hello</a>";" <a>wolrd</a>";" <a>hello</a>";" <a>hello</a>";" <a>wolrd</a>";"</root>"]; +doc=xmlReadStr(xml); +xp=xmlXPath(doc, "//root"); +c=xp(1).children; +doc.root.children(2)=c; +doc.root.children(size(doc.root.children, "*") + 1)=c; +result=xmlDump(doc); +xmlDelete(doc); +assert_checkequal(expected, result); diff --git a/modules/xml/tests/nonreg_tests/bug_11487.tst b/modules/xml/tests/nonreg_tests/bug_11487.tst new file mode 100755 index 000000000..e893acc27 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_11487.tst @@ -0,0 +1,28 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 11487 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/11487 +// +// <-- Short Description --> +// Infinite loop when a list was inserted into itself. +// + +xml=["<root>";"<a>hello</a>";"<a>wolrd</a>";"</root>"]; +expected=["<?xml version=""1.0""?>";"<root>";" <a>hello</a>";" <a>hello</a>";" <a>wolrd</a>";" <a>hello</a>";" <a>hello</a>";" <a>wolrd</a>";"</root>"]; +doc=xmlReadStr(xml); +xp=xmlXPath(doc, "//root"); +c=xp(1).children; +doc.root.children(2)=c; +doc.root.children(size(doc.root.children, "*") + 1)=c; +result=xmlDump(doc); +xmlDelete(doc); +assert_checkequal(expected, result); diff --git a/modules/xml/tests/nonreg_tests/bug_13174.dia.ref b/modules/xml/tests/nonreg_tests/bug_13174.dia.ref new file mode 100755 index 000000000..40d0e0ba4 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13174.dia.ref @@ -0,0 +1,27 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13174 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13174 +// +// <-- Short Description --> +// Crash after element removal. +// +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +assert_checkequal("Scilab", doc.root.children(1).content); +assert_checkequal("World", doc.root.children(2).content); +xmlDelete(doc) +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(2)); +assert_checkequal("Hello", doc.root.children(1).content); +assert_checkequal("World", doc.root.children(2).content); +xmlDelete(doc) diff --git a/modules/xml/tests/nonreg_tests/bug_13174.tst b/modules/xml/tests/nonreg_tests/bug_13174.tst new file mode 100755 index 000000000..02f56b947 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13174.tst @@ -0,0 +1,30 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13174 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13174 +// +// <-- Short Description --> +// Crash after element removal. +// + +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +assert_checkequal("Scilab", doc.root.children(1).content); +assert_checkequal("World", doc.root.children(2).content); +xmlDelete(doc) + +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(2)); +assert_checkequal("Hello", doc.root.children(1).content); +assert_checkequal("World", doc.root.children(2).content); +xmlDelete(doc) + diff --git a/modules/xml/tests/nonreg_tests/bug_13435.dia.ref b/modules/xml/tests/nonreg_tests/bug_13435.dia.ref new file mode 100755 index 000000000..e87c791e9 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13435.dia.ref @@ -0,0 +1,23 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13435 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13435 +// +// <-- Short Description --> +// Crash under Windows when xmlRemove on the first child +// +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +c = doc.root.children; +assert_checkequal(3, c.size); +xmlRemove(doc.root.children(1)); +assert_checkequal(2, c.size); +xmlDelete(doc) diff --git a/modules/xml/tests/nonreg_tests/bug_13435.tst b/modules/xml/tests/nonreg_tests/bug_13435.tst new file mode 100755 index 000000000..347ee1930 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13435.tst @@ -0,0 +1,25 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13435 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13435 +// +// <-- Short Description --> +// Crash under Windows when xmlRemove on the first child +// + +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +c = doc.root.children; +assert_checkequal(3, c.size); +xmlRemove(doc.root.children(1)); +assert_checkequal(2, c.size); + +xmlDelete(doc) diff --git a/modules/xml/tests/nonreg_tests/bug_13509.dia.ref b/modules/xml/tests/nonreg_tests/bug_13509.dia.ref new file mode 100755 index 000000000..bfae934fa --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13509.dia.ref @@ -0,0 +1,49 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13509 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13509 +// +// <-- Short Description --> +// It was not possible to have an empty prefix with xmlNs +// +s = "<root><a/><b/></root>" + s = + + <root><a/><b/></root> +doc = xmlReadStr(s) + doc = + +XML Document +url: Undefined +root: XML Element +ns=xmlNs(doc.root,"","http://name.space"); +xmlAddNs(doc.root.children(1),ns); +xmlAddNs(doc.root.children(2),ns); +out = xmlDump(doc); +assert_checkequal(out(3), " <a xmlns:=""http://name.space""/>"); +xmlDelete(doc) +s = "<root><a/><b/></root>" + s = + + <root><a/><b/></root> +doc = xmlReadStr(s) + doc = + +XML Document +url: Undefined +root: XML Element +ns=xmlNs(doc.root,[],"http://name.space"); +xmlAddNs(doc.root.children(1),ns); +xmlAddNs(doc.root.children(2),ns); +out = xmlDump(doc); +assert_checkequal(out(3), " <a xmlns=""http://name.space""/>"); +xmlDelete(doc) diff --git a/modules/xml/tests/nonreg_tests/bug_13509.tst b/modules/xml/tests/nonreg_tests/bug_13509.tst new file mode 100755 index 000000000..daeba7248 --- /dev/null +++ b/modules/xml/tests/nonreg_tests/bug_13509.tst @@ -0,0 +1,39 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13509 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13509 +// +// <-- Short Description --> +// It was not possible to have an empty prefix with xmlNs +// + +s = "<root><a/><b/></root>" +doc = xmlReadStr(s) +ns=xmlNs(doc.root,"","http://name.space"); +xmlAddNs(doc.root.children(1),ns); +xmlAddNs(doc.root.children(2),ns); +out = xmlDump(doc); + +assert_checkequal(out(3), " <a xmlns:=""http://name.space""/>"); + +xmlDelete(doc) + +s = "<root><a/><b/></root>" +doc = xmlReadStr(s) +ns=xmlNs(doc.root,[],"http://name.space"); +xmlAddNs(doc.root.children(1),ns); +xmlAddNs(doc.root.children(2),ns); +out = xmlDump(doc); + +assert_checkequal(out(3), " <a xmlns=""http://name.space""/>"); + +xmlDelete(doc) diff --git a/modules/xml/tests/unit_tests/htmlRead.dia.ref b/modules/xml/tests/unit_tests/htmlRead.dia.ref new file mode 100755 index 000000000..83f47c454 --- /dev/null +++ b/modules/xml/tests/unit_tests/htmlRead.dia.ref @@ -0,0 +1,20 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = htmlRead(SCI + "/modules/helptools/data/pages/homepage-en_US.html"); +xp = xmlXPath(doc,"//a/@href"); +assert_checktrue(xp.size > 0); +links = xmlAsText(xp); +assert_checktrue(or(links=="http://www.scilab.org/")); +htmlWrite(doc, TMPDIR + "/foo.html"); +xmlDelete(doc); +doc = htmlRead(TMPDIR + "/foo.html"); +xp = xmlXPath(doc,"//a/@href"); +assert_checktrue(xp.size > 0); +links2 = xmlAsText(xp); +assert_checkequal(links, links2); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/htmlRead.tst b/modules/xml/tests/unit_tests/htmlRead.tst new file mode 100755 index 000000000..393ef3bbc --- /dev/null +++ b/modules/xml/tests/unit_tests/htmlRead.tst @@ -0,0 +1,22 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = htmlRead(SCI + "/modules/helptools/data/pages/homepage-en_US.html"); +xp = xmlXPath(doc,"//a/@href"); +assert_checktrue(xp.size > 0); +links = xmlAsText(xp); +assert_checktrue(or(links=="http://www.scilab.org/")); +htmlWrite(doc, TMPDIR + "/foo.html"); +xmlDelete(doc); +doc = htmlRead(TMPDIR + "/foo.html"); +xp = xmlXPath(doc,"//a/@href"); +assert_checktrue(xp.size > 0); +links2 = xmlAsText(xp); +assert_checkequal(links, links2); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/invalid_library.xml b/modules/xml/tests/unit_tests/invalid_library.xml new file mode 100755 index 000000000..79fbb1931 --- /dev/null +++ b/modules/xml/tests/unit_tests/invalid_library.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE library SYSTEM "library.dtd"> + +<library> + <book title="Ulysses"> + <author>James Joyce</author> + <hero>Leopold Bloom</hero> + </book> + <book title="Don Quichotte"> + <author>Miguel de Cervantes</author> + <hero>Don Quichotte de la Mancha</hero> + </book> + <a/> +</library> diff --git a/modules/xml/tests/unit_tests/library.dtd b/modules/xml/tests/unit_tests/library.dtd new file mode 100755 index 000000000..511a21161 --- /dev/null +++ b/modules/xml/tests/unit_tests/library.dtd @@ -0,0 +1,5 @@ +<!ELEMENT library (book)+> +<!ELEMENT book (author,hero)> +<!ATTLIST book title CDATA #REQUIRED> +<!ELEMENT author (#PCDATA)> +<!ELEMENT hero (#PCDATA)> diff --git a/modules/xml/tests/unit_tests/library.rng b/modules/xml/tests/unit_tests/library.rng new file mode 100755 index 000000000..1306f16ed --- /dev/null +++ b/modules/xml/tests/unit_tests/library.rng @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <ref name="library"/> + </start> + <define name="library"> + <element name="library"> + <zeroOrMore> + <ref name="book"/> + </zeroOrMore> + </element> + </define> + <define name="book"> + <element name="book"> + <attribute name="title"> + <text/> + </attribute> + <interleave> + <ref name="author"/> + <ref name="hero"/> + </interleave> + </element> + </define> + <define name="author"> + <element name="author"> + <text/> + </element> + </define> + <define name="hero"> + <element name="hero"> + <text/> + </element> + </define> +</grammar>
\ No newline at end of file diff --git a/modules/xml/tests/unit_tests/library.xml b/modules/xml/tests/unit_tests/library.xml new file mode 100755 index 000000000..2bb0ebf1e --- /dev/null +++ b/modules/xml/tests/unit_tests/library.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE library SYSTEM "library.dtd"> + +<library> + <book title="Ulysses"> + <author>James Joyce</author> + <hero>Leopold Bloom</hero> + </book> + <book title="Don Quichotte"> + <author>Miguel de Cervantes</author> + <hero>Don Quichotte de la Mancha</hero> + </book> +</library> diff --git a/modules/xml/tests/unit_tests/library.xsd b/modules/xml/tests/unit_tests/library.xsd new file mode 100755 index 000000000..8f94076d6 --- /dev/null +++ b/modules/xml/tests/unit_tests/library.xsd @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> + <xs:element name="library" type="TypeLibrary"/> + <xs:complexType name="TypeLibrary"> + <xs:sequence maxOccurs="unbounded" minOccurs="1"> + <xs:element name="book" type="TypeBook"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="TypeBook"> + <xs:sequence> + <xs:element name="author" type="xs:string"/> + <xs:element name="hero" type="xs:string"/> + </xs:sequence> + <xs:attribute name="title" type="xs:string" use="required"/> + </xs:complexType> +</xs:schema>
\ No newline at end of file diff --git a/modules/xml/tests/unit_tests/sep_69_example.xml b/modules/xml/tests/unit_tests/sep_69_example.xml new file mode 100755 index 000000000..68497e54d --- /dev/null +++ b/modules/xml/tests/unit_tests/sep_69_example.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<root> + <hello lang="fr">bonjour</hello> + <hello lang="de">Hallo</hello> + <world lang="fr">monde</world> + <world lang="de">Welt</world> +</root> diff --git a/modules/xml/tests/unit_tests/size.dia.ref b/modules/xml/tests/unit_tests/size.dia.ref new file mode 100755 index 000000000..eb41ebb19 --- /dev/null +++ b/modules/xml/tests/unit_tests/size.dia.ref @@ -0,0 +1,17 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a b=""b"" c=""c"" d=""d""><b>b</b></a><c>c</c></root>"); +assert_checkequal(size(doc.root.children), [1 2]); +assert_checkequal(size(doc.root.children, "r"), 1); +assert_checkequal(size(doc.root.children, "c"), 2); +assert_checkequal(size(doc.root.children, "*"), 2); +assert_checkequal(size(doc.root.children(1).attributes), [1 3]); +assert_checkequal(size(doc.root.children(1).attributes, "r"), 1); +assert_checkequal(size(doc.root.children(1).attributes, "c"), 3); +assert_checkequal(size(doc.root.children(1).attributes, "*"), 3); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/size.tst b/modules/xml/tests/unit_tests/size.tst new file mode 100755 index 000000000..7685918ad --- /dev/null +++ b/modules/xml/tests/unit_tests/size.tst @@ -0,0 +1,21 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a b=""b"" c=""c"" d=""d""><b>b</b></a><c>c</c></root>"); +assert_checkequal(size(doc.root.children), [1 2]); +assert_checkequal(size(doc.root.children, "r"), 1); +assert_checkequal(size(doc.root.children, "c"), 2); +assert_checkequal(size(doc.root.children, "*"), 2); + +assert_checkequal(size(doc.root.children(1).attributes), [1 3]); +assert_checkequal(size(doc.root.children(1).attributes, "r"), 1); +assert_checkequal(size(doc.root.children(1).attributes, "c"), 3); +assert_checkequal(size(doc.root.children(1).attributes, "*"), 3); + +xmlDelete(doc);
\ No newline at end of file diff --git a/modules/xml/tests/unit_tests/w3cExample.xml b/modules/xml/tests/unit_tests/w3cExample.xml new file mode 100755 index 000000000..c3d62b8ef --- /dev/null +++ b/modules/xml/tests/unit_tests/w3cExample.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- DO NOT TOUCCH THIS FILE... EVENT FOR COMMENTS --> +<bookstore> + <book category="COOKING"> + <title lang="en">Everyday Italian</title> + <author>Giada De Laurentiis</author> + <year>2005</year> + <price>30.00</price> + </book> + <book category="CHILDREN"> + <title lang="en">Harry Potter</title> + <author>J K. Rowling</author> + <year>2005</year> + <price>29.99</price> + </book> + <book category="WEB"> + <title lang="en">XQuery Kick Start</title> + <author>James McGovern</author> + <author>Per Bothner</author> + <author>Kurt Cagle</author> + <author>James Linn</author> + <author>Vaidyanathan Nagarajan</author> + <year>2003</year> + <price>49.99</price> + </book> + <book category="WEB"> + <title lang="en">Learning XML</title> + <author>Erik T. Ray</author> + <year>2003</year> + <price>39.95</price> + </book> + <book category="WEB"> + <title lang="en">Scilab rox</title> + <author>the Scilab team</author> + <year>2011</year> + <price>0.0</price> + </book> +</bookstore> diff --git a/modules/xml/tests/unit_tests/xmlAddNs.dia.ref b/modules/xml/tests/unit_tests/xmlAddNs.dia.ref new file mode 100755 index 000000000..04339a7b0 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAddNs.dia.ref @@ -0,0 +1,37 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlDocument("TMPDIR/foo.xml"); +doc.root = xmlElement(doc, "root"); +a = xmlElement(doc, "a"); +b = xmlElement(doc, "b"); +ns_scilab = xmlNs(a, "scilab", "http://www.scilab.org"); +ns_balics = xmlNs(a, "balics", "http://gro.balics.www"); +xmlAddNs(b, ns_scilab, ns_balics); +doc.root.children(1) = a; +doc.root.children(2) = b; +tmp=xmlGetNsByPrefix(doc.root.children(1), "scilab"); +assert_checktrue(tmp.prefix=="scilab"); +assert_checktrue(tmp.href=="http://www.scilab.org"); +tmp=xmlGetNsByPrefix(doc.root.children(2), "scilab"); +assert_checktrue(tmp.prefix=="scilab"); +assert_checktrue(tmp.href=="http://www.scilab.org"); +tmp=xmlGetNsByPrefix(doc.root.children(1), "balics"); +assert_checktrue(tmp.prefix=="balics"); +assert_checktrue(tmp.href=="http://gro.balics.www"); +tmp=xmlGetNsByPrefix(doc.root.children(2), "balics"); +assert_checktrue(tmp.prefix=="balics"); +assert_checktrue(tmp.href=="http://gro.balics.www"); +assert_checktrue(grep(xmlDump(doc),"http://www.scilab.")<>[]); +assert_checktrue(grep(xmlDump(doc),"http://gro.ba")<>[]); +xmlDelete(doc); +doc = xmlReadStr("<root><a xmlns:scilab=""http://www.scilab.org""><b>Hello </b><scilab:c>World</scilab:c></a></root>"); +c = doc.root.children(1).children(2); +a=xmlGetNsByHref(c, "http://www.scilab.org"); +assert_checkequal(a.prefix,"scilab"); +assert_checkequal(a.href,"http://www.scilab.org"); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlAddNs.tst b/modules/xml/tests/unit_tests/xmlAddNs.tst new file mode 100755 index 000000000..9f3c6df6b --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAddNs.tst @@ -0,0 +1,45 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlDocument("TMPDIR/foo.xml"); +doc.root = xmlElement(doc, "root"); +a = xmlElement(doc, "a"); +b = xmlElement(doc, "b"); +ns_scilab = xmlNs(a, "scilab", "http://www.scilab.org"); +ns_balics = xmlNs(a, "balics", "http://gro.balics.www"); +xmlAddNs(b, ns_scilab, ns_balics); + +doc.root.children(1) = a; +doc.root.children(2) = b; + +tmp=xmlGetNsByPrefix(doc.root.children(1), "scilab"); +assert_checktrue(tmp.prefix=="scilab"); +assert_checktrue(tmp.href=="http://www.scilab.org"); +tmp=xmlGetNsByPrefix(doc.root.children(2), "scilab"); +assert_checktrue(tmp.prefix=="scilab"); +assert_checktrue(tmp.href=="http://www.scilab.org"); + +tmp=xmlGetNsByPrefix(doc.root.children(1), "balics"); +assert_checktrue(tmp.prefix=="balics"); +assert_checktrue(tmp.href=="http://gro.balics.www"); +tmp=xmlGetNsByPrefix(doc.root.children(2), "balics"); +assert_checktrue(tmp.prefix=="balics"); +assert_checktrue(tmp.href=="http://gro.balics.www"); + +assert_checktrue(grep(xmlDump(doc),"http://www.scilab.")<>[]); +assert_checktrue(grep(xmlDump(doc),"http://gro.ba")<>[]); + +xmlDelete(doc); + +doc = xmlReadStr("<root><a xmlns:scilab=""http://www.scilab.org""><b>Hello </b><scilab:c>World</scilab:c></a></root>"); +c = doc.root.children(1).children(2); +a=xmlGetNsByHref(c, "http://www.scilab.org"); +assert_checkequal(a.prefix,"scilab"); +assert_checkequal(a.href,"http://www.scilab.org"); +xmlDelete(doc);
\ No newline at end of file diff --git a/modules/xml/tests/unit_tests/xmlAppend.dia.ref b/modules/xml/tests/unit_tests/xmlAppend.dia.ref new file mode 100755 index 000000000..0fd3e86ba --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAppend.dia.ref @@ -0,0 +1,19 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlDocument(); +root = xmlElement(doc, "root"); +doc.root = root; +for i=1:5 +xmlAppend(doc.root, xmlElement(doc, "child_" + string(i))); +end; +assert_checkequal(doc.root.children(1).name,"child_1"); +assert_checkequal(doc.root.children(2).name,"child_2"); +assert_checkequal(doc.root.children(3).name,"child_3"); +assert_checkequal(doc.root.children(4).name,"child_4"); +assert_checkequal(doc.root.children(5).name,"child_5"); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlAppend.tst b/modules/xml/tests/unit_tests/xmlAppend.tst new file mode 100755 index 000000000..33f2c800a --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAppend.tst @@ -0,0 +1,23 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlDocument(); +root = xmlElement(doc, "root"); +doc.root = root; +for i=1:5 +xmlAppend(doc.root, xmlElement(doc, "child_" + string(i))); +end; + +assert_checkequal(doc.root.children(1).name,"child_1"); +assert_checkequal(doc.root.children(2).name,"child_2"); +assert_checkequal(doc.root.children(3).name,"child_3"); +assert_checkequal(doc.root.children(4).name,"child_4"); +assert_checkequal(doc.root.children(5).name,"child_5"); + +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref b/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref new file mode 100755 index 000000000..8d605db35 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAsNumber.dia.ref @@ -0,0 +1,16 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>"); +xp = xmlXPath(doc, "//a/text()"); +assert_checkequal(xmlAsNumber(xp), [%nan,13,1.2345678,%nan,0.0023]); +assert_checkequal(xmlAsNumber(doc.root.children), [%nan,13,1.2345678,%nan,0.0023]); +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +plop=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(xmlAsNumber(plop), [30,29.99,49.99,39.95,0]); +assert_checkequal(xmlAsNumber(xmlFile.root.children), [%nan, %nan,%nan,%nan,%nan]); +assert_checkequal(xmlAsNumber(xmlFile.root.children(1).children), [%nan, %nan, 2005, 30]); diff --git a/modules/xml/tests/unit_tests/xmlAsNumber.tst b/modules/xml/tests/unit_tests/xmlAsNumber.tst new file mode 100755 index 000000000..22954f964 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAsNumber.tst @@ -0,0 +1,19 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>"); +xp = xmlXPath(doc, "//a/text()"); +assert_checkequal(xmlAsNumber(xp), [%nan,13,1.2345678,%nan,0.0023]); +assert_checkequal(xmlAsNumber(doc.root.children), [%nan,13,1.2345678,%nan,0.0023]); + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +plop=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(xmlAsNumber(plop), [30,29.99,49.99,39.95,0]); +assert_checkequal(xmlAsNumber(xmlFile.root.children), [%nan, %nan,%nan,%nan,%nan]); +assert_checkequal(xmlAsNumber(xmlFile.root.children(1).children), [%nan, %nan, 2005, 30]); diff --git a/modules/xml/tests/unit_tests/xmlAsText.dia.ref b/modules/xml/tests/unit_tests/xmlAsText.dia.ref new file mode 100755 index 000000000..8862a47ec --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAsText.dia.ref @@ -0,0 +1,16 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>"); +xp = xmlXPath(doc, "//a/text()"); +assert_checkequal(xmlAsText(xp), ["bug","13","1.2345678","b",".23E-2"]); +assert_checkequal(xmlAsText(doc.root.children), ["bug","13","1.2345678","b",".23E-2"]); +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +plop=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(xmlAsText(plop), ["30.00","29.99","49.99","39.95","0.0"]); +firstElement= ["Everyday Italian","Giada De Laurentiis","2005","30.00"]; +assert_checkequal(xmlAsText(xmlFile.root.children(1).children), firstElement); diff --git a/modules/xml/tests/unit_tests/xmlAsText.tst b/modules/xml/tests/unit_tests/xmlAsText.tst new file mode 100755 index 000000000..237e0e584 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAsText.tst @@ -0,0 +1,19 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a>bug</a><a>13</a><a>1.2345678</a><a>b</a><a>.23E-2</a></root>"); +xp = xmlXPath(doc, "//a/text()"); +assert_checkequal(xmlAsText(xp), ["bug","13","1.2345678","b",".23E-2"]); +assert_checkequal(xmlAsText(doc.root.children), ["bug","13","1.2345678","b",".23E-2"]); + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +plop=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(xmlAsText(plop), ["30.00","29.99","49.99","39.95","0.0"]); +firstElement= ["Everyday Italian","Giada De Laurentiis","2005","30.00"]; +assert_checkequal(xmlAsText(xmlFile.root.children(1).children), firstElement); diff --git a/modules/xml/tests/unit_tests/xmlAttributes.dia.ref b/modules/xml/tests/unit_tests/xmlAttributes.dia.ref new file mode 100755 index 000000000..8e5793e10 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAttributes.dia.ref @@ -0,0 +1,46 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +xmlWrite(doc, TMPDIR+"/foo.xml"); +// Now we open the previous file, modify it and save it +doc1 = xmlRead(TMPDIR+"/foo.xml"); +assert_checkequal(doc1.root.children.size,1); +assert_checkequal(doc1.root.children(1).name,"a"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +a = doc1.root.children(1).attributes; +assert_checkequal(a.att,"foo"); +assert_checkequal(a.rib,"bar"); +assert_checkequal(a(1),"foo"); +assert_checkequal(a(2),"bar"); +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); +XMLStream="<?xml version=""1.0""?>"; +XMLStream=XMLStream+"<root attr=""value""><a>hello</a>"; +XMLStream=XMLStream+"<b id=""123""> world</b></root>"; +fd_w = mopen(TMPDIR+'/plop.xml','w+'); +mputl(XMLStream, fd_w); +mclose(fd_w); +doc2 = xmlRead("TMPDIR/plop.xml"); +a2 = doc2.root.children(2).attributes; +assert_checkequal(a2(1),"123"); +assert_checkequal(a2(2),[]); +xmlDelete(doc2); +doc2 = xmlRead("TMPDIR/plop.xml"); +doc2.root.children(2).attributes.id=""; +a2 = doc2.root.children(2).attributes; +assert_checkequal(a2(1),""); +assert_checkequal(doc2.root.children(2).attributes.id,""); +assert_checkequal(a2(2),[]); +xmlDelete(doc2); +doc2 = xmlRead("TMPDIR/plop.xml"); +a2 = doc2.root.children(2).attributes; +a2.id=""; +doc2.root.children(2).attributes=a2; +assert_checkequal(doc2.root.children(2).attributes.id,""); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlAttributes.tst b/modules/xml/tests/unit_tests/xmlAttributes.tst new file mode 100755 index 000000000..e50a1e68a --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlAttributes.tst @@ -0,0 +1,56 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +xmlWrite(doc, TMPDIR+"/foo.xml"); + +// Now we open the previous file, modify it and save it +doc1 = xmlRead(TMPDIR+"/foo.xml"); +assert_checkequal(doc1.root.children.size,1); +assert_checkequal(doc1.root.children(1).name,"a"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +a = doc1.root.children(1).attributes; +assert_checkequal(a.att,"foo"); +assert_checkequal(a.rib,"bar"); +assert_checkequal(a(1),"foo"); +assert_checkequal(a(2),"bar"); + +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); + + +XMLStream="<?xml version=""1.0""?>"; +XMLStream=XMLStream+"<root attr=""value""><a>hello</a>"; +XMLStream=XMLStream+"<b id=""123""> world</b></root>"; + +fd_w = mopen(TMPDIR+'/plop.xml','w+'); +mputl(XMLStream, fd_w); +mclose(fd_w); + +doc2 = xmlRead("TMPDIR/plop.xml"); +a2 = doc2.root.children(2).attributes; +assert_checkequal(a2(1),"123"); +assert_checkequal(a2(2),[]); +xmlDelete(doc2); + +doc2 = xmlRead("TMPDIR/plop.xml"); +doc2.root.children(2).attributes.id=""; +a2 = doc2.root.children(2).attributes; +assert_checkequal(a2(1),""); +assert_checkequal(doc2.root.children(2).attributes.id,""); +assert_checkequal(a2(2),[]); +xmlDelete(doc2); + +doc2 = xmlRead("TMPDIR/plop.xml"); +a2 = doc2.root.children(2).attributes; +a2.id=""; +doc2.root.children(2).attributes=a2; +assert_checkequal(doc2.root.children(2).attributes.id,""); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlDocument.dia.ref b/modules/xml/tests/unit_tests/xmlDocument.dia.ref new file mode 100755 index 000000000..cb6706d50 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlDocument.dia.ref @@ -0,0 +1,28 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlDocument("TMPDIR/foo.xml"); +root = xmlElement(doc, "root"); +root.attributes.attr = "value"; +assert_checkequal(root.line,0); +root.children(1) = "<a>hello</a>"; +root.children(2) = xmlElement(doc, "b"); +root.children(2).attributes.id = "123"; +root.children(2).content = " world"; +doc.root = root; +xmlDump(doc); +assert_checkequal(doc.root.children(1).name,"a"); +assert_checkequal(doc.root.children(1).content,"hello"); +assert_checkequal(doc.root.children(2).name,"b"); +assert_checkequal(doc.root.children(2).content," world"); +xmlWrite(doc); +xmlDelete(doc); +doc2 = xmlRead("TMPDIR/foo.xml"); +assert_checkfalse(execstr("doc2.line","errcatch") == 0); +assert_checkequal(doc2.root.line,2); +assert_checkequal(doc2.root.children(1).line,3); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlDocument.tst b/modules/xml/tests/unit_tests/xmlDocument.tst new file mode 100755 index 000000000..0f33d1f27 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlDocument.tst @@ -0,0 +1,35 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlDocument("TMPDIR/foo.xml"); +root = xmlElement(doc, "root"); +root.attributes.attr = "value"; + +assert_checkequal(root.line,0); + +root.children(1) = "<a>hello</a>"; +root.children(2) = xmlElement(doc, "b"); +root.children(2).attributes.id = "123"; +root.children(2).content = " world"; + +doc.root = root; +xmlDump(doc); + +assert_checkequal(doc.root.children(1).name,"a"); +assert_checkequal(doc.root.children(1).content,"hello"); +assert_checkequal(doc.root.children(2).name,"b"); +assert_checkequal(doc.root.children(2).content," world"); +xmlWrite(doc); +xmlDelete(doc); + +doc2 = xmlRead("TMPDIR/foo.xml"); +assert_checkfalse(execstr("doc2.line","errcatch") == 0); +assert_checkequal(doc2.root.line,2); +assert_checkequal(doc2.root.children(1).line,3); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlDump.dia.ref b/modules/xml/tests/unit_tests/xmlDump.dia.ref new file mode 100755 index 000000000..ef19d11e8 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlDump.dia.ref @@ -0,0 +1,22 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlDocument("TMPDIR/foo.xml"); +root = xmlElement(doc, "root"); +root.attributes.attr = "value"; +assert_checkequal(root.line,0); +root.children(1) = "<a>hello</a>"; +root.children(2) = xmlElement(doc, "b"); +root.children(2).attributes.id = "123"; +root.children(2).content = " world"; +doc.root = root; +result=xmlDump(doc); +result_ref = ["<?xml version=""1.0""?>";"<root attr=""value"">";" <a>hello</a>";" <b id=""123""> world</b>";"</root>"]; +assert_checkequal(result, result_ref); +result=xmlDump(doc,%f); +result_ref=["<?xml version=""1.0""?>";"<root attr=""value""><a>hello</a><b id=""123""> world</b></root>"]; +assert_checkequal(result, result_ref); diff --git a/modules/xml/tests/unit_tests/xmlDump.tst b/modules/xml/tests/unit_tests/xmlDump.tst new file mode 100755 index 000000000..f02f18369 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlDump.tst @@ -0,0 +1,29 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlDocument("TMPDIR/foo.xml"); +root = xmlElement(doc, "root"); +root.attributes.attr = "value"; + +assert_checkequal(root.line,0); + +root.children(1) = "<a>hello</a>"; +root.children(2) = xmlElement(doc, "b"); +root.children(2).attributes.id = "123"; +root.children(2).content = " world"; + +doc.root = root; + +result=xmlDump(doc); +result_ref = ["<?xml version=""1.0""?>";"<root attr=""value"">";" <a>hello</a>";" <b id=""123""> world</b>";"</root>"]; +assert_checkequal(result, result_ref); + +result=xmlDump(doc,%f); +result_ref=["<?xml version=""1.0""?>";"<root attr=""value""><a>hello</a><b id=""123""> world</b></root>"]; +assert_checkequal(result, result_ref); diff --git a/modules/xml/tests/unit_tests/xmlFormat.dia.ref b/modules/xml/tests/unit_tests/xmlFormat.dia.ref new file mode 100755 index 000000000..04419c449 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlFormat.dia.ref @@ -0,0 +1,22 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +// An error +// Now we define %s_xmlFormat to handle double type +// Take care, in this example, the double matrix is not handled +function y=%s_xmlFormat(x), y="<number>" + string(x) + "</number>", endfunction; +// we retry a number insertion +doc.root.children(1.5) = 1.23456; +xmlDump(doc); +assert_checkequal(doc.root.children(2).content,"1.23456"); +assert_checkequal(evstr(doc.root.children(2).content),1.23456); +doc.root.children(1.5) = "plop"; +assert_checkequal(doc.root.children(2).content,"plop"); +assert_checkequal(doc.root.children(3).content,"1.23456"); +assert_checkequal(evstr(doc.root.children(3).content),1.23456); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlFormat.tst b/modules/xml/tests/unit_tests/xmlFormat.tst new file mode 100755 index 000000000..32353f54a --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlFormat.tst @@ -0,0 +1,26 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +// An error + +// Now we define %s_xmlFormat to handle double type +// Take care, in this example, the double matrix is not handled +function y=%s_xmlFormat(x), y="<number>" + string(x) + "</number>", endfunction; + +// we retry a number insertion +doc.root.children(1.5) = 1.23456; +xmlDump(doc); +assert_checkequal(doc.root.children(2).content,"1.23456"); +assert_checkequal(evstr(doc.root.children(2).content),1.23456); +doc.root.children(1.5) = "plop"; +assert_checkequal(doc.root.children(2).content,"plop"); +assert_checkequal(doc.root.children(3).content,"1.23456"); +assert_checkequal(evstr(doc.root.children(3).content),1.23456); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlLine.dia.ref b/modules/xml/tests/unit_tests/xmlLine.dia.ref new file mode 100755 index 000000000..c8943e5bc --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlLine.dia.ref @@ -0,0 +1,26 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +XMLStream="<?xml version=""1.0""?>"; +XMLStream=XMLStream+"<root attr=""value""><a>hello</a>"; +XMLStream=XMLStream+"<b id=""123""> world</b></root>"; +fd_w = mopen(TMPDIR+'/plop.xml','w+'); +mputl(XMLStream, fd_w); +mclose(fd_w); +doc2 = xmlRead("TMPDIR/plop.xml"); +assert_checkequal(doc2.root.line,1); +assert_checkequal(doc2.root.children(1).line,1); +assert_checkequal(doc2.root.children(2).line,1); +xmlDelete(doc2); +doc3 = xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +assert_checkequal(doc3.root.line,3); +assert_checkequal(doc3.root.children(1).line,4); +assert_checkequal(doc3.root.children(2).line,10); +assert_checkequal(doc3.root.children(3).line,16); +assert_checkequal(doc3.root.children(3).children(1).line,17); +assert_checkequal(doc3.root.children(3).children(2).line,18); +xmlDelete(doc3); diff --git a/modules/xml/tests/unit_tests/xmlLine.tst b/modules/xml/tests/unit_tests/xmlLine.tst new file mode 100755 index 000000000..e11bc5f07 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlLine.tst @@ -0,0 +1,31 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +XMLStream="<?xml version=""1.0""?>"; +XMLStream=XMLStream+"<root attr=""value""><a>hello</a>"; +XMLStream=XMLStream+"<b id=""123""> world</b></root>"; + +fd_w = mopen(TMPDIR+'/plop.xml','w+'); +mputl(XMLStream, fd_w); +mclose(fd_w); + +doc2 = xmlRead("TMPDIR/plop.xml"); +assert_checkequal(doc2.root.line,1); +assert_checkequal(doc2.root.children(1).line,1); +assert_checkequal(doc2.root.children(2).line,1); +xmlDelete(doc2); + +doc3 = xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +assert_checkequal(doc3.root.line,3); +assert_checkequal(doc3.root.children(1).line,4); +assert_checkequal(doc3.root.children(2).line,10); +assert_checkequal(doc3.root.children(3).line,16); +assert_checkequal(doc3.root.children(3).children(1).line,17); +assert_checkequal(doc3.root.children(3).children(2).line,18); +xmlDelete(doc3); diff --git a/modules/xml/tests/unit_tests/xmlName.dia.ref b/modules/xml/tests/unit_tests/xmlName.dia.ref new file mode 100755 index 000000000..4aec78a8d --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlName.dia.ref @@ -0,0 +1,18 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><foo a=""123"" b=""456"" c=""789""/></root>") + doc = + +XML Document +url: Undefined +root: XML Element +assert_checkequal(xmlName(doc.root.children(1)),"foo"); +assert_checkequal(xmlName(doc.root.children(1).attributes),["a" "b" "c"]); +assert_checkequal(xmlName(xmlXPath(doc,"//foo/@*")),["a" "b" "c"]); +assert_checkequal(xmlName(xmlXPath(doc,"//foo")),"foo"); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlName.tst b/modules/xml/tests/unit_tests/xmlName.tst new file mode 100755 index 000000000..fc8f0d6b2 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlName.tst @@ -0,0 +1,17 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><foo a=""123"" b=""456"" c=""789""/></root>") + +assert_checkequal(xmlName(doc.root.children(1)),"foo"); +assert_checkequal(xmlName(doc.root.children(1).attributes),["a" "b" "c"]); +assert_checkequal(xmlName(xmlXPath(doc,"//foo/@*")),["a" "b" "c"]); +assert_checkequal(xmlName(xmlXPath(doc,"//foo")),"foo"); + +xmlDelete(doc);
\ No newline at end of file diff --git a/modules/xml/tests/unit_tests/xmlRead.dia.ref b/modules/xml/tests/unit_tests/xmlRead.dia.ref new file mode 100755 index 000000000..eed565938 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlRead.dia.ref @@ -0,0 +1,57 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checktrue(xmlIsValidObject(xmlFile)); +a=xmlGetOpenDocs(); +if getos() == "Windows" then + assert_checkequal(a(1).url, "file:///" + SCI+"/etc/modules.xml"); +else + assert_checkequal(a(1).url, SCI+"/etc/modules.xml"); +end +content=xmlDump(xmlFile); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[20,1]); +xmlDelete(xmlFile); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checktrue(xmlIsValidObject(xmlFile)); +xmlFile2=xmlRead(SCI+"/etc/classpath.xml"); +assert_checktrue(xmlIsValidObject(xmlFile2)); +content=xmlDump(xmlFile); +content2=xmlDump(xmlFile2); +//assert_checkequal(content, content2); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[20,1]); +assert_checktrue(length(content2)>0); +assert_checktrue(size(content2)>=[20,1]); +xmlDelete(xmlFile); +xmlDelete(xmlFile2); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); +// Work with the structure +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checkequal(xmlFile.root.name,"modules"); +assert_checkequal(xmlFile.root.type,"XML_ELEMENT_NODE"); +elements=xmlFile.root.children; +assert_checktrue(xmlIsValidObject(elements)); +assert_checktrue(size(elements)>0); +for (i=1:length(elements)) + if (xmlFile.root.children(i).type<>"XML_COMMENT_NODE") + assert_checktrue(length(xmlFile.root.children(i).attributes.name)> 0); + assert_checktrue(xmlFile.root.children(i).attributes.activate=="yes" ... + | xmlFile.root.children(i).attributes.activate=="no"); + else +// It is a comment, no attributes + assert_checkequal(length(xmlFile.root.children(i).attributes),0); + end +end +xmlDelete(xmlFile); diff --git a/modules/xml/tests/unit_tests/xmlRead.tst b/modules/xml/tests/unit_tests/xmlRead.tst new file mode 100755 index 000000000..ecb5302ea --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlRead.tst @@ -0,0 +1,65 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// Copyright (C) 2013 - Scilab Enterprises - Adeline CARNIS +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checktrue(xmlIsValidObject(xmlFile)); +a=xmlGetOpenDocs(); +if getos() == "Windows" then + assert_checkequal(a(1).url, "file:///" + SCI+"/etc/modules.xml"); +else + assert_checkequal(a(1).url, SCI+"/etc/modules.xml"); +end + + +content=xmlDump(xmlFile); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[20,1]); +xmlDelete(xmlFile); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); + + +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checktrue(xmlIsValidObject(xmlFile)); +xmlFile2=xmlRead(SCI+"/etc/classpath.xml"); +assert_checktrue(xmlIsValidObject(xmlFile2)); + +content=xmlDump(xmlFile); +content2=xmlDump(xmlFile2); +//assert_checkequal(content, content2); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[20,1]); +assert_checktrue(length(content2)>0); +assert_checktrue(size(content2)>=[20,1]); +xmlDelete(xmlFile); +xmlDelete(xmlFile2); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); + +// Work with the structure +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +assert_checkequal(xmlFile.root.name,"modules"); +assert_checkequal(xmlFile.root.type,"XML_ELEMENT_NODE"); +elements=xmlFile.root.children; +assert_checktrue(xmlIsValidObject(elements)); +assert_checktrue(size(elements)>0); +for (i=1:length(elements)) + if (xmlFile.root.children(i).type<>"XML_COMMENT_NODE") + assert_checktrue(length(xmlFile.root.children(i).attributes.name)> 0); + assert_checktrue(xmlFile.root.children(i).attributes.activate=="yes" ... + | xmlFile.root.children(i).attributes.activate=="no"); + else +// It is a comment, no attributes + assert_checkequal(length(xmlFile.root.children(i).attributes),0); + end +end +xmlDelete(xmlFile); diff --git a/modules/xml/tests/unit_tests/xmlRemove.dia.ref b/modules/xml/tests/unit_tests/xmlRemove.dia.ref new file mode 100755 index 000000000..b161717ce --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlRemove.dia.ref @@ -0,0 +1,68 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +assert_checkequal(doc.root.children(1).name,"a"); +assert_checkequal(doc.root.children(2).name,"b"); +assert_checkequal(doc.root.children(3).name,"a"); +// Remove all the <a> +xp = xmlXPath(doc, "//a"); +xmlRemove(xp); +assert_checkequal(doc.root.children(1).name,"b"); +msgerr = msprintf(gettext("%s: Wrong index in the XMLList.\n"), "%XMLList_e"); +assert_checkerror("doc.root.children(2).name", msgerr); +assert_checkerror("doc.root.children(3).name", msgerr); +xp = xmlXPath(doc, "//a"); +assert_checkequal(length(xp),0); +doc2 = xmlReadStr("<root><b>Scilab</b></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlDelete(doc); +xmlDelete(doc2); +// Remove the first element +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +doc2 = xmlReadStr("<root><b>Scilab</b><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlRemove(doc.root.children(1)); +doc3 = xmlReadStr("<root><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc3))); +xmlRemove(doc.root.children(1)); +doc4 = xmlReadStr("<root></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc4))); +//Remove all the root children +doc5 = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc5.root.children); +doc6 = xmlReadStr("<root></root>"); +assert_checktrue(and(xmlDump(doc5)==xmlDump(doc6))); +xmlDelete(doc); +xmlDelete(doc2); +xmlDelete(doc3); +xmlDelete(doc4); +xmlDelete(doc5); +xmlDelete(doc6); +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +doc2 = xmlReadStr("<root><mynode><b>Scilab</b></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlRemove(doc.root.children(1).children(1)); +doc3 = xmlReadStr("<root><mynode></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc3))); +xmlDelete(doc); +xmlDelete(doc2); +xmlDelete(doc3); +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(1).children(1)); +doc2 = xmlReadStr("<root><a></a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlDelete(doc); +xmlDelete(doc2); +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(2).children(1)); +doc2 = xmlReadStr("<root><a>Hello</a><mynode></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlDelete(doc); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlRemove.tst b/modules/xml/tests/unit_tests/xmlRemove.tst new file mode 100755 index 000000000..945c34585 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlRemove.tst @@ -0,0 +1,85 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); + +assert_checkequal(doc.root.children(1).name,"a"); +assert_checkequal(doc.root.children(2).name,"b"); +assert_checkequal(doc.root.children(3).name,"a"); + +// Remove all the <a> +xp = xmlXPath(doc, "//a"); +xmlRemove(xp); +assert_checkequal(doc.root.children(1).name,"b"); + +msgerr = msprintf(gettext("%s: Wrong index in the XMLList.\n"), "%XMLList_e"); +assert_checkerror("doc.root.children(2).name", msgerr); +assert_checkerror("doc.root.children(3).name", msgerr); + +xp = xmlXPath(doc, "//a"); +assert_checkequal(length(xp),0); + +doc2 = xmlReadStr("<root><b>Scilab</b></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); + +xmlDelete(doc); +xmlDelete(doc2); + + +// Remove the first element +doc = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +doc2 = xmlReadStr("<root><b>Scilab</b><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlRemove(doc.root.children(1)); +doc3 = xmlReadStr("<root><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc3))); +xmlRemove(doc.root.children(1)); +doc4 = xmlReadStr("<root></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc4))); + +//Remove all the root children +doc5 = xmlReadStr("<root><a>Hello</a><b>Scilab</b><a>World</a></root>"); +xmlRemove(doc5.root.children); +doc6 = xmlReadStr("<root></root>"); +assert_checktrue(and(xmlDump(doc5)==xmlDump(doc6))); + +xmlDelete(doc); +xmlDelete(doc2); +xmlDelete(doc3); +xmlDelete(doc4); +xmlDelete(doc5); +xmlDelete(doc6); + +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(1)); +doc2 = xmlReadStr("<root><mynode><b>Scilab</b></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlRemove(doc.root.children(1).children(1)); +doc3 = xmlReadStr("<root><mynode></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc3))); + +xmlDelete(doc); +xmlDelete(doc2); +xmlDelete(doc3); + +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(1).children(1)); +doc2 = xmlReadStr("<root><a></a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); + +xmlDelete(doc); +xmlDelete(doc2); + +doc = xmlReadStr("<root><a>Hello</a><mynode><b>Scilab</b></mynode><a>World</a></root>"); +xmlRemove(doc.root.children(2).children(1)); +doc2 = xmlReadStr("<root><a>Hello</a><mynode></mynode><a>World</a></root>"); +assert_checktrue(and(xmlDump(doc)==xmlDump(doc2))); +xmlDelete(doc); +xmlDelete(doc2); diff --git a/modules/xml/tests/unit_tests/xmlSetAttributes.dia.ref b/modules/xml/tests/unit_tests/xmlSetAttributes.dia.ref new file mode 100755 index 000000000..65a83c446 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlSetAttributes.dia.ref @@ -0,0 +1,36 @@ +// ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a><b><c></c></b></a><b></b></root>"); +// Retrieve all the nodes +xp = xmlXPath(doc, "//a"); +// Add the attributes hello="world" and bonjour="monde" to all the nodes +xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde""><b><c></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +xp = xmlXPath(doc, "//*/*/c"); +xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde""><b><c hello=""world"" bonjour=""monde""></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +// Add the attribute foo="bar" to the first child of root +xmlSetAttributes(doc.root.children(1), ["foo" "bar"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar""><b><c hello=""world"" bonjour=""monde""></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +// Add the attribute bar="foo" to all the children of root +xmlSetAttributes(doc.root.children, ["bar" "foo2"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar"" bar=""foo2""><b><c hello=""world"" bonjour=""monde""></c></b></a><b bar=""foo2""></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +// Add the attribute truc="machin" to the list of the attributes of the second <b> +xmlSetAttributes(doc.root.children(2).attributes, ["truc" "machin"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar"" bar=""foo2""><b><c hello=""world"" bonjour=""monde""></c></b></a><b bar=""foo2"" truc=""machin""></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +xmlDelete(doc); +xmlDelete(doc2); +doc = xmlReadStr("<root><a><b><c></c></b></a><b></b></root>"); +xp = xmlXPath(doc, "//accc"); +a=xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +assert_checkequal(length(a),0); diff --git a/modules/xml/tests/unit_tests/xmlSetAttributes.tst b/modules/xml/tests/unit_tests/xmlSetAttributes.tst new file mode 100755 index 000000000..aca8e9945 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlSetAttributes.tst @@ -0,0 +1,50 @@ +// ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,= + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a><b><c></c></b></a><b></b></root>"); + +// Retrieve all the nodes +xp = xmlXPath(doc, "//a"); + +// Add the attributes hello="world" and bonjour="monde" to all the nodes +xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde""><b><c></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); +xp = xmlXPath(doc, "//*/*/c"); +xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde""><b><c hello=""world"" bonjour=""monde""></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); + + +// Add the attribute foo="bar" to the first child of root +xmlSetAttributes(doc.root.children(1), ["foo" "bar"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar""><b><c hello=""world"" bonjour=""monde""></c></b></a><b></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); + + +// Add the attribute bar="foo" to all the children of root +xmlSetAttributes(doc.root.children, ["bar" "foo2"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar"" bar=""foo2""><b><c hello=""world"" bonjour=""monde""></c></b></a><b bar=""foo2""></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); + +// Add the attribute truc="machin" to the list of the attributes of the second <b> +xmlSetAttributes(doc.root.children(2).attributes, ["truc" "machin"]); +doc2 = xmlReadStr("<root><a hello=""world"" bonjour=""monde"" foo=""bar"" bar=""foo2""><b><c hello=""world"" bonjour=""monde""></c></b></a><b bar=""foo2"" truc=""machin""></b></root>"); +assert_checkequal(xmlDump(doc),xmlDump(doc2)); + +xmlDelete(doc); +xmlDelete(doc2); + + +doc = xmlReadStr("<root><a><b><c></c></b></a><b></b></root>"); + +xp = xmlXPath(doc, "//accc"); + +a=xmlSetAttributes(xp, ["hello" "world" ; "bonjour" "monde"]); +assert_checkequal(length(a),0); diff --git a/modules/xml/tests/unit_tests/xmlValidate.dia.ref b/modules/xml/tests/unit_tests/xmlValidate.dia.ref new file mode 100755 index 000000000..968bbaeb3 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlValidate.dia.ref @@ -0,0 +1,27 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml"); +dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd"); +schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd"); +rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng"); +assert_checkequal(doc.root.children.size,2); +xmlValidate(doc, dtd); +xmlValidate(doc, rng); +xmlValidate(doc, schema); +xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml"); +//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml") +xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml", schema); +//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml", rng) +// Commented because I don't know how to check that now +//doc.root.children(3) = "<a>error</a>" +xmlValidate(doc, dtd); +xmlValidate(doc, rng); +xmlValidate(doc, schema); +xmlDelete(doc, dtd, schema, rng); +// Used to crash +assert_checktrue(size(xmlValidate("SCI/DO_NOT_EXIST.XML"))>0); diff --git a/modules/xml/tests/unit_tests/xmlValidate.tst b/modules/xml/tests/unit_tests/xmlValidate.tst new file mode 100755 index 000000000..6466ef25d --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlValidate.tst @@ -0,0 +1,38 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlRead("SCI/modules/xml/tests/unit_tests/library.xml"); +dtd = xmlDTD("SCI/modules/xml/tests/unit_tests/library.dtd"); +schema = xmlSchema("SCI/modules/xml/tests/unit_tests/library.xsd"); +rng = xmlRelaxNG("SCI/modules/xml/tests/unit_tests/library.rng"); +assert_checkequal(doc.root.children.size,2); +xmlValidate(doc, dtd); + +xmlValidate(doc, rng); + +xmlValidate(doc, schema); + +xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml"); +//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml") + +xmlValidate("SCI/modules/xml/tests/unit_tests/library.xml", schema); +//xmlValidate("SCI/modules/xml/tests/unit_tests/invalid_library.xml", rng) + +// Commented because I don't know how to check that now +//doc.root.children(3) = "<a>error</a>" + +xmlValidate(doc, dtd); +xmlValidate(doc, rng); +xmlValidate(doc, schema); + + +xmlDelete(doc, dtd, schema, rng); + +// Used to crash +assert_checktrue(size(xmlValidate("SCI/DO_NOT_EXIST.XML"))>0); diff --git a/modules/xml/tests/unit_tests/xmlWrite.dia.ref b/modules/xml/tests/unit_tests/xmlWrite.dia.ref new file mode 100755 index 000000000..954ca5408 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlWrite.dia.ref @@ -0,0 +1,32 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +xmlWrite(doc, TMPDIR+"/foo.xml"); +// Now we open the previous file, modify it and save it +doc1 = xmlRead(TMPDIR+"/foo.xml"); +assert_checkequal(doc1.root.children.size,1); +assert_checkequal(doc1.root.children(1).name,"a"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); +doc1.root.children(1).name = "newName"; +xmlWrite(doc1); +assert_checkequal(doc1.root.children(1).name,"newName"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); +// Now we check that the modification has been done +doc2 = xmlRead(TMPDIR+"/foo.xml"); +assert_checkequal(doc2.root.children(1).name,"newName"); +assert_checkequal(doc2.root.children(1).attributes.att,"foo"); +assert_checkequal(doc2.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc2.root.children(1).children(1).name,"b"); +assert_checkequal(doc2.root.children(1).children(1).content,"Hello"); +xmlDelete("all"); diff --git a/modules/xml/tests/unit_tests/xmlWrite.tst b/modules/xml/tests/unit_tests/xmlWrite.tst new file mode 100755 index 000000000..e43189f83 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlWrite.tst @@ -0,0 +1,40 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +doc = xmlReadStr("<root><a att=""foo"" rib=""bar""><b>Hello</b></a></root>"); +xmlWrite(doc, TMPDIR+"/foo.xml"); + +// Now we open the previous file, modify it and save it +doc1 = xmlRead(TMPDIR+"/foo.xml"); +assert_checkequal(doc1.root.children.size,1); +assert_checkequal(doc1.root.children(1).name,"a"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); +doc1.root.children(1).name = "newName"; + +xmlWrite(doc1); + +assert_checkequal(doc1.root.children(1).name,"newName"); +assert_checkequal(doc1.root.children(1).attributes.att,"foo"); +assert_checkequal(doc1.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc1.root.children(1).children(1).name,"b"); +assert_checkequal(doc1.root.children(1).children(1).content,"Hello"); + +// Now we check that the modification has been done +doc2 = xmlRead(TMPDIR+"/foo.xml"); + +assert_checkequal(doc2.root.children(1).name,"newName"); +assert_checkequal(doc2.root.children(1).attributes.att,"foo"); +assert_checkequal(doc2.root.children(1).attributes.rib,"bar"); +assert_checkequal(doc2.root.children(1).children(1).name,"b"); +assert_checkequal(doc2.root.children(1).children(1).content,"Hello"); + +xmlDelete("all"); diff --git a/modules/xml/tests/unit_tests/xmlXPath.dia.ref b/modules/xml/tests/unit_tests/xmlXPath.dia.ref new file mode 100755 index 000000000..4b85d9d7f --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlXPath.dia.ref @@ -0,0 +1,84 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== +// <-- CLI SHELL MODE --> +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore/book/title"); +assert_checkequal(titles.size,5); +assert_checkequal(titles(4).name,"title"); +assert_checkequal(titles(4).content,"Learning XML"); +assert_checkequal(titles(4).type,"XML_ELEMENT_NODE"); +assert_checkequal(titles(5).name,"title"); +assert_checkequal(titles(5).content,"Scilab rox"); +assert_checkequal(titles(5).type,"XML_ELEMENT_NODE"); +attribs=titles(4).attributes; +assert_checkequal(titles(4).attributes.size,[]); +assert_checkequal(attribs.lang,"en"); +// Get all the books where the price is more than 35 euros +moreThan35eList=xmlXPath(xmlFile,"/bookstore/book[price>35]/title"); +assert_checkequal(moreThan35eList.size,2); +assert_checkequal(size(moreThan35eList),[1,2]); +assert_checkequal(moreThan35eList(1).content,"XQuery Kick Start"); +assert_checkequal(moreThan35eList(2).content,"Learning XML"); +// Get all the free books +freeBooks=xmlXPath(xmlFile,"/bookstore/book[price=0]/title"); +assert_checkequal(freeBooks.size,1); +assert_checkequal(size(freeBooks),[1,1]); +assert_checkequal(freeBooks(1).content,"Scilab rox"); +xmlDelete(xmlFile); +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/sep_69_example.xml"); +titles=xmlXPath(xmlFile, "/root/hello"); +assert_checkequal(titles.size,2); +xmlDelete(xmlFile); +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +content=xmlDump(xmlFile); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[1,1]); +xmlDelete(xmlFile); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +xmlFile2=xmlRead(SCI+"/etc/classpath.xml"); +content=xmlDump(xmlFile); +content2=xmlDump(xmlFile2); +//assert_checkequal(content, content2); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[1,1]); +assert_checktrue(length(content2)>0); +assert_checktrue(size(content2)>=[1,1]); +xmlDelete(xmlFile); +xmlDelete(xmlFile2); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore/book/title"); +assert_checkequal(titles.name,["title","title","title","title","title"]); +assert_checkequal(titles.content,["Everyday Italian","Harry Potter","XQuery Kick Start","Learning XML","Scilab rox"]); +prices=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(prices.name,["price","price","price","price","price"]); +assert_checkequal(prices.content,["30.00","29.99","49.99","39.95","0.0"]); +titlesEmpty=xmlXPath(xmlFile, "/bookstore/book/prices"); +assert_checkequal(length(titlesEmpty),0); +xmlDelete(xmlFile); +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore"); +results=xmlXPath(titles(1), "book[title=''Everyday Italian'']"); +assert_checkequal(length(results),1); +assert_checkequal(results.name,"book"); +assert_checkequal(results.content,"Everyday ItalianGiada De Laurentiis200530.00"); +assert_checkequal(results(1).children(1).content,"Everyday Italian"); +xmlDelete(xmlFile); +doc = xmlReadStr("<root att=""attribute""><a a1=""A1"" a2=""A2"" a3=""A3""><b>Hello</b><c>Scilab</c><b>World</b></a><b>Nothing</b></root>"); +e = doc.root.children(1); +assert_checkequal(e.content,"HelloScilabWorld"); +assert_checkequal(e.name,"a"); +xp = xmlXPath(e, "@*"); +assert_checkequal(["A1","A2","A3"],xmlAsText(xp)); +xp = xmlXPath(e, "b"); +assert_checkequal(["Hello","World"],xmlAsText(xp)); +xmlDelete(doc); diff --git a/modules/xml/tests/unit_tests/xmlXPath.tst b/modules/xml/tests/unit_tests/xmlXPath.tst new file mode 100755 index 000000000..fa6927d23 --- /dev/null +++ b/modules/xml/tests/unit_tests/xmlXPath.tst @@ -0,0 +1,103 @@ +// =========================================================================== +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU +// +// This file is distributed under the same license as the Scilab package. +// =========================================================================== + +// <-- CLI SHELL MODE --> + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore/book/title"); +assert_checkequal(titles.size,5); +assert_checkequal(titles(4).name,"title"); +assert_checkequal(titles(4).content,"Learning XML"); +assert_checkequal(titles(4).type,"XML_ELEMENT_NODE"); +assert_checkequal(titles(5).name,"title"); +assert_checkequal(titles(5).content,"Scilab rox"); +assert_checkequal(titles(5).type,"XML_ELEMENT_NODE"); +attribs=titles(4).attributes; +assert_checkequal(titles(4).attributes.size,[]); +assert_checkequal(attribs.lang,"en"); + +// Get all the books where the price is more than 35 euros +moreThan35eList=xmlXPath(xmlFile,"/bookstore/book[price>35]/title"); +assert_checkequal(moreThan35eList.size,2); +assert_checkequal(size(moreThan35eList),[1,2]); +assert_checkequal(moreThan35eList(1).content,"XQuery Kick Start"); +assert_checkequal(moreThan35eList(2).content,"Learning XML"); + +// Get all the free books +freeBooks=xmlXPath(xmlFile,"/bookstore/book[price=0]/title"); +assert_checkequal(freeBooks.size,1); +assert_checkequal(size(freeBooks),[1,1]); +assert_checkequal(freeBooks(1).content,"Scilab rox"); + +xmlDelete(xmlFile); + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/sep_69_example.xml"); +titles=xmlXPath(xmlFile, "/root/hello"); +assert_checkequal(titles.size,2); +xmlDelete(xmlFile); + +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +content=xmlDump(xmlFile); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[1,1]); +xmlDelete(xmlFile); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); + +xmlFile=xmlRead(SCI+"/etc/modules.xml"); +xmlFile2=xmlRead(SCI+"/etc/classpath.xml"); +content=xmlDump(xmlFile); +content2=xmlDump(xmlFile2); +//assert_checkequal(content, content2); +assert_checktrue(length(content)>0); +assert_checktrue(size(content)>=[1,1]); +assert_checktrue(length(content2)>0); +assert_checktrue(size(content2)>=[1,1]); +xmlDelete(xmlFile); +xmlDelete(xmlFile2); +// Delete the file a second time +msgerr = msprintf(gettext("%s: XML document does not exist.\n"), "xmlDelete"); +assert_checkerror("xmlDelete(xmlFile)", msgerr); + + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore/book/title"); +assert_checkequal(titles.name,["title","title","title","title","title"]); +assert_checkequal(titles.content,["Everyday Italian","Harry Potter","XQuery Kick Start","Learning XML","Scilab rox"]); + +prices=xmlXPath(xmlFile, "/bookstore/book/price"); +assert_checkequal(prices.name,["price","price","price","price","price"]); +assert_checkequal(prices.content,["30.00","29.99","49.99","39.95","0.0"]); + +titlesEmpty=xmlXPath(xmlFile, "/bookstore/book/prices"); +assert_checkequal(length(titlesEmpty),0); + +xmlDelete(xmlFile); + +xmlFile=xmlRead(SCI+"/modules/xml/tests/unit_tests/w3cExample.xml"); +titles=xmlXPath(xmlFile, "/bookstore"); +results=xmlXPath(titles(1), "book[title=''Everyday Italian'']"); +assert_checkequal(length(results),1); +assert_checkequal(results.name,"book"); +assert_checkequal(results.content,"Everyday ItalianGiada De Laurentiis200530.00"); +assert_checkequal(results(1).children(1).content,"Everyday Italian"); +xmlDelete(xmlFile); + +doc = xmlReadStr("<root att=""attribute""><a a1=""A1"" a2=""A2"" a3=""A3""><b>Hello</b><c>Scilab</c><b>World</b></a><b>Nothing</b></root>"); + +e = doc.root.children(1); +assert_checkequal(e.content,"HelloScilabWorld"); +assert_checkequal(e.name,"a"); + +xp = xmlXPath(e, "@*"); +assert_checkequal(["A1","A2","A3"],xmlAsText(xp)); + +xp = xmlXPath(e, "b"); +assert_checkequal(["Hello","World"],xmlAsText(xp)); + +xmlDelete(doc); |