Skip to content
Browse files

Added testing and fixed bugs.

  • Loading branch information...
1 parent 06fff3f commit c1dfc90eabe6b7250a3767e612b60ab3079ef3c3 @jbeard4 committed
Showing with 95 additions and 14 deletions.
  1. +6 −4 lib/browser/SCXML.js
  2. +7 −7 lib/node/SCXML.js
  3. +6 −3 lib/rhino/SCXML.js
  4. +14 −0 test/run-surface-test.sh
  5. +9 −0 test/surface-test.html
  6. +53 −0 test/surface-test.js
View
10 lib/browser/SCXML.js
@@ -15,11 +15,12 @@ function urlToModel(url,cb){
},"xml");
}
-function documentStringToModel(s){
- var dp = new window.DOMParser();
- var doc = dp.parseFromString(s);
+function parseDocumentString(s){
+ return (new window.DOMParser()).parseFromString(s,"application/xml");
+}
- return documentToModel(doc);
+function documentStringToModel(s){
+ return documentToModel(parseDocumentString(s));
}
function documentToModel(doc){
@@ -49,5 +50,6 @@ module.exports = {
urlToModel : urlToModel,
documentStringToModel : documentStringToModel,
documentToModel : documentToModel,
+ parseDocumentString : parseDocumentString,
SCXML : scxml.SimpleInterpreter
};
View
14 lib/node/SCXML.js
@@ -34,16 +34,15 @@ function pathToModel(path,cb){
var doc = documentStringToModel(s);
cb(null,doc);
}
- });
+ },'utf8');
}
-function documentStringToModel(s){
- var dp = new xmldom.DOMParser();
- console.log(s);
- var doc = dp.parseFromString(s);
- console.log( (new xmldom.XMLSerializer()).serializeToString(doc) );
+function parseDocumentString(s){
+ return (new xmldom.DOMParser()).parseFromString(s);
+}
- return documentToModel(doc);
+function documentStringToModel(s){
+ return documentToModel(parseDocumentString(s));
}
//TODO: move this out, as it is shared code
@@ -68,5 +67,6 @@ module.exports = {
urlToModel : urlToModel,
documentStringToModel : documentStringToModel,
documentToModel : documentToModel,
+ parseDocumentString : parseDocumentString,
SCXML : scxml.SimpleInterpreter
};
View
9 lib/rhino/SCXML.js
@@ -25,14 +25,16 @@ function urlToModel(url,cb){
cb(null,documentToModel(doc));
}
-function documentStringToModel(s){
+function parseDocumentString(s){
var db = getDb();
var is = new Packages.org.xml.sax.InputSource();
is.setCharacterStream(new Packages.java.io.StringReader(s));
- var doc = db.parse(is);
+ return db.parse(is);
+}
- return documentToModel(doc);
+function documentStringToModel(s){
+ return documentToModel(parseDocumentString(s));
}
//TODO: move this out, as it is shared code
@@ -81,5 +83,6 @@ module.exports = {
urlToModel : urlToModel,
documentStringToModel : documentStringToModel,
documentToModel : documentToModel,
+ parseDocumentString : parseDocumentString,
SCXML : scxml.SimpleInterpreter
};
View
14 test/run-surface-test.sh
@@ -0,0 +1,14 @@
+#this is to run the surface test - a test which is not supposed to test statechart semantics, but
+#instead should test the standard interface exposed by node, rhino and browser scion modules.
+
+python -m SimpleHTTPServer 8888 &
+pid=$!
+
+#run node test
+node surface-test.js
+
+#run browser test
+java -cp ~/Downloads/rhino1_7R3/js.jar org.mozilla.javascript.tools.shell.Main -debug -modules ../lib -main surface-test.js
+
+#open your browser of choice
+gnome-open http://localhost:8888/surface-test.html
View
9 test/surface-test.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/es5-shim/1.2.4/es5-shim.min.js"></script>
+ <script type="text/javascript" src="scion.js"></script>
+ <script type="text/javascript" src="surface-test.js"></script>
+ </head>
+</html>
+
View
53 test/surface-test.js
@@ -0,0 +1,53 @@
+//the goal of this test script is not to test the detailed semantics of SCION (this is what scxml-test-framework is for),
+//but instead is to provide test coverage of the unified API exposed by rhino, node and browser versions of SCION
+//assume we have an http fileserver running in this directory on port 8888, and can require scion
+
+var scion = require('scion');
+
+
+//basic0 test
+var s =
+'<?xml version="1.0" encoding="UTF-8"?>\n' +
+'<scxml \n' +
+' xmlns="http://www.w3.org/2005/07/scxml"\n' +
+' version="1.0"\n' +
+' profile="ecmascript"\n' +
+' id="root"\n' +
+' initial="a">\n' +
+' <state id="a"/>\n' +
+'</scxml>';
+
+var tests = [
+ function(){
+ scion.pathToModel('./scxml-test-framework/test/basic/basic0.scxml',function(err,model){
+ go(model);
+ });
+ },
+ function(){
+ scion.urlToModel('http://localhost:8888/scxml-test-framework/test/basic/basic0.scxml',function(err,model){
+ go(model);
+ });
+ },
+ function(){
+ go(scion.documentStringToModel(s));
+ },
+ function(){
+ go(scion.documentToModel(scion.parseDocumentString(s)));
+ }
+];
+
+
+
+
+function go(model){
+ var scxml = new scion.SCXML(model);
+ var conf = scxml.start();
+ if(!( conf && conf[0] === 'a' )) throw new Error('assertion failed');
+}
+
+tests.forEach(function(fn){fn();});
+
+//for rhino to finish:
+if(typeof quit !== 'undefined'){
+ quit(0);
+}

0 comments on commit c1dfc90

Please sign in to comment.
Something went wrong with that request. Please try again.