RegressionTests__XMLCanonicalEncodingTests.st
changeset 1898 894ff733ec4d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RegressionTests__XMLCanonicalEncodingTests.st	Thu Feb 15 14:56:53 2018 +0100
@@ -0,0 +1,101 @@
+"{ Encoding: utf8 }"
+
+"{ Package: 'stx:goodies/regression' }"
+
+"{ NameSpace: RegressionTests }"
+
+TestCase subclass:#XMLCanonicalEncodingTests
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'tests-Regression-XML'
+!
+
+!XMLCanonicalEncodingTests class methodsFor:'documentation'!
+
+documentation
+"
+    documentation to be added.
+
+    [author:]
+        cg
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!XMLCanonicalEncodingTests methodsFor:'testing'!
+
+test01
+    "see examples in https://www.w3.org/TR/2001/REC-xml-c14n-20010315"
+
+    |dom out canonOut|
+
+    dom := XML::XMLParser 
+                parse:
+'<?xml version="1.0" encoding="ISO-8859-1"?>
+<doc>&#169;</doc>'.
+
+    out := dom printString.
+    self assert:(out = 
+'<?xml version="1.0"?>
+<doc>©</doc>').
+    canonOut := dom canonicalPrintString.
+    self assert:(canonOut = '<doc>©</doc>').
+!
+
+test02
+    "see examples in https://www.w3.org/TR/2001/REC-xml-c14n-20010315"
+
+    |dom out canonOut worldFile|
+
+    "/ <!!-- Let world.txt contain "world" (excluding the quotes) -->
+
+    worldFile := 'world.txt' asFilename.
+    [
+        worldFile contents:'world'.
+
+        dom := XML::XMLParser 
+                parse:
+'<!!DOCTYPE doc [
+<!!ATTLIST doc attrExtEnt ENTITY #IMPLIED>
+<!!ENTITY ent1 "Hello">
+<!!ENTITY ent2 SYSTEM "world.txt">
+<!!ENTITY entExt SYSTEM "earth.gif" NDATA gif>
+<!!NOTATION gif SYSTEM "viewgif.exe">
+]>
+<doc attrExtEnt="entExt">
+   &ent1;, &ent2;!!
+</doc>'.
+
+        out := dom printString.
+        self assert:(out = 
+'<doc attrExtEnt="entExt">
+   Hello, world!!
+</doc>'
+        ).
+
+        canonOut := dom canonicalPrintString.
+        self assert:(canonOut = '<doc attrExtEnt="entExt">
+   Hello, world!!
+</doc>').
+    ] ensure:[
+        worldFile remove
+    ]
+! !
+
+!XMLCanonicalEncodingTests class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+