xquery/trunk/XQuery__XQTSTestCase.st
changeset 23 6fbb595a44bc
child 232 9d8fd28b99b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xquery/trunk/XQuery__XQTSTestCase.st	Mon Nov 10 18:05:47 2008 +0000
@@ -0,0 +1,111 @@
+"{ Package: 'stx:goodies/xmlsuite/xquery' }"
+
+"{ NameSpace: XQuery }"
+
+TestCase subclass:#XQTSTestCase
+	instanceVariableNames:'interpreter'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'XQuery-Tests-XQTS'
+!
+
+
+!XQTSTestCase class methodsFor:'accessing'!
+
+resources
+
+    ^Array with: XQTSTestResource
+
+    "Created: / 10-11-2008 / 16:23:19 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase class methodsFor:'testing'!
+
+isAbstract
+
+    ^self == XQTSTestCase
+
+    "Created: / 10-11-2008 / 16:22:09 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase methodsFor:'assertions'!
+
+should: block raiseErrorCodes: arrayOfErrorCodes
+
+    <resource: #skipInDebuggersWalkBack>
+
+    ^ self assert:
+            (self 
+                executeShould:block 
+                inScopeOf:(XQueryParserError, XQueryInterpreterError)
+                suchThat:[:ex|arrayOfErrorCodes includes:ex errorCode])
+
+    "Created: / 10-11-2008 / 16:53:51 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 10-11-2008 / 18:39:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase methodsFor:'initialization & release'!
+
+setUp
+
+    super setUp.
+    interpreter := XQueryInterpreter new.
+
+    "Created: / 10-11-2008 / 17:01:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase methodsFor:'private'!
+
+executeShould: aBlock inScopeOf: anExceptionalEvent suchThat: suchBlock
+
+    [aBlock value]
+        on: anExceptionalEvent
+        do: [:ex | ^suchBlock value: ex].
+    ^false.
+
+    "Created: / 10-11-2008 / 18:40:05 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase methodsFor:'xqts utilities'!
+
+xqtsBind: variableName toContentsOf: fileName
+
+    | variableValue document documentAdaptor |
+    document := XMLv2::Parser forDOM3 processDocumentInFilename:
+                    (XQTSTestResource current xqtsInputFile: fileName).
+    documentAdaptor := XMLv2::XPathDOM3DocumentAdaptor new document: document.
+    variableValue := XQuerySequence withNode:
+                        (XQueryAccessedNode new 
+                            documentAdaptor: documentAdaptor;
+                            nodeId: documentAdaptor xpathDocument).
+    "This will end up with an error, because context
+     is created right before the evaluation begun...
+     Im looking for elegnt solution..."
+    "
+    interpreter
+        bindVar: variableName
+        to: fileName
+    "
+
+    "Created: / 10-11-2008 / 17:23:19 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+xqtsResultTextFromFile: fileName
+
+    ^(XQTSTestResource current xqtsResultFile: fileName) contents
+
+    "Created: / 10-11-2008 / 17:10:35 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+xqtsResultTextFromResult: xqueryResult
+
+    ^xqueryResult asDocumentFragment asXMLString
+
+    "Created: / 10-11-2008 / 17:10:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!XQTSTestCase class methodsFor:'documentation'!
+
+version
+    ^'$Id$'
+! !