Skip to content

Commit

Permalink
dom: Add simple tests for serialize
Browse files Browse the repository at this point in the history
We don't check for error condition (e.g. in previous
commit) yet as it's not obvious how to trigger it
without first raising an error elsewhere when we
build our dom.
  • Loading branch information
andreww committed Jun 5, 2013
1 parent 4c3522b commit c17beb5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dom/test/test_dom_serialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh -e

for t in ${0%.sh}_*.f90
do
TEST=${t%.f90}
./test.sh $TEST
done
25 changes: 25 additions & 0 deletions dom/test/test_dom_serialize_1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
program test_serialize_1

use FoX_dom

implicit none

type(Node), pointer :: myDoc, root, np, dummy

! Create a new document and get a pointer to the root element, this gives you the minimum empty dom
myDoc => createDocument(getImplementation(), "http://www.example.com", "root-element", null())
root => getDocumentElement(myDoc)

! You can now do DOMish things like create new elements and append them to the document root element
! dummy ends up pointing at the child-element
np => createElementNS(myDoc, "http://www.example.com", "child-element")
dummy => appendChild(root, np)

! Call serialize to produce the document
call serialize(myDoc, "test.xml")

! And don't forget to clean up the memory
call destroy(myDoc)

end program test_serialize_1

2 changes: 2 additions & 0 deletions dom/test/test_dom_serialize_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<root-element xmlns="http://www.example.com"><child-element/></root-element>
26 changes: 26 additions & 0 deletions dom/test/test_dom_serialize_2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
program test_serialize_2

use FoX_dom

implicit none

type(Node), pointer :: myDoc, root, np, dummy
type(DOMException) :: ex

! Create a new document and get a pointer to the root element, this gives you the minimum empty dom
myDoc => createDocument(getImplementation(), "http://www.example.com", "root-element", null())
root => getDocumentElement(myDoc)

! You can now do DOMish things like create new elements and append them to the document root element
! dummy ends up pointing at the child-element
np => createElementNS(myDoc, "http://www.example.com", "child-element")
dummy => appendChild(root, np)

! Call serialize to produce the document
call serialize(myDoc, "test.xml", ex)

! And don't forget to clean up the memory
call destroy(myDoc)

end program test_serialize_2

2 changes: 2 additions & 0 deletions dom/test/test_dom_serialize_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<root-element xmlns="http://www.example.com"><child-element/></root-element>

0 comments on commit c17beb5

Please sign in to comment.